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:
Zishun (Zack) Wei
2024-04-08 19:01:01 +08:00
committed by GitHub
parent 2c663561ef
commit 453facc81c
56 changed files with 2246 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ docs/AdditionalPropertiesAnyType.md
docs/AdditionalPropertiesClass.md
docs/AdditionalPropertiesObject.md
docs/AdditionalPropertiesWithDescriptionOnly.md
docs/AllOfSuperModel.md
docs/AllOfWithSingleRef.md
docs/Animal.md
docs/AnotherFakeApi.md
@@ -22,6 +23,7 @@ docs/Bathing.md
docs/Capitalization.md
docs/Cat.md
docs/Category.md
docs/CircularAllOfRef.md
docs/CircularReferenceModel.md
docs/ClassModel.md
docs/Client.md
@@ -85,6 +87,7 @@ docs/PoopCleaning.md
docs/PropertyMap.md
docs/PropertyNameCollision.md
docs/ReadOnlyFirst.md
docs/SecondCircularAllOfRef.md
docs/SecondRef.md
docs/SelfReferenceModel.md
docs/SingleRefType.md
@@ -125,6 +128,7 @@ petstore_api/models/additional_properties_any_type.py
petstore_api/models/additional_properties_class.py
petstore_api/models/additional_properties_object.py
petstore_api/models/additional_properties_with_description_only.py
petstore_api/models/all_of_super_model.py
petstore_api/models/all_of_with_single_ref.py
petstore_api/models/animal.py
petstore_api/models/any_of_color.py
@@ -139,6 +143,7 @@ petstore_api/models/bathing.py
petstore_api/models/capitalization.py
petstore_api/models/cat.py
petstore_api/models/category.py
petstore_api/models/circular_all_of_ref.py
petstore_api/models/circular_reference_model.py
petstore_api/models/class_model.py
petstore_api/models/client.py
@@ -197,6 +202,7 @@ petstore_api/models/poop_cleaning.py
petstore_api/models/property_map.py
petstore_api/models/property_name_collision.py
petstore_api/models/read_only_first.py
petstore_api/models/second_circular_all_of_ref.py
petstore_api/models/second_ref.py
petstore_api/models/self_reference_model.py
petstore_api/models/single_ref_type.py

View File

