From 7f71c5f4c60cdae5699186319c4666d5b64db899 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Wed, 27 May 2020 17:00:48 +0200 Subject: [PATCH 1/5] Date and date-time examples --- ...ke-endpoints-models-for-testing-with-http-signature.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 9e01283cc8c8..b392dbdd2ab1 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -758,6 +758,7 @@ paths: description: None type: string format: date-time + example: '2020-02-02T20:20:20.22222Z' password: description: None type: string @@ -1202,6 +1203,7 @@ components: shipDate: type: string format: date-time + example: '2020-02-02T20:20:20.000222Z' status: type: string description: Order Status @@ -1439,7 +1441,7 @@ components: maximum: 543.2 minimum: 32.1 type: number - multipleOf: 32.5 + multipleOf: 32.5 float: type: number format: float @@ -1462,9 +1464,11 @@ components: date: type: string format: date + example: '2020-02-02' dateTime: type: string format: date-time + example: '2020-02-02T20:20:20.000222Z' uuid: type: string format: uuid From 54d14bddaf3615a26242d76381a13efe29d55052 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Wed, 27 May 2020 22:13:40 +0200 Subject: [PATCH 2/5] [python-experimental] fix date-time processing --- .../PythonClientExperimentalCodegen.java | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 92c76bb89bbb..9d04cb67ced9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -38,8 +38,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DateFormat; -import java.text.SimpleDateFormat; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; import java.io.File; import java.util.*; import java.util.regex.Pattern; @@ -180,15 +181,15 @@ public String getName() { return "python-experimental"; } - public String dateToString(Schema p, Date date, DateFormat dateFormatter, DateFormat dateTimeFormatter) { + public String dateToString(Schema p, OffsetDateTime date, DateTimeFormatter dateFormatter, DateTimeFormatter dateTimeFormatter) { // converts a date into a date or date-time python string if (!(ModelUtils.isDateSchema(p) || ModelUtils.isDateTimeSchema(p))) { throw new RuntimeException("passed schema must be of type Date or DateTime"); } if (ModelUtils.isDateSchema(p)) { - return "dateutil_parser('" + dateFormatter.format(date) + "').date()"; + return "dateutil_parser('" + date.format(dateFormatter) + "').date()"; } - return "dateutil_parser('" + dateTimeFormatter.format(date) + "')"; + return "dateutil_parser('" + date.format(dateTimeFormatter) + "')"; } /** @@ -212,20 +213,19 @@ public String toDefaultValue(Schema p) { } // convert datetime and date enums if they exist - DateFormat iso8601Date = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT); - DateFormat iso8601DateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.ROOT); - TimeZone utc = TimeZone.getTimeZone("UTC"); - iso8601Date.setTimeZone(utc); - iso8601DateTime.setTimeZone(utc); + DateTimeFormatter iso8601Date = DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ROOT); + DateTimeFormatter iso8601DateTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.ROOT); + iso8601Date.withZone(ZoneOffset.UTC.normalized()); + iso8601DateTime.withZone(ZoneOffset.UTC.normalized()); if (ModelUtils.isDateSchema(p) || ModelUtils.isDateTimeSchema(p)) { List currentEnum = p.getEnum(); List fixedEnum = new ArrayList(); String fixedValue = null; - Date date = null; + OffsetDateTime date = null; if (currentEnum != null && !currentEnum.isEmpty()) { for (Object enumItem : currentEnum) { - date = (Date) enumItem; + date = (OffsetDateTime) enumItem; fixedValue = dateToString(p, date, iso8601Date, iso8601DateTime); fixedEnum.add(fixedValue); } @@ -235,7 +235,11 @@ public String toDefaultValue(Schema p) { // convert the example if it exists Object currentExample = p.getExample(); if (currentExample != null) { - date = (Date) currentExample; + try { + date = (OffsetDateTime) currentExample; + } catch (ClassCastException e) { + date = ((Date) currentExample).toInstant().atOffset(ZoneOffset.UTC); + } fixedValue = dateToString(p, date, iso8601Date, iso8601DateTime); fixedEnum.add(fixedValue); p.setExample(fixedValue); @@ -243,7 +247,7 @@ public String toDefaultValue(Schema p) { // fix defaultObject if (defaultObject != null) { - date = (Date) defaultObject; + date = (OffsetDateTime) defaultObject; fixedValue = dateToString(p, date, iso8601Date, iso8601DateTime); p.setDefault(fixedValue); defaultObject = fixedValue; @@ -887,7 +891,7 @@ public String getSimpleTypeDeclaration(Schema schema) { * Primitive types in the OAS specification are implemented in Python using the corresponding * Python primitive types. * Composed types (e.g. allAll, oneOf, anyOf) are represented in Python using list of types. - * + * * The caller should set the prefix and suffix arguments to empty string, except when * getTypeString invokes itself recursively. A non-empty prefix/suffix may be specified * to wrap the return value in a python dict, list or tuple. @@ -895,7 +899,7 @@ public String getSimpleTypeDeclaration(Schema schema) { * Examples: * - "bool, date, float" The data must be a bool, date or float. * - "[bool, date]" The data must be an array, and the array items must be a bool or date. - * + * * @param p The OAS schema. * @param prefix prepended to the returned value. * @param suffix appended to the returned value. From b4192348c8594c23612cdf00e2b20a7655bac423 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Fri, 29 May 2020 18:42:16 +0200 Subject: [PATCH 3/5] Apply suggestions from code review --- ...h-fake-endpoints-models-for-testing-with-http-signature.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index b392dbdd2ab1..fb996b509b4c 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1468,7 +1468,7 @@ components: dateTime: type: string format: date-time - example: '2020-02-02T20:20:20.000222Z' + example: '2007-12-03T10:15:30+01:00' uuid: type: string format: uuid From 24832a1cc13dd42a5fd2a7df1d02ae8212cc62e2 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Mon, 1 Jun 2020 16:01:46 +0200 Subject: [PATCH 4/5] Fix date(-time) example parsing --- .../codegen/languages/PythonClientCodegen.java | 2 +- .../PythonClientExperimentalCodegen.java | 1 + ...s-models-for-testing-with-http-signature.yaml | 3 ++- .../python-experimental/docs/InlineObject3.md | 2 +- .../petstore_api/model/inline_object3.py | 2 +- .../client/petstore/python/docs/Animal.md | 2 +- .../client/petstore/python/docs/Category.md | 2 +- .../client/petstore/python/docs/FakeApi.md | 16 ++++++++-------- .../openapi3/client/petstore/python/docs/Foo.md | 2 +- .../client/petstore/python/docs/InlineObject2.md | 2 +- .../python/petstore_api/models/animal.py | 2 +- .../python/petstore_api/models/category.py | 2 +- .../petstore/python/petstore_api/models/foo.py | 2 +- .../python/petstore_api/models/inline_object2.py | 2 +- 14 files changed, 22 insertions(+), 20 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 612e7dc8f86d..d7a6339fa320 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 @@ -728,7 +728,7 @@ private String toExampleValueRecursive(Schema schema, List included_sche } // correct "'"s into "'"s after toString() - if (ModelUtils.isStringSchema(schema) && schema.getDefault() != null) { + if (ModelUtils.isStringSchema(schema) && schema.getDefault() != null && !ModelUtils.isDateSchema(schema) && !ModelUtils.isDateTimeSchema(schema)) { example = (String) schema.getDefault(); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 938e6445a240..30396798e492 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -247,6 +247,7 @@ public String toDefaultValue(Schema p) { date = (OffsetDateTime) currentExample; } catch (ClassCastException e) { date = ((Date) currentExample).toInstant().atOffset(ZoneOffset.UTC); + LOGGER.warn("Invalid `date-time` format for value {}", currentExample); } fixedValue = dateToString(p, date, iso8601Date, iso8601DateTime); fixedEnum.add(fixedValue); diff --git a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index d3699ac62076..484f8777ca7c 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -758,6 +758,7 @@ paths: description: None type: string format: date-time + default: '2010-02-01T10:20:10.11111+01:00' example: '2020-02-02T20:20:20.22222Z' password: description: None @@ -1973,7 +1974,7 @@ components: # Here the additional properties are specified using a referenced schema. # This is just to validate the generated code works when using $ref # under 'additionalProperties'. - $ref: '#/components/schemas/fruit' + $ref: '#/components/schemas/fruit' Shape: oneOf: - $ref: '#/components/schemas/Triangle' diff --git a/samples/openapi3/client/petstore/python-experimental/docs/InlineObject3.md b/samples/openapi3/client/petstore/python-experimental/docs/InlineObject3.md index 050d635dd255..69815c5e63c0 100644 --- a/samples/openapi3/client/petstore/python-experimental/docs/InlineObject3.md +++ b/samples/openapi3/client/petstore/python-experimental/docs/InlineObject3.md @@ -14,7 +14,7 @@ Name | Type | Description | Notes **string** | **str** | None | [optional] **binary** | **file_type** | None | [optional] **date** | **date** | None | [optional] -**date_time** | **datetime** | None | [optional] +**date_time** | **datetime** | None | [optional] if omitted the server will use the default value of dateutil_parser('2010-02-01T10:20:10.11111+01:00') **password** | **str** | None | [optional] **callback** | **str** | None | [optional] diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/inline_object3.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/inline_object3.py index ff595ddaa1fd..01c49c375e72 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/inline_object3.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/inline_object3.py @@ -210,7 +210,7 @@ def __init__(self, number, double, pattern_without_delimiter, byte, *args, **kwa string (str): None. [optional] # noqa: E501 binary (file_type): None. [optional] # noqa: E501 date (date): None. [optional] # noqa: E501 - date_time (datetime): None. [optional] # noqa: E501 + date_time (datetime): None. [optional] if omitted the server will use the default value of dateutil_parser('2010-02-01T10:20:10.11111+01:00') # noqa: E501 password (str): None. [optional] # noqa: E501 callback (str): None. [optional] # noqa: E501 """ diff --git a/samples/openapi3/client/petstore/python/docs/Animal.md b/samples/openapi3/client/petstore/python/docs/Animal.md index 7ed4ba541fa3..d9a9be5bfe66 100644 --- a/samples/openapi3/client/petstore/python/docs/Animal.md +++ b/samples/openapi3/client/petstore/python/docs/Animal.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **class_name** | **str** | | -**color** | **str** | | [optional] [default to 'red'] +**color** | **str** | | [optional] [default to "red"] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Category.md b/samples/openapi3/client/petstore/python/docs/Category.md index 7e5c1e316499..e6f8efaf2f54 100644 --- a/samples/openapi3/client/petstore/python/docs/Category.md +++ b/samples/openapi3/client/petstore/python/docs/Category.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **id** | **int** | | [optional] -**name** | **str** | | [default to 'default-name'] +**name** | **str** | | [default to "default-name"] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/FakeApi.md b/samples/openapi3/client/petstore/python/docs/FakeApi.md index 50de8cc758fa..ffa1cfa1ef5d 100644 --- a/samples/openapi3/client/petstore/python/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/python/docs/FakeApi.md @@ -756,13 +756,13 @@ with petstore_api.ApiClient() as api_client: # Create an instance of the API class api_instance = petstore_api.FakeApi(api_client) enum_header_string_array = ['enum_header_string_array_example'] # list[str] | Header parameter enum test (string array) (optional) -enum_header_string = '-efg' # str | Header parameter enum test (string) (optional) (default to '-efg') +enum_header_string = -efg # str | Header parameter enum test (string) (optional) (default to -efg) enum_query_string_array = ['enum_query_string_array_example'] # list[str] | Query parameter enum test (string array) (optional) -enum_query_string = '-efg' # str | Query parameter enum test (string) (optional) (default to '-efg') +enum_query_string = -efg # str | Query parameter enum test (string) (optional) (default to -efg) enum_query_integer = 56 # int | Query parameter enum test (double) (optional) enum_query_double = 3.4 # float | Query parameter enum test (double) (optional) -enum_form_string_array = '$' # list[str] | Form parameter enum test (string array) (optional) (default to '$') -enum_form_string = '-efg' # str | Form parameter enum test (string) (optional) (default to '-efg') +enum_form_string_array = $ # list[str] | Form parameter enum test (string array) (optional) (default to $) +enum_form_string = -efg # str | Form parameter enum test (string) (optional) (default to -efg) try: # To test enum parameters @@ -776,13 +776,13 @@ enum_form_string = '-efg' # str | Form parameter enum test (string) (optional) ( Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **enum_header_string_array** | [**list[str]**](str.md)| Header parameter enum test (string array) | [optional] - **enum_header_string** | **str**| Header parameter enum test (string) | [optional] [default to '-efg'] + **enum_header_string** | **str**| Header parameter enum test (string) | [optional] [default to -efg] **enum_query_string_array** | [**list[str]**](str.md)| Query parameter enum test (string array) | [optional] - **enum_query_string** | **str**| Query parameter enum test (string) | [optional] [default to '-efg'] + **enum_query_string** | **str**| Query parameter enum test (string) | [optional] [default to -efg] **enum_query_integer** | **int**| Query parameter enum test (double) | [optional] **enum_query_double** | **float**| Query parameter enum test (double) | [optional] - **enum_form_string_array** | [**list[str]**](str.md)| Form parameter enum test (string array) | [optional] [default to '$'] - **enum_form_string** | **str**| Form parameter enum test (string) | [optional] [default to '-efg'] + **enum_form_string_array** | [**list[str]**](str.md)| Form parameter enum test (string array) | [optional] [default to $] + **enum_form_string** | **str**| Form parameter enum test (string) | [optional] [default to -efg] ### Return type diff --git a/samples/openapi3/client/petstore/python/docs/Foo.md b/samples/openapi3/client/petstore/python/docs/Foo.md index c55aa2cf103c..e895b805e2e7 100644 --- a/samples/openapi3/client/petstore/python/docs/Foo.md +++ b/samples/openapi3/client/petstore/python/docs/Foo.md @@ -3,7 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**bar** | **str** | | [optional] [default to 'bar'] +**bar** | **str** | | [optional] [default to "bar"] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/InlineObject2.md b/samples/openapi3/client/petstore/python/docs/InlineObject2.md index 9bfba12f6f15..11227d53fffb 100644 --- a/samples/openapi3/client/petstore/python/docs/InlineObject2.md +++ b/samples/openapi3/client/petstore/python/docs/InlineObject2.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **enum_form_string_array** | **list[str]** | Form parameter enum test (string array) | [optional] -**enum_form_string** | **str** | Form parameter enum test (string) | [optional] [default to '-efg'] +**enum_form_string** | **str** | Form parameter enum test (string) | [optional] [default to -efg] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/animal.py b/samples/openapi3/client/petstore/python/petstore_api/models/animal.py index 65cef1a60885..be6372cac4e5 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/animal.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/animal.py @@ -47,7 +47,7 @@ class Animal(object): 'Cat': 'Cat' } - def __init__(self, class_name=None, color='red', local_vars_configuration=None): # noqa: E501 + def __init__(self, class_name=None, color="red", local_vars_configuration=None): # noqa: E501 """Animal - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/category.py b/samples/openapi3/client/petstore/python/petstore_api/models/category.py index b47c148953ea..95e1b8312d3f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/category.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/category.py @@ -42,7 +42,7 @@ class Category(object): 'name': 'name' } - def __init__(self, id=None, name='default-name', local_vars_configuration=None): # noqa: E501 + def __init__(self, id=None, name="default-name", local_vars_configuration=None): # noqa: E501 """Category - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/foo.py b/samples/openapi3/client/petstore/python/petstore_api/models/foo.py index 0a98b8837cac..74ebca1bb2ac 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/foo.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/foo.py @@ -40,7 +40,7 @@ class Foo(object): 'bar': 'bar' } - def __init__(self, bar='bar', local_vars_configuration=None): # noqa: E501 + def __init__(self, bar="bar", local_vars_configuration=None): # noqa: E501 """Foo - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object2.py b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object2.py index f904d0a24d5d..dcb3f971d010 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object2.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object2.py @@ -42,7 +42,7 @@ class InlineObject2(object): 'enum_form_string': 'enum_form_string' } - def __init__(self, enum_form_string_array=None, enum_form_string='-efg', local_vars_configuration=None): # noqa: E501 + def __init__(self, enum_form_string_array=None, enum_form_string=-efg, local_vars_configuration=None): # noqa: E501 """InlineObject2 - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() From a1ba8b3250ffa23e54d24e5ea9431da0185d997e Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Mon, 1 Jun 2020 18:24:09 +0200 Subject: [PATCH 5/5] Add unit test for toDefaultValue --- .../PythonClientExperimentalCodegen.java | 1 + .../python/PythonClientExperimentalTest.java | 12 ++++++++++++ ...s-models-for-testing-with-http-signature.yaml | 5 +++++ .../client/petstore/python/docs/Animal.md | 2 +- .../client/petstore/python/docs/Category.md | 2 +- .../client/petstore/python/docs/FakeApi.md | 16 ++++++++-------- .../openapi3/client/petstore/python/docs/Foo.md | 2 +- .../client/petstore/python/docs/InlineObject2.md | 2 +- .../python/petstore_api/models/animal.py | 2 +- .../python/petstore_api/models/category.py | 2 +- .../petstore/python/petstore_api/models/foo.py | 2 +- .../python/petstore_api/models/inline_object2.py | 2 +- 12 files changed, 34 insertions(+), 16 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index a3d3bcb5f466..6096b444ca32 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -258,6 +258,7 @@ public String toDefaultValue(Schema p) { fixedValue = dateToString(p, date, iso8601Date, iso8601DateTime); fixedEnum.add(fixedValue); p.setExample(fixedValue); + LOGGER.warn(fixedValue); } // fix defaultObject diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientExperimentalTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientExperimentalTest.java index c7988952b7f5..8ad4990a5543 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientExperimentalTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientExperimentalTest.java @@ -21,8 +21,10 @@ import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.media.*; import io.swagger.v3.parser.util.SchemaTypeUtil; +import java.time.OffsetDateTime; import org.openapitools.codegen.*; import org.openapitools.codegen.languages.PythonClientExperimentalCodegen; +import org.openapitools.codegen.utils.ModelUtils; import org.testng.Assert; import org.testng.annotations.Test; @@ -293,4 +295,14 @@ public void mapModelTest() { Assert.assertEquals(cm.imports.size(), 0); } + @Test(description = "parse date and date-time example value") + public void parseDateAndDateTimeExamplesTest() { + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml"); + final DefaultCodegen codegen = new PythonClientExperimentalCodegen(); + + Schema modelSchema = ModelUtils.getSchema(openAPI, "DateTimeTest"); + String defaultValue = codegen.toDefaultValue(modelSchema); + Assert.assertEquals(defaultValue, "dateutil_parser('2010-01-01T10:10:10.000111+01:00')"); + } + } diff --git a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 484f8777ca7c..c9bf37fe1a15 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -2074,3 +2074,8 @@ components: properties: name: type: string + DateTimeTest: + type: string + default: '2010-01-01T10:10:10.000111+01:00' + example: '2010-01-01T10:10:10.000111+01:00' + format: date-time diff --git a/samples/openapi3/client/petstore/python/docs/Animal.md b/samples/openapi3/client/petstore/python/docs/Animal.md index d9a9be5bfe66..7ed4ba541fa3 100644 --- a/samples/openapi3/client/petstore/python/docs/Animal.md +++ b/samples/openapi3/client/petstore/python/docs/Animal.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **class_name** | **str** | | -**color** | **str** | | [optional] [default to "red"] +**color** | **str** | | [optional] [default to 'red'] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Category.md b/samples/openapi3/client/petstore/python/docs/Category.md index e6f8efaf2f54..7e5c1e316499 100644 --- a/samples/openapi3/client/petstore/python/docs/Category.md +++ b/samples/openapi3/client/petstore/python/docs/Category.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **id** | **int** | | [optional] -**name** | **str** | | [default to "default-name"] +**name** | **str** | | [default to 'default-name'] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/FakeApi.md b/samples/openapi3/client/petstore/python/docs/FakeApi.md index ffa1cfa1ef5d..50de8cc758fa 100644 --- a/samples/openapi3/client/petstore/python/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/python/docs/FakeApi.md @@ -756,13 +756,13 @@ with petstore_api.ApiClient() as api_client: # Create an instance of the API class api_instance = petstore_api.FakeApi(api_client) enum_header_string_array = ['enum_header_string_array_example'] # list[str] | Header parameter enum test (string array) (optional) -enum_header_string = -efg # str | Header parameter enum test (string) (optional) (default to -efg) +enum_header_string = '-efg' # str | Header parameter enum test (string) (optional) (default to '-efg') enum_query_string_array = ['enum_query_string_array_example'] # list[str] | Query parameter enum test (string array) (optional) -enum_query_string = -efg # str | Query parameter enum test (string) (optional) (default to -efg) +enum_query_string = '-efg' # str | Query parameter enum test (string) (optional) (default to '-efg') enum_query_integer = 56 # int | Query parameter enum test (double) (optional) enum_query_double = 3.4 # float | Query parameter enum test (double) (optional) -enum_form_string_array = $ # list[str] | Form parameter enum test (string array) (optional) (default to $) -enum_form_string = -efg # str | Form parameter enum test (string) (optional) (default to -efg) +enum_form_string_array = '$' # list[str] | Form parameter enum test (string array) (optional) (default to '$') +enum_form_string = '-efg' # str | Form parameter enum test (string) (optional) (default to '-efg') try: # To test enum parameters @@ -776,13 +776,13 @@ enum_form_string = -efg # str | Form parameter enum test (string) (optional) (de Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **enum_header_string_array** | [**list[str]**](str.md)| Header parameter enum test (string array) | [optional] - **enum_header_string** | **str**| Header parameter enum test (string) | [optional] [default to -efg] + **enum_header_string** | **str**| Header parameter enum test (string) | [optional] [default to '-efg'] **enum_query_string_array** | [**list[str]**](str.md)| Query parameter enum test (string array) | [optional] - **enum_query_string** | **str**| Query parameter enum test (string) | [optional] [default to -efg] + **enum_query_string** | **str**| Query parameter enum test (string) | [optional] [default to '-efg'] **enum_query_integer** | **int**| Query parameter enum test (double) | [optional] **enum_query_double** | **float**| Query parameter enum test (double) | [optional] - **enum_form_string_array** | [**list[str]**](str.md)| Form parameter enum test (string array) | [optional] [default to $] - **enum_form_string** | **str**| Form parameter enum test (string) | [optional] [default to -efg] + **enum_form_string_array** | [**list[str]**](str.md)| Form parameter enum test (string array) | [optional] [default to '$'] + **enum_form_string** | **str**| Form parameter enum test (string) | [optional] [default to '-efg'] ### Return type diff --git a/samples/openapi3/client/petstore/python/docs/Foo.md b/samples/openapi3/client/petstore/python/docs/Foo.md index e895b805e2e7..c55aa2cf103c 100644 --- a/samples/openapi3/client/petstore/python/docs/Foo.md +++ b/samples/openapi3/client/petstore/python/docs/Foo.md @@ -3,7 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**bar** | **str** | | [optional] [default to "bar"] +**bar** | **str** | | [optional] [default to 'bar'] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/InlineObject2.md b/samples/openapi3/client/petstore/python/docs/InlineObject2.md index 11227d53fffb..9bfba12f6f15 100644 --- a/samples/openapi3/client/petstore/python/docs/InlineObject2.md +++ b/samples/openapi3/client/petstore/python/docs/InlineObject2.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **enum_form_string_array** | **list[str]** | Form parameter enum test (string array) | [optional] -**enum_form_string** | **str** | Form parameter enum test (string) | [optional] [default to -efg] +**enum_form_string** | **str** | Form parameter enum test (string) | [optional] [default to '-efg'] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/animal.py b/samples/openapi3/client/petstore/python/petstore_api/models/animal.py index be6372cac4e5..65cef1a60885 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/animal.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/animal.py @@ -47,7 +47,7 @@ class Animal(object): 'Cat': 'Cat' } - def __init__(self, class_name=None, color="red", local_vars_configuration=None): # noqa: E501 + def __init__(self, class_name=None, color='red', local_vars_configuration=None): # noqa: E501 """Animal - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/category.py b/samples/openapi3/client/petstore/python/petstore_api/models/category.py index 95e1b8312d3f..b47c148953ea 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/category.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/category.py @@ -42,7 +42,7 @@ class Category(object): 'name': 'name' } - def __init__(self, id=None, name="default-name", local_vars_configuration=None): # noqa: E501 + def __init__(self, id=None, name='default-name', local_vars_configuration=None): # noqa: E501 """Category - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/foo.py b/samples/openapi3/client/petstore/python/petstore_api/models/foo.py index 74ebca1bb2ac..0a98b8837cac 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/foo.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/foo.py @@ -40,7 +40,7 @@ class Foo(object): 'bar': 'bar' } - def __init__(self, bar="bar", local_vars_configuration=None): # noqa: E501 + def __init__(self, bar='bar', local_vars_configuration=None): # noqa: E501 """Foo - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object2.py b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object2.py index dcb3f971d010..f904d0a24d5d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object2.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object2.py @@ -42,7 +42,7 @@ class InlineObject2(object): 'enum_form_string': 'enum_form_string' } - def __init__(self, enum_form_string_array=None, enum_form_string=-efg, local_vars_configuration=None): # noqa: E501 + def __init__(self, enum_form_string_array=None, enum_form_string='-efg', local_vars_configuration=None): # noqa: E501 """InlineObject2 - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration()