forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add enum default value tests to python clients (OpenAPITools#18883)
* add enum default value tests to python clients * add new files
- Loading branch information
Showing
53 changed files
with
1,583 additions
and
1 deletion.
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
16 changes: 16 additions & 0 deletions
16
samples/openapi3/client/petstore/python-aiohttp/docs/TestEnum.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,16 @@ | ||
# TestEnum | ||
|
||
|
||
## Enum | ||
|
||
* `ONE` (value: `'ONE'`) | ||
|
||
* `TWO` (value: `'TWO'`) | ||
|
||
* `THREE` (value: `'THREE'`) | ||
|
||
* `FOUR` (value: `'foUr'`) | ||
|
||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) | ||
|
||
|
14 changes: 14 additions & 0 deletions
14
samples/openapi3/client/petstore/python-aiohttp/docs/TestEnumWithDefault.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,14 @@ | ||
# TestEnumWithDefault | ||
|
||
|
||
## Enum | ||
|
||
* `EIN` (value: `'EIN'`) | ||
|
||
* `ZWEI` (value: `'ZWEI'`) | ||
|
||
* `DREI` (value: `'DREI'`) | ||
|
||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) | ||
|
||
|
33 changes: 33 additions & 0 deletions
33
samples/openapi3/client/petstore/python-aiohttp/docs/TestModelWithEnumDefault.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,33 @@ | ||
# TestModelWithEnumDefault | ||
|
||
|
||
## Properties | ||
|
||
Name | Type | Description | Notes | ||
------------ | ------------- | ------------- | ------------- | ||
**test_enum** | [**TestEnum**](TestEnum.md) | | | ||
**test_string** | **str** | | [optional] | ||
**test_enum_with_default** | [**TestEnumWithDefault**](TestEnumWithDefault.md) | | [optional] [default to TestEnumWithDefault.ZWEI] | ||
**test_string_with_default** | **str** | | [optional] [default to 'ahoy matey'] | ||
**test_inline_defined_enum_with_default** | **str** | | [optional] [default to 'B'] | ||
|
||
## Example | ||
|
||
```python | ||
from petstore_api.models.test_model_with_enum_default import TestModelWithEnumDefault | ||
|
||
# TODO update the JSON string below | ||
json = "{}" | ||
# create an instance of TestModelWithEnumDefault from a JSON string | ||
test_model_with_enum_default_instance = TestModelWithEnumDefault.from_json(json) | ||
# print the JSON string representation of the object | ||
print(TestModelWithEnumDefault.to_json()) | ||
|
||
# convert the object into a dict | ||
test_model_with_enum_default_dict = test_model_with_enum_default_instance.to_dict() | ||
# create an instance of TestModelWithEnumDefault from a dict | ||
test_model_with_enum_default_from_dict = TestModelWithEnumDefault.from_dict(test_model_with_enum_default_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
39 changes: 39 additions & 0 deletions
39
samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum.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,39 @@ | ||
# 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 json | ||
from enum import Enum | ||
from typing_extensions import Self | ||
|
||
|
||
class TestEnum(str, Enum): | ||
""" | ||
TestEnum | ||
""" | ||
|
||
""" | ||
allowed enum values | ||
""" | ||
ONE = 'ONE' | ||
TWO = 'TWO' | ||
THREE = 'THREE' | ||
FOUR = 'foUr' | ||
|
||
@classmethod | ||
def from_json(cls, json_str: str) -> Self: | ||
"""Create an instance of TestEnum from a JSON string""" | ||
return cls(json.loads(json_str)) | ||
|
||
|
38 changes: 38 additions & 0 deletions
38
...les/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum_with_default.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,38 @@ | ||
# 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 json | ||
from enum import Enum | ||
from typing_extensions import Self | ||
|
||
|
||
class TestEnumWithDefault(str, Enum): | ||
""" | ||
TestEnumWithDefault | ||
""" | ||
|
||
""" | ||
allowed enum values | ||
""" | ||
EIN = 'EIN' | ||
ZWEI = 'ZWEI' | ||
DREI = 'DREI' | ||
|
||
@classmethod | ||
def from_json(cls, json_str: str) -> Self: | ||
"""Create an instance of TestEnumWithDefault from a JSON string""" | ||
return cls(json.loads(json_str)) | ||
|
||
|
107 changes: 107 additions & 0 deletions
107
...enapi3/client/petstore/python-aiohttp/petstore_api/models/test_model_with_enum_default.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,107 @@ | ||
# 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, StrictStr, field_validator | ||
from typing import Any, ClassVar, Dict, List, Optional | ||
from petstore_api.models.test_enum import TestEnum | ||
from petstore_api.models.test_enum_with_default import TestEnumWithDefault | ||
from typing import Optional, Set | ||
from typing_extensions import Self | ||
|
||
class TestModelWithEnumDefault(BaseModel): | ||
""" | ||
TestModelWithEnumDefault | ||
""" # noqa: E501 | ||
test_enum: TestEnum | ||
test_string: Optional[StrictStr] = None | ||
test_enum_with_default: Optional[TestEnumWithDefault] = TestEnumWithDefault.ZWEI | ||
test_string_with_default: Optional[StrictStr] = 'ahoy matey' | ||
test_inline_defined_enum_with_default: Optional[StrictStr] = 'B' | ||
__properties: ClassVar[List[str]] = ["test_enum", "test_string", "test_enum_with_default", "test_string_with_default", "test_inline_defined_enum_with_default"] | ||
|
||
@field_validator('test_inline_defined_enum_with_default') | ||
def test_inline_defined_enum_with_default_validate_enum(cls, value): | ||
"""Validates the enum""" | ||
if value is None: | ||
return value | ||
|
||
if value not in set(['A', 'B', 'C']): | ||
raise ValueError("must be one of enum values ('A', 'B', 'C')") | ||
return value | ||
|
||
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 TestModelWithEnumDefault 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 TestModelWithEnumDefault from a dict""" | ||
if obj is None: | ||
return None | ||
|
||
if not isinstance(obj, dict): | ||
return cls.model_validate(obj) | ||
|
||
_obj = cls.model_validate({ | ||
"test_enum": obj.get("test_enum"), | ||
"test_string": obj.get("test_string"), | ||
"test_enum_with_default": obj.get("test_enum_with_default") if obj.get("test_enum_with_default") is not None else TestEnumWithDefault.ZWEI, | ||
"test_string_with_default": obj.get("test_string_with_default") if obj.get("test_string_with_default") is not None else 'ahoy matey', | ||
"test_inline_defined_enum_with_default": obj.get("test_inline_defined_enum_with_default") if obj.get("test_inline_defined_enum_with_default") is not None else 'B' | ||
}) | ||
return _obj | ||
|
||
|
33 changes: 33 additions & 0 deletions
33
samples/openapi3/client/petstore/python-aiohttp/test/test_test_enum.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,33 @@ | ||
# 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.test_enum import TestEnum | ||
|
||
class TestTestEnum(unittest.TestCase): | ||
"""TestEnum unit test stubs""" | ||
|
||
def setUp(self): | ||
pass | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def testTestEnum(self): | ||
"""Test TestEnum""" | ||
# inst = TestEnum() | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.