From 3d92ea0edab23e191da29b693c22ebf1a0207795 Mon Sep 17 00:00:00 2001 From: Tim Bedard Date: Tue, 16 Apr 2019 21:49:50 -0500 Subject: [PATCH] [Bug] [Python] Fix #2092 python docs example quoting (#2669) * replaced setParameterExampleValue method * removed old method * fixed bool, test fix for objects * continued fix * double override * regenerated petstore client * regenerated oas3 sample * updated asyncio and tornado generated clients for CI --- .../languages/PythonClientCodegen.java | 22 ++++++++++++++++++- .../petstore/python-asyncio/docs/UserApi.md | 4 ++-- .../petstore/python-tornado/docs/UserApi.md | 4 ++-- .../client/petstore/python/docs/UserApi.md | 4 ++-- .../client/petstore/python/docs/UserApi.md | 4 ++-- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index 94cf5bbc0a4..9f99a4472a9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -17,8 +17,10 @@ package org.openapitools.codegen.languages; +import io.swagger.v3.oas.models.examples.Example; import io.swagger.v3.oas.models.media.ArraySchema; import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.parameters.Parameter; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.*; @@ -704,7 +706,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig } if (example == null) { - example = "NULL"; + example = "None"; } else if (Boolean.TRUE.equals(p.isListContainer)) { example = "[" + example + "]"; } else if (Boolean.TRUE.equals(p.isMapContainer)) { @@ -714,6 +716,24 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig p.example = example; } + @Override + public void setParameterExampleValue(CodegenParameter codegenParameter, Parameter parameter) { + Schema schema = parameter.getSchema(); + + if (parameter.getExample() != null) { + codegenParameter.example = parameter.getExample().toString(); + } else if (parameter.getExamples() != null && !parameter.getExamples().isEmpty()) { + Example example = parameter.getExamples().values().iterator().next(); + if (example.getValue() != null) { + codegenParameter.example = example.getValue().toString(); + } + } else if (schema != null && schema.getExample() != null) { + codegenParameter.example = schema.getExample().toString(); + } + + setParameterExampleValue(codegenParameter); + } + @Override public String sanitizeTag(String tag) { return sanitizeName(tag); diff --git a/samples/client/petstore/python-asyncio/docs/UserApi.md b/samples/client/petstore/python-asyncio/docs/UserApi.md index 33e86f9e8fd..907dc9ec365 100644 --- a/samples/client/petstore/python-asyncio/docs/UserApi.md +++ b/samples/client/petstore/python-asyncio/docs/UserApi.md @@ -78,7 +78,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -body = NULL # list[User] | List of user object +body = None # list[User] | List of user object try: # Creates list of users with given input array @@ -124,7 +124,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -body = NULL # list[User] | List of user object +body = None # list[User] | List of user object try: # Creates list of users with given input array diff --git a/samples/client/petstore/python-tornado/docs/UserApi.md b/samples/client/petstore/python-tornado/docs/UserApi.md index 33e86f9e8fd..907dc9ec365 100644 --- a/samples/client/petstore/python-tornado/docs/UserApi.md +++ b/samples/client/petstore/python-tornado/docs/UserApi.md @@ -78,7 +78,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -body = NULL # list[User] | List of user object +body = None # list[User] | List of user object try: # Creates list of users with given input array @@ -124,7 +124,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -body = NULL # list[User] | List of user object +body = None # list[User] | List of user object try: # Creates list of users with given input array diff --git a/samples/client/petstore/python/docs/UserApi.md b/samples/client/petstore/python/docs/UserApi.md index 33e86f9e8fd..907dc9ec365 100644 --- a/samples/client/petstore/python/docs/UserApi.md +++ b/samples/client/petstore/python/docs/UserApi.md @@ -78,7 +78,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -body = NULL # list[User] | List of user object +body = None # list[User] | List of user object try: # Creates list of users with given input array @@ -124,7 +124,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -body = NULL # list[User] | List of user object +body = None # list[User] | List of user object try: # Creates list of users with given input array diff --git a/samples/openapi3/client/petstore/python/docs/UserApi.md b/samples/openapi3/client/petstore/python/docs/UserApi.md index da87cd282d1..3741dc40bc6 100644 --- a/samples/openapi3/client/petstore/python/docs/UserApi.md +++ b/samples/openapi3/client/petstore/python/docs/UserApi.md @@ -78,7 +78,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -user = NULL # list[User] | List of user object +user = None # list[User] | List of user object try: # Creates list of users with given input array @@ -124,7 +124,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -user = NULL # list[User] | List of user object +user = None # list[User] | List of user object try: # Creates list of users with given input array