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