From 453facc81c322155a7309738352480281bd325ea Mon Sep 17 00:00:00 2001 From: "Zishun (Zack) Wei" <56001105+zishunwei@users.noreply.github.com> Date: Mon, 8 Apr 2024 19:01:01 +0800 Subject: [PATCH] Fix 18271: Circular imports on AllOf generation with REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=True (#18272) * fix issue 18271 * the same update for python-pydantic-v1 * add test * update samples * update samples * put properties under allOf for python client tests * update samples * add a test in test model --- .../languages/AbstractPythonCodegen.java | 5 + .../AbstractPythonPydanticV1Codegen.java | 5 + ...ith-fake-endpoints-models-for-testing.yaml | 23 ++++ .../python-aiohttp/.openapi-generator/FILES | 6 + .../client/petstore/python-aiohttp/README.md | 3 + .../python-aiohttp/docs/AllOfSuperModel.md | 29 +++++ .../python-aiohttp/docs/CircularAllOfRef.md | 30 +++++ .../docs/SecondCircularAllOfRef.md | 30 +++++ .../python-aiohttp/petstore_api/__init__.py | 3 + .../petstore_api/models/__init__.py | 3 + .../petstore_api/models/all_of_super_model.py | 87 ++++++++++++++ .../models/circular_all_of_ref.py | 99 ++++++++++++++++ .../models/second_circular_all_of_ref.py | 99 ++++++++++++++++ .../test/test_all_of_super_model.py | 51 ++++++++ .../test/test_circular_all_of_ref.py | 60 ++++++++++ .../test/test_second_circular_all_of_ref.py | 57 +++++++++ .../.openapi-generator/FILES | 6 + .../python-pydantic-v1-aiohttp/README.md | 3 + .../docs/AllOfSuperModel.md | 28 +++++ .../docs/CircularAllOfRef.md | 29 +++++ .../docs/SecondCircularAllOfRef.md | 29 +++++ .../petstore_api/__init__.py | 3 + .../petstore_api/models/__init__.py | 3 + .../petstore_api/models/all_of_super_model.py | 71 +++++++++++ .../models/circular_all_of_ref.py | 82 +++++++++++++ .../models/second_circular_all_of_ref.py | 82 +++++++++++++ .../test/test_all_of_super_model.py | 52 ++++++++ .../test/test_circular_all_of_ref.py | 61 ++++++++++ .../test/test_second_circular_all_of_ref.py | 58 +++++++++ .../.openapi-generator/FILES | 6 + .../petstore/python-pydantic-v1/README.md | 3 + .../docs/AllOfSuperModel.md | 28 +++++ .../docs/CircularAllOfRef.md | 29 +++++ .../docs/SecondCircularAllOfRef.md | 29 +++++ .../petstore_api/__init__.py | 3 + .../petstore_api/models/__init__.py | 3 + .../petstore_api/models/all_of_super_model.py | 83 +++++++++++++ .../models/circular_all_of_ref.py | 94 +++++++++++++++ .../models/second_circular_all_of_ref.py | 94 +++++++++++++++ .../test/test_all_of_super_model.py | 52 ++++++++ .../test/test_circular_all_of_ref.py | 61 ++++++++++ .../test/test_second_circular_all_of_ref.py | 58 +++++++++ .../petstore/python/.openapi-generator/FILES | 6 + .../openapi3/client/petstore/python/README.md | 3 + .../petstore/python/docs/AllOfSuperModel.md | 29 +++++ .../petstore/python/docs/CircularAllOfRef.md | 30 +++++ .../python/docs/SecondCircularAllOfRef.md | 30 +++++ .../petstore/python/petstore_api/__init__.py | 3 + .../python/petstore_api/models/__init__.py | 3 + .../petstore_api/models/all_of_super_model.py | 100 ++++++++++++++++ .../models/circular_all_of_ref.py | 112 ++++++++++++++++++ .../models/second_circular_all_of_ref.py | 112 ++++++++++++++++++ .../python/test/test_all_of_super_model.py | 51 ++++++++ .../python/test/test_circular_all_of_ref.py | 60 ++++++++++ .../test/test_second_circular_all_of_ref.py | 57 +++++++++ .../petstore/python/tests/test_model.py | 10 ++ 56 files changed, 2246 insertions(+) create mode 100644 samples/openapi3/client/petstore/python-aiohttp/docs/AllOfSuperModel.md create mode 100644 samples/openapi3/client/petstore/python-aiohttp/docs/CircularAllOfRef.md create mode 100644 samples/openapi3/client/petstore/python-aiohttp/docs/SecondCircularAllOfRef.md create mode 100644 samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_super_model.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/test/test_all_of_super_model.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/test/test_circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/test/test_second_circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/AllOfSuperModel.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/CircularAllOfRef.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/SecondCircularAllOfRef.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/all_of_super_model.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/second_circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_all_of_super_model.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_second_circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/docs/AllOfSuperModel.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/docs/CircularAllOfRef.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/docs/SecondCircularAllOfRef.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/all_of_super_model.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/second_circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/test/test_all_of_super_model.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/test/test_circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/test/test_second_circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python/docs/AllOfSuperModel.md create mode 100644 samples/openapi3/client/petstore/python/docs/CircularAllOfRef.md create mode 100644 samples/openapi3/client/petstore/python/docs/SecondCircularAllOfRef.md create mode 100644 samples/openapi3/client/petstore/python/petstore_api/models/all_of_super_model.py create mode 100644 samples/openapi3/client/petstore/python/petstore_api/models/circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python/petstore_api/models/second_circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python/test/test_all_of_super_model.py create mode 100644 samples/openapi3/client/petstore/python/test/test_circular_all_of_ref.py create mode 100644 samples/openapi3/client/petstore/python/test/test_second_circular_all_of_ref.py diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java index e944c9d9fe5..7808c7ffb29 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java @@ -1000,6 +1000,11 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co // set the extensions if the key is absent model.getVendorExtensions().putIfAbsent("x-py-readonly", readOnlyFields); + // remove the items of postponedModelImports in modelImports to avoid circular imports error + if (!modelImports.isEmpty() && !postponedModelImports.isEmpty()){ + modelImports.removeAll(postponedModelImports); + } + // import models one by one if (!modelImports.isEmpty()) { Set modelsToImport = new TreeSet<>(); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonPydanticV1Codegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonPydanticV1Codegen.java index 299ed40048c..617da587f84 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonPydanticV1Codegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonPydanticV1Codegen.java @@ -1002,6 +1002,11 @@ public abstract class AbstractPythonPydanticV1Codegen extends DefaultCodegen imp model.getVendorExtensions().putIfAbsent("x-py-datetime-imports", datetimeImports); model.getVendorExtensions().putIfAbsent("x-py-readonly", readOnlyFields); + // remove the items of postponedModelImports in modelImports to avoid circular imports error + if (!modelImports.isEmpty() && !postponedModelImports.isEmpty()){ + modelImports.removeAll(postponedModelImports); + } + // import models one by one if (!modelImports.isEmpty()) { Set modelsToImport = new TreeSet<>(); 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 a3d0ab708e6..2fc18c1d644 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 @@ -2711,3 +2711,26 @@ components: properties: field: type: string + CircularAllOfRef: + allOf: + - $ref: '#/components/schemas/AllOfSuperModel' + - properties: + secondCircularAllOfRef: + items: + $ref: '#/components/schemas/SecondCircularAllOfRef' + type: array + type: object + SecondCircularAllOfRef: + allOf: + - $ref: '#/components/schemas/AllOfSuperModel' + - properties: + circularAllOfRef: + items: + $ref: '#/components/schemas/CircularAllOfRef' + type: array + type: object + AllOfSuperModel: + properties: + _name: + type: string + type: object diff --git a/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES index 208f26992a1..f7e65690c39 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES @@ -7,6 +7,7 @@ docs/AdditionalPropertiesAnyType.md docs/AdditionalPropertiesClass.md docs/AdditionalPropertiesObject.md docs/AdditionalPropertiesWithDescriptionOnly.md +docs/AllOfSuperModel.md docs/AllOfWithSingleRef.md docs/Animal.md docs/AnotherFakeApi.md @@ -21,6 +22,7 @@ docs/Bathing.md docs/Capitalization.md docs/Cat.md docs/Category.md +docs/CircularAllOfRef.md docs/CircularReferenceModel.md docs/ClassModel.md docs/Client.md @@ -85,6 +87,7 @@ docs/PoopCleaning.md docs/PropertyMap.md docs/PropertyNameCollision.md docs/ReadOnlyFirst.md +docs/SecondCircularAllOfRef.md docs/SecondRef.md docs/SelfReferenceModel.md docs/SingleRefType.md @@ -125,6 +128,7 @@ petstore_api/models/additional_properties_any_type.py petstore_api/models/additional_properties_class.py petstore_api/models/additional_properties_object.py petstore_api/models/additional_properties_with_description_only.py +petstore_api/models/all_of_super_model.py petstore_api/models/all_of_with_single_ref.py petstore_api/models/animal.py petstore_api/models/any_of_color.py @@ -138,6 +142,7 @@ petstore_api/models/bathing.py petstore_api/models/capitalization.py petstore_api/models/cat.py petstore_api/models/category.py +petstore_api/models/circular_all_of_ref.py petstore_api/models/circular_reference_model.py petstore_api/models/class_model.py petstore_api/models/client.py @@ -197,6 +202,7 @@ petstore_api/models/poop_cleaning.py petstore_api/models/property_map.py petstore_api/models/property_name_collision.py petstore_api/models/read_only_first.py +petstore_api/models/second_circular_all_of_ref.py petstore_api/models/second_ref.py petstore_api/models/self_reference_model.py petstore_api/models/single_ref_type.py diff --git a/samples/openapi3/client/petstore/python-aiohttp/README.md b/samples/openapi3/client/petstore/python-aiohttp/README.md index c48cda64543..5f51fa17bff 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-aiohttp/README.md @@ -154,6 +154,7 @@ Class | Method | HTTP request | Description - [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) - [AdditionalPropertiesObject](docs/AdditionalPropertiesObject.md) - [AdditionalPropertiesWithDescriptionOnly](docs/AdditionalPropertiesWithDescriptionOnly.md) + - [AllOfSuperModel](docs/AllOfSuperModel.md) - [AllOfWithSingleRef](docs/AllOfWithSingleRef.md) - [Animal](docs/Animal.md) - [AnyOfColor](docs/AnyOfColor.md) @@ -167,6 +168,7 @@ Class | Method | HTTP request | Description - [Capitalization](docs/Capitalization.md) - [Cat](docs/Cat.md) - [Category](docs/Category.md) + - [CircularAllOfRef](docs/CircularAllOfRef.md) - [CircularReferenceModel](docs/CircularReferenceModel.md) - [ClassModel](docs/ClassModel.md) - [Client](docs/Client.md) @@ -226,6 +228,7 @@ Class | Method | HTTP request | Description - [PropertyMap](docs/PropertyMap.md) - [PropertyNameCollision](docs/PropertyNameCollision.md) - [ReadOnlyFirst](docs/ReadOnlyFirst.md) + - [SecondCircularAllOfRef](docs/SecondCircularAllOfRef.md) - [SecondRef](docs/SecondRef.md) - [SelfReferenceModel](docs/SelfReferenceModel.md) - [SingleRefType](docs/SingleRefType.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/AllOfSuperModel.md b/samples/openapi3/client/petstore/python-aiohttp/docs/AllOfSuperModel.md new file mode 100644 index 00000000000..1262bd9dc51 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/AllOfSuperModel.md @@ -0,0 +1,29 @@ +# AllOfSuperModel + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **str** | | [optional] + +## Example + +```python +from petstore_api.models.all_of_super_model import AllOfSuperModel + +# TODO update the JSON string below +json = "{}" +# create an instance of AllOfSuperModel from a JSON string +all_of_super_model_instance = AllOfSuperModel.from_json(json) +# print the JSON string representation of the object +print(AllOfSuperModel.to_json()) + +# convert the object into a dict +all_of_super_model_dict = all_of_super_model_instance.to_dict() +# create an instance of AllOfSuperModel from a dict +all_of_super_model_form_dict = all_of_super_model.from_dict(all_of_super_model_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/docs/CircularAllOfRef.md b/samples/openapi3/client/petstore/python-aiohttp/docs/CircularAllOfRef.md new file mode 100644 index 00000000000..a00be37d4d1 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/CircularAllOfRef.md @@ -0,0 +1,30 @@ +# CircularAllOfRef + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **str** | | [optional] +**second_circular_all_of_ref** | [**List[SecondCircularAllOfRef]**](SecondCircularAllOfRef.md) | | [optional] + +## Example + +```python +from petstore_api.models.circular_all_of_ref import CircularAllOfRef + +# TODO update the JSON string below +json = "{}" +# create an instance of CircularAllOfRef from a JSON string +circular_all_of_ref_instance = CircularAllOfRef.from_json(json) +# print the JSON string representation of the object +print(CircularAllOfRef.to_json()) + +# convert the object into a dict +circular_all_of_ref_dict = circular_all_of_ref_instance.to_dict() +# create an instance of CircularAllOfRef from a dict +circular_all_of_ref_form_dict = circular_all_of_ref.from_dict(circular_all_of_ref_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/docs/SecondCircularAllOfRef.md b/samples/openapi3/client/petstore/python-aiohttp/docs/SecondCircularAllOfRef.md new file mode 100644 index 00000000000..eae28911ed2 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/SecondCircularAllOfRef.md @@ -0,0 +1,30 @@ +# SecondCircularAllOfRef + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **str** | | [optional] +**circular_all_of_ref** | [**List[CircularAllOfRef]**](CircularAllOfRef.md) | | [optional] + +## Example + +```python +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef + +# TODO update the JSON string below +json = "{}" +# create an instance of SecondCircularAllOfRef from a JSON string +second_circular_all_of_ref_instance = SecondCircularAllOfRef.from_json(json) +# print the JSON string representation of the object +print(SecondCircularAllOfRef.to_json()) + +# convert the object into a dict +second_circular_all_of_ref_dict = second_circular_all_of_ref_instance.to_dict() +# create an instance of SecondCircularAllOfRef from a dict +second_circular_all_of_ref_form_dict = second_circular_all_of_ref.from_dict(second_circular_all_of_ref_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 f0548eda859..1d2a609f13b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py @@ -43,6 +43,7 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert from petstore_api.models.additional_properties_class import AdditionalPropertiesClass from petstore_api.models.additional_properties_object import AdditionalPropertiesObject from petstore_api.models.additional_properties_with_description_only import AdditionalPropertiesWithDescriptionOnly +from petstore_api.models.all_of_super_model import AllOfSuperModel from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef from petstore_api.models.animal import Animal from petstore_api.models.any_of_color import AnyOfColor @@ -56,6 +57,7 @@ from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization from petstore_api.models.cat import Cat from petstore_api.models.category import Category +from petstore_api.models.circular_all_of_ref import CircularAllOfRef from petstore_api.models.circular_reference_model import CircularReferenceModel from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client @@ -115,6 +117,7 @@ from petstore_api.models.poop_cleaning import PoopCleaning from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef from petstore_api.models.second_ref import SecondRef from petstore_api.models.self_reference_model import SelfReferenceModel from petstore_api.models.single_ref_type import SingleRefType 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 421ad6fe846..efd9c939d21 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 @@ -18,6 +18,7 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert from petstore_api.models.additional_properties_class import AdditionalPropertiesClass from petstore_api.models.additional_properties_object import AdditionalPropertiesObject from petstore_api.models.additional_properties_with_description_only import AdditionalPropertiesWithDescriptionOnly +from petstore_api.models.all_of_super_model import AllOfSuperModel from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef from petstore_api.models.animal import Animal from petstore_api.models.any_of_color import AnyOfColor @@ -31,6 +32,7 @@ from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization from petstore_api.models.cat import Cat from petstore_api.models.category import Category +from petstore_api.models.circular_all_of_ref import CircularAllOfRef from petstore_api.models.circular_reference_model import CircularReferenceModel from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client @@ -90,6 +92,7 @@ from petstore_api.models.poop_cleaning import PoopCleaning from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef from petstore_api.models.second_ref import SecondRef from petstore_api.models.self_reference_model import SelfReferenceModel from petstore_api.models.single_ref_type import SingleRefType diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_super_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_super_model.py new file mode 100644 index 00000000000..03f55459293 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_super_model.py @@ -0,0 +1,87 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, Field, StrictStr +from typing import Any, ClassVar, Dict, List, Optional +from typing import Optional, Set +from typing_extensions import Self + +class AllOfSuperModel(BaseModel): + """ + AllOfSuperModel + """ # noqa: E501 + name: Optional[StrictStr] = Field(default=None, alias="_name") + __properties: ClassVar[List[str]] = ["_name"] + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of AllOfSuperModel from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + """ + excluded_fields: Set[str] = set([ + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of AllOfSuperModel from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "_name": obj.get("_name") + }) + return _obj + + diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_all_of_ref.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_all_of_ref.py new file mode 100644 index 00000000000..32c742e9d10 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_all_of_ref.py @@ -0,0 +1,99 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, Field, StrictStr +from typing import Any, ClassVar, Dict, List, Optional +from typing import Optional, Set +from typing_extensions import Self + +class CircularAllOfRef(BaseModel): + """ + CircularAllOfRef + """ # noqa: E501 + name: Optional[StrictStr] = Field(default=None, alias="_name") + second_circular_all_of_ref: Optional[List[SecondCircularAllOfRef]] = Field(default=None, alias="secondCircularAllOfRef") + __properties: ClassVar[List[str]] = ["_name", "secondCircularAllOfRef"] + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of CircularAllOfRef from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + """ + excluded_fields: Set[str] = set([ + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # override the default output from pydantic by calling `to_dict()` of each item in second_circular_all_of_ref (list) + _items = [] + if self.second_circular_all_of_ref: + for _item in self.second_circular_all_of_ref: + if _item: + _items.append(_item.to_dict()) + _dict['secondCircularAllOfRef'] = _items + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of CircularAllOfRef from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "_name": obj.get("_name"), + "secondCircularAllOfRef": [SecondCircularAllOfRef.from_dict(_item) for _item in obj["secondCircularAllOfRef"]] if obj.get("secondCircularAllOfRef") is not None else None + }) + return _obj + +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef +# TODO: Rewrite to not use raise_errors +CircularAllOfRef.model_rebuild(raise_errors=False) + diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_circular_all_of_ref.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_circular_all_of_ref.py new file mode 100644 index 00000000000..b7668004013 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_circular_all_of_ref.py @@ -0,0 +1,99 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, Field, StrictStr +from typing import Any, ClassVar, Dict, List, Optional +from typing import Optional, Set +from typing_extensions import Self + +class SecondCircularAllOfRef(BaseModel): + """ + SecondCircularAllOfRef + """ # noqa: E501 + name: Optional[StrictStr] = Field(default=None, alias="_name") + circular_all_of_ref: Optional[List[CircularAllOfRef]] = Field(default=None, alias="circularAllOfRef") + __properties: ClassVar[List[str]] = ["_name", "circularAllOfRef"] + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of SecondCircularAllOfRef from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + """ + excluded_fields: Set[str] = set([ + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # override the default output from pydantic by calling `to_dict()` of each item in circular_all_of_ref (list) + _items = [] + if self.circular_all_of_ref: + for _item in self.circular_all_of_ref: + if _item: + _items.append(_item.to_dict()) + _dict['circularAllOfRef'] = _items + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of SecondCircularAllOfRef from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "_name": obj.get("_name"), + "circularAllOfRef": [CircularAllOfRef.from_dict(_item) for _item in obj["circularAllOfRef"]] if obj.get("circularAllOfRef") is not None else None + }) + return _obj + +from petstore_api.models.circular_all_of_ref import CircularAllOfRef +# TODO: Rewrite to not use raise_errors +SecondCircularAllOfRef.model_rebuild(raise_errors=False) + diff --git a/samples/openapi3/client/petstore/python-aiohttp/test/test_all_of_super_model.py b/samples/openapi3/client/petstore/python-aiohttp/test/test_all_of_super_model.py new file mode 100644 index 00000000000..dfc6d444ba7 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/test/test_all_of_super_model.py @@ -0,0 +1,51 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from petstore_api.models.all_of_super_model import AllOfSuperModel + +class TestAllOfSuperModel(unittest.TestCase): + """AllOfSuperModel unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> AllOfSuperModel: + """Test AllOfSuperModel + 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 `AllOfSuperModel` + """ + model = AllOfSuperModel() + if include_optional: + return AllOfSuperModel( + name = '' + ) + else: + return AllOfSuperModel( + ) + """ + + def testAllOfSuperModel(self): + """Test AllOfSuperModel""" + # 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-aiohttp/test/test_circular_all_of_ref.py b/samples/openapi3/client/petstore/python-aiohttp/test/test_circular_all_of_ref.py new file mode 100644 index 00000000000..767c758a733 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/test/test_circular_all_of_ref.py @@ -0,0 +1,60 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from petstore_api.models.circular_all_of_ref import CircularAllOfRef + +class TestCircularAllOfRef(unittest.TestCase): + """CircularAllOfRef unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> CircularAllOfRef: + """Test CircularAllOfRef + 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 `CircularAllOfRef` + """ + model = CircularAllOfRef() + if include_optional: + return CircularAllOfRef( + second_circular_all_of_ref = [ + petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef( + circular_all_of_ref = [ + petstore_api.models.circular_all_of_ref.CircularAllOfRef( + second_circular_all_of_ref = [ + petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef() + ], ) + ], ) + ], + name = '' + ) + else: + return CircularAllOfRef( + ) + """ + + def testCircularAllOfRef(self): + """Test CircularAllOfRef""" + # 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-aiohttp/test/test_second_circular_all_of_ref.py b/samples/openapi3/client/petstore/python-aiohttp/test/test_second_circular_all_of_ref.py new file mode 100644 index 00000000000..5e6d12f756b --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/test/test_second_circular_all_of_ref.py @@ -0,0 +1,57 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef + +class TestSecondCircularAllOfRef(unittest.TestCase): + """SecondCircularAllOfRef unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> SecondCircularAllOfRef: + """Test SecondCircularAllOfRef + 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 `SecondCircularAllOfRef` + """ + model = SecondCircularAllOfRef() + if include_optional: + return SecondCircularAllOfRef( + circular_all_of_ref = [ + petstore_api.models.circular_all_of_ref.CircularAllOfRef( + second_circular_all_of_ref = [ + petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef() + ], ) + ], + name = '' + ) + else: + return SecondCircularAllOfRef( + ) + """ + + def testSecondCircularAllOfRef(self): + """Test SecondCircularAllOfRef""" + # 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-pydantic-v1-aiohttp/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/.openapi-generator/FILES index 02d075573be..c9774b574f8 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/.openapi-generator/FILES @@ -7,6 +7,7 @@ docs/AdditionalPropertiesAnyType.md docs/AdditionalPropertiesClass.md docs/AdditionalPropertiesObject.md docs/AdditionalPropertiesWithDescriptionOnly.md +docs/AllOfSuperModel.md docs/AllOfWithSingleRef.md docs/Animal.md docs/AnotherFakeApi.md @@ -22,6 +23,7 @@ docs/Bathing.md docs/Capitalization.md docs/Cat.md docs/Category.md +docs/CircularAllOfRef.md docs/CircularReferenceModel.md docs/ClassModel.md docs/Client.md @@ -85,6 +87,7 @@ docs/PoopCleaning.md docs/PropertyMap.md docs/PropertyNameCollision.md docs/ReadOnlyFirst.md +docs/SecondCircularAllOfRef.md docs/SecondRef.md docs/SelfReferenceModel.md docs/SingleRefType.md @@ -125,6 +128,7 @@ petstore_api/models/additional_properties_any_type.py petstore_api/models/additional_properties_class.py petstore_api/models/additional_properties_object.py petstore_api/models/additional_properties_with_description_only.py +petstore_api/models/all_of_super_model.py petstore_api/models/all_of_with_single_ref.py petstore_api/models/animal.py petstore_api/models/any_of_color.py @@ -139,6 +143,7 @@ petstore_api/models/bathing.py petstore_api/models/capitalization.py petstore_api/models/cat.py petstore_api/models/category.py +petstore_api/models/circular_all_of_ref.py petstore_api/models/circular_reference_model.py petstore_api/models/class_model.py petstore_api/models/client.py @@ -197,6 +202,7 @@ petstore_api/models/poop_cleaning.py petstore_api/models/property_map.py petstore_api/models/property_name_collision.py petstore_api/models/read_only_first.py +petstore_api/models/second_circular_all_of_ref.py petstore_api/models/second_ref.py petstore_api/models/self_reference_model.py petstore_api/models/single_ref_type.py diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md index dea9ef0b85e..55e4f81dc29 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md @@ -155,6 +155,7 @@ Class | Method | HTTP request | Description - [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) - [AdditionalPropertiesObject](docs/AdditionalPropertiesObject.md) - [AdditionalPropertiesWithDescriptionOnly](docs/AdditionalPropertiesWithDescriptionOnly.md) + - [AllOfSuperModel](docs/AllOfSuperModel.md) - [AllOfWithSingleRef](docs/AllOfWithSingleRef.md) - [Animal](docs/Animal.md) - [AnyOfColor](docs/AnyOfColor.md) @@ -169,6 +170,7 @@ Class | Method | HTTP request | Description - [Capitalization](docs/Capitalization.md) - [Cat](docs/Cat.md) - [Category](docs/Category.md) + - [CircularAllOfRef](docs/CircularAllOfRef.md) - [CircularReferenceModel](docs/CircularReferenceModel.md) - [ClassModel](docs/ClassModel.md) - [Client](docs/Client.md) @@ -227,6 +229,7 @@ Class | Method | HTTP request | Description - [PropertyMap](docs/PropertyMap.md) - [PropertyNameCollision](docs/PropertyNameCollision.md) - [ReadOnlyFirst](docs/ReadOnlyFirst.md) + - [SecondCircularAllOfRef](docs/SecondCircularAllOfRef.md) - [SecondRef](docs/SecondRef.md) - [SelfReferenceModel](docs/SelfReferenceModel.md) - [SingleRefType](docs/SingleRefType.md) diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/AllOfSuperModel.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/AllOfSuperModel.md new file mode 100644 index 00000000000..0e8a9bacf0e --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/AllOfSuperModel.md @@ -0,0 +1,28 @@ +# AllOfSuperModel + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **str** | | [optional] + +## Example + +```python +from petstore_api.models.all_of_super_model import AllOfSuperModel + +# TODO update the JSON string below +json = "{}" +# create an instance of AllOfSuperModel from a JSON string +all_of_super_model_instance = AllOfSuperModel.from_json(json) +# print the JSON string representation of the object +print AllOfSuperModel.to_json() + +# convert the object into a dict +all_of_super_model_dict = all_of_super_model_instance.to_dict() +# create an instance of AllOfSuperModel from a dict +all_of_super_model_form_dict = all_of_super_model.from_dict(all_of_super_model_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-pydantic-v1-aiohttp/docs/CircularAllOfRef.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/CircularAllOfRef.md new file mode 100644 index 00000000000..d4c78e1f402 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/CircularAllOfRef.md @@ -0,0 +1,29 @@ +# CircularAllOfRef + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **str** | | [optional] +**second_circular_all_of_ref** | [**List[SecondCircularAllOfRef]**](SecondCircularAllOfRef.md) | | [optional] + +## Example + +```python +from petstore_api.models.circular_all_of_ref import CircularAllOfRef + +# TODO update the JSON string below +json = "{}" +# create an instance of CircularAllOfRef from a JSON string +circular_all_of_ref_instance = CircularAllOfRef.from_json(json) +# print the JSON string representation of the object +print CircularAllOfRef.to_json() + +# convert the object into a dict +circular_all_of_ref_dict = circular_all_of_ref_instance.to_dict() +# create an instance of CircularAllOfRef from a dict +circular_all_of_ref_form_dict = circular_all_of_ref.from_dict(circular_all_of_ref_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-pydantic-v1-aiohttp/docs/SecondCircularAllOfRef.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/SecondCircularAllOfRef.md new file mode 100644 index 00000000000..4460634382a --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/SecondCircularAllOfRef.md @@ -0,0 +1,29 @@ +# SecondCircularAllOfRef + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **str** | | [optional] +**circular_all_of_ref** | [**List[CircularAllOfRef]**](CircularAllOfRef.md) | | [optional] + +## Example + +```python +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef + +# TODO update the JSON string below +json = "{}" +# create an instance of SecondCircularAllOfRef from a JSON string +second_circular_all_of_ref_instance = SecondCircularAllOfRef.from_json(json) +# print the JSON string representation of the object +print SecondCircularAllOfRef.to_json() + +# convert the object into a dict +second_circular_all_of_ref_dict = second_circular_all_of_ref_instance.to_dict() +# create an instance of SecondCircularAllOfRef from a dict +second_circular_all_of_ref_form_dict = second_circular_all_of_ref.from_dict(second_circular_all_of_ref_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-pydantic-v1-aiohttp/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/__init__.py index 0e8b20ea6d7..daedab928cf 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/__init__.py @@ -43,6 +43,7 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert from petstore_api.models.additional_properties_class import AdditionalPropertiesClass from petstore_api.models.additional_properties_object import AdditionalPropertiesObject from petstore_api.models.additional_properties_with_description_only import AdditionalPropertiesWithDescriptionOnly +from petstore_api.models.all_of_super_model import AllOfSuperModel from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef from petstore_api.models.animal import Animal from petstore_api.models.any_of_color import AnyOfColor @@ -57,6 +58,7 @@ from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization from petstore_api.models.cat import Cat from petstore_api.models.category import Category +from petstore_api.models.circular_all_of_ref import CircularAllOfRef from petstore_api.models.circular_reference_model import CircularReferenceModel from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client @@ -115,6 +117,7 @@ from petstore_api.models.poop_cleaning import PoopCleaning from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef from petstore_api.models.second_ref import SecondRef from petstore_api.models.self_reference_model import SelfReferenceModel from petstore_api.models.single_ref_type import SingleRefType diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/__init__.py index 84aaefdf30c..92d7dc877f2 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/__init__.py @@ -18,6 +18,7 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert from petstore_api.models.additional_properties_class import AdditionalPropertiesClass from petstore_api.models.additional_properties_object import AdditionalPropertiesObject from petstore_api.models.additional_properties_with_description_only import AdditionalPropertiesWithDescriptionOnly +from petstore_api.models.all_of_super_model import AllOfSuperModel from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef from petstore_api.models.animal import Animal from petstore_api.models.any_of_color import AnyOfColor @@ -32,6 +33,7 @@ from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization from petstore_api.models.cat import Cat from petstore_api.models.category import Category +from petstore_api.models.circular_all_of_ref import CircularAllOfRef from petstore_api.models.circular_reference_model import CircularReferenceModel from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client @@ -90,6 +92,7 @@ from petstore_api.models.poop_cleaning import PoopCleaning from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef from petstore_api.models.second_ref import SecondRef from petstore_api.models.self_reference_model import SelfReferenceModel from petstore_api.models.single_ref_type import SingleRefType diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/all_of_super_model.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/all_of_super_model.py new file mode 100644 index 00000000000..88fdc0e2011 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/all_of_super_model.py @@ -0,0 +1,71 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import Optional +from pydantic import BaseModel, Field, StrictStr + +class AllOfSuperModel(BaseModel): + """ + AllOfSuperModel + """ + name: Optional[StrictStr] = Field(default=None, alias="_name") + __properties = ["_name"] + + 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) -> AllOfSuperModel: + """Create an instance of AllOfSuperModel 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) -> AllOfSuperModel: + """Create an instance of AllOfSuperModel from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return AllOfSuperModel.parse_obj(obj) + + _obj = AllOfSuperModel.parse_obj({ + "name": obj.get("_name") + }) + return _obj + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/circular_all_of_ref.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/circular_all_of_ref.py new file mode 100644 index 00000000000..9177641a136 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/circular_all_of_ref.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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import List, Optional +from pydantic import BaseModel, Field, StrictStr, conlist + +class CircularAllOfRef(BaseModel): + """ + CircularAllOfRef + """ + name: Optional[StrictStr] = Field(default=None, alias="_name") + second_circular_all_of_ref: Optional[conlist(SecondCircularAllOfRef)] = Field(default=None, alias="secondCircularAllOfRef") + __properties = ["_name", "secondCircularAllOfRef"] + + 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) -> CircularAllOfRef: + """Create an instance of CircularAllOfRef 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) + # override the default output from pydantic by calling `to_dict()` of each item in second_circular_all_of_ref (list) + _items = [] + if self.second_circular_all_of_ref: + for _item in self.second_circular_all_of_ref: + if _item: + _items.append(_item.to_dict()) + _dict['secondCircularAllOfRef'] = _items + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> CircularAllOfRef: + """Create an instance of CircularAllOfRef from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return CircularAllOfRef.parse_obj(obj) + + _obj = CircularAllOfRef.parse_obj({ + "name": obj.get("_name"), + "second_circular_all_of_ref": [SecondCircularAllOfRef.from_dict(_item) for _item in obj.get("secondCircularAllOfRef")] if obj.get("secondCircularAllOfRef") is not None else None + }) + return _obj + +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef +CircularAllOfRef.update_forward_refs() + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/second_circular_all_of_ref.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/second_circular_all_of_ref.py new file mode 100644 index 00000000000..2d000534484 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/second_circular_all_of_ref.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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import List, Optional +from pydantic import BaseModel, Field, StrictStr, conlist + +class SecondCircularAllOfRef(BaseModel): + """ + SecondCircularAllOfRef + """ + name: Optional[StrictStr] = Field(default=None, alias="_name") + circular_all_of_ref: Optional[conlist(CircularAllOfRef)] = Field(default=None, alias="circularAllOfRef") + __properties = ["_name", "circularAllOfRef"] + + 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) -> SecondCircularAllOfRef: + """Create an instance of SecondCircularAllOfRef 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) + # override the default output from pydantic by calling `to_dict()` of each item in circular_all_of_ref (list) + _items = [] + if self.circular_all_of_ref: + for _item in self.circular_all_of_ref: + if _item: + _items.append(_item.to_dict()) + _dict['circularAllOfRef'] = _items + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> SecondCircularAllOfRef: + """Create an instance of SecondCircularAllOfRef from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return SecondCircularAllOfRef.parse_obj(obj) + + _obj = SecondCircularAllOfRef.parse_obj({ + "name": obj.get("_name"), + "circular_all_of_ref": [CircularAllOfRef.from_dict(_item) for _item in obj.get("circularAllOfRef")] if obj.get("circularAllOfRef") is not None else None + }) + return _obj + +from petstore_api.models.circular_all_of_ref import CircularAllOfRef +SecondCircularAllOfRef.update_forward_refs() + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_all_of_super_model.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_all_of_super_model.py new file mode 100644 index 00000000000..31eeafdb0cf --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_all_of_super_model.py @@ -0,0 +1,52 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.all_of_super_model import AllOfSuperModel # noqa: E501 + +class TestAllOfSuperModel(unittest.TestCase): + """AllOfSuperModel unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> AllOfSuperModel: + """Test AllOfSuperModel + 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 `AllOfSuperModel` + """ + model = AllOfSuperModel() # noqa: E501 + if include_optional: + return AllOfSuperModel( + name = '' + ) + else: + return AllOfSuperModel( + ) + """ + + def testAllOfSuperModel(self): + """Test AllOfSuperModel""" + # 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-pydantic-v1-aiohttp/test/test_circular_all_of_ref.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_circular_all_of_ref.py new file mode 100644 index 00000000000..f72aa632ba8 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_circular_all_of_ref.py @@ -0,0 +1,61 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.circular_all_of_ref import CircularAllOfRef # noqa: E501 + +class TestCircularAllOfRef(unittest.TestCase): + """CircularAllOfRef unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> CircularAllOfRef: + """Test CircularAllOfRef + 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 `CircularAllOfRef` + """ + model = CircularAllOfRef() # noqa: E501 + if include_optional: + return CircularAllOfRef( + second_circular_all_of_ref = [ + petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef( + circular_all_of_ref = [ + petstore_api.models.circular_all_of_ref.CircularAllOfRef( + second_circular_all_of_ref = [ + petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef() + ], ) + ], ) + ], + name = '' + ) + else: + return CircularAllOfRef( + ) + """ + + def testCircularAllOfRef(self): + """Test CircularAllOfRef""" + # 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-pydantic-v1-aiohttp/test/test_second_circular_all_of_ref.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_second_circular_all_of_ref.py new file mode 100644 index 00000000000..3b9a26f72d8 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_second_circular_all_of_ref.py @@ -0,0 +1,58 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef # noqa: E501 + +class TestSecondCircularAllOfRef(unittest.TestCase): + """SecondCircularAllOfRef unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> SecondCircularAllOfRef: + """Test SecondCircularAllOfRef + 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 `SecondCircularAllOfRef` + """ + model = SecondCircularAllOfRef() # noqa: E501 + if include_optional: + return SecondCircularAllOfRef( + circular_all_of_ref = [ + petstore_api.models.circular_all_of_ref.CircularAllOfRef( + second_circular_all_of_ref = [ + petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef() + ], ) + ], + name = '' + ) + else: + return SecondCircularAllOfRef( + ) + """ + + def testSecondCircularAllOfRef(self): + """Test SecondCircularAllOfRef""" + # 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-pydantic-v1/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES index 02d075573be..c9774b574f8 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES @@ -7,6 +7,7 @@ docs/AdditionalPropertiesAnyType.md docs/AdditionalPropertiesClass.md docs/AdditionalPropertiesObject.md docs/AdditionalPropertiesWithDescriptionOnly.md +docs/AllOfSuperModel.md docs/AllOfWithSingleRef.md docs/Animal.md docs/AnotherFakeApi.md @@ -22,6 +23,7 @@ docs/Bathing.md docs/Capitalization.md docs/Cat.md docs/Category.md +docs/CircularAllOfRef.md docs/CircularReferenceModel.md docs/ClassModel.md docs/Client.md @@ -85,6 +87,7 @@ docs/PoopCleaning.md docs/PropertyMap.md docs/PropertyNameCollision.md docs/ReadOnlyFirst.md +docs/SecondCircularAllOfRef.md docs/SecondRef.md docs/SelfReferenceModel.md docs/SingleRefType.md @@ -125,6 +128,7 @@ petstore_api/models/additional_properties_any_type.py petstore_api/models/additional_properties_class.py petstore_api/models/additional_properties_object.py petstore_api/models/additional_properties_with_description_only.py +petstore_api/models/all_of_super_model.py petstore_api/models/all_of_with_single_ref.py petstore_api/models/animal.py petstore_api/models/any_of_color.py @@ -139,6 +143,7 @@ petstore_api/models/bathing.py petstore_api/models/capitalization.py petstore_api/models/cat.py petstore_api/models/category.py +petstore_api/models/circular_all_of_ref.py petstore_api/models/circular_reference_model.py petstore_api/models/class_model.py petstore_api/models/client.py @@ -197,6 +202,7 @@ petstore_api/models/poop_cleaning.py petstore_api/models/property_map.py petstore_api/models/property_name_collision.py petstore_api/models/read_only_first.py +petstore_api/models/second_circular_all_of_ref.py petstore_api/models/second_ref.py petstore_api/models/self_reference_model.py petstore_api/models/single_ref_type.py diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/README.md b/samples/openapi3/client/petstore/python-pydantic-v1/README.md index c1218afcdfe..33a188dcb5f 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/README.md +++ b/samples/openapi3/client/petstore/python-pydantic-v1/README.md @@ -155,6 +155,7 @@ Class | Method | HTTP request | Description - [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) - [AdditionalPropertiesObject](docs/AdditionalPropertiesObject.md) - [AdditionalPropertiesWithDescriptionOnly](docs/AdditionalPropertiesWithDescriptionOnly.md) + - [AllOfSuperModel](docs/AllOfSuperModel.md) - [AllOfWithSingleRef](docs/AllOfWithSingleRef.md) - [Animal](docs/Animal.md) - [AnyOfColor](docs/AnyOfColor.md) @@ -169,6 +170,7 @@ Class | Method | HTTP request | Description - [Capitalization](docs/Capitalization.md) - [Cat](docs/Cat.md) - [Category](docs/Category.md) + - [CircularAllOfRef](docs/CircularAllOfRef.md) - [CircularReferenceModel](docs/CircularReferenceModel.md) - [ClassModel](docs/ClassModel.md) - [Client](docs/Client.md) @@ -227,6 +229,7 @@ Class | Method | HTTP request | Description - [PropertyMap](docs/PropertyMap.md) - [PropertyNameCollision](docs/PropertyNameCollision.md) - [ReadOnlyFirst](docs/ReadOnlyFirst.md) + - [SecondCircularAllOfRef](docs/SecondCircularAllOfRef.md) - [SecondRef](docs/SecondRef.md) - [SelfReferenceModel](docs/SelfReferenceModel.md) - [SingleRefType](docs/SingleRefType.md) diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/docs/AllOfSuperModel.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/AllOfSuperModel.md new file mode 100644 index 00000000000..0e8a9bacf0e --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/AllOfSuperModel.md @@ -0,0 +1,28 @@ +# AllOfSuperModel + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **str** | | [optional] + +## Example + +```python +from petstore_api.models.all_of_super_model import AllOfSuperModel + +# TODO update the JSON string below +json = "{}" +# create an instance of AllOfSuperModel from a JSON string +all_of_super_model_instance = AllOfSuperModel.from_json(json) +# print the JSON string representation of the object +print AllOfSuperModel.to_json() + +# convert the object into a dict +all_of_super_model_dict = all_of_super_model_instance.to_dict() +# create an instance of AllOfSuperModel from a dict +all_of_super_model_form_dict = all_of_super_model.from_dict(all_of_super_model_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-pydantic-v1/docs/CircularAllOfRef.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/CircularAllOfRef.md new file mode 100644 index 00000000000..d4c78e1f402 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/CircularAllOfRef.md @@ -0,0 +1,29 @@ +# CircularAllOfRef + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **str** | | [optional] +**second_circular_all_of_ref** | [**List[SecondCircularAllOfRef]**](SecondCircularAllOfRef.md) | | [optional] + +## Example + +```python +from petstore_api.models.circular_all_of_ref import CircularAllOfRef + +# TODO update the JSON string below +json = "{}" +# create an instance of CircularAllOfRef from a JSON string +circular_all_of_ref_instance = CircularAllOfRef.from_json(json) +# print the JSON string representation of the object +print CircularAllOfRef.to_json() + +# convert the object into a dict +circular_all_of_ref_dict = circular_all_of_ref_instance.to_dict() +# create an instance of CircularAllOfRef from a dict +circular_all_of_ref_form_dict = circular_all_of_ref.from_dict(circular_all_of_ref_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-pydantic-v1/docs/SecondCircularAllOfRef.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/SecondCircularAllOfRef.md new file mode 100644 index 00000000000..4460634382a --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/SecondCircularAllOfRef.md @@ -0,0 +1,29 @@ +# SecondCircularAllOfRef + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **str** | | [optional] +**circular_all_of_ref** | [**List[CircularAllOfRef]**](CircularAllOfRef.md) | | [optional] + +## Example + +```python +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef + +# TODO update the JSON string below +json = "{}" +# create an instance of SecondCircularAllOfRef from a JSON string +second_circular_all_of_ref_instance = SecondCircularAllOfRef.from_json(json) +# print the JSON string representation of the object +print SecondCircularAllOfRef.to_json() + +# convert the object into a dict +second_circular_all_of_ref_dict = second_circular_all_of_ref_instance.to_dict() +# create an instance of SecondCircularAllOfRef from a dict +second_circular_all_of_ref_form_dict = second_circular_all_of_ref.from_dict(second_circular_all_of_ref_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-pydantic-v1/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/__init__.py index 0e8b20ea6d7..daedab928cf 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/__init__.py @@ -43,6 +43,7 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert from petstore_api.models.additional_properties_class import AdditionalPropertiesClass from petstore_api.models.additional_properties_object import AdditionalPropertiesObject from petstore_api.models.additional_properties_with_description_only import AdditionalPropertiesWithDescriptionOnly +from petstore_api.models.all_of_super_model import AllOfSuperModel from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef from petstore_api.models.animal import Animal from petstore_api.models.any_of_color import AnyOfColor @@ -57,6 +58,7 @@ from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization from petstore_api.models.cat import Cat from petstore_api.models.category import Category +from petstore_api.models.circular_all_of_ref import CircularAllOfRef from petstore_api.models.circular_reference_model import CircularReferenceModel from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client @@ -115,6 +117,7 @@ from petstore_api.models.poop_cleaning import PoopCleaning from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef from petstore_api.models.second_ref import SecondRef from petstore_api.models.self_reference_model import SelfReferenceModel from petstore_api.models.single_ref_type import SingleRefType diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/__init__.py index 84aaefdf30c..92d7dc877f2 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/__init__.py @@ -18,6 +18,7 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert from petstore_api.models.additional_properties_class import AdditionalPropertiesClass from petstore_api.models.additional_properties_object import AdditionalPropertiesObject from petstore_api.models.additional_properties_with_description_only import AdditionalPropertiesWithDescriptionOnly +from petstore_api.models.all_of_super_model import AllOfSuperModel from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef from petstore_api.models.animal import Animal from petstore_api.models.any_of_color import AnyOfColor @@ -32,6 +33,7 @@ from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization from petstore_api.models.cat import Cat from petstore_api.models.category import Category +from petstore_api.models.circular_all_of_ref import CircularAllOfRef from petstore_api.models.circular_reference_model import CircularReferenceModel from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client @@ -90,6 +92,7 @@ from petstore_api.models.poop_cleaning import PoopCleaning from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef from petstore_api.models.second_ref import SecondRef from petstore_api.models.self_reference_model import SelfReferenceModel from petstore_api.models.single_ref_type import SingleRefType diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/all_of_super_model.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/all_of_super_model.py new file mode 100644 index 00000000000..77ab6c369b7 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/all_of_super_model.py @@ -0,0 +1,83 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import Any, Dict, Optional +from pydantic import BaseModel, Field, StrictStr + +class AllOfSuperModel(BaseModel): + """ + AllOfSuperModel + """ + name: Optional[StrictStr] = Field(default=None, alias="_name") + additional_properties: Dict[str, Any] = {} + __properties = ["_name"] + + 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) -> AllOfSuperModel: + """Create an instance of AllOfSuperModel 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) -> AllOfSuperModel: + """Create an instance of AllOfSuperModel from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return AllOfSuperModel.parse_obj(obj) + + _obj = AllOfSuperModel.parse_obj({ + "name": obj.get("_name") + }) + # 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-pydantic-v1/petstore_api/models/circular_all_of_ref.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/circular_all_of_ref.py new file mode 100644 index 00000000000..1ab1def59ac --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/circular_all_of_ref.py @@ -0,0 +1,94 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import Any, Dict, List, Optional +from pydantic import BaseModel, Field, StrictStr, conlist + +class CircularAllOfRef(BaseModel): + """ + CircularAllOfRef + """ + name: Optional[StrictStr] = Field(default=None, alias="_name") + second_circular_all_of_ref: Optional[conlist(SecondCircularAllOfRef)] = Field(default=None, alias="secondCircularAllOfRef") + additional_properties: Dict[str, Any] = {} + __properties = ["_name", "secondCircularAllOfRef"] + + 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) -> CircularAllOfRef: + """Create an instance of CircularAllOfRef 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) + # override the default output from pydantic by calling `to_dict()` of each item in second_circular_all_of_ref (list) + _items = [] + if self.second_circular_all_of_ref: + for _item in self.second_circular_all_of_ref: + if _item: + _items.append(_item.to_dict()) + _dict['secondCircularAllOfRef'] = _items + # 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) -> CircularAllOfRef: + """Create an instance of CircularAllOfRef from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return CircularAllOfRef.parse_obj(obj) + + _obj = CircularAllOfRef.parse_obj({ + "name": obj.get("_name"), + "second_circular_all_of_ref": [SecondCircularAllOfRef.from_dict(_item) for _item in obj.get("secondCircularAllOfRef")] if obj.get("secondCircularAllOfRef") is not None else None + }) + # 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 + +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef +CircularAllOfRef.update_forward_refs() + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/second_circular_all_of_ref.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/second_circular_all_of_ref.py new file mode 100644 index 00000000000..328df27a584 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/second_circular_all_of_ref.py @@ -0,0 +1,94 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import Any, Dict, List, Optional +from pydantic import BaseModel, Field, StrictStr, conlist + +class SecondCircularAllOfRef(BaseModel): + """ + SecondCircularAllOfRef + """ + name: Optional[StrictStr] = Field(default=None, alias="_name") + circular_all_of_ref: Optional[conlist(CircularAllOfRef)] = Field(default=None, alias="circularAllOfRef") + additional_properties: Dict[str, Any] = {} + __properties = ["_name", "circularAllOfRef"] + + 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) -> SecondCircularAllOfRef: + """Create an instance of SecondCircularAllOfRef 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) + # override the default output from pydantic by calling `to_dict()` of each item in circular_all_of_ref (list) + _items = [] + if self.circular_all_of_ref: + for _item in self.circular_all_of_ref: + if _item: + _items.append(_item.to_dict()) + _dict['circularAllOfRef'] = _items + # 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) -> SecondCircularAllOfRef: + """Create an instance of SecondCircularAllOfRef from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return SecondCircularAllOfRef.parse_obj(obj) + + _obj = SecondCircularAllOfRef.parse_obj({ + "name": obj.get("_name"), + "circular_all_of_ref": [CircularAllOfRef.from_dict(_item) for _item in obj.get("circularAllOfRef")] if obj.get("circularAllOfRef") is not None else None + }) + # 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 + +from petstore_api.models.circular_all_of_ref import CircularAllOfRef +SecondCircularAllOfRef.update_forward_refs() + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/test/test_all_of_super_model.py b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_all_of_super_model.py new file mode 100644 index 00000000000..31eeafdb0cf --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_all_of_super_model.py @@ -0,0 +1,52 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.all_of_super_model import AllOfSuperModel # noqa: E501 + +class TestAllOfSuperModel(unittest.TestCase): + """AllOfSuperModel unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> AllOfSuperModel: + """Test AllOfSuperModel + 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 `AllOfSuperModel` + """ + model = AllOfSuperModel() # noqa: E501 + if include_optional: + return AllOfSuperModel( + name = '' + ) + else: + return AllOfSuperModel( + ) + """ + + def testAllOfSuperModel(self): + """Test AllOfSuperModel""" + # 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-pydantic-v1/test/test_circular_all_of_ref.py b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_circular_all_of_ref.py new file mode 100644 index 00000000000..f72aa632ba8 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_circular_all_of_ref.py @@ -0,0 +1,61 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.circular_all_of_ref import CircularAllOfRef # noqa: E501 + +class TestCircularAllOfRef(unittest.TestCase): + """CircularAllOfRef unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> CircularAllOfRef: + """Test CircularAllOfRef + 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 `CircularAllOfRef` + """ + model = CircularAllOfRef() # noqa: E501 + if include_optional: + return CircularAllOfRef( + second_circular_all_of_ref = [ + petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef( + circular_all_of_ref = [ + petstore_api.models.circular_all_of_ref.CircularAllOfRef( + second_circular_all_of_ref = [ + petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef() + ], ) + ], ) + ], + name = '' + ) + else: + return CircularAllOfRef( + ) + """ + + def testCircularAllOfRef(self): + """Test CircularAllOfRef""" + # 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-pydantic-v1/test/test_second_circular_all_of_ref.py b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_second_circular_all_of_ref.py new file mode 100644 index 00000000000..3b9a26f72d8 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_second_circular_all_of_ref.py @@ -0,0 +1,58 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef # noqa: E501 + +class TestSecondCircularAllOfRef(unittest.TestCase): + """SecondCircularAllOfRef unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> SecondCircularAllOfRef: + """Test SecondCircularAllOfRef + 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 `SecondCircularAllOfRef` + """ + model = SecondCircularAllOfRef() # noqa: E501 + if include_optional: + return SecondCircularAllOfRef( + circular_all_of_ref = [ + petstore_api.models.circular_all_of_ref.CircularAllOfRef( + second_circular_all_of_ref = [ + petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef() + ], ) + ], + name = '' + ) + else: + return SecondCircularAllOfRef( + ) + """ + + def testSecondCircularAllOfRef(self): + """Test SecondCircularAllOfRef""" + # 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 208f26992a1..f7e65690c39 100755 --- a/samples/openapi3/client/petstore/python/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python/.openapi-generator/FILES @@ -7,6 +7,7 @@ docs/AdditionalPropertiesAnyType.md docs/AdditionalPropertiesClass.md docs/AdditionalPropertiesObject.md docs/AdditionalPropertiesWithDescriptionOnly.md +docs/AllOfSuperModel.md docs/AllOfWithSingleRef.md docs/Animal.md docs/AnotherFakeApi.md @@ -21,6 +22,7 @@ docs/Bathing.md docs/Capitalization.md docs/Cat.md docs/Category.md +docs/CircularAllOfRef.md docs/CircularReferenceModel.md docs/ClassModel.md docs/Client.md @@ -85,6 +87,7 @@ docs/PoopCleaning.md docs/PropertyMap.md docs/PropertyNameCollision.md docs/ReadOnlyFirst.md +docs/SecondCircularAllOfRef.md docs/SecondRef.md docs/SelfReferenceModel.md docs/SingleRefType.md @@ -125,6 +128,7 @@ petstore_api/models/additional_properties_any_type.py petstore_api/models/additional_properties_class.py petstore_api/models/additional_properties_object.py petstore_api/models/additional_properties_with_description_only.py +petstore_api/models/all_of_super_model.py petstore_api/models/all_of_with_single_ref.py petstore_api/models/animal.py petstore_api/models/any_of_color.py @@ -138,6 +142,7 @@ petstore_api/models/bathing.py petstore_api/models/capitalization.py petstore_api/models/cat.py petstore_api/models/category.py +petstore_api/models/circular_all_of_ref.py petstore_api/models/circular_reference_model.py petstore_api/models/class_model.py petstore_api/models/client.py @@ -197,6 +202,7 @@ petstore_api/models/poop_cleaning.py petstore_api/models/property_map.py petstore_api/models/property_name_collision.py petstore_api/models/read_only_first.py +petstore_api/models/second_circular_all_of_ref.py petstore_api/models/second_ref.py petstore_api/models/self_reference_model.py petstore_api/models/single_ref_type.py diff --git a/samples/openapi3/client/petstore/python/README.md b/samples/openapi3/client/petstore/python/README.md index 3c3fc878ce7..8d1dabef923 100755 --- a/samples/openapi3/client/petstore/python/README.md +++ b/samples/openapi3/client/petstore/python/README.md @@ -154,6 +154,7 @@ Class | Method | HTTP request | Description - [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) - [AdditionalPropertiesObject](docs/AdditionalPropertiesObject.md) - [AdditionalPropertiesWithDescriptionOnly](docs/AdditionalPropertiesWithDescriptionOnly.md) + - [AllOfSuperModel](docs/AllOfSuperModel.md) - [AllOfWithSingleRef](docs/AllOfWithSingleRef.md) - [Animal](docs/Animal.md) - [AnyOfColor](docs/AnyOfColor.md) @@ -167,6 +168,7 @@ Class | Method | HTTP request | Description - [Capitalization](docs/Capitalization.md) - [Cat](docs/Cat.md) - [Category](docs/Category.md) + - [CircularAllOfRef](docs/CircularAllOfRef.md) - [CircularReferenceModel](docs/CircularReferenceModel.md) - [ClassModel](docs/ClassModel.md) - [Client](docs/Client.md) @@ -226,6 +228,7 @@ Class | Method | HTTP request | Description - [PropertyMap](docs/PropertyMap.md) - [PropertyNameCollision](docs/PropertyNameCollision.md) - [ReadOnlyFirst](docs/ReadOnlyFirst.md) + - [SecondCircularAllOfRef](docs/SecondCircularAllOfRef.md) - [SecondRef](docs/SecondRef.md) - [SelfReferenceModel](docs/SelfReferenceModel.md) - [SingleRefType](docs/SingleRefType.md) diff --git a/samples/openapi3/client/petstore/python/docs/AllOfSuperModel.md b/samples/openapi3/client/petstore/python/docs/AllOfSuperModel.md new file mode 100644 index 00000000000..1262bd9dc51 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/AllOfSuperModel.md @@ -0,0 +1,29 @@ +# AllOfSuperModel + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **str** | | [optional] + +## Example + +```python +from petstore_api.models.all_of_super_model import AllOfSuperModel + +# TODO update the JSON string below +json = "{}" +# create an instance of AllOfSuperModel from a JSON string +all_of_super_model_instance = AllOfSuperModel.from_json(json) +# print the JSON string representation of the object +print(AllOfSuperModel.to_json()) + +# convert the object into a dict +all_of_super_model_dict = all_of_super_model_instance.to_dict() +# create an instance of AllOfSuperModel from a dict +all_of_super_model_form_dict = all_of_super_model.from_dict(all_of_super_model_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/docs/CircularAllOfRef.md b/samples/openapi3/client/petstore/python/docs/CircularAllOfRef.md new file mode 100644 index 00000000000..a00be37d4d1 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/CircularAllOfRef.md @@ -0,0 +1,30 @@ +# CircularAllOfRef + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **str** | | [optional] +**second_circular_all_of_ref** | [**List[SecondCircularAllOfRef]**](SecondCircularAllOfRef.md) | | [optional] + +## Example + +```python +from petstore_api.models.circular_all_of_ref import CircularAllOfRef + +# TODO update the JSON string below +json = "{}" +# create an instance of CircularAllOfRef from a JSON string +circular_all_of_ref_instance = CircularAllOfRef.from_json(json) +# print the JSON string representation of the object +print(CircularAllOfRef.to_json()) + +# convert the object into a dict +circular_all_of_ref_dict = circular_all_of_ref_instance.to_dict() +# create an instance of CircularAllOfRef from a dict +circular_all_of_ref_form_dict = circular_all_of_ref.from_dict(circular_all_of_ref_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/docs/SecondCircularAllOfRef.md b/samples/openapi3/client/petstore/python/docs/SecondCircularAllOfRef.md new file mode 100644 index 00000000000..eae28911ed2 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/SecondCircularAllOfRef.md @@ -0,0 +1,30 @@ +# SecondCircularAllOfRef + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **str** | | [optional] +**circular_all_of_ref** | [**List[CircularAllOfRef]**](CircularAllOfRef.md) | | [optional] + +## Example + +```python +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef + +# TODO update the JSON string below +json = "{}" +# create an instance of SecondCircularAllOfRef from a JSON string +second_circular_all_of_ref_instance = SecondCircularAllOfRef.from_json(json) +# print the JSON string representation of the object +print(SecondCircularAllOfRef.to_json()) + +# convert the object into a dict +second_circular_all_of_ref_dict = second_circular_all_of_ref_instance.to_dict() +# create an instance of SecondCircularAllOfRef from a dict +second_circular_all_of_ref_form_dict = second_circular_all_of_ref.from_dict(second_circular_all_of_ref_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 f0548eda859..1d2a609f13b 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/__init__.py @@ -43,6 +43,7 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert from petstore_api.models.additional_properties_class import AdditionalPropertiesClass from petstore_api.models.additional_properties_object import AdditionalPropertiesObject from petstore_api.models.additional_properties_with_description_only import AdditionalPropertiesWithDescriptionOnly +from petstore_api.models.all_of_super_model import AllOfSuperModel from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef from petstore_api.models.animal import Animal from petstore_api.models.any_of_color import AnyOfColor @@ -56,6 +57,7 @@ from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization from petstore_api.models.cat import Cat from petstore_api.models.category import Category +from petstore_api.models.circular_all_of_ref import CircularAllOfRef from petstore_api.models.circular_reference_model import CircularReferenceModel from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client @@ -115,6 +117,7 @@ from petstore_api.models.poop_cleaning import PoopCleaning from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef from petstore_api.models.second_ref import SecondRef from petstore_api.models.self_reference_model import SelfReferenceModel from petstore_api.models.single_ref_type import SingleRefType 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 421ad6fe846..efd9c939d21 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py @@ -18,6 +18,7 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert from petstore_api.models.additional_properties_class import AdditionalPropertiesClass from petstore_api.models.additional_properties_object import AdditionalPropertiesObject from petstore_api.models.additional_properties_with_description_only import AdditionalPropertiesWithDescriptionOnly +from petstore_api.models.all_of_super_model import AllOfSuperModel from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef from petstore_api.models.animal import Animal from petstore_api.models.any_of_color import AnyOfColor @@ -31,6 +32,7 @@ from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization from petstore_api.models.cat import Cat from petstore_api.models.category import Category +from petstore_api.models.circular_all_of_ref import CircularAllOfRef from petstore_api.models.circular_reference_model import CircularReferenceModel from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client @@ -90,6 +92,7 @@ from petstore_api.models.poop_cleaning import PoopCleaning from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef from petstore_api.models.second_ref import SecondRef from petstore_api.models.self_reference_model import SelfReferenceModel from petstore_api.models.single_ref_type import SingleRefType diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/all_of_super_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/all_of_super_model.py new file mode 100644 index 00000000000..b63bba1206a --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/all_of_super_model.py @@ -0,0 +1,100 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, Field, StrictStr +from typing import Any, ClassVar, Dict, List, Optional +from typing import Optional, Set +from typing_extensions import Self + +class AllOfSuperModel(BaseModel): + """ + AllOfSuperModel + """ # noqa: E501 + name: Optional[StrictStr] = Field(default=None, alias="_name") + additional_properties: Dict[str, Any] = {} + __properties: ClassVar[List[str]] = ["_name"] + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of AllOfSuperModel from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + * Fields in `self.additional_properties` are added to the output dict. + """ + excluded_fields: Set[str] = set([ + "additional_properties", + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + 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: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of AllOfSuperModel from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "_name": obj.get("_name") + }) + # 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/petstore_api/models/circular_all_of_ref.py b/samples/openapi3/client/petstore/python/petstore_api/models/circular_all_of_ref.py new file mode 100644 index 00000000000..fb2241d0dae --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/circular_all_of_ref.py @@ -0,0 +1,112 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, Field, StrictStr +from typing import Any, ClassVar, Dict, List, Optional +from typing import Optional, Set +from typing_extensions import Self + +class CircularAllOfRef(BaseModel): + """ + CircularAllOfRef + """ # noqa: E501 + name: Optional[StrictStr] = Field(default=None, alias="_name") + second_circular_all_of_ref: Optional[List[SecondCircularAllOfRef]] = Field(default=None, alias="secondCircularAllOfRef") + additional_properties: Dict[str, Any] = {} + __properties: ClassVar[List[str]] = ["_name", "secondCircularAllOfRef"] + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of CircularAllOfRef from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + * Fields in `self.additional_properties` are added to the output dict. + """ + excluded_fields: Set[str] = set([ + "additional_properties", + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # override the default output from pydantic by calling `to_dict()` of each item in second_circular_all_of_ref (list) + _items = [] + if self.second_circular_all_of_ref: + for _item in self.second_circular_all_of_ref: + if _item: + _items.append(_item.to_dict()) + _dict['secondCircularAllOfRef'] = _items + # 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: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of CircularAllOfRef from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "_name": obj.get("_name"), + "secondCircularAllOfRef": [SecondCircularAllOfRef.from_dict(_item) for _item in obj["secondCircularAllOfRef"]] if obj.get("secondCircularAllOfRef") is not None else None + }) + # 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 + +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef +# TODO: Rewrite to not use raise_errors +CircularAllOfRef.model_rebuild(raise_errors=False) + diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/second_circular_all_of_ref.py b/samples/openapi3/client/petstore/python/petstore_api/models/second_circular_all_of_ref.py new file mode 100644 index 00000000000..34d4dc24457 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/second_circular_all_of_ref.py @@ -0,0 +1,112 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, Field, StrictStr +from typing import Any, ClassVar, Dict, List, Optional +from typing import Optional, Set +from typing_extensions import Self + +class SecondCircularAllOfRef(BaseModel): + """ + SecondCircularAllOfRef + """ # noqa: E501 + name: Optional[StrictStr] = Field(default=None, alias="_name") + circular_all_of_ref: Optional[List[CircularAllOfRef]] = Field(default=None, alias="circularAllOfRef") + additional_properties: Dict[str, Any] = {} + __properties: ClassVar[List[str]] = ["_name", "circularAllOfRef"] + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of SecondCircularAllOfRef from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + * Fields in `self.additional_properties` are added to the output dict. + """ + excluded_fields: Set[str] = set([ + "additional_properties", + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # override the default output from pydantic by calling `to_dict()` of each item in circular_all_of_ref (list) + _items = [] + if self.circular_all_of_ref: + for _item in self.circular_all_of_ref: + if _item: + _items.append(_item.to_dict()) + _dict['circularAllOfRef'] = _items + # 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: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of SecondCircularAllOfRef from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "_name": obj.get("_name"), + "circularAllOfRef": [CircularAllOfRef.from_dict(_item) for _item in obj["circularAllOfRef"]] if obj.get("circularAllOfRef") is not None else None + }) + # 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 + +from petstore_api.models.circular_all_of_ref import CircularAllOfRef +# TODO: Rewrite to not use raise_errors +SecondCircularAllOfRef.model_rebuild(raise_errors=False) + diff --git a/samples/openapi3/client/petstore/python/test/test_all_of_super_model.py b/samples/openapi3/client/petstore/python/test/test_all_of_super_model.py new file mode 100644 index 00000000000..dfc6d444ba7 --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_all_of_super_model.py @@ -0,0 +1,51 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from petstore_api.models.all_of_super_model import AllOfSuperModel + +class TestAllOfSuperModel(unittest.TestCase): + """AllOfSuperModel unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> AllOfSuperModel: + """Test AllOfSuperModel + 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 `AllOfSuperModel` + """ + model = AllOfSuperModel() + if include_optional: + return AllOfSuperModel( + name = '' + ) + else: + return AllOfSuperModel( + ) + """ + + def testAllOfSuperModel(self): + """Test AllOfSuperModel""" + # 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/test/test_circular_all_of_ref.py b/samples/openapi3/client/petstore/python/test/test_circular_all_of_ref.py new file mode 100644 index 00000000000..767c758a733 --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_circular_all_of_ref.py @@ -0,0 +1,60 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from petstore_api.models.circular_all_of_ref import CircularAllOfRef + +class TestCircularAllOfRef(unittest.TestCase): + """CircularAllOfRef unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> CircularAllOfRef: + """Test CircularAllOfRef + 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 `CircularAllOfRef` + """ + model = CircularAllOfRef() + if include_optional: + return CircularAllOfRef( + second_circular_all_of_ref = [ + petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef( + circular_all_of_ref = [ + petstore_api.models.circular_all_of_ref.CircularAllOfRef( + second_circular_all_of_ref = [ + petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef() + ], ) + ], ) + ], + name = '' + ) + else: + return CircularAllOfRef( + ) + """ + + def testCircularAllOfRef(self): + """Test CircularAllOfRef""" + # 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/test/test_second_circular_all_of_ref.py b/samples/openapi3/client/petstore/python/test/test_second_circular_all_of_ref.py new file mode 100644 index 00000000000..5e6d12f756b --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_second_circular_all_of_ref.py @@ -0,0 +1,57 @@ +# 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: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef + +class TestSecondCircularAllOfRef(unittest.TestCase): + """SecondCircularAllOfRef unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> SecondCircularAllOfRef: + """Test SecondCircularAllOfRef + 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 `SecondCircularAllOfRef` + """ + model = SecondCircularAllOfRef() + if include_optional: + return SecondCircularAllOfRef( + circular_all_of_ref = [ + petstore_api.models.circular_all_of_ref.CircularAllOfRef( + second_circular_all_of_ref = [ + petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef() + ], ) + ], + name = '' + ) + else: + return SecondCircularAllOfRef( + ) + """ + + def testSecondCircularAllOfRef(self): + """Test SecondCircularAllOfRef""" + # 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 1d3c29e2f4a..f65d6274508 100644 --- a/samples/openapi3/client/petstore/python/tests/test_model.py +++ b/samples/openapi3/client/petstore/python/tests/test_model.py @@ -619,6 +619,16 @@ class ModelTests(unittest.TestCase): assert model is not None self.assertEqual(model.to_json(), '{"skill": "none", "type": "tiger", "info": {"name": "creature info"}}') + def test_allof_circular_imports(self): + # for issue 18271 + model_a = petstore_api.models.circular_all_of_ref.CircularAllOfRef.from_json('{"_name": "nameA", "second_circular_all_of_ref": {"name": "nameB"}}') + model_b = petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef.from_json('{"_name": "nameB", "circular_all_of_ref": {"name": "nameA"}}') + # shouldn't throw ImportError + assert model_a is not None + assert model_b is not None + self.assertEqual(model_a.to_json(), '{"_name": "nameA", "second_circular_all_of_ref": {"name": "nameB"}}') + self.assertEqual(model_b.to_json(), '{"_name": "nameB", "circular_all_of_ref": {"name": "nameA"}}') + class TestdditionalPropertiesAnyType(unittest.TestCase): def test_additional_properties(self):