forked from loafle/openapi-generator-original
[python] Add field as a reserved word (#18279)
* add field as a reserved word * remove tabs * update
This commit is contained in:
parent
88204b247a
commit
2a39b29684
@ -91,6 +91,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
<li>except</li>
|
||||
<li>exec</li>
|
||||
<li>false</li>
|
||||
<li>field</li>
|
||||
<li>finally</li>
|
||||
<li>float</li>
|
||||
<li>for</li>
|
||||
|
@ -91,6 +91,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
<li>except</li>
|
||||
<li>exec</li>
|
||||
<li>false</li>
|
||||
<li>field</li>
|
||||
<li>finally</li>
|
||||
<li>float</li>
|
||||
<li>for</li>
|
||||
|
@ -91,6 +91,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
<li>except</li>
|
||||
<li>exec</li>
|
||||
<li>false</li>
|
||||
<li>field</li>
|
||||
<li>finally</li>
|
||||
<li>float</li>
|
||||
<li>for</li>
|
||||
|
@ -88,6 +88,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
<li>except</li>
|
||||
<li>exec</li>
|
||||
<li>false</li>
|
||||
<li>field</li>
|
||||
<li>finally</li>
|
||||
<li>float</li>
|
||||
<li>for</li>
|
||||
|
@ -105,6 +105,8 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co
|
||||
// from https://docs.python.org/3/reference/lexical_analysis.html#keywords
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// pydantic
|
||||
"field",
|
||||
// local variable name used in API methods (endpoints)
|
||||
"all_params", "resource_path", "path_params", "query_params",
|
||||
"header_params", "form_params", "local_var_files", "body_params", "auth_settings",
|
||||
|
@ -2706,3 +2706,8 @@ components:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/CreatureInfo"
|
||||
field:
|
||||
type: object
|
||||
properties:
|
||||
field:
|
||||
type: string
|
||||
|
@ -60,6 +60,7 @@ docs/MapTest.md
|
||||
docs/MixedPropertiesAndAdditionalPropertiesClass.md
|
||||
docs/Model200Response.md
|
||||
docs/ModelApiResponse.md
|
||||
docs/ModelField.md
|
||||
docs/ModelReturn.md
|
||||
docs/Name.md
|
||||
docs/NullableClass.md
|
||||
@ -172,6 +173,7 @@ petstore_api/models/map_test.py
|
||||
petstore_api/models/mixed_properties_and_additional_properties_class.py
|
||||
petstore_api/models/model200_response.py
|
||||
petstore_api/models/model_api_response.py
|
||||
petstore_api/models/model_field.py
|
||||
petstore_api/models/model_return.py
|
||||
petstore_api/models/name.py
|
||||
petstore_api/models/nullable_class.py
|
||||
|
@ -202,6 +202,7 @@ Class | Method | HTTP request | Description
|
||||
- [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
|
||||
- [Model200Response](docs/Model200Response.md)
|
||||
- [ModelApiResponse](docs/ModelApiResponse.md)
|
||||
- [ModelField](docs/ModelField.md)
|
||||
- [ModelReturn](docs/ModelReturn.md)
|
||||
- [Name](docs/Name.md)
|
||||
- [NullableClass](docs/NullableClass.md)
|
||||
|
@ -0,0 +1,29 @@
|
||||
# ModelField
|
||||
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**var_field** | **str** | | [optional]
|
||||
|
||||
## Example
|
||||
|
||||
```python
|
||||
from petstore_api.models.model_field import ModelField
|
||||
|
||||
# TODO update the JSON string below
|
||||
json = "{}"
|
||||
# create an instance of ModelField from a JSON string
|
||||
model_field_instance = ModelField.from_json(json)
|
||||
# print the JSON string representation of the object
|
||||
print(ModelField.to_json())
|
||||
|
||||
# convert the object into a dict
|
||||
model_field_dict = model_field_instance.to_dict()
|
||||
# create an instance of ModelField from a dict
|
||||
model_field_form_dict = model_field.from_dict(model_field_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)
|
||||
|
||||
|
@ -91,6 +91,7 @@ from petstore_api.models.map_test import MapTest
|
||||
from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass
|
||||
from petstore_api.models.model200_response import Model200Response
|
||||
from petstore_api.models.model_api_response import ModelApiResponse
|
||||
from petstore_api.models.model_field import ModelField
|
||||
from petstore_api.models.model_return import ModelReturn
|
||||
from petstore_api.models.name import Name
|
||||
from petstore_api.models.nullable_class import NullableClass
|
||||
|
@ -66,6 +66,7 @@ from petstore_api.models.map_test import MapTest
|
||||
from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass
|
||||
from petstore_api.models.model200_response import Model200Response
|
||||
from petstore_api.models.model_api_response import ModelApiResponse
|
||||
from petstore_api.models.model_field import ModelField
|
||||
from petstore_api.models.model_return import ModelReturn
|
||||
from petstore_api.models.name import Name
|
||||
from petstore_api.models.nullable_class import NullableClass
|
||||
|
@ -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 ModelField(BaseModel):
|
||||
"""
|
||||
ModelField
|
||||
""" # noqa: E501
|
||||
var_field: Optional[StrictStr] = Field(default=None, alias="field")
|
||||
__properties: ClassVar[List[str]] = ["field"]
|
||||
|
||||
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 ModelField 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 ModelField from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = cls.model_validate({
|
||||
"field": obj.get("field")
|
||||
})
|
||||
return _obj
|
||||
|
||||
|
@ -0,0 +1,51 @@
|
||||
# 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.model_field import ModelField
|
||||
|
||||
class TestModelField(unittest.TestCase):
|
||||
"""ModelField unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional) -> ModelField:
|
||||
"""Test ModelField
|
||||
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 `ModelField`
|
||||
"""
|
||||
model = ModelField()
|
||||
if include_optional:
|
||||
return ModelField(
|
||||
dummy = ''
|
||||
)
|
||||
else:
|
||||
return ModelField(
|
||||
)
|
||||
"""
|
||||
|
||||
def testModelField(self):
|
||||
"""Test ModelField"""
|
||||
# inst_req_only = self.make_instance(include_optional=False)
|
||||
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@ -43,6 +43,7 @@ docs/EnumTest.md
|
||||
docs/FakeApi.md
|
||||
docs/FakeClassnameTags123Api.md
|
||||
docs/Feeding.md
|
||||
docs/Field.md
|
||||
docs/File.md
|
||||
docs/FileSchemaTestClass.md
|
||||
docs/FirstRef.md
|
||||
@ -156,6 +157,7 @@ petstore_api/models/enum_string1.py
|
||||
petstore_api/models/enum_string2.py
|
||||
petstore_api/models/enum_test.py
|
||||
petstore_api/models/feeding.py
|
||||
petstore_api/models/field.py
|
||||
petstore_api/models/file.py
|
||||
petstore_api/models/file_schema_test_class.py
|
||||
petstore_api/models/first_ref.py
|
||||
|
@ -187,6 +187,7 @@ Class | Method | HTTP request | Description
|
||||
- [EnumString2](docs/EnumString2.md)
|
||||
- [EnumTest](docs/EnumTest.md)
|
||||
- [Feeding](docs/Feeding.md)
|
||||
- [Field](docs/Field.md)
|
||||
- [File](docs/File.md)
|
||||
- [FileSchemaTestClass](docs/FileSchemaTestClass.md)
|
||||
- [FirstRef](docs/FirstRef.md)
|
||||
|
@ -0,0 +1,28 @@
|
||||
# Field
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**field** | **str** | | [optional]
|
||||
|
||||
## Example
|
||||
|
||||
```python
|
||||
from petstore_api.models.field import Field
|
||||
|
||||
# TODO update the JSON string below
|
||||
json = "{}"
|
||||
# create an instance of Field from a JSON string
|
||||
field_instance = Field.from_json(json)
|
||||
# print the JSON string representation of the object
|
||||
print Field.to_json()
|
||||
|
||||
# convert the object into a dict
|
||||
field_dict = field_instance.to_dict()
|
||||
# create an instance of Field from a dict
|
||||
field_form_dict = field.from_dict(field_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)
|
||||
|
||||
|
@ -75,6 +75,7 @@ from petstore_api.models.enum_string1 import EnumString1
|
||||
from petstore_api.models.enum_string2 import EnumString2
|
||||
from petstore_api.models.enum_test import EnumTest
|
||||
from petstore_api.models.feeding import Feeding
|
||||
from petstore_api.models.field import Field
|
||||
from petstore_api.models.file import File
|
||||
from petstore_api.models.file_schema_test_class import FileSchemaTestClass
|
||||
from petstore_api.models.first_ref import FirstRef
|
||||
|
@ -50,6 +50,7 @@ from petstore_api.models.enum_string1 import EnumString1
|
||||
from petstore_api.models.enum_string2 import EnumString2
|
||||
from petstore_api.models.enum_test import EnumTest
|
||||
from petstore_api.models.feeding import Feeding
|
||||
from petstore_api.models.field import Field
|
||||
from petstore_api.models.file import File
|
||||
from petstore_api.models.file_schema_test_class import FileSchemaTestClass
|
||||
from petstore_api.models.first_ref import FirstRef
|
||||
|
@ -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, StrictStr
|
||||
|
||||
class Field(BaseModel):
|
||||
"""
|
||||
Field
|
||||
"""
|
||||
field: Optional[StrictStr] = None
|
||||
__properties = ["field"]
|
||||
|
||||
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) -> Field:
|
||||
"""Create an instance of Field 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) -> Field:
|
||||
"""Create an instance of Field from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Field.parse_obj(obj)
|
||||
|
||||
_obj = Field.parse_obj({
|
||||
"field": obj.get("field")
|
||||
})
|
||||
return _obj
|
||||
|
||||
|
@ -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.field import Field # noqa: E501
|
||||
|
||||
class TestField(unittest.TestCase):
|
||||
"""Field unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional) -> Field:
|
||||
"""Test Field
|
||||
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 `Field`
|
||||
"""
|
||||
model = Field() # noqa: E501
|
||||
if include_optional:
|
||||
return Field(
|
||||
dummy = ''
|
||||
)
|
||||
else:
|
||||
return Field(
|
||||
)
|
||||
"""
|
||||
|
||||
def testField(self):
|
||||
"""Test Field"""
|
||||
# inst_req_only = self.make_instance(include_optional=False)
|
||||
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@ -43,6 +43,7 @@ docs/EnumTest.md
|
||||
docs/FakeApi.md
|
||||
docs/FakeClassnameTags123Api.md
|
||||
docs/Feeding.md
|
||||
docs/Field.md
|
||||
docs/File.md
|
||||
docs/FileSchemaTestClass.md
|
||||
docs/FirstRef.md
|
||||
@ -156,6 +157,7 @@ petstore_api/models/enum_string1.py
|
||||
petstore_api/models/enum_string2.py
|
||||
petstore_api/models/enum_test.py
|
||||
petstore_api/models/feeding.py
|
||||
petstore_api/models/field.py
|
||||
petstore_api/models/file.py
|
||||
petstore_api/models/file_schema_test_class.py
|
||||
petstore_api/models/first_ref.py
|
||||
|
@ -187,6 +187,7 @@ Class | Method | HTTP request | Description
|
||||
- [EnumString2](docs/EnumString2.md)
|
||||
- [EnumTest](docs/EnumTest.md)
|
||||
- [Feeding](docs/Feeding.md)
|
||||
- [Field](docs/Field.md)
|
||||
- [File](docs/File.md)
|
||||
- [FileSchemaTestClass](docs/FileSchemaTestClass.md)
|
||||
- [FirstRef](docs/FirstRef.md)
|
||||
|
@ -0,0 +1,28 @@
|
||||
# Field
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**field** | **str** | | [optional]
|
||||
|
||||
## Example
|
||||
|
||||
```python
|
||||
from petstore_api.models.field import Field
|
||||
|
||||
# TODO update the JSON string below
|
||||
json = "{}"
|
||||
# create an instance of Field from a JSON string
|
||||
field_instance = Field.from_json(json)
|
||||
# print the JSON string representation of the object
|
||||
print Field.to_json()
|
||||
|
||||
# convert the object into a dict
|
||||
field_dict = field_instance.to_dict()
|
||||
# create an instance of Field from a dict
|
||||
field_form_dict = field.from_dict(field_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)
|
||||
|
||||
|
@ -75,6 +75,7 @@ from petstore_api.models.enum_string1 import EnumString1
|
||||
from petstore_api.models.enum_string2 import EnumString2
|
||||
from petstore_api.models.enum_test import EnumTest
|
||||
from petstore_api.models.feeding import Feeding
|
||||
from petstore_api.models.field import Field
|
||||
from petstore_api.models.file import File
|
||||
from petstore_api.models.file_schema_test_class import FileSchemaTestClass
|
||||
from petstore_api.models.first_ref import FirstRef
|
||||
|
@ -50,6 +50,7 @@ from petstore_api.models.enum_string1 import EnumString1
|
||||
from petstore_api.models.enum_string2 import EnumString2
|
||||
from petstore_api.models.enum_test import EnumTest
|
||||
from petstore_api.models.feeding import Feeding
|
||||
from petstore_api.models.field import Field
|
||||
from petstore_api.models.file import File
|
||||
from petstore_api.models.file_schema_test_class import FileSchemaTestClass
|
||||
from petstore_api.models.first_ref import FirstRef
|
||||
|
@ -0,0 +1,83 @@
|
||||
# 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, Dict, Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
|
||||
class Field(BaseModel):
|
||||
"""
|
||||
Field
|
||||
"""
|
||||
field: Optional[StrictStr] = None
|
||||
additional_properties: Dict[str, Any] = {}
|
||||
__properties = ["field"]
|
||||
|
||||
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) -> Field:
|
||||
"""Create an instance of Field 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={
|
||||
"additional_properties"
|
||||
},
|
||||
exclude_none=True)
|
||||
# puts key-value pairs in additional_properties in the top level
|
||||
if self.additional_properties is not None:
|
||||
for _key, _value in self.additional_properties.items():
|
||||
_dict[_key] = _value
|
||||
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Field:
|
||||
"""Create an instance of Field from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Field.parse_obj(obj)
|
||||
|
||||
_obj = Field.parse_obj({
|
||||
"field": obj.get("field")
|
||||
})
|
||||
# store additional fields in additional_properties
|
||||
for _key in obj.keys():
|
||||
if _key not in cls.__properties:
|
||||
_obj.additional_properties[_key] = obj.get(_key)
|
||||
|
||||
return _obj
|
||||
|
||||
|
@ -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.field import Field # noqa: E501
|
||||
|
||||
class TestField(unittest.TestCase):
|
||||
"""Field unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional) -> Field:
|
||||
"""Test Field
|
||||
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 `Field`
|
||||
"""
|
||||
model = Field() # noqa: E501
|
||||
if include_optional:
|
||||
return Field(
|
||||
dummy = ''
|
||||
)
|
||||
else:
|
||||
return Field(
|
||||
)
|
||||
"""
|
||||
|
||||
def testField(self):
|
||||
"""Test Field"""
|
||||
# inst_req_only = self.make_instance(include_optional=False)
|
||||
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@ -60,6 +60,7 @@ docs/MapTest.md
|
||||
docs/MixedPropertiesAndAdditionalPropertiesClass.md
|
||||
docs/Model200Response.md
|
||||
docs/ModelApiResponse.md
|
||||
docs/ModelField.md
|
||||
docs/ModelReturn.md
|
||||
docs/Name.md
|
||||
docs/NullableClass.md
|
||||
@ -172,6 +173,7 @@ petstore_api/models/map_test.py
|
||||
petstore_api/models/mixed_properties_and_additional_properties_class.py
|
||||
petstore_api/models/model200_response.py
|
||||
petstore_api/models/model_api_response.py
|
||||
petstore_api/models/model_field.py
|
||||
petstore_api/models/model_return.py
|
||||
petstore_api/models/name.py
|
||||
petstore_api/models/nullable_class.py
|
||||
|
@ -202,6 +202,7 @@ Class | Method | HTTP request | Description
|
||||
- [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
|
||||
- [Model200Response](docs/Model200Response.md)
|
||||
- [ModelApiResponse](docs/ModelApiResponse.md)
|
||||
- [ModelField](docs/ModelField.md)
|
||||
- [ModelReturn](docs/ModelReturn.md)
|
||||
- [Name](docs/Name.md)
|
||||
- [NullableClass](docs/NullableClass.md)
|
||||
|
29
samples/openapi3/client/petstore/python/docs/ModelField.md
Normal file
29
samples/openapi3/client/petstore/python/docs/ModelField.md
Normal file
@ -0,0 +1,29 @@
|
||||
# ModelField
|
||||
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**var_field** | **str** | | [optional]
|
||||
|
||||
## Example
|
||||
|
||||
```python
|
||||
from petstore_api.models.model_field import ModelField
|
||||
|
||||
# TODO update the JSON string below
|
||||
json = "{}"
|
||||
# create an instance of ModelField from a JSON string
|
||||
model_field_instance = ModelField.from_json(json)
|
||||
# print the JSON string representation of the object
|
||||
print(ModelField.to_json())
|
||||
|
||||
# convert the object into a dict
|
||||
model_field_dict = model_field_instance.to_dict()
|
||||
# create an instance of ModelField from a dict
|
||||
model_field_form_dict = model_field.from_dict(model_field_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)
|
||||
|
||||
|
@ -91,6 +91,7 @@ from petstore_api.models.map_test import MapTest
|
||||
from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass
|
||||
from petstore_api.models.model200_response import Model200Response
|
||||
from petstore_api.models.model_api_response import ModelApiResponse
|
||||
from petstore_api.models.model_field import ModelField
|
||||
from petstore_api.models.model_return import ModelReturn
|
||||
from petstore_api.models.name import Name
|
||||
from petstore_api.models.nullable_class import NullableClass
|
||||
|
@ -66,6 +66,7 @@ from petstore_api.models.map_test import MapTest
|
||||
from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass
|
||||
from petstore_api.models.model200_response import Model200Response
|
||||
from petstore_api.models.model_api_response import ModelApiResponse
|
||||
from petstore_api.models.model_field import ModelField
|
||||
from petstore_api.models.model_return import ModelReturn
|
||||
from petstore_api.models.name import Name
|
||||
from petstore_api.models.nullable_class import NullableClass
|
||||
|
@ -0,0 +1,100 @@
|
||||
# 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 ModelField(BaseModel):
|
||||
"""
|
||||
ModelField
|
||||
""" # noqa: E501
|
||||
var_field: Optional[StrictStr] = Field(default=None, alias="field")
|
||||
additional_properties: Dict[str, Any] = {}
|
||||
__properties: ClassVar[List[str]] = ["field"]
|
||||
|
||||
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 ModelField 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.
|
||||
* Fields in `self.additional_properties` are added to the output dict.
|
||||
"""
|
||||
excluded_fields: Set[str] = set([
|
||||
"additional_properties",
|
||||
])
|
||||
|
||||
_dict = self.model_dump(
|
||||
by_alias=True,
|
||||
exclude=excluded_fields,
|
||||
exclude_none=True,
|
||||
)
|
||||
# puts key-value pairs in additional_properties in the top level
|
||||
if self.additional_properties is not None:
|
||||
for _key, _value in self.additional_properties.items():
|
||||
_dict[_key] = _value
|
||||
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
||||
"""Create an instance of ModelField from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = cls.model_validate({
|
||||
"field": obj.get("field")
|
||||
})
|
||||
# store additional fields in additional_properties
|
||||
for _key in obj.keys():
|
||||
if _key not in cls.__properties:
|
||||
_obj.additional_properties[_key] = obj.get(_key)
|
||||
|
||||
return _obj
|
||||
|
||||
|
@ -0,0 +1,51 @@
|
||||
# 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.model_field import ModelField
|
||||
|
||||
class TestModelField(unittest.TestCase):
|
||||
"""ModelField unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional) -> ModelField:
|
||||
"""Test ModelField
|
||||
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 `ModelField`
|
||||
"""
|
||||
model = ModelField()
|
||||
if include_optional:
|
||||
return ModelField(
|
||||
dummy = ''
|
||||
)
|
||||
else:
|
||||
return ModelField(
|
||||
)
|
||||
"""
|
||||
|
||||
def testModelField(self):
|
||||
"""Test ModelField"""
|
||||
# inst_req_only = self.make_instance(include_optional=False)
|
||||
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user