@@ -155,6 +155,7 @@ Class | Method | HTTP request | Description
- [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
- [AdditionalPropertiesObject](docs/AdditionalPropertiesObject.md)
- [AdditionalPropertiesWithDescriptionOnly](docs/AdditionalPropertiesWithDescriptionOnly.md)
- [AllOfSuperModel](docs/AllOfSuperModel.md)
- [AllOfWithSingleRef](docs/AllOfWithSingleRef.md)
- [Animal](docs/Animal.md)
- [AnyOfColor](docs/AnyOfColor.md)
@@ -169,6 +170,7 @@ Class | Method | HTTP request | Description
- [Capitalization](docs/Capitalization.md)
- [Cat](docs/Cat.md)
- [Category](docs/Category.md)
- [CircularAllOfRef](docs/CircularAllOfRef.md)
- [CircularReferenceModel](docs/CircularReferenceModel.md)
- [ClassModel](docs/ClassModel.md)
- [Client](docs/Client.md)
@@ -227,6 +229,7 @@ Class | Method | HTTP request | Description
- [PropertyMap](docs/PropertyMap.md)
- [PropertyNameCollision](docs/PropertyNameCollision.md)
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [SecondCircularAllOfRef](docs/SecondCircularAllOfRef.md)
- [SecondRef](docs/SecondRef.md)
- [SelfReferenceModel](docs/SelfReferenceModel.md)
- [SingleRefType](docs/SingleRefType.md)

View File

@@ -0,0 +1,28 @@
# AllOfSuperModel
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **str** | | [optional]
## Example
```python
from petstore_api.models.all_of_super_model import AllOfSuperModel
# TODO update the JSON string below
json = "{}"
# create an instance of AllOfSuperModel from a JSON string
all_of_super_model_instance = AllOfSuperModel.from_json(json)
# print the JSON string representation of the object
print AllOfSuperModel.to_json()
# convert the object into a dict
all_of_super_model_dict = all_of_super_model_instance.to_dict()
# create an instance of AllOfSuperModel from a dict
all_of_super_model_form_dict = all_of_super_model.from_dict(all_of_super_model_dict)
```
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -0,0 +1,29 @@
# CircularAllOfRef
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **str** | | [optional]
**second_circular_all_of_ref** | [**List[SecondCircularAllOfRef]**](SecondCircularAllOfRef.md) | | [optional]
## Example
```python
from petstore_api.models.circular_all_of_ref import CircularAllOfRef
# TODO update the JSON string below
json = "{}"
# create an instance of CircularAllOfRef from a JSON string
circular_all_of_ref_instance = CircularAllOfRef.from_json(json)
# print the JSON string representation of the object
print CircularAllOfRef.to_json()
# convert the object into a dict
circular_all_of_ref_dict = circular_all_of_ref_instance.to_dict()
# create an instance of CircularAllOfRef from a dict
circular_all_of_ref_form_dict = circular_all_of_ref.from_dict(circular_all_of_ref_dict)
```
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -0,0 +1,29 @@
# SecondCircularAllOfRef
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **str** | | [optional]
**circular_all_of_ref** | [**List[CircularAllOfRef]**](CircularAllOfRef.md) | | [optional]
## Example
```python
from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef
# TODO update the JSON string below
json = "{}"
# create an instance of SecondCircularAllOfRef from a JSON string
second_circular_all_of_ref_instance = SecondCircularAllOfRef.from_json(json)
# print the JSON string representation of the object
print SecondCircularAllOfRef.to_json()
# convert the object into a dict
second_circular_all_of_ref_dict = second_circular_all_of_ref_instance.to_dict()
# create an instance of SecondCircularAllOfRef from a dict
second_circular_all_of_ref_form_dict = second_circular_all_of_ref.from_dict(second_circular_all_of_ref_dict)
```
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -43,6 +43,7 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert
from petstore_api.models.additional_properties_class import AdditionalPropertiesClass
from petstore_api.models.additional_properties_object import AdditionalPropertiesObject
from petstore_api.models.additional_properties_with_description_only import AdditionalPropertiesWithDescriptionOnly
from petstore_api.models.all_of_super_model import AllOfSuperModel
from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef
from petstore_api.models.animal import Animal
from petstore_api.models.any_of_color import AnyOfColor
@@ -57,6 +58,7 @@ from petstore_api.models.bathing import Bathing
from petstore_api.models.capitalization import Capitalization
from petstore_api.models.cat import Cat
from petstore_api.models.category import Category
from petstore_api.models.circular_all_of_ref import CircularAllOfRef
from petstore_api.models.circular_reference_model import CircularReferenceModel
from petstore_api.models.class_model import ClassModel
from petstore_api.models.client import Client
@@ -115,6 +117,7 @@ from petstore_api.models.poop_cleaning import PoopCleaning
from petstore_api.models.property_map import PropertyMap
from petstore_api.models.property_name_collision import PropertyNameCollision
from petstore_api.models.read_only_first import ReadOnlyFirst
from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef
from petstore_api.models.second_ref import SecondRef
from petstore_api.models.self_reference_model import SelfReferenceModel
from petstore_api.models.single_ref_type import SingleRefType

View File

@@ -18,6 +18,7 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert
from petstore_api.models.additional_properties_class import AdditionalPropertiesClass
from petstore_api.models.additional_properties_object import AdditionalPropertiesObject
from petstore_api.models.additional_properties_with_description_only import AdditionalPropertiesWithDescriptionOnly
from petstore_api.models.all_of_super_model import AllOfSuperModel
from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef
from petstore_api.models.animal import Animal
from petstore_api.models.any_of_color import AnyOfColor
@@ -32,6 +33,7 @@ from petstore_api.models.bathing import Bathing
from petstore_api.models.capitalization import Capitalization
from petstore_api.models.cat import Cat
from petstore_api.models.category import Category
from petstore_api.models.circular_all_of_ref import CircularAllOfRef
from petstore_api.models.circular_reference_model import CircularReferenceModel
from petstore_api.models.class_model import ClassModel
from petstore_api.models.client import Client
@@ -90,6 +92,7 @@ from petstore_api.models.poop_cleaning import PoopCleaning
from petstore_api.models.property_map import PropertyMap
from petstore_api.models.property_name_collision import PropertyNameCollision
from petstore_api.models.read_only_first import ReadOnlyFirst
from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef
from petstore_api.models.second_ref import SecondRef
from petstore_api.models.self_reference_model import SelfReferenceModel
from petstore_api.models.single_ref_type import SingleRefType

View File

@@ -0,0 +1,71 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from typing import Optional
from pydantic import BaseModel, Field, StrictStr
class AllOfSuperModel(BaseModel):
"""
AllOfSuperModel
"""
name: Optional[StrictStr] = Field(default=None, alias="_name")
__properties = ["_name"]
class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.dict(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> AllOfSuperModel:
"""Create an instance of AllOfSuperModel from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
exclude={
},
exclude_none=True)
return _dict
@classmethod
def from_dict(cls, obj: dict) -> AllOfSuperModel:
"""Create an instance of AllOfSuperModel from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return AllOfSuperModel.parse_obj(obj)
_obj = AllOfSuperModel.parse_obj({
"name": obj.get("_name")
})
return _obj

View File

@@ -0,0 +1,82 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from typing import List, Optional
from pydantic import BaseModel, Field, StrictStr, conlist
class CircularAllOfRef(BaseModel):
"""
CircularAllOfRef
"""
name: Optional[StrictStr] = Field(default=None, alias="_name")
second_circular_all_of_ref: Optional[conlist(SecondCircularAllOfRef)] = Field(default=None, alias="secondCircularAllOfRef")
__properties = ["_name", "secondCircularAllOfRef"]
class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.dict(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> CircularAllOfRef:
"""Create an instance of CircularAllOfRef from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
exclude={
},
exclude_none=True)
# override the default output from pydantic by calling `to_dict()` of each item in second_circular_all_of_ref (list)
_items = []
if self.second_circular_all_of_ref:
for _item in self.second_circular_all_of_ref:
if _item:
_items.append(_item.to_dict())
_dict['secondCircularAllOfRef'] = _items
return _dict
@classmethod
def from_dict(cls, obj: dict) -> CircularAllOfRef:
"""Create an instance of CircularAllOfRef from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return CircularAllOfRef.parse_obj(obj)
_obj = CircularAllOfRef.parse_obj({
"name": obj.get("_name"),
"second_circular_all_of_ref": [SecondCircularAllOfRef.from_dict(_item) for _item in obj.get("secondCircularAllOfRef")] if obj.get("secondCircularAllOfRef") is not None else None
})
return _obj
from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef
CircularAllOfRef.update_forward_refs()

View File

@@ -0,0 +1,82 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from typing import List, Optional
from pydantic import BaseModel, Field, StrictStr, conlist
class SecondCircularAllOfRef(BaseModel):
"""
SecondCircularAllOfRef
"""
name: Optional[StrictStr] = Field(default=None, alias="_name")
circular_all_of_ref: Optional[conlist(CircularAllOfRef)] = Field(default=None, alias="circularAllOfRef")
__properties = ["_name", "circularAllOfRef"]
class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.dict(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> SecondCircularAllOfRef:
"""Create an instance of SecondCircularAllOfRef from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
exclude={
},
exclude_none=True)
# override the default output from pydantic by calling `to_dict()` of each item in circular_all_of_ref (list)
_items = []
if self.circular_all_of_ref:
for _item in self.circular_all_of_ref:
if _item:
_items.append(_item.to_dict())
_dict['circularAllOfRef'] = _items
return _dict
@classmethod
def from_dict(cls, obj: dict) -> SecondCircularAllOfRef:
"""Create an instance of SecondCircularAllOfRef from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return SecondCircularAllOfRef.parse_obj(obj)
_obj = SecondCircularAllOfRef.parse_obj({
"name": obj.get("_name"),
"circular_all_of_ref": [CircularAllOfRef.from_dict(_item) for _item in obj.get("circularAllOfRef")] if obj.get("circularAllOfRef") is not None else None
})
return _obj
from petstore_api.models.circular_all_of_ref import CircularAllOfRef
SecondCircularAllOfRef.update_forward_refs()

View File

@@ -0,0 +1,52 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
import unittest
import datetime
from petstore_api.models.all_of_super_model import AllOfSuperModel # noqa: E501
class TestAllOfSuperModel(unittest.TestCase):
"""AllOfSuperModel unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional) -> AllOfSuperModel:
"""Test AllOfSuperModel
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
# uncomment below to create an instance of `AllOfSuperModel`
"""
model = AllOfSuperModel() # noqa: E501
if include_optional:
return AllOfSuperModel(
name = ''
)
else:
return AllOfSuperModel(
)
"""
def testAllOfSuperModel(self):
"""Test AllOfSuperModel"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,61 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
import unittest
import datetime
from petstore_api.models.circular_all_of_ref import CircularAllOfRef # noqa: E501
class TestCircularAllOfRef(unittest.TestCase):
"""CircularAllOfRef unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional) -> CircularAllOfRef:
"""Test CircularAllOfRef
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
# uncomment below to create an instance of `CircularAllOfRef`
"""
model = CircularAllOfRef() # noqa: E501
if include_optional:
return CircularAllOfRef(
second_circular_all_of_ref = [
petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef(
circular_all_of_ref = [
petstore_api.models.circular_all_of_ref.CircularAllOfRef(
second_circular_all_of_ref = [
petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef()
], )
], )
],
name = ''
)
else:
return CircularAllOfRef(
)
"""
def testCircularAllOfRef(self):
"""Test CircularAllOfRef"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,58 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
import unittest
import datetime
from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef # noqa: E501
class TestSecondCircularAllOfRef(unittest.TestCase):
"""SecondCircularAllOfRef unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional) -> SecondCircularAllOfRef:
"""Test SecondCircularAllOfRef
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
# uncomment below to create an instance of `SecondCircularAllOfRef`
"""
model = SecondCircularAllOfRef() # noqa: E501
if include_optional:
return SecondCircularAllOfRef(
circular_all_of_ref = [
petstore_api.models.circular_all_of_ref.CircularAllOfRef(
second_circular_all_of_ref = [
petstore_api.models.second_circular_all_of_ref.SecondCircularAllOfRef()
], )
],
name = ''
)
else:
return SecondCircularAllOfRef(
)
"""
def testSecondCircularAllOfRef(self):
"""Test SecondCircularAllOfRef"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()