-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[python] Fix circular imports on AllOf generation #18272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c90107b
fix issue 18271
zishunwei d67fbc5
the same update for python-pydantic-v1
zishunwei efc876a
add test
zishunwei 190de9f
update samples
zishunwei 8bc9943
update samples
zishunwei 99ca559
Merge branch 'master' into fix_issue18271
zishunwei 510b0df
put properties under allOf for python client tests
zishunwei 8c8fcf2
update samples
zishunwei c73310b
add a test in test model
zishunwei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
samples/openapi3/client/petstore/python-aiohttp/docs/AllOfSuperModel.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
|
30 changes: 30 additions & 0 deletions
30
samples/openapi3/client/petstore/python-aiohttp/docs/CircularAllOfRef.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
|
30 changes: 30 additions & 0 deletions
30
samples/openapi3/client/petstore/python-aiohttp/docs/SecondCircularAllOfRef.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_super_model.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# coding: utf-8 | ||
|
||
""" | ||
OpenAPI Petstore | ||
|
||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ | ||
|
||
The version of the OpenAPI document: 1.0.0 | ||
Generated by OpenAPI Generator (https://openapi-generator.tech) | ||
|
||
Do not edit the class manually. | ||
""" # noqa: E501 | ||
|
||
|
||
from __future__ import annotations | ||
import pprint | ||
import re # noqa: F401 | ||
import json | ||
|
||
from pydantic import BaseModel, ConfigDict, Field, StrictStr | ||
from typing import Any, ClassVar, Dict, List, Optional | ||
from typing import Optional, Set | ||
from typing_extensions import Self | ||
|
||
class AllOfSuperModel(BaseModel): | ||
""" | ||
AllOfSuperModel | ||
""" # noqa: E501 | ||
name: Optional[StrictStr] = Field(default=None, alias="_name") | ||
__properties: ClassVar[List[str]] = ["_name"] | ||
|
||
model_config = ConfigDict( | ||
populate_by_name=True, | ||
validate_assignment=True, | ||
protected_namespaces=(), | ||
) | ||
|
||
|
||
def to_str(self) -> str: | ||
"""Returns the string representation of the model using alias""" | ||
return pprint.pformat(self.model_dump(by_alias=True)) | ||
|
||
def to_json(self) -> str: | ||
"""Returns the JSON representation of the model using alias""" | ||
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||
return json.dumps(self.to_dict()) | ||
|
||
@classmethod | ||
def from_json(cls, json_str: str) -> Optional[Self]: | ||
"""Create an instance of AllOfSuperModel from a JSON string""" | ||
return cls.from_dict(json.loads(json_str)) | ||
|
||
def to_dict(self) -> Dict[str, Any]: | ||
"""Return the dictionary representation of the model using alias. | ||
|
||
This has the following differences from calling pydantic's | ||
`self.model_dump(by_alias=True)`: | ||
|
||
* `None` is only added to the output dict for nullable fields that | ||
were set at model initialization. Other fields with value `None` | ||
are ignored. | ||
""" | ||
excluded_fields: Set[str] = set([ | ||
]) | ||
|
||
_dict = self.model_dump( | ||
by_alias=True, | ||
exclude=excluded_fields, | ||
exclude_none=True, | ||
) | ||
return _dict | ||
|
||
@classmethod | ||
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: | ||
"""Create an instance of AllOfSuperModel from a dict""" | ||
if obj is None: | ||
return None | ||
|
||
if not isinstance(obj, dict): | ||
return cls.model_validate(obj) | ||
|
||
_obj = cls.model_validate({ | ||
"_name": obj.get("_name") | ||
}) | ||
return _obj | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.