diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonNextgenClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonNextgenClientCodegen.java index 376dc40786f..2685fde8dbb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonNextgenClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonNextgenClientCodegen.java @@ -64,6 +64,11 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements private String testFolder; + // map of set (model imports) + private HashMap> circularImports = new HashMap<>(); + // map of codegen models + private HashMap codegenModelMap = new HashMap<>(); + public PythonNextgenClientCodegen() { super(); @@ -404,6 +409,8 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements * @param typingImports typing imports * @param pydantic pydantic imports * @param datetimeImports datetime imports + * @param modelImports model imports + * @param classname class name * @return pydantic type * */ @@ -411,7 +418,8 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements Set typingImports, Set pydanticImports, Set datetimeImports, - Set modelImports) { + Set modelImports, + String classname) { if (cp == null) { // if codegen parameter (e.g. map/dict of undefined type) is null, default to string LOGGER.warn("Codegen property is null (e.g. map/dict of undefined type). Default to typing.Any."); @@ -432,11 +440,12 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements } pydanticImports.add("conlist"); return String.format(Locale.ROOT, "conlist(%s%s)", - getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports), + getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports, classname), constraints); } else if (cp.isMap) { typingImports.add("Dict"); - return String.format(Locale.ROOT, "Dict[str, %s]", getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports)); + return String.format(Locale.ROOT, "Dict[str, %s]", + getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports, classname)); } else if (cp.isString || cp.isBinary || cp.isByteArray) { if (cp.hasValidation) { List fieldCustomization = new ArrayList<>(); @@ -612,7 +621,7 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements CodegenMediaType cmt = contents.get(key); // TODO process the first one only at the moment if (cmt != null) - return getPydanticType(cmt.getSchema(), typingImports, pydanticImports, datetimeImports, modelImports); + return getPydanticType(cmt.getSchema(), typingImports, pydanticImports, datetimeImports, modelImports, classname); } throw new RuntimeException("Error! Failed to process getPydanticType when getting the content: " + cp); } else { @@ -627,6 +636,8 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements * @param typingImports typing imports * @param pydantic pydantic imports * @param datetimeImports datetime imports + * @param modelImports model imports + * @param classname class name * @return pydantic type * */ @@ -634,7 +645,8 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements Set typingImports, Set pydanticImports, Set datetimeImports, - Set modelImports) { + Set modelImports, + String classname) { if (cp == null) { // if codegen property (e.g. map/dict of undefined type) is null, default to string LOGGER.warn("Codegen property is null (e.g. map/dict of undefined type). Default to typing.Any."); @@ -674,11 +686,11 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements pydanticImports.add("conlist"); typingImports.add("List"); // for return type return String.format(Locale.ROOT, "conlist(%s%s)", - getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports), + getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports, classname), constraints); } else if (cp.isMap) { typingImports.add("Dict"); - return String.format(Locale.ROOT, "Dict[str, %s]", getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports)); + return String.format(Locale.ROOT, "Dict[str, %s]", getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports, classname)); } else if (cp.isString) { if (cp.hasValidation) { List fieldCustomization = new ArrayList<>(); @@ -846,10 +858,24 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements typingImports.add("Any"); return "Dict[str, Any]"; } else if (!cp.isPrimitiveType || cp.isModel) { // model - if (!cp.isCircularReference) { - // skip import if it's a circular reference + // skip import if it's a circular reference + if (classname == null) { + // for parameter model, import directly hasModelsToImport = true; modelImports.add(cp.dataType); + } else { + if (circularImports.containsKey(cp.dataType)) { + if (circularImports.get(cp.dataType).contains(classname)) { + // cp.dataType import map of set contains this model (classname), don't import + LOGGER.debug("Skipped importing {} in {} due to circular import.", cp.dataType, classname); + } else { + // not circular import, so ok to import it + hasModelsToImport = true; + modelImports.add(cp.dataType); + } + } else { + LOGGER.error("Failed to look up {} from the imports (map of set) of models.", cp.dataType); + } } return cp.dataType; } else { @@ -871,7 +897,7 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements List params = operation.allParams; for (CodegenParameter param : params) { - String typing = getPydanticType(param, typingImports, pydanticImports, datetimeImports, modelImports); + String typing = getPydanticType(param, typingImports, pydanticImports, datetimeImports, modelImports, null); List fields = new ArrayList<>(); String firstField = ""; @@ -923,7 +949,7 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements // update typing import for operation return type if (!StringUtils.isEmpty(operation.returnType)) { String typing = getPydanticType(operation.returnProperty, typingImports, - new TreeSet<>() /* skip pydantic import for return type */, datetimeImports, modelImports); + new TreeSet<>() /* skip pydantic import for return type */, datetimeImports, modelImports, null); } } @@ -983,6 +1009,18 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements @Override public Map postProcessAllModels(Map objs) { final Map processed = super.postProcessAllModels(objs); + + for (Map.Entry entry : objs.entrySet()) { + // create hash map of codegen model + CodegenModel cm = ModelUtils.getModelByName(entry.getKey(), objs); + codegenModelMap.put(cm.classname, ModelUtils.getModelByName(entry.getKey(), objs)); + } + + // create circular import + for (String m : codegenModelMap.keySet()) { + createImportMapOfSet(m, codegenModelMap); + } + for (Map.Entry entry : processed.entrySet()) { entry.setValue(postProcessModelsMap(entry.getValue())); } @@ -990,6 +1028,99 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements return processed; } + /** + * Update circularImports with the model name (key) and its imports gathered recursively + * + * @param modelName model name + * @param codegenModelMap a map of CodegenModel + */ + void createImportMapOfSet(String modelName, Map codegenModelMap) { + HashSet imports = new HashSet<>(); + circularImports.put(modelName, imports); + + CodegenModel cm = codegenModelMap.get(modelName); + + if (cm == null) { + LOGGER.warn("Failed to lookup model in createImportMapOfSet: " + modelName); + return; + } + + List codegenProperties = null; + if (cm.oneOf != null && !cm.oneOf.isEmpty()) { // oneOf + codegenProperties = cm.getComposedSchemas().getOneOf(); + } else if (cm.anyOf != null && !cm.anyOf.isEmpty()) { // anyOF + codegenProperties = cm.getComposedSchemas().getAnyOf(); + } else { // typical model + codegenProperties = cm.vars; + } + + for (CodegenProperty cp : codegenProperties) { + String modelNameFromDataType = getModelNameFromDataType(cp); + if (modelNameFromDataType != null) { // model + imports.add(modelNameFromDataType); // update import + // go through properties or sub-schemas of the model recursively to identify more (model) import if any + updateImportsFromCodegenModel(modelNameFromDataType, codegenModelMap.get(modelNameFromDataType), imports); + } + } + } + + /** + * Update set of imports from codegen model recursivly + * + * @param modelName model name + * @param cm codegen model + * @param imports set of imports + */ + public void updateImportsFromCodegenModel(String modelName, CodegenModel cm, Set imports) { + if (cm == null) { + LOGGER.warn("Failed to lookup model in createImportMapOfSet " + modelName); + return; + } + + List codegenProperties = null; + if (cm.oneOf != null && !cm.oneOf.isEmpty()) { // oneOfValidationError + codegenProperties = cm.getComposedSchemas().getOneOf(); + } else if (cm.anyOf != null && !cm.anyOf.isEmpty()) { // anyOF + codegenProperties = cm.getComposedSchemas().getAnyOf(); + } else { // typical model + codegenProperties = cm.vars; + } + + for (CodegenProperty cp : codegenProperties) { + String modelNameFromDataType = getModelNameFromDataType(cp); + if (modelNameFromDataType != null) { // model + if (modelName.equals(modelNameFromDataType)) { // self referencing + continue; + } else if (imports.contains(modelNameFromDataType)) { // circular import + continue; + } else { + imports.add(modelNameFromDataType); // update import + // go through properties of the model recursively to identify more (model) import if any + updateImportsFromCodegenModel(modelNameFromDataType, codegenModelMap.get(modelNameFromDataType), imports); + } + } + } + } + + /** + * Returns the model name (if any) from data type of codegen property. + * Returns null if it's not a model. + * + * @param cp Codegen property + * @return model name + */ + private String getModelNameFromDataType(CodegenProperty cp) { + if (cp.isArray) { + return getModelNameFromDataType(cp.items); + } else if (cp.isMap) { + return getModelNameFromDataType(cp.items); + } else if (!cp.isPrimitiveType || cp.isModel) { + return cp.dataType; + } else { + return null; + } + } + private ModelsMap postProcessModelsMap(ModelsMap objs) { // process enum in models objs = postProcessModelsEnum(objs); @@ -1044,7 +1175,7 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements //loop through properties/schemas to set up typing, pydantic for (CodegenProperty cp : codegenProperties) { - String typing = getPydanticType(cp, typingImports, pydanticImports, datetimeImports, modelImports); + String typing = getPydanticType(cp, typingImports, pydanticImports, datetimeImports, modelImports, model.classname); List fields = new ArrayList<>(); String firstField = ""; 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 c8e80e14301..9dedcf30521 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 @@ -2126,3 +2126,24 @@ components: properties: optionalDict: $ref: "#/components/schemas/DictWithAdditionalProperties" + Circular-Reference-Model: + type: object + properties: + size: + type: integer + nested: + $ref: '#/components/schemas/FirstRef' + FirstRef: + type: object + properties: + category: + type: string + self_ref: + $ref: '#/components/schemas/SecondRef' + SecondRef: + type: object + properties: + category: + type: string + circular_ref: + $ref: '#/components/schemas/Circular-Reference-Model' diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-nextgen-aiohttp/.openapi-generator/FILES index 5d9cf72b28b..970be2c4e66 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/.openapi-generator/FILES @@ -18,6 +18,7 @@ docs/Capitalization.md docs/Cat.md docs/CatAllOf.md docs/Category.md +docs/CircularReferenceModel.md docs/ClassModel.md docs/Client.md docs/Color.md @@ -34,6 +35,7 @@ docs/FakeApi.md docs/FakeClassnameTags123Api.md docs/File.md docs/FileSchemaTestClass.md +docs/FirstRef.md docs/Foo.md docs/FooGetDefaultResponse.md docs/FormatTest.md @@ -61,6 +63,7 @@ docs/Pet.md docs/PetApi.md docs/Pig.md docs/ReadOnlyFirst.md +docs/SecondRef.md docs/SelfReferenceModel.md docs/SingleRefType.md docs/SpecialCharacterEnum.md @@ -99,6 +102,7 @@ petstore_api/models/capitalization.py petstore_api/models/cat.py petstore_api/models/cat_all_of.py petstore_api/models/category.py +petstore_api/models/circular_reference_model.py petstore_api/models/class_model.py petstore_api/models/client.py petstore_api/models/color.py @@ -112,6 +116,7 @@ petstore_api/models/enum_class.py petstore_api/models/enum_test.py petstore_api/models/file.py petstore_api/models/file_schema_test_class.py +petstore_api/models/first_ref.py petstore_api/models/foo.py petstore_api/models/foo_get_default_response.py petstore_api/models/format_test.py @@ -138,6 +143,7 @@ petstore_api/models/parent_with_optional_dict.py petstore_api/models/pet.py petstore_api/models/pig.py petstore_api/models/read_only_first.py +petstore_api/models/second_ref.py petstore_api/models/self_reference_model.py petstore_api/models/single_ref_type.py petstore_api/models/special_character_enum.py diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/README.md b/samples/openapi3/client/petstore/python-nextgen-aiohttp/README.md index 9a72457e234..e26d9f33e89 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/README.md @@ -146,6 +146,7 @@ Class | Method | HTTP request | Description - [Cat](docs/Cat.md) - [CatAllOf](docs/CatAllOf.md) - [Category](docs/Category.md) + - [CircularReferenceModel](docs/CircularReferenceModel.md) - [ClassModel](docs/ClassModel.md) - [Client](docs/Client.md) - [Color](docs/Color.md) @@ -159,6 +160,7 @@ Class | Method | HTTP request | Description - [EnumTest](docs/EnumTest.md) - [File](docs/File.md) - [FileSchemaTestClass](docs/FileSchemaTestClass.md) + - [FirstRef](docs/FirstRef.md) - [Foo](docs/Foo.md) - [FooGetDefaultResponse](docs/FooGetDefaultResponse.md) - [FormatTest](docs/FormatTest.md) @@ -185,6 +187,7 @@ Class | Method | HTTP request | Description - [Pet](docs/Pet.md) - [Pig](docs/Pig.md) - [ReadOnlyFirst](docs/ReadOnlyFirst.md) + - [SecondRef](docs/SecondRef.md) - [SelfReferenceModel](docs/SelfReferenceModel.md) - [SingleRefType](docs/SingleRefType.md) - [SpecialCharacterEnum](docs/SpecialCharacterEnum.md) diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/CircularReferenceModel.md b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/CircularReferenceModel.md new file mode 100644 index 00000000000..d5e97934d2b --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/CircularReferenceModel.md @@ -0,0 +1,29 @@ +# CircularReferenceModel + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**size** | **int** | | [optional] +**nested** | [**FirstRef**](FirstRef.md) | | [optional] + +## Example + +```python +from petstore_api.models.circular_reference_model import CircularReferenceModel + +# TODO update the JSON string below +json = "{}" +# create an instance of CircularReferenceModel from a JSON string +circular_reference_model_instance = CircularReferenceModel.from_json(json) +# print the JSON string representation of the object +print CircularReferenceModel.to_json() + +# convert the object into a dict +circular_reference_model_dict = circular_reference_model_instance.to_dict() +# create an instance of CircularReferenceModel from a dict +circular_reference_model_form_dict = circular_reference_model.from_dict(circular_reference_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-nextgen-aiohttp/docs/FirstRef.md b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/FirstRef.md new file mode 100644 index 00000000000..b5e7ab766b4 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/FirstRef.md @@ -0,0 +1,29 @@ +# FirstRef + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**category** | **str** | | [optional] +**self_ref** | [**SecondRef**](SecondRef.md) | | [optional] + +## Example + +```python +from petstore_api.models.first_ref import FirstRef + +# TODO update the JSON string below +json = "{}" +# create an instance of FirstRef from a JSON string +first_ref_instance = FirstRef.from_json(json) +# print the JSON string representation of the object +print FirstRef.to_json() + +# convert the object into a dict +first_ref_dict = first_ref_instance.to_dict() +# create an instance of FirstRef from a dict +first_ref_form_dict = first_ref.from_dict(first_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-nextgen-aiohttp/docs/SecondRef.md b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/SecondRef.md new file mode 100644 index 00000000000..e6fb1e2d4f7 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/SecondRef.md @@ -0,0 +1,29 @@ +# SecondRef + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**category** | **str** | | [optional] +**circular_ref** | [**CircularReferenceModel**](CircularReferenceModel.md) | | [optional] + +## Example + +```python +from petstore_api.models.second_ref import SecondRef + +# TODO update the JSON string below +json = "{}" +# create an instance of SecondRef from a JSON string +second_ref_instance = SecondRef.from_json(json) +# print the JSON string representation of the object +print SecondRef.to_json() + +# convert the object into a dict +second_ref_dict = second_ref_instance.to_dict() +# create an instance of SecondRef from a dict +second_ref_form_dict = second_ref.from_dict(second_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-nextgen-aiohttp/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/__init__.py index 31cf58fec33..417db16491d 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/__init__.py @@ -49,6 +49,7 @@ from petstore_api.models.capitalization import Capitalization from petstore_api.models.cat import Cat from petstore_api.models.cat_all_of import CatAllOf from petstore_api.models.category import Category +from petstore_api.models.circular_reference_model import CircularReferenceModel from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client from petstore_api.models.color import Color @@ -62,6 +63,7 @@ from petstore_api.models.enum_class import EnumClass from petstore_api.models.enum_test import EnumTest from petstore_api.models.file import File from petstore_api.models.file_schema_test_class import FileSchemaTestClass +from petstore_api.models.first_ref import FirstRef from petstore_api.models.foo import Foo from petstore_api.models.foo_get_default_response import FooGetDefaultResponse from petstore_api.models.format_test import FormatTest @@ -88,6 +90,7 @@ from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig from petstore_api.models.read_only_first import ReadOnlyFirst +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 from petstore_api.models.special_character_enum import SpecialCharacterEnum diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/__init__.py index b6cd78aa71c..212f2096311 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/__init__.py @@ -28,6 +28,7 @@ from petstore_api.models.capitalization import Capitalization from petstore_api.models.cat import Cat from petstore_api.models.cat_all_of import CatAllOf from petstore_api.models.category import Category +from petstore_api.models.circular_reference_model import CircularReferenceModel from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client from petstore_api.models.color import Color @@ -41,6 +42,7 @@ from petstore_api.models.enum_class import EnumClass from petstore_api.models.enum_test import EnumTest from petstore_api.models.file import File from petstore_api.models.file_schema_test_class import FileSchemaTestClass +from petstore_api.models.first_ref import FirstRef from petstore_api.models.foo import Foo from petstore_api.models.foo_get_default_response import FooGetDefaultResponse from petstore_api.models.format_test import FormatTest @@ -67,6 +69,7 @@ from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig from petstore_api.models.read_only_first import ReadOnlyFirst +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 from petstore_api.models.special_character_enum import SpecialCharacterEnum diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/circular_reference_model.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/circular_reference_model.py new file mode 100644 index 00000000000..3a03dad4ddd --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/circular_reference_model.py @@ -0,0 +1,75 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import annotations +from inspect import getfullargspec +import pprint +import re # noqa: F401 +import json + + +from typing import Optional +from pydantic import BaseModel, StrictInt + +class CircularReferenceModel(BaseModel): + """ + CircularReferenceModel + """ + size: Optional[StrictInt] = None + nested: Optional[FirstRef] = None + __properties = ["size", "nested"] + + class Config: + 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) -> CircularReferenceModel: + """Create an instance of CircularReferenceModel 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 nested + if self.nested: + _dict['nested'] = self.nested.to_dict() + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> CircularReferenceModel: + """Create an instance of CircularReferenceModel from a dict""" + if obj is None: + return None + + if type(obj) is not dict: + return CircularReferenceModel.parse_obj(obj) + + _obj = CircularReferenceModel.parse_obj({ + "size": obj.get("size"), + "nested": FirstRef.from_dict(obj.get("nested")) if obj.get("nested") is not None else None + }) + return _obj + diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/first_ref.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/first_ref.py new file mode 100644 index 00000000000..0856f9b0daf --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/first_ref.py @@ -0,0 +1,75 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import annotations +from inspect import getfullargspec +import pprint +import re # noqa: F401 +import json + + +from typing import Optional +from pydantic import BaseModel, StrictStr + +class FirstRef(BaseModel): + """ + FirstRef + """ + category: Optional[StrictStr] = None + self_ref: Optional[SecondRef] = None + __properties = ["category", "self_ref"] + + class Config: + 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) -> FirstRef: + """Create an instance of FirstRef 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 self_ref + if self.self_ref: + _dict['self_ref'] = self.self_ref.to_dict() + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> FirstRef: + """Create an instance of FirstRef from a dict""" + if obj is None: + return None + + if type(obj) is not dict: + return FirstRef.parse_obj(obj) + + _obj = FirstRef.parse_obj({ + "category": obj.get("category"), + "self_ref": SecondRef.from_dict(obj.get("self_ref")) if obj.get("self_ref") is not None else None + }) + return _obj + diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/second_ref.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/second_ref.py new file mode 100644 index 00000000000..f00e2756920 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/second_ref.py @@ -0,0 +1,75 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import annotations +from inspect import getfullargspec +import pprint +import re # noqa: F401 +import json + + +from typing import Optional +from pydantic import BaseModel, StrictStr + +class SecondRef(BaseModel): + """ + SecondRef + """ + category: Optional[StrictStr] = None + circular_ref: Optional[CircularReferenceModel] = None + __properties = ["category", "circular_ref"] + + class Config: + 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) -> SecondRef: + """Create an instance of SecondRef 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 circular_ref + if self.circular_ref: + _dict['circular_ref'] = self.circular_ref.to_dict() + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> SecondRef: + """Create an instance of SecondRef from a dict""" + if obj is None: + return None + + if type(obj) is not dict: + return SecondRef.parse_obj(obj) + + _obj = SecondRef.parse_obj({ + "category": obj.get("category"), + "circular_ref": CircularReferenceModel.from_dict(obj.get("circular_ref")) if obj.get("circular_ref") is not None else None + }) + return _obj + diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_circular_reference_model.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_circular_reference_model.py new file mode 100644 index 00000000000..f734d3fc0ff --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_circular_reference_model.py @@ -0,0 +1,64 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import absolute_import + +import unittest +import datetime + +import petstore_api +from petstore_api.models.circular_reference_model import CircularReferenceModel # noqa: E501 +from petstore_api.rest import ApiException + +class TestCircularReferenceModel(unittest.TestCase): + """CircularReferenceModel unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test CircularReferenceModel + 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 `CircularReferenceModel` + """ + model = petstore_api.models.circular_reference_model.CircularReferenceModel() # noqa: E501 + if include_optional : + return CircularReferenceModel( + size = 56, + nested = petstore_api.models.first_ref.FirstRef( + category = '', + self_ref = petstore_api.models.second_ref.SecondRef( + category = '', + circular_ref = petstore_api.models.circular_reference_model.Circular-Reference-Model( + size = 56, + nested = petstore_api.models.first_ref.FirstRef( + category = '', ), ), ), ) + ) + else : + return CircularReferenceModel( + ) + """ + + def testCircularReferenceModel(self): + """Test CircularReferenceModel""" + # 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-nextgen-aiohttp/test/test_first_ref.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_first_ref.py new file mode 100644 index 00000000000..bcec1c0334b --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_first_ref.py @@ -0,0 +1,62 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import absolute_import + +import unittest +import datetime + +import petstore_api +from petstore_api.models.first_ref import FirstRef # noqa: E501 +from petstore_api.rest import ApiException + +class TestFirstRef(unittest.TestCase): + """FirstRef unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test FirstRef + 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 `FirstRef` + """ + model = petstore_api.models.first_ref.FirstRef() # noqa: E501 + if include_optional : + return FirstRef( + category = '', + self_ref = petstore_api.models.second_ref.SecondRef( + category = '', + circular_ref = petstore_api.models.circular_reference_model.Circular-Reference-Model( + size = 56, + nested = petstore_api.models.first_ref.FirstRef( + category = '', ), ), ) + ) + else : + return FirstRef( + ) + """ + + def testFirstRef(self): + """Test FirstRef""" + # 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-nextgen-aiohttp/test/test_second_ref.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_second_ref.py new file mode 100644 index 00000000000..782892fd4e1 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_second_ref.py @@ -0,0 +1,62 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import absolute_import + +import unittest +import datetime + +import petstore_api +from petstore_api.models.second_ref import SecondRef # noqa: E501 +from petstore_api.rest import ApiException + +class TestSecondRef(unittest.TestCase): + """SecondRef unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test SecondRef + 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 `SecondRef` + """ + model = petstore_api.models.second_ref.SecondRef() # noqa: E501 + if include_optional : + return SecondRef( + category = '', + circular_ref = petstore_api.models.circular_reference_model.Circular-Reference-Model( + size = 56, + nested = petstore_api.models.first_ref.FirstRef( + category = '', + self_ref = petstore_api.models.second_ref.SecondRef( + category = '', ), ), ) + ) + else : + return SecondRef( + ) + """ + + def testSecondRef(self): + """Test SecondRef""" + # 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-nextgen/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES index c84577aa151..1c063f5f802 100755 --- a/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES @@ -18,6 +18,7 @@ docs/Capitalization.md docs/Cat.md docs/CatAllOf.md docs/Category.md +docs/CircularReferenceModel.md docs/ClassModel.md docs/Client.md docs/Color.md @@ -34,6 +35,7 @@ docs/FakeApi.md docs/FakeClassnameTags123Api.md docs/File.md docs/FileSchemaTestClass.md +docs/FirstRef.md docs/Foo.md docs/FooGetDefaultResponse.md docs/FormatTest.md @@ -61,6 +63,7 @@ docs/Pet.md docs/PetApi.md docs/Pig.md docs/ReadOnlyFirst.md +docs/SecondRef.md docs/SelfReferenceModel.md docs/SingleRefType.md docs/SpecialCharacterEnum.md @@ -99,6 +102,7 @@ petstore_api/models/capitalization.py petstore_api/models/cat.py petstore_api/models/cat_all_of.py petstore_api/models/category.py +petstore_api/models/circular_reference_model.py petstore_api/models/class_model.py petstore_api/models/client.py petstore_api/models/color.py @@ -112,6 +116,7 @@ petstore_api/models/enum_class.py petstore_api/models/enum_test.py petstore_api/models/file.py petstore_api/models/file_schema_test_class.py +petstore_api/models/first_ref.py petstore_api/models/foo.py petstore_api/models/foo_get_default_response.py petstore_api/models/format_test.py @@ -138,6 +143,7 @@ petstore_api/models/parent_with_optional_dict.py petstore_api/models/pet.py petstore_api/models/pig.py petstore_api/models/read_only_first.py +petstore_api/models/second_ref.py petstore_api/models/self_reference_model.py petstore_api/models/single_ref_type.py petstore_api/models/special_character_enum.py diff --git a/samples/openapi3/client/petstore/python-nextgen/README.md b/samples/openapi3/client/petstore/python-nextgen/README.md index e64a6743b26..a7b98f0887e 100755 --- a/samples/openapi3/client/petstore/python-nextgen/README.md +++ b/samples/openapi3/client/petstore/python-nextgen/README.md @@ -146,6 +146,7 @@ Class | Method | HTTP request | Description - [Cat](docs/Cat.md) - [CatAllOf](docs/CatAllOf.md) - [Category](docs/Category.md) + - [CircularReferenceModel](docs/CircularReferenceModel.md) - [ClassModel](docs/ClassModel.md) - [Client](docs/Client.md) - [Color](docs/Color.md) @@ -159,6 +160,7 @@ Class | Method | HTTP request | Description - [EnumTest](docs/EnumTest.md) - [File](docs/File.md) - [FileSchemaTestClass](docs/FileSchemaTestClass.md) + - [FirstRef](docs/FirstRef.md) - [Foo](docs/Foo.md) - [FooGetDefaultResponse](docs/FooGetDefaultResponse.md) - [FormatTest](docs/FormatTest.md) @@ -185,6 +187,7 @@ Class | Method | HTTP request | Description - [Pet](docs/Pet.md) - [Pig](docs/Pig.md) - [ReadOnlyFirst](docs/ReadOnlyFirst.md) + - [SecondRef](docs/SecondRef.md) - [SelfReferenceModel](docs/SelfReferenceModel.md) - [SingleRefType](docs/SingleRefType.md) - [SpecialCharacterEnum](docs/SpecialCharacterEnum.md) diff --git a/samples/openapi3/client/petstore/python-nextgen/docs/CircularReferenceModel.md b/samples/openapi3/client/petstore/python-nextgen/docs/CircularReferenceModel.md new file mode 100644 index 00000000000..d5e97934d2b --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/docs/CircularReferenceModel.md @@ -0,0 +1,29 @@ +# CircularReferenceModel + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**size** | **int** | | [optional] +**nested** | [**FirstRef**](FirstRef.md) | | [optional] + +## Example + +```python +from petstore_api.models.circular_reference_model import CircularReferenceModel + +# TODO update the JSON string below +json = "{}" +# create an instance of CircularReferenceModel from a JSON string +circular_reference_model_instance = CircularReferenceModel.from_json(json) +# print the JSON string representation of the object +print CircularReferenceModel.to_json() + +# convert the object into a dict +circular_reference_model_dict = circular_reference_model_instance.to_dict() +# create an instance of CircularReferenceModel from a dict +circular_reference_model_form_dict = circular_reference_model.from_dict(circular_reference_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-nextgen/docs/FirstRef.md b/samples/openapi3/client/petstore/python-nextgen/docs/FirstRef.md new file mode 100644 index 00000000000..b5e7ab766b4 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/docs/FirstRef.md @@ -0,0 +1,29 @@ +# FirstRef + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**category** | **str** | | [optional] +**self_ref** | [**SecondRef**](SecondRef.md) | | [optional] + +## Example + +```python +from petstore_api.models.first_ref import FirstRef + +# TODO update the JSON string below +json = "{}" +# create an instance of FirstRef from a JSON string +first_ref_instance = FirstRef.from_json(json) +# print the JSON string representation of the object +print FirstRef.to_json() + +# convert the object into a dict +first_ref_dict = first_ref_instance.to_dict() +# create an instance of FirstRef from a dict +first_ref_form_dict = first_ref.from_dict(first_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-nextgen/docs/SecondRef.md b/samples/openapi3/client/petstore/python-nextgen/docs/SecondRef.md new file mode 100644 index 00000000000..e6fb1e2d4f7 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/docs/SecondRef.md @@ -0,0 +1,29 @@ +# SecondRef + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**category** | **str** | | [optional] +**circular_ref** | [**CircularReferenceModel**](CircularReferenceModel.md) | | [optional] + +## Example + +```python +from petstore_api.models.second_ref import SecondRef + +# TODO update the JSON string below +json = "{}" +# create an instance of SecondRef from a JSON string +second_ref_instance = SecondRef.from_json(json) +# print the JSON string representation of the object +print SecondRef.to_json() + +# convert the object into a dict +second_ref_dict = second_ref_instance.to_dict() +# create an instance of SecondRef from a dict +second_ref_form_dict = second_ref.from_dict(second_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-nextgen/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/__init__.py index 31cf58fec33..417db16491d 100755 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/__init__.py @@ -49,6 +49,7 @@ from petstore_api.models.capitalization import Capitalization from petstore_api.models.cat import Cat from petstore_api.models.cat_all_of import CatAllOf from petstore_api.models.category import Category +from petstore_api.models.circular_reference_model import CircularReferenceModel from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client from petstore_api.models.color import Color @@ -62,6 +63,7 @@ from petstore_api.models.enum_class import EnumClass from petstore_api.models.enum_test import EnumTest from petstore_api.models.file import File from petstore_api.models.file_schema_test_class import FileSchemaTestClass +from petstore_api.models.first_ref import FirstRef from petstore_api.models.foo import Foo from petstore_api.models.foo_get_default_response import FooGetDefaultResponse from petstore_api.models.format_test import FormatTest @@ -88,6 +90,7 @@ from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig from petstore_api.models.read_only_first import ReadOnlyFirst +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 from petstore_api.models.special_character_enum import SpecialCharacterEnum diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/__init__.py index b6cd78aa71c..212f2096311 100644 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/__init__.py @@ -28,6 +28,7 @@ from petstore_api.models.capitalization import Capitalization from petstore_api.models.cat import Cat from petstore_api.models.cat_all_of import CatAllOf from petstore_api.models.category import Category +from petstore_api.models.circular_reference_model import CircularReferenceModel from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client from petstore_api.models.color import Color @@ -41,6 +42,7 @@ from petstore_api.models.enum_class import EnumClass from petstore_api.models.enum_test import EnumTest from petstore_api.models.file import File from petstore_api.models.file_schema_test_class import FileSchemaTestClass +from petstore_api.models.first_ref import FirstRef from petstore_api.models.foo import Foo from petstore_api.models.foo_get_default_response import FooGetDefaultResponse from petstore_api.models.format_test import FormatTest @@ -67,6 +69,7 @@ from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig from petstore_api.models.read_only_first import ReadOnlyFirst +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 from petstore_api.models.special_character_enum import SpecialCharacterEnum diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/circular_reference_model.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/circular_reference_model.py new file mode 100644 index 00000000000..eacb22736b3 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/circular_reference_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: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import annotations +from inspect import getfullargspec +import pprint +import re # noqa: F401 +import json + + +from typing import Optional +from pydantic import BaseModel, StrictInt + +class CircularReferenceModel(BaseModel): + """ + CircularReferenceModel + """ + size: Optional[StrictInt] = None + nested: Optional[FirstRef] = None + additional_properties: Dict[str, Any] = {} + __properties = ["size", "nested"] + + class Config: + 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) -> CircularReferenceModel: + """Create an instance of CircularReferenceModel 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 nested + if self.nested: + _dict['nested'] = self.nested.to_dict() + # puts key-value pairs in additional_properties in the top level + if self.additional_properties is not None: + for _key, _value in self.additional_properties.items(): + _dict[_key] = _value + + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> CircularReferenceModel: + """Create an instance of CircularReferenceModel from a dict""" + if obj is None: + return None + + if type(obj) is not dict: + return CircularReferenceModel.parse_obj(obj) + + _obj = CircularReferenceModel.parse_obj({ + "size": obj.get("size"), + "nested": FirstRef.from_dict(obj.get("nested")) if obj.get("nested") 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 + diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/first_ref.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/first_ref.py new file mode 100644 index 00000000000..31ac2390677 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/first_ref.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: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import annotations +from inspect import getfullargspec +import pprint +import re # noqa: F401 +import json + + +from typing import Optional +from pydantic import BaseModel, StrictStr + +class FirstRef(BaseModel): + """ + FirstRef + """ + category: Optional[StrictStr] = None + self_ref: Optional[SecondRef] = None + additional_properties: Dict[str, Any] = {} + __properties = ["category", "self_ref"] + + class Config: + 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) -> FirstRef: + """Create an instance of FirstRef 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 self_ref + if self.self_ref: + _dict['self_ref'] = self.self_ref.to_dict() + # puts key-value pairs in additional_properties in the top level + if self.additional_properties is not None: + for _key, _value in self.additional_properties.items(): + _dict[_key] = _value + + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> FirstRef: + """Create an instance of FirstRef from a dict""" + if obj is None: + return None + + if type(obj) is not dict: + return FirstRef.parse_obj(obj) + + _obj = FirstRef.parse_obj({ + "category": obj.get("category"), + "self_ref": SecondRef.from_dict(obj.get("self_ref")) if obj.get("self_ref") 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 + diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/second_ref.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/second_ref.py new file mode 100644 index 00000000000..228c8b24b92 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/second_ref.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: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import annotations +from inspect import getfullargspec +import pprint +import re # noqa: F401 +import json + + +from typing import Optional +from pydantic import BaseModel, StrictStr + +class SecondRef(BaseModel): + """ + SecondRef + """ + category: Optional[StrictStr] = None + circular_ref: Optional[CircularReferenceModel] = None + additional_properties: Dict[str, Any] = {} + __properties = ["category", "circular_ref"] + + class Config: + 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) -> SecondRef: + """Create an instance of SecondRef 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 circular_ref + if self.circular_ref: + _dict['circular_ref'] = self.circular_ref.to_dict() + # puts key-value pairs in additional_properties in the top level + if self.additional_properties is not None: + for _key, _value in self.additional_properties.items(): + _dict[_key] = _value + + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> SecondRef: + """Create an instance of SecondRef from a dict""" + if obj is None: + return None + + if type(obj) is not dict: + return SecondRef.parse_obj(obj) + + _obj = SecondRef.parse_obj({ + "category": obj.get("category"), + "circular_ref": CircularReferenceModel.from_dict(obj.get("circular_ref")) if obj.get("circular_ref") 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 + diff --git a/samples/openapi3/client/petstore/python-nextgen/test/test_circular_reference_model.py b/samples/openapi3/client/petstore/python-nextgen/test/test_circular_reference_model.py new file mode 100644 index 00000000000..f734d3fc0ff --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/test/test_circular_reference_model.py @@ -0,0 +1,64 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import absolute_import + +import unittest +import datetime + +import petstore_api +from petstore_api.models.circular_reference_model import CircularReferenceModel # noqa: E501 +from petstore_api.rest import ApiException + +class TestCircularReferenceModel(unittest.TestCase): + """CircularReferenceModel unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test CircularReferenceModel + 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 `CircularReferenceModel` + """ + model = petstore_api.models.circular_reference_model.CircularReferenceModel() # noqa: E501 + if include_optional : + return CircularReferenceModel( + size = 56, + nested = petstore_api.models.first_ref.FirstRef( + category = '', + self_ref = petstore_api.models.second_ref.SecondRef( + category = '', + circular_ref = petstore_api.models.circular_reference_model.Circular-Reference-Model( + size = 56, + nested = petstore_api.models.first_ref.FirstRef( + category = '', ), ), ), ) + ) + else : + return CircularReferenceModel( + ) + """ + + def testCircularReferenceModel(self): + """Test CircularReferenceModel""" + # 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-nextgen/test/test_first_ref.py b/samples/openapi3/client/petstore/python-nextgen/test/test_first_ref.py new file mode 100644 index 00000000000..bcec1c0334b --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/test/test_first_ref.py @@ -0,0 +1,62 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import absolute_import + +import unittest +import datetime + +import petstore_api +from petstore_api.models.first_ref import FirstRef # noqa: E501 +from petstore_api.rest import ApiException + +class TestFirstRef(unittest.TestCase): + """FirstRef unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test FirstRef + 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 `FirstRef` + """ + model = petstore_api.models.first_ref.FirstRef() # noqa: E501 + if include_optional : + return FirstRef( + category = '', + self_ref = petstore_api.models.second_ref.SecondRef( + category = '', + circular_ref = petstore_api.models.circular_reference_model.Circular-Reference-Model( + size = 56, + nested = petstore_api.models.first_ref.FirstRef( + category = '', ), ), ) + ) + else : + return FirstRef( + ) + """ + + def testFirstRef(self): + """Test FirstRef""" + # 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-nextgen/test/test_second_ref.py b/samples/openapi3/client/petstore/python-nextgen/test/test_second_ref.py new file mode 100644 index 00000000000..782892fd4e1 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/test/test_second_ref.py @@ -0,0 +1,62 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import absolute_import + +import unittest +import datetime + +import petstore_api +from petstore_api.models.second_ref import SecondRef # noqa: E501 +from petstore_api.rest import ApiException + +class TestSecondRef(unittest.TestCase): + """SecondRef unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test SecondRef + 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 `SecondRef` + """ + model = petstore_api.models.second_ref.SecondRef() # noqa: E501 + if include_optional : + return SecondRef( + category = '', + circular_ref = petstore_api.models.circular_reference_model.Circular-Reference-Model( + size = 56, + nested = petstore_api.models.first_ref.FirstRef( + category = '', + self_ref = petstore_api.models.second_ref.SecondRef( + category = '', ), ), ) + ) + else : + return SecondRef( + ) + """ + + def testSecondRef(self): + """Test SecondRef""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main()