Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/generators/python-experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ sidebar_label: python-experimental

<ul class="column-ul">
<li>bool</li>
<li>bytes</li>
<li>date</li>
<li>datetime</li>
<li>dict</li>
Expand Down
1 change: 0 additions & 1 deletion docs/generators/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ sidebar_label: python

<ul class="column-ul">
<li>bool</li>
<li>bytes</li>
<li>date</li>
<li>datetime</li>
<li>dict</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,8 @@ public String toDefaultValue(Schema p) {
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find())
return "'''" + p.getDefault() + "'''";
else
return "'" + ((String) p.getDefault()).replaceAll("'", "\'") + "'";
// wrap using double quotes to avoid the need to escape any embedded single quotes
return "\"" + p.getDefault() + "\"";
}
} else if (ModelUtils.isArraySchema(p)) {
if (p.getDefault() != null) {
Expand Down Expand Up @@ -726,7 +727,8 @@ private String toExampleValueRecursive(Schema schema, List<String> included_sche

if (StringUtils.isNotBlank(example) && !"null".equals(example)) {
if (ModelUtils.isStringSchema(schema)) {
example = "'" + example + "'";
// wrap using double quotes to avoid the need to escape any embedded single quotes
example = "\"" + example + "\"";
}
return example;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,21 @@ public void testRegularExpressionOpenAPISchemaVersion3() {
Assert.assertEquals(op.allParams.get(5).pattern, "/^pattern\\d{3}$/i");
}

@Test(description = "test single quotes escape")
public void testSingleQuotes() {
@Test(description = "test default value with single quotes")
public void testSingleQuotesDefaultValue() {
final PythonClientCodegen codegen = new PythonClientCodegen();
StringSchema schema = new StringSchema();
schema.setDefault("Text containing 'single' quote");
String defaultValue = codegen.toDefaultValue(schema);
Assert.assertEquals("'Text containing \'single\' quote'", defaultValue);
Assert.assertEquals(defaultValue, "\"Text containing 'single' quote\"");
}

@Test(description = "test example value with single quotes")
public void testSingleQuotesExampleValue() {
final PythonClientCodegen codegen = new PythonClientCodegen();
StringSchema schema = new StringSchema();
schema.setExample("Text containing 'single' quote");
String exampleValue = codegen.toExampleValue(schema);
Assert.assertEquals(exampleValue, "\"Text containing 'single' quote\"");
}
}
48 changes: 24 additions & 24 deletions samples/client/petstore/dart2/openapi/lib/api/pet_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class PetApi {

List<String> contentTypes = ["application/json","application/xml"];

String contentType = contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
String nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
List<String> authNames = ["petstore_auth"];

if(contentType.startsWith("multipart/form-data")) {
if(nullableContentType != null && nullableContentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = MultipartRequest(null, null);
if(hasFields)
Expand All @@ -46,7 +46,7 @@ class PetApi {
postBody,
headerParams,
formParams,
contentType,
nullableContentType,
authNames);
return response;
}
Expand Down Expand Up @@ -86,10 +86,10 @@ class PetApi {

List<String> contentTypes = [];

String contentType = contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
String nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
List<String> authNames = ["petstore_auth"];

if(contentType.startsWith("multipart/form-data")) {
if(nullableContentType != null && nullableContentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = MultipartRequest(null, null);
if(hasFields)
Expand All @@ -104,7 +104,7 @@ class PetApi {
postBody,
headerParams,
formParams,
contentType,
nullableContentType,
authNames);
return response;
}
Expand Down Expand Up @@ -144,10 +144,10 @@ class PetApi {

List<String> contentTypes = [];

String contentType = contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
String nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
List<String> authNames = ["petstore_auth"];

if(contentType.startsWith("multipart/form-data")) {
if(nullableContentType != null && nullableContentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = MultipartRequest(null, null);
if(hasFields)
Expand All @@ -162,7 +162,7 @@ class PetApi {
postBody,
headerParams,
formParams,
contentType,
nullableContentType,
authNames);
return response;
}
Expand Down Expand Up @@ -203,10 +203,10 @@ class PetApi {

List<String> contentTypes = [];

String contentType = contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
String nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
List<String> authNames = ["petstore_auth"];

if(contentType.startsWith("multipart/form-data")) {
if(nullableContentType != null && nullableContentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = MultipartRequest(null, null);
if(hasFields)
Expand All @@ -221,7 +221,7 @@ class PetApi {
postBody,
headerParams,
formParams,
contentType,
nullableContentType,
authNames);
return response;
}
Expand Down Expand Up @@ -261,10 +261,10 @@ class PetApi {

List<String> contentTypes = [];

String contentType = contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
String nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
List<String> authNames = ["api_key"];

if(contentType.startsWith("multipart/form-data")) {
if(nullableContentType != null && nullableContentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = MultipartRequest(null, null);
if(hasFields)
Expand All @@ -279,7 +279,7 @@ class PetApi {
postBody,
headerParams,
formParams,
contentType,
nullableContentType,
authNames);
return response;
}
Expand Down Expand Up @@ -319,10 +319,10 @@ class PetApi {

List<String> contentTypes = ["application/json","application/xml"];

String contentType = contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
String nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
List<String> authNames = ["petstore_auth"];

if(contentType.startsWith("multipart/form-data")) {
if(nullableContentType != null && nullableContentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = MultipartRequest(null, null);
if(hasFields)
Expand All @@ -337,7 +337,7 @@ class PetApi {
postBody,
headerParams,
formParams,
contentType,
nullableContentType,
authNames);
return response;
}
Expand Down Expand Up @@ -376,10 +376,10 @@ class PetApi {

List<String> contentTypes = ["application/x-www-form-urlencoded"];

String contentType = contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
String nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
List<String> authNames = ["petstore_auth"];

if(contentType.startsWith("multipart/form-data")) {
if(nullableContentType != null && nullableContentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = MultipartRequest(null, null);
if (name != null) {
Expand All @@ -406,7 +406,7 @@ class PetApi {
postBody,
headerParams,
formParams,
contentType,
nullableContentType,
authNames);
return response;
}
Expand Down Expand Up @@ -445,10 +445,10 @@ class PetApi {

List<String> contentTypes = ["multipart/form-data"];

String contentType = contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
String nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
List<String> authNames = ["petstore_auth"];

if(contentType.startsWith("multipart/form-data")) {
if(nullableContentType != null && nullableContentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = MultipartRequest(null, null);
if (additionalMetadata != null) {
Expand All @@ -474,7 +474,7 @@ class PetApi {
postBody,
headerParams,
formParams,
contentType,
nullableContentType,
authNames);
return response;
}
Expand Down
24 changes: 12 additions & 12 deletions samples/client/petstore/dart2/openapi/lib/api/store_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class StoreApi {

List<String> contentTypes = [];

String contentType = contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
String nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
List<String> authNames = [];

if(contentType.startsWith("multipart/form-data")) {
if(nullableContentType != null && nullableContentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = MultipartRequest(null, null);
if(hasFields)
Expand All @@ -46,7 +46,7 @@ class StoreApi {
postBody,
headerParams,
formParams,
contentType,
nullableContentType,
authNames);
return response;
}
Expand Down Expand Up @@ -82,10 +82,10 @@ class StoreApi {

List<String> contentTypes = [];

String contentType = contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
String nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
List<String> authNames = ["api_key"];

if(contentType.startsWith("multipart/form-data")) {
if(nullableContentType != null && nullableContentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = MultipartRequest(null, null);
if(hasFields)
Expand All @@ -100,7 +100,7 @@ class StoreApi {
postBody,
headerParams,
formParams,
contentType,
nullableContentType,
authNames);
return response;
}
Expand Down Expand Up @@ -141,10 +141,10 @@ class StoreApi {

List<String> contentTypes = [];

String contentType = contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
String nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
List<String> authNames = [];

if(contentType.startsWith("multipart/form-data")) {
if(nullableContentType != null && nullableContentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = MultipartRequest(null, null);
if(hasFields)
Expand All @@ -159,7 +159,7 @@ class StoreApi {
postBody,
headerParams,
formParams,
contentType,
nullableContentType,
authNames);
return response;
}
Expand Down Expand Up @@ -199,10 +199,10 @@ class StoreApi {

List<String> contentTypes = [];

String contentType = contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
String nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
List<String> authNames = [];

if(contentType.startsWith("multipart/form-data")) {
if(nullableContentType != null && nullableContentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = MultipartRequest(null, null);
if(hasFields)
Expand All @@ -217,7 +217,7 @@ class StoreApi {
postBody,
headerParams,
formParams,
contentType,
nullableContentType,
authNames);
return response;
}
Expand Down
Loading