forked from loafle/openapi-generator-original
add python name mapping support (#16120)
This commit is contained in:
@@ -68,6 +68,7 @@ docs/ParentWithOptionalDict.md
|
||||
docs/Pet.md
|
||||
docs/PetApi.md
|
||||
docs/Pig.md
|
||||
docs/PropertyNameCollision.md
|
||||
docs/ReadOnlyFirst.md
|
||||
docs/SecondRef.md
|
||||
docs/SelfReferenceModel.md
|
||||
@@ -155,6 +156,7 @@ petstore_api/models/parent.py
|
||||
petstore_api/models/parent_with_optional_dict.py
|
||||
petstore_api/models/pet.py
|
||||
petstore_api/models/pig.py
|
||||
petstore_api/models/property_name_collision.py
|
||||
petstore_api/models/read_only_first.py
|
||||
petstore_api/models/second_ref.py
|
||||
petstore_api/models/self_reference_model.py
|
||||
|
||||
@@ -192,6 +192,7 @@ Class | Method | HTTP request | Description
|
||||
- [ParentWithOptionalDict](docs/ParentWithOptionalDict.md)
|
||||
- [Pet](docs/Pet.md)
|
||||
- [Pig](docs/Pig.md)
|
||||
- [PropertyNameCollision](docs/PropertyNameCollision.md)
|
||||
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
- [SecondRef](docs/SecondRef.md)
|
||||
- [SelfReferenceModel](docs/SelfReferenceModel.md)
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# PropertyNameCollision
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**underscore_type** | **str** | | [optional]
|
||||
**type** | **str** | | [optional]
|
||||
**type_with_underscore** | **str** | | [optional]
|
||||
|
||||
## Example
|
||||
|
||||
```python
|
||||
from petstore_api.models.property_name_collision import PropertyNameCollision
|
||||
|
||||
# TODO update the JSON string below
|
||||
json = "{}"
|
||||
# create an instance of PropertyNameCollision from a JSON string
|
||||
property_name_collision_instance = PropertyNameCollision.from_json(json)
|
||||
# print the JSON string representation of the object
|
||||
print PropertyNameCollision.to_json()
|
||||
|
||||
# convert the object into a dict
|
||||
property_name_collision_dict = property_name_collision_instance.to_dict()
|
||||
# create an instance of PropertyNameCollision from a dict
|
||||
property_name_collision_form_dict = property_name_collision.from_dict(property_name_collision_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)
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ from petstore_api.models.parent import Parent
|
||||
from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict
|
||||
from petstore_api.models.pet import Pet
|
||||
from petstore_api.models.pig import Pig
|
||||
from petstore_api.models.property_name_collision import PropertyNameCollision
|
||||
from petstore_api.models.read_only_first import ReadOnlyFirst
|
||||
from petstore_api.models.second_ref import SecondRef
|
||||
from petstore_api.models.self_reference_model import SelfReferenceModel
|
||||
|
||||
@@ -74,6 +74,7 @@ from petstore_api.models.parent import Parent
|
||||
from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict
|
||||
from petstore_api.models.pet import Pet
|
||||
from petstore_api.models.pig import Pig
|
||||
from petstore_api.models.property_name_collision import PropertyNameCollision
|
||||
from petstore_api.models.read_only_first import ReadOnlyFirst
|
||||
from petstore_api.models.second_ref import SecondRef
|
||||
from petstore_api.models.self_reference_model import SelfReferenceModel
|
||||
|
||||
@@ -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: \" \\ # noqa: E501
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import annotations
|
||||
import pprint
|
||||
import re # noqa: F401
|
||||
import json
|
||||
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, Field, StrictStr
|
||||
|
||||
class PropertyNameCollision(BaseModel):
|
||||
"""
|
||||
PropertyNameCollision
|
||||
"""
|
||||
underscore_type: Optional[StrictStr] = Field(None, alias="_type")
|
||||
type: Optional[StrictStr] = None
|
||||
type_with_underscore: Optional[StrictStr] = Field(None, alias="type_")
|
||||
additional_properties: Dict[str, Any] = {}
|
||||
__properties = ["_type", "type", "type_"]
|
||||
|
||||
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) -> PropertyNameCollision:
|
||||
"""Create an instance of PropertyNameCollision 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) -> PropertyNameCollision:
|
||||
"""Create an instance of PropertyNameCollision from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return PropertyNameCollision.parse_obj(obj)
|
||||
|
||||
_obj = PropertyNameCollision.parse_obj({
|
||||
"underscore_type": obj.get("_type"),
|
||||
"type": obj.get("type"),
|
||||
"type_with_underscore": obj.get("type_")
|
||||
})
|
||||
# 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,56 @@
|
||||
# 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: \" \\ # noqa: E501
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
import unittest
|
||||
import datetime
|
||||
|
||||
import petstore_api
|
||||
from petstore_api.models.property_name_collision import PropertyNameCollision # noqa: E501
|
||||
from petstore_api.rest import ApiException
|
||||
|
||||
class TestPropertyNameCollision(unittest.TestCase):
|
||||
"""PropertyNameCollision unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional):
|
||||
"""Test PropertyNameCollision
|
||||
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 `PropertyNameCollision`
|
||||
"""
|
||||
model = petstore_api.models.property_name_collision.PropertyNameCollision() # noqa: E501
|
||||
if include_optional :
|
||||
return PropertyNameCollision(
|
||||
underscoreType = '',
|
||||
type = '',
|
||||
typeWithUnderscore = ''
|
||||
)
|
||||
else :
|
||||
return PropertyNameCollision(
|
||||
)
|
||||
"""
|
||||
|
||||
def testPropertyNameCollision(self):
|
||||
"""Test PropertyNameCollision"""
|
||||
# inst_req_only = self.make_instance(include_optional=False)
|
||||
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user