[python] change Private attr to Class vars (#16687)

* [python] fix TypeError

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update Private model attributes to Class vars

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] rename the List of test cases to ListClass

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] rename the List of v1 test cases to ListClass

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] rename the List of v1-aiohttp test cases to ListClass

Signed-off-by: ふぁ <yuki@yuki0311.com>

* update samples

---------

Signed-off-by: ふぁ <yuki@yuki0311.com>
Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
ふぁ
2023-10-01 17:52:23 +09:00
committed by GitHub
parent e2f249ba35
commit c6e9a4e1ae
171 changed files with 962 additions and 334 deletions

View File

@@ -49,7 +49,7 @@ docs/HasOnlyReadOnly.md
docs/HealthCheckResult.md
docs/InnerDictWithProperty.md
docs/IntOrString.md
docs/List.md
docs/ListClass.md
docs/MapOfArrayOfModel.md
docs/MapTest.md
docs/MixedPropertiesAndAdditionalPropertiesClass.md
@@ -146,7 +146,7 @@ petstore_api/models/has_only_read_only.py
petstore_api/models/health_check_result.py
petstore_api/models/inner_dict_with_property.py
petstore_api/models/int_or_string.py
petstore_api/models/list.py
petstore_api/models/list_class.py
petstore_api/models/map_of_array_of_model.py
petstore_api/models/map_test.py
petstore_api/models/mixed_properties_and_additional_properties_class.py

View File

@@ -177,7 +177,7 @@ Class | Method | HTTP request | Description
- [HealthCheckResult](docs/HealthCheckResult.md)
- [InnerDictWithProperty](docs/InnerDictWithProperty.md)
- [IntOrString](docs/IntOrString.md)
- [List](docs/List.md)
- [ListClass](docs/ListClass.md)
- [MapOfArrayOfModel](docs/MapOfArrayOfModel.md)
- [MapTest](docs/MapTest.md)
- [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)

View File

@@ -0,0 +1,28 @@
# ListClass
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**var_123_list** | **str** | | [optional]
## Example
```python
from petstore_api.models.list_class import ListClass
# TODO update the JSON string below
json = "{}"
# create an instance of ListClass from a JSON string
list_class_instance = ListClass.from_json(json)
# print the JSON string representation of the object
print ListClass.to_json()
# convert the object into a dict
list_class_dict = list_class_instance.to_dict()
# create an instance of ListClass from a dict
list_class_form_dict = list_class.from_dict(list_class_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

@@ -80,7 +80,7 @@ from petstore_api.models.has_only_read_only import HasOnlyReadOnly
from petstore_api.models.health_check_result import HealthCheckResult
from petstore_api.models.inner_dict_with_property import InnerDictWithProperty
from petstore_api.models.int_or_string import IntOrString
from petstore_api.models.list import List
from petstore_api.models.list_class import ListClass
from petstore_api.models.map_of_array_of_model import MapOfArrayOfModel
from petstore_api.models.map_test import MapTest
from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass

View File

@@ -56,7 +56,7 @@ from petstore_api.models.has_only_read_only import HasOnlyReadOnly
from petstore_api.models.health_check_result import HealthCheckResult
from petstore_api.models.inner_dict_with_property import InnerDictWithProperty
from petstore_api.models.int_or_string import IntOrString
from petstore_api.models.list import List
from petstore_api.models.list_class import ListClass
from petstore_api.models.map_of_array_of_model import MapOfArrayOfModel
from petstore_api.models.map_test import MapTest
from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass

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 ListClass(BaseModel):
"""
ListClass
"""
var_123_list: Optional[StrictStr] = Field(None, alias="123-list")
__properties = ["123-list"]
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) -> ListClass:
"""Create an instance of ListClass 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) -> ListClass:
"""Create an instance of ListClass from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return ListClass.parse_obj(obj)
_obj = ListClass.parse_obj({
"var_123_list": obj.get("123-list")
})
return _obj

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.list_class import ListClass # noqa: E501
class TestListClass(unittest.TestCase):
"""ListClass unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional) -> ListClass:
"""Test ListClass
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 `ListClass`
"""
model = ListClass() # noqa: E501
if include_optional:
return ListClass(
var_123_list = ''
)
else:
return ListClass(
)
"""
def testListClass(self):
"""Test ListClass"""
# 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

@@ -173,7 +173,7 @@ class ModelTests(unittest.TestCase):
def test_list(self):
# should throw exception as var_123_list should be string
try:
l3 = petstore_api.List(var_123_list=123)
l3 = petstore_api.ListClass(var_123_list=123)
self.assertTrue(False) # this line shouldn't execute
except ValueError as e:
#error_message = (
@@ -182,13 +182,13 @@ class ModelTests(unittest.TestCase):
# " str type expected (type=type_error.str)\n")
self.assertTrue("str type expected" in str(e))
l = petstore_api.List(var_123_list="bulldog")
l = petstore_api.ListClass(var_123_list="bulldog")
self.assertEqual(l.to_json(), '{"123-list": "bulldog"}')
self.assertEqual(l.to_dict(), {'123-list': 'bulldog'})
l2 = petstore_api.List.from_json(l.to_json())
l2 = petstore_api.ListClass.from_json(l.to_json())
self.assertEqual(l2.var_123_list, 'bulldog')
self.assertTrue(isinstance(l2, petstore_api.List))
self.assertTrue(isinstance(l2, petstore_api.ListClass))
def test_enum_ref_property(self):
# test enum ref property