forked from loafle/openapi-generator-original
Fix 18271: Circular imports on AllOf generation with REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=True (#18272)
* fix issue 18271 * the same update for python-pydantic-v1 * add test * update samples * update samples * put properties under allOf for python client tests * update samples * add a test in test model
This commit is contained in:
committed by
GitHub
parent
2c663561ef
commit
453facc81c
@@ -7,6 +7,7 @@ docs/AdditionalPropertiesAnyType.md
|
||||
docs/AdditionalPropertiesClass.md
|
||||
docs/AdditionalPropertiesObject.md
|
||||
docs/AdditionalPropertiesWithDescriptionOnly.md
|
||||
docs/AllOfSuperModel.md
|
||||
docs/AllOfWithSingleRef.md
|
||||
docs/Animal.md
|
||||
docs/AnotherFakeApi.md
|
||||
@@ -21,6 +22,7 @@ docs/Bathing.md
|
||||
docs/Capitalization.md
|
||||
docs/Cat.md
|
||||
docs/Category.md
|
||||
docs/CircularAllOfRef.md
|
||||
docs/CircularReferenceModel.md
|
||||
docs/ClassModel.md
|
||||
docs/Client.md
|
||||
@@ -85,6 +87,7 @@ docs/PoopCleaning.md
|
||||
docs/PropertyMap.md
|
||||
docs/PropertyNameCollision.md
|
||||
docs/ReadOnlyFirst.md
|
||||
docs/SecondCircularAllOfRef.md
|
||||
docs/SecondRef.md
|
||||
docs/SelfReferenceModel.md
|
||||
docs/SingleRefType.md
|
||||
@@ -125,6 +128,7 @@ petstore_api/models/additional_properties_any_type.py
|
||||
petstore_api/models/additional_properties_class.py
|
||||
petstore_api/models/additional_properties_object.py
|
||||
petstore_api/models/additional_properties_with_description_only.py
|
||||
petstore_api/models/all_of_super_model.py
|
||||
petstore_api/models/all_of_with_single_ref.py
|
||||
petstore_api/models/animal.py
|
||||
petstore_api/models/any_of_color.py
|
||||
@@ -138,6 +142,7 @@ petstore_api/models/bathing.py
|
||||
petstore_api/models/capitalization.py
|
||||
petstore_api/models/cat.py
|
||||
petstore_api/models/category.py
|
||||
petstore_api/models/circular_all_of_ref.py
|
||||
petstore_api/models/circular_reference_model.py
|
||||
petstore_api/models/class_model.py
|
||||
petstore_api/models/client.py
|
||||
@@ -197,6 +202,7 @@ petstore_api/models/poop_cleaning.py
|
||||
petstore_api/models/property_map.py
|
||||
petstore_api/models/property_name_collision.py
|
||||
petstore_api/models/read_only_first.py
|
||||
petstore_api/models/second_circular_all_of_ref.py
|
||||
petstore_api/models/second_ref.py
|
||||
petstore_api/models/self_reference_model.py
|
||||
petstore_api/models/single_ref_type.py
|
||||
|
||||
@@ -154,6 +154,7 @@ Class | Method | HTTP request | Description
|
||||
- [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
|
||||
- [AdditionalPropertiesObject](docs/AdditionalPropertiesObject.md)
|
||||
- [AdditionalPropertiesWithDescriptionOnly](docs/AdditionalPropertiesWithDescriptionOnly.md)
|
||||
- [AllOfSuperModel](docs/AllOfSuperModel.md)
|
||||
- [AllOfWithSingleRef](docs/AllOfWithSingleRef.md)
|
||||
- [Animal](docs/Animal.md)
|
||||
- [AnyOfColor](docs/AnyOfColor.md)
|
||||
@@ -167,6 +168,7 @@ Class | Method | HTTP request | Description
|
||||
- [Capitalization](docs/Capitalization.md)
|
||||
- [Cat](docs/Cat.md)
|
||||
- [Category](docs/Category.md)
|
||||
- [CircularAllOfRef](docs/CircularAllOfRef.md)
|
||||
- [CircularReferenceModel](docs/CircularReferenceModel.md)
|
||||
- [ClassModel](docs/ClassModel.md)
|
||||
- [Client](docs/Client.md)
|
||||
@@ -226,6 +228,7 @@ Class | Method | HTTP request | Description
|
||||
- [PropertyMap](docs/PropertyMap.md)
|
||||
- [PropertyNameCollision](docs/PropertyNameCollision.md)
|
||||
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
- [SecondCircularAllOfRef](docs/SecondCircularAllOfRef.md)
|
||||
- [SecondRef](docs/SecondRef.md)
|
||||
- [SelfReferenceModel](docs/SelfReferenceModel.md)
|
||||
- [SingleRefType](docs/SingleRefType.md)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# AllOfSuperModel
|
||||
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**name** | **str** | | [optional]
|
||||
|
||||
## Example
|
||||
|
||||
```python
|
||||
from petstore_api.models.all_of_super_model import AllOfSuperModel
|
||||
|
||||
# TODO update the JSON string below
|
||||
json = "{}"
|
||||
# create an instance of AllOfSuperModel from a JSON string
|
||||
all_of_super_model_instance = AllOfSuperModel.from_json(json)
|
||||
# print the JSON string representation of the object
|
||||
print(AllOfSuperModel.to_json())
|
||||
|
||||
# convert the object into a dict
|
||||
all_of_super_model_dict = all_of_super_model_instance.to_dict()
|
||||
# create an instance of AllOfSuperModel from a dict
|
||||
all_of_super_model_form_dict = all_of_super_model.from_dict(all_of_super_model_dict)
|
||||
```
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# CircularAllOfRef
|
||||
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**name** | **str** | | [optional]
|
||||
**second_circular_all_of_ref** | [**List[SecondCircularAllOfRef]**](SecondCircularAllOfRef.md) | | [optional]
|
||||
|
||||
## Example
|
||||
|
||||
```python
|
||||
from petstore_api.models.circular_all_of_ref import CircularAllOfRef
|
||||
|
||||
# TODO update the JSON string below
|
||||
json = "{}"
|
||||
# create an instance of CircularAllOfRef from a JSON string
|
||||
circular_all_of_ref_instance = CircularAllOfRef.from_json(json)
|
||||
# print the JSON string representation of the object
|
||||
print(CircularAllOfRef.to_json())
|
||||
|
||||
# convert the object into a dict
|
||||
circular_all_of_ref_dict = circular_all_of_ref_instance.to_dict()
|
||||
# create an instance of CircularAllOfRef from a dict
|
||||
circular_all_of_ref_form_dict = circular_all_of_ref.from_dict(circular_all_of_ref_dict)
|
||||
```
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# SecondCircularAllOfRef
|
||||
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**name** | **str** | | [optional]
|
||||
**circular_all_of_ref** | [**List[CircularAllOfRef]**](CircularAllOfRef.md) | | [optional]
|
||||
|
||||
## Example
|
||||
|
||||
```python
|
||||
from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef
|
||||
|
||||
# TODO update the JSON string below
|
||||
json = "{}"
|
||||
# create an instance of SecondCircularAllOfRef from a JSON string
|
||||
second_circular_all_of_ref_instance = SecondCircularAllOfRef.from_json(json)
|
||||
# print the JSON string representation of the object
|
||||
print(SecondCircularAllOfRef.to_json())
|
||||
|
||||
# convert the object into a dict
|
||||
second_circular_all_of_ref_dict = second_circular_all_of_ref_instance.to_dict()
|
||||
# create an instance of SecondCircularAllOfRef from a dict
|
||||
second_circular_all_of_ref_form_dict = second_circular_all_of_ref.from_dict(second_circular_all_of_ref_dict)
|
||||
```
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert
|
||||
from petstore_api.models.additional_properties_class import AdditionalPropertiesClass
|
||||
from petstore_api.models.additional_properties_object import AdditionalPropertiesObject
|
||||
from petstore_api.models.additional_properties_with_description_only import AdditionalPropertiesWithDescriptionOnly
|
||||
from petstore_api.models.all_of_super_model import AllOfSuperModel
|
||||
from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef
|
||||
from petstore_api.models.animal import Animal
|
||||
from petstore_api.models.any_of_color import AnyOfColor
|
||||
@@ -56,6 +57,7 @@ from petstore_api.models.bathing import Bathing
|
||||
from petstore_api.models.capitalization import Capitalization
|
||||
from petstore_api.models.cat import Cat
|
||||
from petstore_api.models.category import Category
|
||||
from petstore_api.models.circular_all_of_ref import CircularAllOfRef
|
||||
from petstore_api.models.circular_reference_model import CircularReferenceModel
|
||||
from petstore_api.models.class_model import ClassModel
|
||||
from petstore_api.models.client import Client
|
||||
@@ -115,6 +117,7 @@ from petstore_api.models.poop_cleaning import PoopCleaning
|
||||
from petstore_api.models.property_map import PropertyMap
|
||||
from petstore_api.models.property_name_collision import PropertyNameCollision
|
||||
from petstore_api.models.read_only_first import ReadOnlyFirst
|
||||
from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef
|
||||
from petstore_api.models.second_ref import SecondRef
|
||||
from petstore_api.models.self_reference_model import SelfReferenceModel
|
||||
from petstore_api.models.single_ref_type import SingleRefType
|
||||
|
||||
@@ -18,6 +18,7 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert
|
||||
from petstore_api.models.additional_properties_class import AdditionalPropertiesClass
|
||||
from petstore_api.models.additional_properties_object import AdditionalPropertiesObject
|
||||
from petstore_api.models.additional_properties_with_description_only import AdditionalPropertiesWithDescriptionOnly
|
||||
from petstore_api.models.all_of_super_model import AllOfSuperModel
|
||||
from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef
|
||||
from petstore_api.models.animal import Animal
|
||||
from petstore_api.models.any_of_color import AnyOfColor
|
||||
@@ -31,6 +32,7 @@ from petstore_api.models.bathing import Bathing
|
||||
from petstore_api.models.capitalization import Capitalization
|
||||
from petstore_api.models.cat import Cat
|
||||
from petstore_api.models.category import Category
|
||||
from petstore_api.models.circular_all_of_ref import CircularAllOfRef
|
||||
from petstore_api.models.circular_reference_model import CircularReferenceModel
|
||||
from petstore_api.models.class_model import ClassModel
|
||||
from petstore_api.models.client import Client
|
||||
@@ -90,6 +92,7 @@ from petstore_api.models.poop_cleaning import PoopCleaning
|
||||
from petstore_api.models.property_map import PropertyMap
|
||||
from petstore_api.models.property_name_collision import PropertyNameCollision
|
||||
from petstore_api.models.read_only_first import ReadOnlyFirst
|
||||
from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef
|
||||
from petstore_api.models.second_ref import SecondRef
|
||||
from petstore_api.models.self_reference_model import SelfReferenceModel
|
||||
from petstore_api.models.single_ref_type import SingleRefType
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
OpenAPI Petstore
|
||||
|
||||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
from __future__ import annotations
|
||||
import pprint
|
||||
import re # noqa: F401
|
||||
import json
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, StrictStr
|
||||
from typing import Any, ClassVar, Dict, List, Optional
|
||||
from typing import Optional, Set
|
||||
from typing_extensions import Self
|
||||
|
||||
class AllOfSuperModel(BaseModel):
|
||||
"""
|
||||
AllOfSuperModel
|
||||
""" # noqa: E501
|
||||
name: Optional[StrictStr] = Field(default=None, alias="_name")
|
||||
additional_properties: Dict[str, Any] = {}
|
||||
__properties: ClassVar[List[str]] = ["_name"]
|
||||
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
validate_assignment=True,
|
||||
protected_namespaces=(),
|
||||
)
|
||||
|
||||
|
||||
def to_str(self) -> str:
|
||||
"""Returns the string representation of the model using alias"""
|
||||
return pprint.pformat(self.model_dump(by_alias=True))
|
||||
|
||||
def to_json(self) -> str:
|
||||
"""Returns the JSON representation of the model using alias"""
|
||||
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Optional[Self]:
|
||||
"""Create an instance of AllOfSuperModel from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
"""Return the dictionary representation of the model using alias.
|
||||
|
||||
This has the following differences from calling pydantic's
|
||||
`self.model_dump(by_alias=True)`:
|
||||
|
||||
* `None` is only added to the output dict for nullable fields that
|
||||
were set at model initialization. Other fields with value `None`
|
||||
are ignored.
|
||||
* Fields in `self.additional_properties` are added to the output dict.
|
||||
"""
|
||||
excluded_fields: Set[str] = set([
|
||||
"additional_properties",
|
||||
])
|
||||
|
||||
_dict = self.model_dump(
|
||||
by_alias=True,
|
||||
exclude=excluded_fields,
|
||||
exclude_none=True,
|
||||
)
|
||||
# puts key-value pairs in additional_properties in the top level
|
||||
if self.additional_properties is not None:
|
||||
for _key, _value in self.additional_properties.items():
|
||||
_dict[_key] = _value
|
||||
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
||||
"""Create an instance of AllOfSuperModel from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = cls.model_validate({
|
||||
"_name": obj.get("_name")
|
||||
})
|
||||
# store additional fields in additional_properties
|
||||
for _key in obj.keys():
|
||||
if _key not in cls.__properties:
|
||||
_obj.additional_properties[_key] = obj.get(_key)
|
||||
|
||||
return _obj
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
OpenAPI Petstore
|
||||
|
||||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
from __future__ import annotations
|
||||
import pprint
|
||||
import re # noqa: F401
|
||||
import json
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, StrictStr
|
||||
from typing import Any, ClassVar, Dict, List, Optional
|
||||
from typing import Optional, Set
|
||||
from typing_extensions import Self
|
||||
|
||||
class CircularAllOfRef(BaseModel):
|
||||
"""
|
||||
CircularAllOfRef
|
||||
""" # noqa: E501
|
||||
name: Optional[StrictStr] = Field(default=None, alias="_name")
|
||||
second_circular_all_of_ref: Optional[List[SecondCircularAllOfRef]] = Field(default=None, alias="secondCircularAllOfRef")
|
||||
additional_properties: Dict[str, Any] = {}
|
||||
__properties: ClassVar[List[str]] = ["_name", "secondCircularAllOfRef"]
|
||||
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
validate_assignment=True,
|
||||
protected_namespaces=(),
|
||||
)
|
||||
|
||||
|
||||
def to_str(self) -> str:
|
||||
"""Returns the string representation of the model using alias"""
|
||||
return pprint.pformat(self.model_dump(by_alias=True))
|
||||
|
||||
def to_json(self) -> str:
|
||||
"""Returns the JSON representation of the model using alias"""
|
||||
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Optional[Self]:
|
||||
"""Create an instance of CircularAllOfRef from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
"""Return the dictionary representation of the model using alias.
|
||||
|
||||
This has the following differences from calling pydantic's
|
||||
`self.model_dump(by_alias=True)`:
|
||||
|
||||
* `None` is only added to the output dict for nullable fields that
|
||||
were set at model initialization. Other fields with value `None`
|
||||
are ignored.
|
||||
* Fields in `self.additional_properties` are added to the output dict.
|
||||
"""
|
||||
excluded_fields: Set[str] = set([
|
||||
"additional_properties",
|
||||
])
|
||||
|
||||
_dict = self.model_dump(
|
||||
by_alias=True,
|
||||
exclude=excluded_fields,
|
||||
exclude_none=True,
|
||||
)
|
||||
# override the default output from pydantic by calling `to_dict()` of each item in second_circular_all_of_ref (list)
|
||||
_items = []
|
||||
if self.second_circular_all_of_ref:
|
||||
for _item in self.second_circular_all_of_ref:
|
||||
if _item:
|
||||
_items.append(_item.to_dict())
|
||||
_dict['secondCircularAllOfRef'] = _items
|
||||
# puts key-value pairs in additional_properties in the top level
|
||||
if self.additional_properties is not None:
|
||||
for _key, _value in self.additional_properties.items():
|
||||
_dict[_key] = _value
|
||||
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
||||
"""Create an instance of CircularAllOfRef from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = cls.model_validate({
|
||||
"_name": obj.get("_name"),
|
||||
"secondCircularAllOfRef": [SecondCircularAllOfRef.from_dict(_item) for _item in obj["secondCircularAllOfRef"]] if obj.get("secondCircularAllOfRef") is not None else None
|
||||
})
|
||||
# store additional fields in additional_properties
|
||||
for _key in obj.keys():
|
||||
if _key not in cls.__properties:
|
||||
_obj.additional_properties[_key] = obj.get(_key)
|
||||
|
||||
return _obj
|
||||
|
||||
from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef
|
||||
# TODO: Rewrite to not use raise_errors
|
||||
CircularAllOfRef.model_rebuild(raise_errors=False)
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
OpenAPI Petstore
|
||||
|
||||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
from __future__ import annotations
|
||||
import pprint
|
||||
import re # noqa: F401
|
||||
import json
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, StrictStr
|
||||
from typing import Any, ClassVar, Dict, List, Optional
|
||||
from typing import Optional, Set
|
||||
from typing_extensions import Self
|
||||
|
||||
class SecondCircularAllOfRef(BaseModel):
|
||||
"""
|
||||
SecondCircularAllOfRef
|
||||
""" # noqa: E501
|
||||
name: Optional[StrictStr] = Field(default=None, alias="_name")
|
||||
circular_all_of_ref: Optional[List[CircularAllOfRef]] = Field(default=None, alias="circularAllOfRef")
|
||||
additional_properties: Dict[str, Any] = {}
|
||||
__properties: ClassVar[List[str]] = ["_name", "circularAllOfRef"]
|
||||
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
validate_assignment=True,
|
||||
protected_namespaces=(),
|
||||
)
|
||||
|
||||
|
||||
def to_str(self) -> str:
|
||||
"""Returns the string representation of the model using alias"""
|
||||
return pprint.pformat(self.model_dump(by_alias=True))
|
||||
|
||||
def to_json(self) -> str:
|
||||
"""Returns the JSON representation of the model using alias"""
|
||||
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Optional[Self]:
|
||||
"""Create an instance of SecondCircularAllOfRef from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
"""Return the dictionary representation of the model using alias.
|
||||
|
||||
This has the following differences from calling pydantic's
|
||||
`self.model_dump(by_alias=True)`:
|
||||
|
||||
* `None` is only added to the output dict for nullable fields that
|
||||
were set at model initialization. Other fields with value `None`
|
||||
are ignored.
|
||||
* Fields in `self.additional_properties` are added to the output dict.
|
||||
"""
|
||||
excluded_fields: Set[str] = set([
|
||||
"additional_properties",
|
||||
])
|
||||
|
||||
_dict = self.model_dump(
|
||||
by_alias=True,
|
||||
exclude=excluded_fields,
|
||||
exclude_none=True,
|
||||
)
|
||||
# override the default output from pydantic by calling `to_dict()` of each item in circular_all_of_ref (list)
|
||||
_items = []
|
||||
if self.circular_all_of_ref:
|
||||
for _item in self.circular_all_of_ref:
|
||||
if _item:
|
||||
_items.append(_item.to_dict())
|
||||
_dict['circularAllOfRef'] = _items
|
||||
# puts key-value pairs in additional_properties in the top level
|
||||
if self.additional_properties is not None:
|
||||
for _key, _value in self.additional_properties.items():
|
||||
_dict[_key] = _value
|
||||
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
||||
"""Create an instance of SecondCircularAllOfRef from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = cls.model_validate({
|
||||
"_name": obj.get("_name"),
|
||||
"circularAllOfRef": [CircularAllOfRef.from_dict(_item) for _item in obj["circularAllOfRef"]] if obj.get("circularAllOfRef") is not None else None
|
||||
})
|
||||
# store additional fields in additional_properties
|
||||
for _key in obj.keys():
|
||||
if _key not in cls.__properties:
|
||||
_obj.additional_properties[_key] = obj.get(_key)
|
||||
|
||||
return _obj
|
||||
|
||||
from petstore_api.models.circular_all_of_ref import CircularAllOfRef
|
||||
# TODO: Rewrite to not use raise_errors
|
||||
SecondCircularAllOfRef.model_rebuild(raise_errors=False)
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
OpenAPI Petstore
|
||||
|
||||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
import unittest
|
||||
|
||||
from petstore_api.models.all_of_super_model import AllOfSuperModel
|
||||
|
||||
class TestAllOfSuperModel(unittest.TestCase):
|
||||
"""AllOfSuperModel unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional) -> AllOfSuperModel:
|
||||
"""Test AllOfSuperModel
|
||||
include_option is a boolean, when False only required
|
||||
params are included, when True both required and
|
||||
optional params are included """
|
||||
# uncomment below to create an instance of `AllOfSuperModel`
|
||||
"""
|
||||
model = AllOfSuperModel()
|
||||
if include_optional:
|
||||
return AllOfSuperModel(
|
||||
name = ''
|
||||
)
|
||||
else:
|
||||
return AllOfSuperModel(
|
||||
)
|
||||
"""
|
||||
|
||||
def testAllOfSuperModel(self):
|
||||
"""Test AllOfSuperModel"""
|
||||
# inst_req_only = self.make_instance(include_optional=False)
|
||||
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,60 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
OpenAPI Petstore
|
||||
|
||||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
import unittest
|
||||
|
||||
from petstore_api.models.circular_all_of_ref import CircularAllOfRef
|
||||
|
||||
class TestCircularAllOfRef(unittest.TestCase):
|
||||
"""CircularAllOfRef unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional) -> CircularAllOfRef:
|
||||
"""Test CircularAllOfRef
|
||||
include_option is a boolean, when False only required
|
||||
params are included, when True both required and
|
||||
optional params are included """
|
||||
# uncomment below to create an instance of `CircularAllOfRef`
|
||||
"""
|
||||
model = CircularAllOfRef()
|
||||
if include_optional:
|
||||
return CircularAllOfRef(
|
||||
second_circular_all_of_ref = [
|
||||
petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef(
|
||||
circular_all_of_ref = [
|
||||
petstore_api.models.circular_all_of_ref.CircularAllOfRef(
|
||||
second_circular_all_of_ref = [
|
||||
petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef()
|
||||
], )
|
||||
], )
|
||||
],
|
||||
name = ''
|
||||
)
|
||||
else:
|
||||
return CircularAllOfRef(
|
||||
)
|
||||
"""
|
||||
|
||||
def testCircularAllOfRef(self):
|
||||
"""Test CircularAllOfRef"""
|
||||
# inst_req_only = self.make_instance(include_optional=False)
|
||||
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,57 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
OpenAPI Petstore
|
||||
|
||||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
import unittest
|
||||
|
||||
from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef
|
||||
|
||||
class TestSecondCircularAllOfRef(unittest.TestCase):
|
||||
"""SecondCircularAllOfRef unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional) -> SecondCircularAllOfRef:
|
||||
"""Test SecondCircularAllOfRef
|
||||
include_option is a boolean, when False only required
|
||||
params are included, when True both required and
|
||||
optional params are included """
|
||||
# uncomment below to create an instance of `SecondCircularAllOfRef`
|
||||
"""
|
||||
model = SecondCircularAllOfRef()
|
||||
if include_optional:
|
||||
return SecondCircularAllOfRef(
|
||||
circular_all_of_ref = [
|
||||
petstore_api.models.circular_all_of_ref.CircularAllOfRef(
|
||||
second_circular_all_of_ref = [
|
||||
petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef()
|
||||
], )
|
||||
],
|
||||
name = ''
|
||||
)
|
||||
else:
|
||||
return SecondCircularAllOfRef(
|
||||
)
|
||||
"""
|
||||
|
||||
def testSecondCircularAllOfRef(self):
|
||||
"""Test SecondCircularAllOfRef"""
|
||||
# inst_req_only = self.make_instance(include_optional=False)
|
||||
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -619,6 +619,16 @@ class ModelTests(unittest.TestCase):
|
||||
assert model is not None
|
||||
self.assertEqual(model.to_json(), '{"skill": "none", "type": "tiger", "info": {"name": "creature info"}}')
|
||||
|
||||
def test_allof_circular_imports(self):
|
||||
# for issue 18271
|
||||
model_a = petstore_api.models.circular_all_of_ref.CircularAllOfRef.from_json('{"_name": "nameA", "second_circular_all_of_ref": {"name": "nameB"}}')
|
||||
model_b = petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef.from_json('{"_name": "nameB", "circular_all_of_ref": {"name": "nameA"}}')
|
||||
# shouldn't throw ImportError
|
||||
assert model_a is not None
|
||||
assert model_b is not None
|
||||
self.assertEqual(model_a.to_json(), '{"_name": "nameA", "second_circular_all_of_ref": {"name": "nameB"}}')
|
||||
self.assertEqual(model_b.to_json(), '{"_name": "nameB", "circular_all_of_ref": {"name": "nameA"}}')
|
||||
|
||||
|
||||
class TestdditionalPropertiesAnyType(unittest.TestCase):
|
||||
def test_additional_properties(self):
|
||||
|
||||
Reference in New Issue
Block a user