From d41fe12c1f64f6ab2f3f24fb945dfccb4b42612d Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 29 Jul 2023 11:43:37 +0800 Subject: [PATCH] [python] Add tests for simple object with additional properties (#16218) * add tests for simple object without additional properties * update logic --- .../languages/PythonClientCodegen.java | 12 +-- ...ith-fake-endpoints-models-for-testing.yaml | 8 ++ .../python-aiohttp/.openapi-generator/FILES | 2 + .../client/petstore/python-aiohttp/README.md | 1 + .../docs/ObjectToTestAdditionalProperties.md | 29 +++++++ .../python-aiohttp/petstore_api/__init__.py | 1 + .../petstore_api/models/__init__.py | 1 + .../object_to_test_additional_properties.py | 70 ++++++++++++++++ ...st_object_to_test_additional_properties.py | 54 ++++++++++++ .../petstore/python/.openapi-generator/FILES | 2 + .../openapi3/client/petstore/python/README.md | 1 + .../docs/ObjectToTestAdditionalProperties.md | 29 +++++++ .../petstore/python/petstore_api/__init__.py | 1 + .../python/petstore_api/models/__init__.py | 1 + .../petstore_api/models/any_of_color.py | 2 +- .../python/petstore_api/models/any_of_pig.py | 2 +- .../object_to_test_additional_properties.py | 82 +++++++++++++++++++ ...st_object_to_test_additional_properties.py | 54 ++++++++++++ .../petstore/python/tests/test_model.py | 7 ++ 19 files changed, 351 insertions(+), 8 deletions(-) create mode 100644 samples/openapi3/client/petstore/python-aiohttp/docs/ObjectToTestAdditionalProperties.md create mode 100644 samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_to_test_additional_properties.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/test/test_object_to_test_additional_properties.py create mode 100644 samples/openapi3/client/petstore/python/docs/ObjectToTestAdditionalProperties.md create mode 100644 samples/openapi3/client/petstore/python/petstore_api/models/object_to_test_additional_properties.py create mode 100644 samples/openapi3/client/petstore/python/test/test_object_to_test_additional_properties.py 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 ffe0f96966a..a348b93397a 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 @@ -1239,12 +1239,12 @@ public class PythonClientCodegen extends AbstractPythonCodegen implements Codege codegenProperties = model.vars; } - // if model_generic.mustache is used - if (model.oneOf.isEmpty() && !model.isEnum) { - if (!this.disallowAdditionalPropertiesIfNotPresent) { - typingImports.add("Dict"); - typingImports.add("Any"); - } + // if model_generic.mustache is used and support additionalProperties + if (model.oneOf.isEmpty() && model.anyOf.isEmpty() + && !model.isEnum + && !this.disallowAdditionalPropertiesIfNotPresent) { + typingImports.add("Dict"); + typingImports.add("Any"); } //loop through properties/schemas to set up typing, pydantic diff --git a/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml index 126aef82d3a..0a1d4d5cfad 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml @@ -2238,3 +2238,11 @@ components: type_: type: string type: object + ObjectToTestAdditionalProperties: + description: Minimal object + type: object + properties: + property: + description: Property + type: boolean + default: false diff --git a/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES index da5a81e587d..c1ffcecbc45 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES @@ -54,6 +54,7 @@ docs/Name.md docs/NullableClass.md docs/NullableProperty.md docs/NumberOnly.md +docs/ObjectToTestAdditionalProperties.md docs/ObjectWithDeprecatedFields.md docs/OneOfEnumString.md docs/Order.md @@ -143,6 +144,7 @@ petstore_api/models/name.py petstore_api/models/nullable_class.py petstore_api/models/nullable_property.py petstore_api/models/number_only.py +petstore_api/models/object_to_test_additional_properties.py petstore_api/models/object_with_deprecated_fields.py petstore_api/models/one_of_enum_string.py petstore_api/models/order.py diff --git a/samples/openapi3/client/petstore/python-aiohttp/README.md b/samples/openapi3/client/petstore/python-aiohttp/README.md index 8a7b13d6871..5732dbce4aa 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-aiohttp/README.md @@ -179,6 +179,7 @@ Class | Method | HTTP request | Description - [NullableClass](docs/NullableClass.md) - [NullableProperty](docs/NullableProperty.md) - [NumberOnly](docs/NumberOnly.md) + - [ObjectToTestAdditionalProperties](docs/ObjectToTestAdditionalProperties.md) - [ObjectWithDeprecatedFields](docs/ObjectWithDeprecatedFields.md) - [OneOfEnumString](docs/OneOfEnumString.md) - [Order](docs/Order.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ObjectToTestAdditionalProperties.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ObjectToTestAdditionalProperties.md new file mode 100644 index 00000000000..c4ba9a95850 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ObjectToTestAdditionalProperties.md @@ -0,0 +1,29 @@ +# ObjectToTestAdditionalProperties + +Minimal object + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**var_property** | **bool** | Property | [optional] [default to False] + +## Example + +```python +from petstore_api.models.object_to_test_additional_properties import ObjectToTestAdditionalProperties + +# TODO update the JSON string below +json = "{}" +# create an instance of ObjectToTestAdditionalProperties from a JSON string +object_to_test_additional_properties_instance = ObjectToTestAdditionalProperties.from_json(json) +# print the JSON string representation of the object +print ObjectToTestAdditionalProperties.to_json() + +# convert the object into a dict +object_to_test_additional_properties_dict = object_to_test_additional_properties_instance.to_dict() +# create an instance of ObjectToTestAdditionalProperties from a dict +object_to_test_additional_properties_form_dict = object_to_test_additional_properties.from_dict(object_to_test_additional_properties_dict) +``` +[[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-aiohttp/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py index 0b1f3fb35ac..7ee83df43a5 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py @@ -85,6 +85,7 @@ from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass from petstore_api.models.nullable_property import NullableProperty from petstore_api.models.number_only import NumberOnly +from petstore_api.models.object_to_test_additional_properties import ObjectToTestAdditionalProperties from petstore_api.models.object_with_deprecated_fields import ObjectWithDeprecatedFields from petstore_api.models.one_of_enum_string import OneOfEnumString from petstore_api.models.order import Order diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/__init__.py index 6b2e45a59cc..d88d6edde7d 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/__init__.py @@ -61,6 +61,7 @@ from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass from petstore_api.models.nullable_property import NullableProperty from petstore_api.models.number_only import NumberOnly +from petstore_api.models.object_to_test_additional_properties import ObjectToTestAdditionalProperties from petstore_api.models.object_with_deprecated_fields import ObjectWithDeprecatedFields from petstore_api.models.one_of_enum_string import OneOfEnumString from petstore_api.models.order import Order diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_to_test_additional_properties.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_to_test_additional_properties.py new file mode 100644 index 00000000000..2166e776bfb --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_to_test_additional_properties.py @@ -0,0 +1,70 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import Optional +from pydantic import BaseModel, Field, StrictBool + +class ObjectToTestAdditionalProperties(BaseModel): + """ + Minimal object + """ + var_property: Optional[StrictBool] = Field(False, alias="property", description="Property") + __properties = ["property"] + + class Config: + """Pydantic configuration""" + allow_population_by_field_name = True + validate_assignment = True + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.dict(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> ObjectToTestAdditionalProperties: + """Create an instance of ObjectToTestAdditionalProperties from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self): + """Returns the dictionary representation of the model using alias""" + _dict = self.dict(by_alias=True, + exclude={ + }, + exclude_none=True) + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> ObjectToTestAdditionalProperties: + """Create an instance of ObjectToTestAdditionalProperties from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return ObjectToTestAdditionalProperties.parse_obj(obj) + + _obj = ObjectToTestAdditionalProperties.parse_obj({ + "var_property": obj.get("property") if obj.get("property") is not None else False + }) + return _obj + diff --git a/samples/openapi3/client/petstore/python-aiohttp/test/test_object_to_test_additional_properties.py b/samples/openapi3/client/petstore/python-aiohttp/test/test_object_to_test_additional_properties.py new file mode 100644 index 00000000000..f1f354cad25 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/test/test_object_to_test_additional_properties.py @@ -0,0 +1,54 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +import unittest +import datetime + +import petstore_api +from petstore_api.models.object_to_test_additional_properties import ObjectToTestAdditionalProperties # noqa: E501 +from petstore_api.rest import ApiException + +class TestObjectToTestAdditionalProperties(unittest.TestCase): + """ObjectToTestAdditionalProperties unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test ObjectToTestAdditionalProperties + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `ObjectToTestAdditionalProperties` + """ + model = petstore_api.models.object_to_test_additional_properties.ObjectToTestAdditionalProperties() # noqa: E501 + if include_optional : + return ObjectToTestAdditionalProperties( + var_property = True + ) + else : + return ObjectToTestAdditionalProperties( + ) + """ + + def testObjectToTestAdditionalProperties(self): + """Test ObjectToTestAdditionalProperties""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python/.openapi-generator/FILES b/samples/openapi3/client/petstore/python/.openapi-generator/FILES index fc31ea985ff..56fbf32a07e 100755 --- a/samples/openapi3/client/petstore/python/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python/.openapi-generator/FILES @@ -54,6 +54,7 @@ docs/Name.md docs/NullableClass.md docs/NullableProperty.md docs/NumberOnly.md +docs/ObjectToTestAdditionalProperties.md docs/ObjectWithDeprecatedFields.md docs/OneOfEnumString.md docs/Order.md @@ -143,6 +144,7 @@ petstore_api/models/name.py petstore_api/models/nullable_class.py petstore_api/models/nullable_property.py petstore_api/models/number_only.py +petstore_api/models/object_to_test_additional_properties.py petstore_api/models/object_with_deprecated_fields.py petstore_api/models/one_of_enum_string.py petstore_api/models/order.py diff --git a/samples/openapi3/client/petstore/python/README.md b/samples/openapi3/client/petstore/python/README.md index e3f46d9d0ce..449912d5c09 100755 --- a/samples/openapi3/client/petstore/python/README.md +++ b/samples/openapi3/client/petstore/python/README.md @@ -179,6 +179,7 @@ Class | Method | HTTP request | Description - [NullableClass](docs/NullableClass.md) - [NullableProperty](docs/NullableProperty.md) - [NumberOnly](docs/NumberOnly.md) + - [ObjectToTestAdditionalProperties](docs/ObjectToTestAdditionalProperties.md) - [ObjectWithDeprecatedFields](docs/ObjectWithDeprecatedFields.md) - [OneOfEnumString](docs/OneOfEnumString.md) - [Order](docs/Order.md) diff --git a/samples/openapi3/client/petstore/python/docs/ObjectToTestAdditionalProperties.md b/samples/openapi3/client/petstore/python/docs/ObjectToTestAdditionalProperties.md new file mode 100644 index 00000000000..c4ba9a95850 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/ObjectToTestAdditionalProperties.md @@ -0,0 +1,29 @@ +# ObjectToTestAdditionalProperties + +Minimal object + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**var_property** | **bool** | Property | [optional] [default to False] + +## Example + +```python +from petstore_api.models.object_to_test_additional_properties import ObjectToTestAdditionalProperties + +# TODO update the JSON string below +json = "{}" +# create an instance of ObjectToTestAdditionalProperties from a JSON string +object_to_test_additional_properties_instance = ObjectToTestAdditionalProperties.from_json(json) +# print the JSON string representation of the object +print ObjectToTestAdditionalProperties.to_json() + +# convert the object into a dict +object_to_test_additional_properties_dict = object_to_test_additional_properties_instance.to_dict() +# create an instance of ObjectToTestAdditionalProperties from a dict +object_to_test_additional_properties_form_dict = object_to_test_additional_properties.from_dict(object_to_test_additional_properties_dict) +``` +[[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/__init__.py b/samples/openapi3/client/petstore/python/petstore_api/__init__.py index 0b1f3fb35ac..7ee83df43a5 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/__init__.py @@ -85,6 +85,7 @@ from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass from petstore_api.models.nullable_property import NullableProperty from petstore_api.models.number_only import NumberOnly +from petstore_api.models.object_to_test_additional_properties import ObjectToTestAdditionalProperties from petstore_api.models.object_with_deprecated_fields import ObjectWithDeprecatedFields from petstore_api.models.one_of_enum_string import OneOfEnumString from petstore_api.models.order import Order diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py index 6b2e45a59cc..d88d6edde7d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py @@ -61,6 +61,7 @@ from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass from petstore_api.models.nullable_property import NullableProperty from petstore_api.models.number_only import NumberOnly +from petstore_api.models.object_to_test_additional_properties import ObjectToTestAdditionalProperties from petstore_api.models.object_with_deprecated_fields import ObjectWithDeprecatedFields from petstore_api.models.one_of_enum_string import OneOfEnumString from petstore_api.models.order import Order diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py b/samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py index c4a61fd6fef..4b66a315d1d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py @@ -18,7 +18,7 @@ import json import pprint import re # noqa: F401 -from typing import Any, Dict, List, Optional +from typing import List, Optional from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, conlist, constr, validator from typing import Union, Any, List, TYPE_CHECKING from pydantic import StrictStr, Field diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/any_of_pig.py b/samples/openapi3/client/petstore/python/petstore_api/models/any_of_pig.py index 09590acddb5..3e98a0089e2 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/any_of_pig.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/any_of_pig.py @@ -18,7 +18,7 @@ import json import pprint import re # noqa: F401 -from typing import Any, Dict, Optional +from typing import Optional from pydantic import BaseModel, Field, StrictStr, ValidationError, validator from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/object_to_test_additional_properties.py b/samples/openapi3/client/petstore/python/petstore_api/models/object_to_test_additional_properties.py new file mode 100644 index 00000000000..6a985aea7cf --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/object_to_test_additional_properties.py @@ -0,0 +1,82 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import Any, Dict, Optional +from pydantic import BaseModel, Field, StrictBool + +class ObjectToTestAdditionalProperties(BaseModel): + """ + Minimal object + """ + var_property: Optional[StrictBool] = Field(False, alias="property", description="Property") + additional_properties: Dict[str, Any] = {} + __properties = ["property"] + + class Config: + """Pydantic configuration""" + allow_population_by_field_name = True + validate_assignment = True + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.dict(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> ObjectToTestAdditionalProperties: + """Create an instance of ObjectToTestAdditionalProperties from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self): + """Returns the dictionary representation of the model using alias""" + _dict = self.dict(by_alias=True, + exclude={ + "additional_properties" + }, + exclude_none=True) + # 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(): + _dict[_key] = _value + + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> ObjectToTestAdditionalProperties: + """Create an instance of ObjectToTestAdditionalProperties from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return ObjectToTestAdditionalProperties.parse_obj(obj) + + _obj = ObjectToTestAdditionalProperties.parse_obj({ + "var_property": obj.get("property") if obj.get("property") is not None else False + }) + # store additional fields in additional_properties + for _key in obj.keys(): + if _key not in cls.__properties: + _obj.additional_properties[_key] = obj.get(_key) + + return _obj + diff --git a/samples/openapi3/client/petstore/python/test/test_object_to_test_additional_properties.py b/samples/openapi3/client/petstore/python/test/test_object_to_test_additional_properties.py new file mode 100644 index 00000000000..f1f354cad25 --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_object_to_test_additional_properties.py @@ -0,0 +1,54 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +import unittest +import datetime + +import petstore_api +from petstore_api.models.object_to_test_additional_properties import ObjectToTestAdditionalProperties # noqa: E501 +from petstore_api.rest import ApiException + +class TestObjectToTestAdditionalProperties(unittest.TestCase): + """ObjectToTestAdditionalProperties unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test ObjectToTestAdditionalProperties + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `ObjectToTestAdditionalProperties` + """ + model = petstore_api.models.object_to_test_additional_properties.ObjectToTestAdditionalProperties() # noqa: E501 + if include_optional : + return ObjectToTestAdditionalProperties( + var_property = True + ) + else : + return ObjectToTestAdditionalProperties( + ) + """ + + def testObjectToTestAdditionalProperties(self): + """Test ObjectToTestAdditionalProperties""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python/tests/test_model.py b/samples/openapi3/client/petstore/python/tests/test_model.py index dc8b13cdc9a..2598b0757d0 100644 --- a/samples/openapi3/client/petstore/python/tests/test_model.py +++ b/samples/openapi3/client/petstore/python/tests/test_model.py @@ -501,3 +501,10 @@ class ModelTests(unittest.TestCase): self.assertEqual(a.to_json(), '{"another_property": [[{"id": 123, "name": "tag name"}]]}') a2 = petstore_api.ArrayOfArrayOfModel.from_dict(a.to_dict()) self.assertEqual(a.to_dict(), a2.to_dict()) + + def test_object_with_additional_properties(self): + a = petstore_api.ObjectToTestAdditionalProperties() + a.additional_properties = { "abc": 123 } + # should not throw the following errors: + # pydantic.errors.ConfigError: field "additional_properties" not yet prepared so type is still a ForwardRef, you might need to call ObjectToTestAdditionalProperties.update_forward_refs(). +