[python-nextgen] fix circular reference import (#15070)

* fix ciruclar reference import in python nextgen

* update samples
This commit is contained in:
William Cheng 2023-03-30 10:07:34 +08:00 committed by GitHub
parent 3ccd9be080
commit 05fa5601dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 1230 additions and 12 deletions

View File

@ -64,6 +64,11 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements
private String testFolder; private String testFolder;
// map of set (model imports)
private HashMap<String, HashSet<String>> circularImports = new HashMap<>();
// map of codegen models
private HashMap<String, CodegenModel> codegenModelMap = new HashMap<>();
public PythonNextgenClientCodegen() { public PythonNextgenClientCodegen() {
super(); super();
@ -404,6 +409,8 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements
* @param typingImports typing imports * @param typingImports typing imports
* @param pydantic pydantic imports * @param pydantic pydantic imports
* @param datetimeImports datetime imports * @param datetimeImports datetime imports
* @param modelImports model imports
* @param classname class name
* @return pydantic type * @return pydantic type
* *
*/ */
@ -411,7 +418,8 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements
Set<String> typingImports, Set<String> typingImports,
Set<String> pydanticImports, Set<String> pydanticImports,
Set<String> datetimeImports, Set<String> datetimeImports,
Set<String> modelImports) { Set<String> modelImports,
String classname) {
if (cp == null) { if (cp == null) {
// if codegen parameter (e.g. map/dict of undefined type) is null, default to string // 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."); 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"); pydanticImports.add("conlist");
return String.format(Locale.ROOT, "conlist(%s%s)", return String.format(Locale.ROOT, "conlist(%s%s)",
getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports), getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports, classname),
constraints); constraints);
} else if (cp.isMap) { } else if (cp.isMap) {
typingImports.add("Dict"); 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) { } else if (cp.isString || cp.isBinary || cp.isByteArray) {
if (cp.hasValidation) { if (cp.hasValidation) {
List<String> fieldCustomization = new ArrayList<>(); List<String> fieldCustomization = new ArrayList<>();
@ -612,7 +621,7 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements
CodegenMediaType cmt = contents.get(key); CodegenMediaType cmt = contents.get(key);
// TODO process the first one only at the moment // TODO process the first one only at the moment
if (cmt != null) 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); throw new RuntimeException("Error! Failed to process getPydanticType when getting the content: " + cp);
} else { } else {
@ -627,6 +636,8 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements
* @param typingImports typing imports * @param typingImports typing imports
* @param pydantic pydantic imports * @param pydantic pydantic imports
* @param datetimeImports datetime imports * @param datetimeImports datetime imports
* @param modelImports model imports
* @param classname class name
* @return pydantic type * @return pydantic type
* *
*/ */
@ -634,7 +645,8 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements
Set<String> typingImports, Set<String> typingImports,
Set<String> pydanticImports, Set<String> pydanticImports,
Set<String> datetimeImports, Set<String> datetimeImports,
Set<String> modelImports) { Set<String> modelImports,
String classname) {
if (cp == null) { if (cp == null) {
// if codegen property (e.g. map/dict of undefined type) is null, default to string // 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."); 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"); pydanticImports.add("conlist");
typingImports.add("List"); // for return type typingImports.add("List"); // for return type
return String.format(Locale.ROOT, "conlist(%s%s)", return String.format(Locale.ROOT, "conlist(%s%s)",
getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports), getPydanticType(cp.items, typingImports, pydanticImports, datetimeImports, modelImports, classname),
constraints); constraints);
} else if (cp.isMap) { } else if (cp.isMap) {
typingImports.add("Dict"); 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) { } else if (cp.isString) {
if (cp.hasValidation) { if (cp.hasValidation) {
List<String> fieldCustomization = new ArrayList<>(); List<String> fieldCustomization = new ArrayList<>();
@ -846,10 +858,24 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements
typingImports.add("Any"); typingImports.add("Any");
return "Dict[str, Any]"; return "Dict[str, Any]";
} else if (!cp.isPrimitiveType || cp.isModel) { // model } 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; hasModelsToImport = true;
modelImports.add(cp.dataType); 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; return cp.dataType;
} else { } else {
@ -871,7 +897,7 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements
List<CodegenParameter> params = operation.allParams; List<CodegenParameter> params = operation.allParams;
for (CodegenParameter param : params) { for (CodegenParameter param : params) {
String typing = getPydanticType(param, typingImports, pydanticImports, datetimeImports, modelImports); String typing = getPydanticType(param, typingImports, pydanticImports, datetimeImports, modelImports, null);
List<String> fields = new ArrayList<>(); List<String> fields = new ArrayList<>();
String firstField = ""; String firstField = "";
@ -923,7 +949,7 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements
// update typing import for operation return type // update typing import for operation return type
if (!StringUtils.isEmpty(operation.returnType)) { if (!StringUtils.isEmpty(operation.returnType)) {
String typing = getPydanticType(operation.returnProperty, typingImports, 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 @Override
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) { public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
final Map<String, ModelsMap> processed = super.postProcessAllModels(objs); final Map<String, ModelsMap> processed = super.postProcessAllModels(objs);
for (Map.Entry<String, ModelsMap> 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<String, ModelsMap> entry : processed.entrySet()) { for (Map.Entry<String, ModelsMap> entry : processed.entrySet()) {
entry.setValue(postProcessModelsMap(entry.getValue())); entry.setValue(postProcessModelsMap(entry.getValue()));
} }
@ -990,6 +1028,99 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements
return processed; 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<String, CodegenModel> codegenModelMap) {
HashSet<String> 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<CodegenProperty> 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<String> imports) {
if (cm == null) {
LOGGER.warn("Failed to lookup model in createImportMapOfSet " + modelName);
return;
}
List<CodegenProperty> 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) { private ModelsMap postProcessModelsMap(ModelsMap objs) {
// process enum in models // process enum in models
objs = postProcessModelsEnum(objs); objs = postProcessModelsEnum(objs);
@ -1044,7 +1175,7 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements
//loop through properties/schemas to set up typing, pydantic //loop through properties/schemas to set up typing, pydantic
for (CodegenProperty cp : codegenProperties) { for (CodegenProperty cp : codegenProperties) {
String typing = getPydanticType(cp, typingImports, pydanticImports, datetimeImports, modelImports); String typing = getPydanticType(cp, typingImports, pydanticImports, datetimeImports, modelImports, model.classname);
List<String> fields = new ArrayList<>(); List<String> fields = new ArrayList<>();
String firstField = ""; String firstField = "";

View File

@ -2126,3 +2126,24 @@ components:
properties: properties:
optionalDict: optionalDict:
$ref: "#/components/schemas/DictWithAdditionalProperties" $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'

View File

@ -18,6 +18,7 @@ docs/Capitalization.md
docs/Cat.md docs/Cat.md
docs/CatAllOf.md docs/CatAllOf.md
docs/Category.md docs/Category.md
docs/CircularReferenceModel.md
docs/ClassModel.md docs/ClassModel.md
docs/Client.md docs/Client.md
docs/Color.md docs/Color.md
@ -34,6 +35,7 @@ docs/FakeApi.md
docs/FakeClassnameTags123Api.md docs/FakeClassnameTags123Api.md
docs/File.md docs/File.md
docs/FileSchemaTestClass.md docs/FileSchemaTestClass.md
docs/FirstRef.md
docs/Foo.md docs/Foo.md
docs/FooGetDefaultResponse.md docs/FooGetDefaultResponse.md
docs/FormatTest.md docs/FormatTest.md
@ -61,6 +63,7 @@ docs/Pet.md
docs/PetApi.md docs/PetApi.md
docs/Pig.md docs/Pig.md
docs/ReadOnlyFirst.md docs/ReadOnlyFirst.md
docs/SecondRef.md
docs/SelfReferenceModel.md docs/SelfReferenceModel.md
docs/SingleRefType.md docs/SingleRefType.md
docs/SpecialCharacterEnum.md docs/SpecialCharacterEnum.md
@ -99,6 +102,7 @@ petstore_api/models/capitalization.py
petstore_api/models/cat.py petstore_api/models/cat.py
petstore_api/models/cat_all_of.py petstore_api/models/cat_all_of.py
petstore_api/models/category.py petstore_api/models/category.py
petstore_api/models/circular_reference_model.py
petstore_api/models/class_model.py petstore_api/models/class_model.py
petstore_api/models/client.py petstore_api/models/client.py
petstore_api/models/color.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/enum_test.py
petstore_api/models/file.py petstore_api/models/file.py
petstore_api/models/file_schema_test_class.py petstore_api/models/file_schema_test_class.py
petstore_api/models/first_ref.py
petstore_api/models/foo.py petstore_api/models/foo.py
petstore_api/models/foo_get_default_response.py petstore_api/models/foo_get_default_response.py
petstore_api/models/format_test.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/pet.py
petstore_api/models/pig.py petstore_api/models/pig.py
petstore_api/models/read_only_first.py petstore_api/models/read_only_first.py
petstore_api/models/second_ref.py
petstore_api/models/self_reference_model.py petstore_api/models/self_reference_model.py
petstore_api/models/single_ref_type.py petstore_api/models/single_ref_type.py
petstore_api/models/special_character_enum.py petstore_api/models/special_character_enum.py

View File

@ -146,6 +146,7 @@ Class | Method | HTTP request | Description
- [Cat](docs/Cat.md) - [Cat](docs/Cat.md)
- [CatAllOf](docs/CatAllOf.md) - [CatAllOf](docs/CatAllOf.md)
- [Category](docs/Category.md) - [Category](docs/Category.md)
- [CircularReferenceModel](docs/CircularReferenceModel.md)
- [ClassModel](docs/ClassModel.md) - [ClassModel](docs/ClassModel.md)
- [Client](docs/Client.md) - [Client](docs/Client.md)
- [Color](docs/Color.md) - [Color](docs/Color.md)
@ -159,6 +160,7 @@ Class | Method | HTTP request | Description
- [EnumTest](docs/EnumTest.md) - [EnumTest](docs/EnumTest.md)
- [File](docs/File.md) - [File](docs/File.md)
- [FileSchemaTestClass](docs/FileSchemaTestClass.md) - [FileSchemaTestClass](docs/FileSchemaTestClass.md)
- [FirstRef](docs/FirstRef.md)
- [Foo](docs/Foo.md) - [Foo](docs/Foo.md)
- [FooGetDefaultResponse](docs/FooGetDefaultResponse.md) - [FooGetDefaultResponse](docs/FooGetDefaultResponse.md)
- [FormatTest](docs/FormatTest.md) - [FormatTest](docs/FormatTest.md)
@ -185,6 +187,7 @@ Class | Method | HTTP request | Description
- [Pet](docs/Pet.md) - [Pet](docs/Pet.md)
- [Pig](docs/Pig.md) - [Pig](docs/Pig.md)
- [ReadOnlyFirst](docs/ReadOnlyFirst.md) - [ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [SecondRef](docs/SecondRef.md)
- [SelfReferenceModel](docs/SelfReferenceModel.md) - [SelfReferenceModel](docs/SelfReferenceModel.md)
- [SingleRefType](docs/SingleRefType.md) - [SingleRefType](docs/SingleRefType.md)
- [SpecialCharacterEnum](docs/SpecialCharacterEnum.md) - [SpecialCharacterEnum](docs/SpecialCharacterEnum.md)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -49,6 +49,7 @@ from petstore_api.models.capitalization import Capitalization
from petstore_api.models.cat import Cat from petstore_api.models.cat import Cat
from petstore_api.models.cat_all_of import CatAllOf from petstore_api.models.cat_all_of import CatAllOf
from petstore_api.models.category import Category 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.class_model import ClassModel
from petstore_api.models.client import Client from petstore_api.models.client import Client
from petstore_api.models.color import Color 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.enum_test import EnumTest
from petstore_api.models.file import File from petstore_api.models.file import File
from petstore_api.models.file_schema_test_class import FileSchemaTestClass 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 import Foo
from petstore_api.models.foo_get_default_response import FooGetDefaultResponse from petstore_api.models.foo_get_default_response import FooGetDefaultResponse
from petstore_api.models.format_test import FormatTest 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.pet import Pet
from petstore_api.models.pig import Pig from petstore_api.models.pig import Pig
from petstore_api.models.read_only_first import ReadOnlyFirst 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.self_reference_model import SelfReferenceModel
from petstore_api.models.single_ref_type import SingleRefType from petstore_api.models.single_ref_type import SingleRefType
from petstore_api.models.special_character_enum import SpecialCharacterEnum from petstore_api.models.special_character_enum import SpecialCharacterEnum

View File

@ -28,6 +28,7 @@ from petstore_api.models.capitalization import Capitalization
from petstore_api.models.cat import Cat from petstore_api.models.cat import Cat
from petstore_api.models.cat_all_of import CatAllOf from petstore_api.models.cat_all_of import CatAllOf
from petstore_api.models.category import Category 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.class_model import ClassModel
from petstore_api.models.client import Client from petstore_api.models.client import Client
from petstore_api.models.color import Color 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.enum_test import EnumTest
from petstore_api.models.file import File from petstore_api.models.file import File
from petstore_api.models.file_schema_test_class import FileSchemaTestClass 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 import Foo
from petstore_api.models.foo_get_default_response import FooGetDefaultResponse from petstore_api.models.foo_get_default_response import FooGetDefaultResponse
from petstore_api.models.format_test import FormatTest 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.pet import Pet
from petstore_api.models.pig import Pig from petstore_api.models.pig import Pig
from petstore_api.models.read_only_first import ReadOnlyFirst 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.self_reference_model import SelfReferenceModel
from petstore_api.models.single_ref_type import SingleRefType from petstore_api.models.single_ref_type import SingleRefType
from petstore_api.models.special_character_enum import SpecialCharacterEnum from petstore_api.models.special_character_enum import SpecialCharacterEnum

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -18,6 +18,7 @@ docs/Capitalization.md
docs/Cat.md docs/Cat.md
docs/CatAllOf.md docs/CatAllOf.md
docs/Category.md docs/Category.md
docs/CircularReferenceModel.md
docs/ClassModel.md docs/ClassModel.md
docs/Client.md docs/Client.md
docs/Color.md docs/Color.md
@ -34,6 +35,7 @@ docs/FakeApi.md
docs/FakeClassnameTags123Api.md docs/FakeClassnameTags123Api.md
docs/File.md docs/File.md
docs/FileSchemaTestClass.md docs/FileSchemaTestClass.md
docs/FirstRef.md
docs/Foo.md docs/Foo.md
docs/FooGetDefaultResponse.md docs/FooGetDefaultResponse.md
docs/FormatTest.md docs/FormatTest.md
@ -61,6 +63,7 @@ docs/Pet.md
docs/PetApi.md docs/PetApi.md
docs/Pig.md docs/Pig.md
docs/ReadOnlyFirst.md docs/ReadOnlyFirst.md
docs/SecondRef.md
docs/SelfReferenceModel.md docs/SelfReferenceModel.md
docs/SingleRefType.md docs/SingleRefType.md
docs/SpecialCharacterEnum.md docs/SpecialCharacterEnum.md
@ -99,6 +102,7 @@ petstore_api/models/capitalization.py
petstore_api/models/cat.py petstore_api/models/cat.py
petstore_api/models/cat_all_of.py petstore_api/models/cat_all_of.py
petstore_api/models/category.py petstore_api/models/category.py
petstore_api/models/circular_reference_model.py
petstore_api/models/class_model.py petstore_api/models/class_model.py
petstore_api/models/client.py petstore_api/models/client.py
petstore_api/models/color.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/enum_test.py
petstore_api/models/file.py petstore_api/models/file.py
petstore_api/models/file_schema_test_class.py petstore_api/models/file_schema_test_class.py
petstore_api/models/first_ref.py
petstore_api/models/foo.py petstore_api/models/foo.py
petstore_api/models/foo_get_default_response.py petstore_api/models/foo_get_default_response.py
petstore_api/models/format_test.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/pet.py
petstore_api/models/pig.py petstore_api/models/pig.py
petstore_api/models/read_only_first.py petstore_api/models/read_only_first.py
petstore_api/models/second_ref.py
petstore_api/models/self_reference_model.py petstore_api/models/self_reference_model.py
petstore_api/models/single_ref_type.py petstore_api/models/single_ref_type.py
petstore_api/models/special_character_enum.py petstore_api/models/special_character_enum.py

View File

@ -146,6 +146,7 @@ Class | Method | HTTP request | Description
- [Cat](docs/Cat.md) - [Cat](docs/Cat.md)
- [CatAllOf](docs/CatAllOf.md) - [CatAllOf](docs/CatAllOf.md)
- [Category](docs/Category.md) - [Category](docs/Category.md)
- [CircularReferenceModel](docs/CircularReferenceModel.md)
- [ClassModel](docs/ClassModel.md) - [ClassModel](docs/ClassModel.md)
- [Client](docs/Client.md) - [Client](docs/Client.md)
- [Color](docs/Color.md) - [Color](docs/Color.md)
@ -159,6 +160,7 @@ Class | Method | HTTP request | Description
- [EnumTest](docs/EnumTest.md) - [EnumTest](docs/EnumTest.md)
- [File](docs/File.md) - [File](docs/File.md)
- [FileSchemaTestClass](docs/FileSchemaTestClass.md) - [FileSchemaTestClass](docs/FileSchemaTestClass.md)
- [FirstRef](docs/FirstRef.md)
- [Foo](docs/Foo.md) - [Foo](docs/Foo.md)
- [FooGetDefaultResponse](docs/FooGetDefaultResponse.md) - [FooGetDefaultResponse](docs/FooGetDefaultResponse.md)
- [FormatTest](docs/FormatTest.md) - [FormatTest](docs/FormatTest.md)
@ -185,6 +187,7 @@ Class | Method | HTTP request | Description
- [Pet](docs/Pet.md) - [Pet](docs/Pet.md)
- [Pig](docs/Pig.md) - [Pig](docs/Pig.md)
- [ReadOnlyFirst](docs/ReadOnlyFirst.md) - [ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [SecondRef](docs/SecondRef.md)
- [SelfReferenceModel](docs/SelfReferenceModel.md) - [SelfReferenceModel](docs/SelfReferenceModel.md)
- [SingleRefType](docs/SingleRefType.md) - [SingleRefType](docs/SingleRefType.md)
- [SpecialCharacterEnum](docs/SpecialCharacterEnum.md) - [SpecialCharacterEnum](docs/SpecialCharacterEnum.md)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -49,6 +49,7 @@ from petstore_api.models.capitalization import Capitalization
from petstore_api.models.cat import Cat from petstore_api.models.cat import Cat
from petstore_api.models.cat_all_of import CatAllOf from petstore_api.models.cat_all_of import CatAllOf
from petstore_api.models.category import Category 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.class_model import ClassModel
from petstore_api.models.client import Client from petstore_api.models.client import Client
from petstore_api.models.color import Color 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.enum_test import EnumTest
from petstore_api.models.file import File from petstore_api.models.file import File
from petstore_api.models.file_schema_test_class import FileSchemaTestClass 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 import Foo
from petstore_api.models.foo_get_default_response import FooGetDefaultResponse from petstore_api.models.foo_get_default_response import FooGetDefaultResponse
from petstore_api.models.format_test import FormatTest 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.pet import Pet
from petstore_api.models.pig import Pig from petstore_api.models.pig import Pig
from petstore_api.models.read_only_first import ReadOnlyFirst 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.self_reference_model import SelfReferenceModel
from petstore_api.models.single_ref_type import SingleRefType from petstore_api.models.single_ref_type import SingleRefType
from petstore_api.models.special_character_enum import SpecialCharacterEnum from petstore_api.models.special_character_enum import SpecialCharacterEnum

View File

@ -28,6 +28,7 @@ from petstore_api.models.capitalization import Capitalization
from petstore_api.models.cat import Cat from petstore_api.models.cat import Cat
from petstore_api.models.cat_all_of import CatAllOf from petstore_api.models.cat_all_of import CatAllOf
from petstore_api.models.category import Category 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.class_model import ClassModel
from petstore_api.models.client import Client from petstore_api.models.client import Client
from petstore_api.models.color import Color 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.enum_test import EnumTest
from petstore_api.models.file import File from petstore_api.models.file import File
from petstore_api.models.file_schema_test_class import FileSchemaTestClass 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 import Foo
from petstore_api.models.foo_get_default_response import FooGetDefaultResponse from petstore_api.models.foo_get_default_response import FooGetDefaultResponse
from petstore_api.models.format_test import FormatTest 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.pet import Pet
from petstore_api.models.pig import Pig from petstore_api.models.pig import Pig
from petstore_api.models.read_only_first import ReadOnlyFirst 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.self_reference_model import SelfReferenceModel
from petstore_api.models.single_ref_type import SingleRefType from petstore_api.models.single_ref_type import SingleRefType
from petstore_api.models.special_character_enum import SpecialCharacterEnum from petstore_api.models.special_character_enum import SpecialCharacterEnum

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -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()