-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[python] Fix Circular imports on inherited discriminators. (#17886)
* [python] add inheritance discriminators test #16808 * [python] update samples * [python] fix assert in test * [python] fix inheritance discriminators circular import * [python] update samples * [python] undo type changes related to discriminator * [python] remove extraneous processing * [python-pydantic-v1] fix inheritance discriminators circular import * [python] remove type ignore comment * [python] update samples * [python] fix avoid the empty line break * [python] update samples
- Loading branch information
Showing
50 changed files
with
1,543 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
28 changes: 28 additions & 0 deletions
28
samples/openapi3/client/petstore/python-aiohttp/docs/DiscriminatorAllOfSub.md
This file contains 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,28 @@ | ||
# DiscriminatorAllOfSub | ||
|
||
|
||
## Properties | ||
|
||
Name | Type | Description | Notes | ||
------------ | ------------- | ------------- | ------------- | ||
|
||
## Example | ||
|
||
```python | ||
from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub | ||
|
||
# TODO update the JSON string below | ||
json = "{}" | ||
# create an instance of DiscriminatorAllOfSub from a JSON string | ||
discriminator_all_of_sub_instance = DiscriminatorAllOfSub.from_json(json) | ||
# print the JSON string representation of the object | ||
print DiscriminatorAllOfSub.to_json() | ||
|
||
# convert the object into a dict | ||
discriminator_all_of_sub_dict = discriminator_all_of_sub_instance.to_dict() | ||
# create an instance of DiscriminatorAllOfSub from a dict | ||
discriminator_all_of_sub_form_dict = discriminator_all_of_sub.from_dict(discriminator_all_of_sub_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) | ||
|
||
|
29 changes: 29 additions & 0 deletions
29
samples/openapi3/client/petstore/python-aiohttp/docs/DiscriminatorAllOfSuper.md
This file contains 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 @@ | ||
# DiscriminatorAllOfSuper | ||
|
||
|
||
## Properties | ||
|
||
Name | Type | Description | Notes | ||
------------ | ------------- | ------------- | ------------- | ||
**element_type** | **str** | | | ||
|
||
## Example | ||
|
||
```python | ||
from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper | ||
|
||
# TODO update the JSON string below | ||
json = "{}" | ||
# create an instance of DiscriminatorAllOfSuper from a JSON string | ||
discriminator_all_of_super_instance = DiscriminatorAllOfSuper.from_json(json) | ||
# print the JSON string representation of the object | ||
print DiscriminatorAllOfSuper.to_json() | ||
|
||
# convert the object into a dict | ||
discriminator_all_of_super_dict = discriminator_all_of_super_instance.to_dict() | ||
# create an instance of DiscriminatorAllOfSuper from a dict | ||
discriminator_all_of_super_form_dict = discriminator_all_of_super.from_dict(discriminator_all_of_super_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 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 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 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
86 changes: 86 additions & 0 deletions
86
...s/openapi3/client/petstore/python-aiohttp/petstore_api/models/discriminator_all_of_sub.py
This file contains 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,86 @@ | ||
# 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 Any, ClassVar, Dict, List | ||
from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper | ||
from typing import Optional, Set | ||
from typing_extensions import Self | ||
|
||
class DiscriminatorAllOfSub(DiscriminatorAllOfSuper): | ||
""" | ||
DiscriminatorAllOfSub | ||
""" # noqa: E501 | ||
__properties: ClassVar[List[str]] = ["elementType"] | ||
|
||
model_config = { | ||
"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 DiscriminatorAllOfSub 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 DiscriminatorAllOfSub from a dict""" | ||
if obj is None: | ||
return None | ||
|
||
if not isinstance(obj, dict): | ||
return cls.model_validate(obj) | ||
|
||
_obj = cls.model_validate({ | ||
"elementType": obj.get("elementType") | ||
}) | ||
return _obj | ||
|
||
|
Oops, something went wrong.