From 5763b1da7f3aec860fa92fba3c97ca3e9cf3f9ff Mon Sep 17 00:00:00 2001 From: Justin Black Date: Tue, 18 Oct 2022 00:42:31 -0700 Subject: [PATCH 1/2] Adds test sample schema and fixes template --- .../python/model_templates/new.handlebars | 8 ++ .../model_templates/schema_dict.handlebars | 4 + ...odels-for-testing-with-http-signature.yaml | 15 ++- .../petstore/python/.openapi-generator/FILES | 8 ++ .../python/.openapi-generator/VERSION | 2 +- .../openapi3/client/petstore/python/README.md | 2 + ...ithAllOfWithReqTestPropFromUnsetAddProp.md | 30 +++++ .../docs/models/ObjectWithOptionalTestProp.md | 15 +++ ..._with_req_test_prop_from_unset_add_prop.py | 124 ++++++++++++++++++ ...with_req_test_prop_from_unset_add_prop.pyi | 124 ++++++++++++++++++ .../model/object_with_optional_test_prop.py | 78 +++++++++++ .../model/object_with_optional_test_prop.pyi | 78 +++++++++++ .../python/petstore_api/models/__init__.py | 2 + ..._with_req_test_prop_from_unset_add_prop.py | 25 ++++ .../test_object_with_optional_test_prop.py | 25 ++++ 15 files changed, 538 insertions(+), 2 deletions(-) create mode 100644 samples/openapi3/client/petstore/python/docs/models/ObjectWithAllOfWithReqTestPropFromUnsetAddProp.md create mode 100644 samples/openapi3/client/petstore/python/docs/models/ObjectWithOptionalTestProp.md create mode 100644 samples/openapi3/client/petstore/python/petstore_api/model/object_with_all_of_with_req_test_prop_from_unset_add_prop.py create mode 100644 samples/openapi3/client/petstore/python/petstore_api/model/object_with_all_of_with_req_test_prop_from_unset_add_prop.pyi create mode 100644 samples/openapi3/client/petstore/python/petstore_api/model/object_with_optional_test_prop.py create mode 100644 samples/openapi3/client/petstore/python/petstore_api/model/object_with_optional_test_prop.pyi create mode 100644 samples/openapi3/client/petstore/python/test/test_models/test_object_with_all_of_with_req_test_prop_from_unset_add_prop.py create mode 100644 samples/openapi3/client/petstore/python/test/test_models/test_object_with_optional_test_prop.py diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/model_templates/new.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/model_templates/new.handlebars index eb47a54a035..fbf25512bad 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/model_templates/new.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/model_templates/new.handlebars @@ -17,7 +17,15 @@ def __new__( {{#if complexType}} {{baseName}}: '{{complexType}}', {{else}} + {{#if getSchemaIsFromAdditionalProperties}} + {{#if addPropsUnset}} + {{baseName}}: typing.Union[schemas.AnyTypeSchema, {{> model_templates/schema_python_types }}], + {{else}} + {{baseName}}: typing.Union[MetaOapg.additional_properties, {{> model_templates/schema_python_types }}], + {{/if}} + {{else}} {{baseName}}: typing.Union[MetaOapg.properties.{{baseName}}, {{> model_templates/schema_python_types }}], + {{/if}} {{/if}} {{/unless}} {{/with}} diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/model_templates/schema_dict.handlebars b/modules/openapi-json-schema-generator/src/main/resources/python/model_templates/schema_dict.handlebars index 1bee51b3067..284590644f7 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/model_templates/schema_dict.handlebars +++ b/modules/openapi-json-schema-generator/src/main/resources/python/model_templates/schema_dict.handlebars @@ -32,4 +32,8 @@ class {{> model_templates/classname }}( {{/if}} {{> model_templates/property_type_hints }} +{{#if additionalProperties}} {{> model_templates/new }} +{{else}} + {{> model_templates/new addPropsUnset=true }} +{{/if}} diff --git a/modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 13338a350aa..fada2f034af 100644 --- a/modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -2978,4 +2978,17 @@ components: $ref: "#/components/schemas/ArrayWithValidationsInItems" required: - from - - "!reference" \ No newline at end of file + - "!reference" + ObjectWithOptionalTestProp: + type: object + properties: + test: + type: string + ObjectWithAllOfWithReqTestPropFromUnsetAddProp: + allOf: + - $ref: '#/components/schemas/ObjectWithOptionalTestProp' + - type: object + required: [ test ] + properties: + name: + type: string \ No newline at end of file diff --git a/samples/openapi3/client/petstore/python/.openapi-generator/FILES b/samples/openapi3/client/petstore/python/.openapi-generator/FILES index f805094f7eb..5d0fd3294f4 100644 --- a/samples/openapi3/client/petstore/python/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python/.openapi-generator/FILES @@ -97,10 +97,12 @@ docs/models/NumberOnly.md docs/models/NumberWithValidations.md docs/models/ObjectInterface.md docs/models/ObjectModelWithRefProps.md +docs/models/ObjectWithAllOfWithReqTestPropFromUnsetAddProp.md docs/models/ObjectWithDecimalProperties.md docs/models/ObjectWithDifficultlyNamedProps.md docs/models/ObjectWithInlineCompositionProperty.md docs/models/ObjectWithInvalidNamedRefedProperties.md +docs/models/ObjectWithOptionalTestProp.md docs/models/ObjectWithValidations.md docs/models/Order.md docs/models/ParentPet.md @@ -318,6 +320,8 @@ petstore_api/model/object_interface.py petstore_api/model/object_interface.pyi petstore_api/model/object_model_with_ref_props.py petstore_api/model/object_model_with_ref_props.pyi +petstore_api/model/object_with_all_of_with_req_test_prop_from_unset_add_prop.py +petstore_api/model/object_with_all_of_with_req_test_prop_from_unset_add_prop.pyi petstore_api/model/object_with_decimal_properties.py petstore_api/model/object_with_decimal_properties.pyi petstore_api/model/object_with_difficultly_named_props.py @@ -326,6 +330,8 @@ petstore_api/model/object_with_inline_composition_property.py petstore_api/model/object_with_inline_composition_property.pyi petstore_api/model/object_with_invalid_named_refed_properties.py petstore_api/model/object_with_invalid_named_refed_properties.pyi +petstore_api/model/object_with_optional_test_prop.py +petstore_api/model/object_with_optional_test_prop.pyi petstore_api/model/object_with_validations.py petstore_api/model/object_with_validations.pyi petstore_api/model/order.py @@ -390,4 +396,6 @@ setup.py test-requirements.txt test/__init__.py test/test_models/__init__.py +test/test_models/test_object_with_all_of_with_req_test_prop_from_unset_add_prop.py +test/test_models/test_object_with_optional_test_prop.py tox.ini diff --git a/samples/openapi3/client/petstore/python/.openapi-generator/VERSION b/samples/openapi3/client/petstore/python/.openapi-generator/VERSION index 7f207341d5d..717311e32e3 100644 --- a/samples/openapi3/client/petstore/python/.openapi-generator/VERSION +++ b/samples/openapi3/client/petstore/python/.openapi-generator/VERSION @@ -1 +1 @@ -1.0.1 \ No newline at end of file +unset \ No newline at end of file diff --git a/samples/openapi3/client/petstore/python/README.md b/samples/openapi3/client/petstore/python/README.md index 7c9d0509b74..ca7562b37e7 100644 --- a/samples/openapi3/client/petstore/python/README.md +++ b/samples/openapi3/client/petstore/python/README.md @@ -319,10 +319,12 @@ Class | Method | HTTP request | Description - [NumberWithValidations](docs/models/NumberWithValidations.md) - [ObjectInterface](docs/models/ObjectInterface.md) - [ObjectModelWithRefProps](docs/models/ObjectModelWithRefProps.md) + - [ObjectWithAllOfWithReqTestPropFromUnsetAddProp](docs/models/ObjectWithAllOfWithReqTestPropFromUnsetAddProp.md) - [ObjectWithDecimalProperties](docs/models/ObjectWithDecimalProperties.md) - [ObjectWithDifficultlyNamedProps](docs/models/ObjectWithDifficultlyNamedProps.md) - [ObjectWithInlineCompositionProperty](docs/models/ObjectWithInlineCompositionProperty.md) - [ObjectWithInvalidNamedRefedProperties](docs/models/ObjectWithInvalidNamedRefedProperties.md) + - [ObjectWithOptionalTestProp](docs/models/ObjectWithOptionalTestProp.md) - [ObjectWithValidations](docs/models/ObjectWithValidations.md) - [Order](docs/models/Order.md) - [ParentPet](docs/models/ParentPet.md) diff --git a/samples/openapi3/client/petstore/python/docs/models/ObjectWithAllOfWithReqTestPropFromUnsetAddProp.md b/samples/openapi3/client/petstore/python/docs/models/ObjectWithAllOfWithReqTestPropFromUnsetAddProp.md new file mode 100644 index 00000000000..6c4f1033e0e --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/models/ObjectWithAllOfWithReqTestPropFromUnsetAddProp.md @@ -0,0 +1,30 @@ +# petstore_api.model.object_with_all_of_with_req_test_prop_from_unset_add_prop.ObjectWithAllOfWithReqTestPropFromUnsetAddProp + +## Model Type Info +Input Type | Accessed Type | Description | Notes +------------ | ------------- | ------------- | ------------- +dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, | frozendict.frozendict, str, decimal.Decimal, BoolClass, NoneClass, tuple, bytes, FileIO | | + +### Composed Schemas (allOf/anyOf/oneOf/not) +#### allOf +Class Name | Input Type | Accessed Type | Description | Notes +------------- | ------------- | ------------- | ------------- | ------------- +[ObjectWithOptionalTestProp](ObjectWithOptionalTestProp.md) | [**ObjectWithOptionalTestProp**](ObjectWithOptionalTestProp.md) | [**ObjectWithOptionalTestProp**](ObjectWithOptionalTestProp.md) | | +[all_of_1](#all_of_1) | dict, frozendict.frozendict, | frozendict.frozendict, | | + +# all_of_1 + +## Model Type Info +Input Type | Accessed Type | Description | Notes +------------ | ------------- | ------------- | ------------- +dict, frozendict.frozendict, | frozendict.frozendict, | | + +### Dictionary Keys +Key | Input Type | Accessed Type | Description | Notes +------------ | ------------- | ------------- | ------------- | ------------- +**test** | dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, | frozendict.frozendict, str, decimal.Decimal, BoolClass, NoneClass, tuple, bytes, FileIO | | +**name** | str, | str, | | [optional] +**any_string_name** | dict, frozendict.frozendict, str, date, datetime, int, float, bool, decimal.Decimal, None, list, tuple, bytes, io.FileIO, io.BufferedReader | frozendict.frozendict, str, BoolClass, decimal.Decimal, NoneClass, tuple, bytes, FileIO | any string name can be used but the value must be the correct type | [optional] + +[[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/models/ObjectWithOptionalTestProp.md b/samples/openapi3/client/petstore/python/docs/models/ObjectWithOptionalTestProp.md new file mode 100644 index 00000000000..2f437c22d07 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/models/ObjectWithOptionalTestProp.md @@ -0,0 +1,15 @@ +# petstore_api.model.object_with_optional_test_prop.ObjectWithOptionalTestProp + +## Model Type Info +Input Type | Accessed Type | Description | Notes +------------ | ------------- | ------------- | ------------- +dict, frozendict.frozendict, | frozendict.frozendict, | | + +### Dictionary Keys +Key | Input Type | Accessed Type | Description | Notes +------------ | ------------- | ------------- | ------------- | ------------- +**test** | str, | str, | | [optional] +**any_string_name** | dict, frozendict.frozendict, str, date, datetime, int, float, bool, decimal.Decimal, None, list, tuple, bytes, io.FileIO, io.BufferedReader | frozendict.frozendict, str, BoolClass, decimal.Decimal, NoneClass, tuple, bytes, FileIO | any string name can be used but the value must be the correct type | [optional] + +[[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/model/object_with_all_of_with_req_test_prop_from_unset_add_prop.py b/samples/openapi3/client/petstore/python/petstore_api/model/object_with_all_of_with_req_test_prop_from_unset_add_prop.py new file mode 100644 index 00000000000..beef11f6556 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/model/object_with_all_of_with_req_test_prop_from_unset_add_prop.py @@ -0,0 +1,124 @@ +# 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: https://openapi-generator.tech +""" + +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import typing_extensions # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + + +class ObjectWithAllOfWithReqTestPropFromUnsetAddProp( + schemas.ComposedSchema, +): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + + class MetaOapg: + + + class all_of_1( + schemas.DictSchema + ): + + + class MetaOapg: + required = { + "test", + } + + class properties: + name = schemas.StrSchema + __annotations__ = { + "name": name, + } + + test: schemas.AnyTypeSchema + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["name"]) -> MetaOapg.properties.name: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.UnsetAnyTypeSchema: ... + + def __getitem__(self, name: typing.Union[typing_extensions.Literal["name", ], str]): + # dict_instance[name] accessor + return super().__getitem__(name) + + + @typing.overload + def get_item_oapg(self, name: typing_extensions.Literal["name"]) -> typing.Union[MetaOapg.properties.name, schemas.Unset]: ... + + @typing.overload + def get_item_oapg(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ... + + def get_item_oapg(self, name: typing.Union[typing_extensions.Literal["name", ], str]): + return super().get_item_oapg(name) + + + def __new__( + cls, + *args: typing.Union[dict, frozendict.frozendict, ], + test: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, ], + name: typing.Union[MetaOapg.properties.name, str, schemas.Unset] = schemas.unset, + _configuration: typing.Optional[schemas.Configuration] = None, + **kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes], + ) -> 'all_of_1': + return super().__new__( + cls, + *args, + test=test, + name=name, + _configuration=_configuration, + **kwargs, + ) + + @classmethod + @functools.lru_cache() + def all_of(cls): + # we need this here to make our import statements work + # we must store _composed_schemas in here so the code is only run + # when we invoke this method. If we kept this at the class + # level we would get an error because the class level + # code would be run when this module is imported, and these composed + # classes don't exist yet because their module has not finished + # loading + return [ + ObjectWithOptionalTestProp, + cls.all_of_1, + ] + + + def __new__( + cls, + *args: typing.Union[dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, ], + _configuration: typing.Optional[schemas.Configuration] = None, + **kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes], + ) -> 'ObjectWithAllOfWithReqTestPropFromUnsetAddProp': + return super().__new__( + cls, + *args, + _configuration=_configuration, + **kwargs, + ) + +from petstore_api.model.object_with_optional_test_prop import ObjectWithOptionalTestProp diff --git a/samples/openapi3/client/petstore/python/petstore_api/model/object_with_all_of_with_req_test_prop_from_unset_add_prop.pyi b/samples/openapi3/client/petstore/python/petstore_api/model/object_with_all_of_with_req_test_prop_from_unset_add_prop.pyi new file mode 100644 index 00000000000..beef11f6556 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/model/object_with_all_of_with_req_test_prop_from_unset_add_prop.pyi @@ -0,0 +1,124 @@ +# 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: https://openapi-generator.tech +""" + +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import typing_extensions # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + + +class ObjectWithAllOfWithReqTestPropFromUnsetAddProp( + schemas.ComposedSchema, +): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + + class MetaOapg: + + + class all_of_1( + schemas.DictSchema + ): + + + class MetaOapg: + required = { + "test", + } + + class properties: + name = schemas.StrSchema + __annotations__ = { + "name": name, + } + + test: schemas.AnyTypeSchema + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["name"]) -> MetaOapg.properties.name: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.UnsetAnyTypeSchema: ... + + def __getitem__(self, name: typing.Union[typing_extensions.Literal["name", ], str]): + # dict_instance[name] accessor + return super().__getitem__(name) + + + @typing.overload + def get_item_oapg(self, name: typing_extensions.Literal["name"]) -> typing.Union[MetaOapg.properties.name, schemas.Unset]: ... + + @typing.overload + def get_item_oapg(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ... + + def get_item_oapg(self, name: typing.Union[typing_extensions.Literal["name", ], str]): + return super().get_item_oapg(name) + + + def __new__( + cls, + *args: typing.Union[dict, frozendict.frozendict, ], + test: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, ], + name: typing.Union[MetaOapg.properties.name, str, schemas.Unset] = schemas.unset, + _configuration: typing.Optional[schemas.Configuration] = None, + **kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes], + ) -> 'all_of_1': + return super().__new__( + cls, + *args, + test=test, + name=name, + _configuration=_configuration, + **kwargs, + ) + + @classmethod + @functools.lru_cache() + def all_of(cls): + # we need this here to make our import statements work + # we must store _composed_schemas in here so the code is only run + # when we invoke this method. If we kept this at the class + # level we would get an error because the class level + # code would be run when this module is imported, and these composed + # classes don't exist yet because their module has not finished + # loading + return [ + ObjectWithOptionalTestProp, + cls.all_of_1, + ] + + + def __new__( + cls, + *args: typing.Union[dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, ], + _configuration: typing.Optional[schemas.Configuration] = None, + **kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes], + ) -> 'ObjectWithAllOfWithReqTestPropFromUnsetAddProp': + return super().__new__( + cls, + *args, + _configuration=_configuration, + **kwargs, + ) + +from petstore_api.model.object_with_optional_test_prop import ObjectWithOptionalTestProp diff --git a/samples/openapi3/client/petstore/python/petstore_api/model/object_with_optional_test_prop.py b/samples/openapi3/client/petstore/python/petstore_api/model/object_with_optional_test_prop.py new file mode 100644 index 00000000000..07cae57d4c2 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/model/object_with_optional_test_prop.py @@ -0,0 +1,78 @@ +# 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: https://openapi-generator.tech +""" + +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import typing_extensions # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + + +class ObjectWithOptionalTestProp( + schemas.DictSchema +): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + + class MetaOapg: + + class properties: + test = schemas.StrSchema + __annotations__ = { + "test": test, + } + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["test"]) -> MetaOapg.properties.test: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.UnsetAnyTypeSchema: ... + + def __getitem__(self, name: typing.Union[typing_extensions.Literal["test", ], str]): + # dict_instance[name] accessor + return super().__getitem__(name) + + + @typing.overload + def get_item_oapg(self, name: typing_extensions.Literal["test"]) -> typing.Union[MetaOapg.properties.test, schemas.Unset]: ... + + @typing.overload + def get_item_oapg(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ... + + def get_item_oapg(self, name: typing.Union[typing_extensions.Literal["test", ], str]): + return super().get_item_oapg(name) + + + def __new__( + cls, + *args: typing.Union[dict, frozendict.frozendict, ], + test: typing.Union[MetaOapg.properties.test, str, schemas.Unset] = schemas.unset, + _configuration: typing.Optional[schemas.Configuration] = None, + **kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes], + ) -> 'ObjectWithOptionalTestProp': + return super().__new__( + cls, + *args, + test=test, + _configuration=_configuration, + **kwargs, + ) diff --git a/samples/openapi3/client/petstore/python/petstore_api/model/object_with_optional_test_prop.pyi b/samples/openapi3/client/petstore/python/petstore_api/model/object_with_optional_test_prop.pyi new file mode 100644 index 00000000000..07cae57d4c2 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/model/object_with_optional_test_prop.pyi @@ -0,0 +1,78 @@ +# 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: https://openapi-generator.tech +""" + +from datetime import date, datetime # noqa: F401 +import decimal # noqa: F401 +import functools # noqa: F401 +import io # noqa: F401 +import re # noqa: F401 +import typing # noqa: F401 +import typing_extensions # noqa: F401 +import uuid # noqa: F401 + +import frozendict # noqa: F401 + +from petstore_api import schemas # noqa: F401 + + +class ObjectWithOptionalTestProp( + schemas.DictSchema +): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + + class MetaOapg: + + class properties: + test = schemas.StrSchema + __annotations__ = { + "test": test, + } + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["test"]) -> MetaOapg.properties.test: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.UnsetAnyTypeSchema: ... + + def __getitem__(self, name: typing.Union[typing_extensions.Literal["test", ], str]): + # dict_instance[name] accessor + return super().__getitem__(name) + + + @typing.overload + def get_item_oapg(self, name: typing_extensions.Literal["test"]) -> typing.Union[MetaOapg.properties.test, schemas.Unset]: ... + + @typing.overload + def get_item_oapg(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ... + + def get_item_oapg(self, name: typing.Union[typing_extensions.Literal["test", ], str]): + return super().get_item_oapg(name) + + + def __new__( + cls, + *args: typing.Union[dict, frozendict.frozendict, ], + test: typing.Union[MetaOapg.properties.test, str, schemas.Unset] = schemas.unset, + _configuration: typing.Optional[schemas.Configuration] = None, + **kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes], + ) -> 'ObjectWithOptionalTestProp': + return super().__new__( + cls, + *args, + test=test, + _configuration=_configuration, + **kwargs, + ) 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 a3f42957f90..92305b81c13 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py @@ -99,10 +99,12 @@ from petstore_api.model.number_with_validations import NumberWithValidations from petstore_api.model.object_interface import ObjectInterface from petstore_api.model.object_model_with_ref_props import ObjectModelWithRefProps +from petstore_api.model.object_with_all_of_with_req_test_prop_from_unset_add_prop import ObjectWithAllOfWithReqTestPropFromUnsetAddProp from petstore_api.model.object_with_decimal_properties import ObjectWithDecimalProperties from petstore_api.model.object_with_difficultly_named_props import ObjectWithDifficultlyNamedProps from petstore_api.model.object_with_inline_composition_property import ObjectWithInlineCompositionProperty from petstore_api.model.object_with_invalid_named_refed_properties import ObjectWithInvalidNamedRefedProperties +from petstore_api.model.object_with_optional_test_prop import ObjectWithOptionalTestProp from petstore_api.model.object_with_validations import ObjectWithValidations from petstore_api.model.order import Order from petstore_api.model.parent_pet import ParentPet diff --git a/samples/openapi3/client/petstore/python/test/test_models/test_object_with_all_of_with_req_test_prop_from_unset_add_prop.py b/samples/openapi3/client/petstore/python/test/test_models/test_object_with_all_of_with_req_test_prop_from_unset_add_prop.py new file mode 100644 index 00000000000..7f9078b4d72 --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_models/test_object_with_all_of_with_req_test_prop_from_unset_add_prop.py @@ -0,0 +1,25 @@ +# 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: https://openapi-generator.tech +""" + +import unittest + +import petstore_api +from petstore_api.model.object_with_all_of_with_req_test_prop_from_unset_add_prop import ObjectWithAllOfWithReqTestPropFromUnsetAddProp +from petstore_api import configuration + + +class TestObjectWithAllOfWithReqTestPropFromUnsetAddProp(unittest.TestCase): + """ObjectWithAllOfWithReqTestPropFromUnsetAddProp unit test stubs""" + _configuration = configuration.Configuration() + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python/test/test_models/test_object_with_optional_test_prop.py b/samples/openapi3/client/petstore/python/test/test_models/test_object_with_optional_test_prop.py new file mode 100644 index 00000000000..fbd21e71b9f --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_models/test_object_with_optional_test_prop.py @@ -0,0 +1,25 @@ +# 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: https://openapi-generator.tech +""" + +import unittest + +import petstore_api +from petstore_api.model.object_with_optional_test_prop import ObjectWithOptionalTestProp +from petstore_api import configuration + + +class TestObjectWithOptionalTestProp(unittest.TestCase): + """ObjectWithOptionalTestProp unit test stubs""" + _configuration = configuration.Configuration() + + +if __name__ == '__main__': + unittest.main() From f9420b3776ea5c805c0eb4adf60cb269385bb44e Mon Sep 17 00:00:00 2001 From: Justin Black Date: Tue, 18 Oct 2022 09:01:00 -0700 Subject: [PATCH 2/2] Samples generated, test added --- .../petstore/python/.openapi-generator/FILES | 2 -- .../python/.openapi-generator/VERSION | 2 +- ..._with_req_test_prop_from_unset_add_prop.py | 36 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 samples/openapi3/client/petstore/python/tests_manual/test_object_with_all_of_with_req_test_prop_from_unset_add_prop.py diff --git a/samples/openapi3/client/petstore/python/.openapi-generator/FILES b/samples/openapi3/client/petstore/python/.openapi-generator/FILES index 5d0fd3294f4..24d52d4e13a 100644 --- a/samples/openapi3/client/petstore/python/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python/.openapi-generator/FILES @@ -396,6 +396,4 @@ setup.py test-requirements.txt test/__init__.py test/test_models/__init__.py -test/test_models/test_object_with_all_of_with_req_test_prop_from_unset_add_prop.py -test/test_models/test_object_with_optional_test_prop.py tox.ini diff --git a/samples/openapi3/client/petstore/python/.openapi-generator/VERSION b/samples/openapi3/client/petstore/python/.openapi-generator/VERSION index 717311e32e3..7f207341d5d 100644 --- a/samples/openapi3/client/petstore/python/.openapi-generator/VERSION +++ b/samples/openapi3/client/petstore/python/.openapi-generator/VERSION @@ -1 +1 @@ -unset \ No newline at end of file +1.0.1 \ No newline at end of file diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_object_with_all_of_with_req_test_prop_from_unset_add_prop.py b/samples/openapi3/client/petstore/python/tests_manual/test_object_with_all_of_with_req_test_prop_from_unset_add_prop.py new file mode 100644 index 00000000000..288ecddd294 --- /dev/null +++ b/samples/openapi3/client/petstore/python/tests_manual/test_object_with_all_of_with_req_test_prop_from_unset_add_prop.py @@ -0,0 +1,36 @@ +# 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: https://openapi-generator.tech +""" + +import unittest + +import petstore_api +from petstore_api.model.object_with_all_of_with_req_test_prop_from_unset_add_prop import ObjectWithAllOfWithReqTestPropFromUnsetAddProp +from petstore_api import configuration + + +class TestObjectWithAllOfWithReqTestPropFromUnsetAddProp(unittest.TestCase): + """ObjectWithAllOfWithReqTestPropFromUnsetAddProp unit test stubs""" + + def test_model_instantiation(self): + inst = ObjectWithAllOfWithReqTestPropFromUnsetAddProp( + test='a' + ) + assert inst == {'test': 'a'} + + # without the required test property an execption is thrown + with self.assertRaises(petstore_api.exceptions.ApiTypeError): + ObjectWithAllOfWithReqTestPropFromUnsetAddProp( + name='a' + ) + + +if __name__ == '__main__': + unittest.main()