From bd7bc9aa798d01031e46c97750ce249bf3271261 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 7 Apr 2023 09:34:04 +0800 Subject: [PATCH] [python-nextgen] Add bytearray, none_type as primitive type (#15130) * add bytearray, none type as primitive type * update samples * update doc --- docs/generators/python-nextgen.md | 2 ++ .../codegen/languages/PythonNextgenClientCodegen.java | 2 ++ samples/client/echo_api/python-nextgen/docs/BodyApi.md | 2 +- .../petstore/python-nextgen-aiohttp/docs/FakeApi.md | 6 +++--- .../petstore/python-nextgen-aiohttp/docs/FormatTest.md | 4 ++-- .../petstore/python-nextgen-aiohttp/docs/PetApi.md | 4 ++-- .../petstore_api/models/format_test.py | 10 ++-------- .../client/petstore/python-nextgen/docs/FakeApi.md | 6 +++--- .../client/petstore/python-nextgen/docs/FormatTest.md | 4 ++-- .../client/petstore/python-nextgen/docs/PetApi.md | 4 ++-- .../python-nextgen/petstore_api/models/format_test.py | 10 ++-------- 11 files changed, 23 insertions(+), 31 deletions(-) diff --git a/docs/generators/python-nextgen.md b/docs/generators/python-nextgen.md index c8a3984195..5343d442b3 100644 --- a/docs/generators/python-nextgen.md +++ b/docs/generators/python-nextgen.md @@ -50,6 +50,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
  • Dict
  • List
  • bool
  • +
  • bytearray
  • bytes
  • date
  • datetime
  • @@ -58,6 +59,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
  • float
  • int
  • list
  • +
  • none_type
  • object
  • str
  • diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonNextgenClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonNextgenClientCodegen.java index ae2b72ac08..4c83af570f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonNextgenClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonNextgenClientCodegen.java @@ -120,6 +120,8 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements languageSpecificPrimitives.remove("file"); languageSpecificPrimitives.add("decimal.Decimal"); + languageSpecificPrimitives.add("bytearray"); + languageSpecificPrimitives.add("none_type"); supportsInheritance = true; modelPackage = "models"; diff --git a/samples/client/echo_api/python-nextgen/docs/BodyApi.md b/samples/client/echo_api/python-nextgen/docs/BodyApi.md index cbe30800e2..f0ba44f974 100644 --- a/samples/client/echo_api/python-nextgen/docs/BodyApi.md +++ b/samples/client/echo_api/python-nextgen/docs/BodyApi.md @@ -51,7 +51,7 @@ This endpoint does not need any parameter. ### Return type -[**bytearray**](bytearray.md) +**bytearray** ### Authorization diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/FakeApi.md b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/FakeApi.md index aba30bd3e1..6c225b2426 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/FakeApi.md @@ -612,7 +612,7 @@ configuration = petstore_api.Configuration( async with petstore_api.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = petstore_api.FakeApi(api_client) - body = petstore_api.bytearray() # bytearray | image to upload + body = None # bytearray | image to upload try: await api_instance.test_body_with_binary(body) @@ -934,13 +934,13 @@ async with petstore_api.ApiClient(configuration) as api_client: number = 3.4 # float | None double = 3.4 # float | None pattern_without_delimiter = 'pattern_without_delimiter_example' # str | None - byte = petstore_api.bytearray() # bytearray | None + byte = None # bytearray | None integer = 56 # int | None (optional) int32 = 56 # int | None (optional) int64 = 56 # int | None (optional) float = 3.4 # float | None (optional) string = 'string_example' # str | None (optional) - binary = petstore_api.bytearray() # bytearray | None (optional) + binary = None # bytearray | None (optional) var_date = '2013-10-20' # date | None (optional) date_time = '2013-10-20T19:20:30+01:00' # datetime | None (optional) password = 'password_example' # str | None (optional) diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/FormatTest.md b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/FormatTest.md index 9ab2ba7624..aa81e58595 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/FormatTest.md +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/FormatTest.md @@ -13,8 +13,8 @@ Name | Type | Description | Notes **decimal** | **decimal.Decimal** | | [optional] **string** | **str** | | [optional] **string_with_double_quote_pattern** | **str** | | [optional] -**byte** | [**bytearray**](bytearray.md) | | [optional] -**binary** | [**bytearray**](bytearray.md) | | [optional] +**byte** | **bytearray** | | [optional] +**binary** | **bytearray** | | [optional] **var_date** | **date** | | **date_time** | **datetime** | | [optional] **uuid** | **str** | | [optional] diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/PetApi.md b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/PetApi.md index ffd45c7f4f..c63c0c6ec4 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/PetApi.md +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/PetApi.md @@ -1176,7 +1176,7 @@ async with petstore_api.ApiClient(configuration) as api_client: api_instance = petstore_api.PetApi(api_client) pet_id = 56 # int | ID of pet to update additional_metadata = 'additional_metadata_example' # str | Additional data to pass to server (optional) - file = petstore_api.bytearray() # bytearray | file to upload (optional) + file = None # bytearray | file to upload (optional) try: # uploads an image @@ -1250,7 +1250,7 @@ async with petstore_api.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = petstore_api.PetApi(api_client) pet_id = 56 # int | ID of pet to update - required_file = petstore_api.bytearray() # bytearray | file to upload + required_file = None # bytearray | file to upload additional_metadata = 'additional_metadata_example' # str | Additional data to pass to server (optional) try: diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/format_test.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/format_test.py index c8b1eb5e69..811d3a4ee2 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/format_test.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/format_test.py @@ -92,12 +92,6 @@ class FormatTest(BaseModel): exclude={ }, exclude_none=True) - # override the default output from pydantic by calling `to_dict()` of byte - if self.byte: - _dict['byte'] = self.byte.to_dict() - # override the default output from pydantic by calling `to_dict()` of binary - if self.binary: - _dict['binary'] = self.binary.to_dict() return _dict @classmethod @@ -119,8 +113,8 @@ class FormatTest(BaseModel): "decimal": obj.get("decimal"), "string": obj.get("string"), "string_with_double_quote_pattern": obj.get("string_with_double_quote_pattern"), - "byte": bytearray.from_dict(obj.get("byte")) if obj.get("byte") is not None else None, - "binary": bytearray.from_dict(obj.get("binary")) if obj.get("binary") is not None else None, + "byte": obj.get("byte"), + "binary": obj.get("binary"), "var_date": obj.get("date"), "date_time": obj.get("dateTime"), "uuid": obj.get("uuid"), diff --git a/samples/openapi3/client/petstore/python-nextgen/docs/FakeApi.md b/samples/openapi3/client/petstore/python-nextgen/docs/FakeApi.md index 34f265a1b5..fc6167ff8b 100755 --- a/samples/openapi3/client/petstore/python-nextgen/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/python-nextgen/docs/FakeApi.md @@ -612,7 +612,7 @@ configuration = petstore_api.Configuration( with petstore_api.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = petstore_api.FakeApi(api_client) - body = petstore_api.bytearray() # bytearray | image to upload + body = None # bytearray | image to upload try: api_instance.test_body_with_binary(body) @@ -934,13 +934,13 @@ with petstore_api.ApiClient(configuration) as api_client: number = 3.4 # float | None double = 3.4 # float | None pattern_without_delimiter = 'pattern_without_delimiter_example' # str | None - byte = petstore_api.bytearray() # bytearray | None + byte = None # bytearray | None integer = 56 # int | None (optional) int32 = 56 # int | None (optional) int64 = 56 # int | None (optional) float = 3.4 # float | None (optional) string = 'string_example' # str | None (optional) - binary = petstore_api.bytearray() # bytearray | None (optional) + binary = None # bytearray | None (optional) var_date = '2013-10-20' # date | None (optional) date_time = '2013-10-20T19:20:30+01:00' # datetime | None (optional) password = 'password_example' # str | None (optional) diff --git a/samples/openapi3/client/petstore/python-nextgen/docs/FormatTest.md b/samples/openapi3/client/petstore/python-nextgen/docs/FormatTest.md index 9ab2ba7624..aa81e58595 100755 --- a/samples/openapi3/client/petstore/python-nextgen/docs/FormatTest.md +++ b/samples/openapi3/client/petstore/python-nextgen/docs/FormatTest.md @@ -13,8 +13,8 @@ Name | Type | Description | Notes **decimal** | **decimal.Decimal** | | [optional] **string** | **str** | | [optional] **string_with_double_quote_pattern** | **str** | | [optional] -**byte** | [**bytearray**](bytearray.md) | | [optional] -**binary** | [**bytearray**](bytearray.md) | | [optional] +**byte** | **bytearray** | | [optional] +**binary** | **bytearray** | | [optional] **var_date** | **date** | | **date_time** | **datetime** | | [optional] **uuid** | **str** | | [optional] diff --git a/samples/openapi3/client/petstore/python-nextgen/docs/PetApi.md b/samples/openapi3/client/petstore/python-nextgen/docs/PetApi.md index 1a33b03031..0321e8336b 100755 --- a/samples/openapi3/client/petstore/python-nextgen/docs/PetApi.md +++ b/samples/openapi3/client/petstore/python-nextgen/docs/PetApi.md @@ -1176,7 +1176,7 @@ with petstore_api.ApiClient(configuration) as api_client: api_instance = petstore_api.PetApi(api_client) pet_id = 56 # int | ID of pet to update additional_metadata = 'additional_metadata_example' # str | Additional data to pass to server (optional) - file = petstore_api.bytearray() # bytearray | file to upload (optional) + file = None # bytearray | file to upload (optional) try: # uploads an image @@ -1250,7 +1250,7 @@ with petstore_api.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = petstore_api.PetApi(api_client) pet_id = 56 # int | ID of pet to update - required_file = petstore_api.bytearray() # bytearray | file to upload + required_file = None # bytearray | file to upload additional_metadata = 'additional_metadata_example' # str | Additional data to pass to server (optional) try: diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/format_test.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/format_test.py index 4fe80d0e6a..89f85aa14c 100644 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/format_test.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/format_test.py @@ -94,12 +94,6 @@ class FormatTest(BaseModel): "additional_properties" }, exclude_none=True) - # override the default output from pydantic by calling `to_dict()` of byte - if self.byte: - _dict['byte'] = self.byte.to_dict() - # override the default output from pydantic by calling `to_dict()` of binary - if self.binary: - _dict['binary'] = self.binary.to_dict() # puts key-value pairs in additional_properties in the top level if self.additional_properties is not None: for _key, _value in self.additional_properties.items(): @@ -126,8 +120,8 @@ class FormatTest(BaseModel): "decimal": obj.get("decimal"), "string": obj.get("string"), "string_with_double_quote_pattern": obj.get("string_with_double_quote_pattern"), - "byte": bytearray.from_dict(obj.get("byte")) if obj.get("byte") is not None else None, - "binary": bytearray.from_dict(obj.get("binary")) if obj.get("binary") is not None else None, + "byte": obj.get("byte"), + "binary": obj.get("binary"), "var_date": obj.get("date"), "date_time": obj.get("dateTime"), "uuid": obj.get("uuid"),