[python] Add field as a reserved word (#18279)

* add field as a reserved word

* remove tabs

* update
This commit is contained in:
William Cheng
2024-04-03 16:43:51 +08:00
committed by GitHub
parent 88204b247a
commit 2a39b29684
34 changed files with 692 additions and 0 deletions

View File

@@ -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

View File

@@ -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)

View 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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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()