Skip to content

Commit

Permalink
[python] update samples
Browse files Browse the repository at this point in the history
Signed-off-by: ふぁ <[email protected]>
  • Loading branch information
fa0311 committed Sep 23, 2023
1 parent fc3e024 commit 99b39ee
Show file tree
Hide file tree
Showing 237 changed files with 1,029 additions and 872 deletions.
6 changes: 5 additions & 1 deletion samples/client/echo_api/python/openapi_client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def __call_api(
self.last_response = response_data

return_data = None # assuming deserialization is not needed
return_headers = None
# data needs deserialization or returns HTTP data (deserialized) only
if _preload_content or _return_http_data_only:
response_type = response_types_map.get(str(response_data.status), None)
Expand All @@ -244,17 +245,20 @@ def __call_api(
# deserialize response data
if response_type == "bytearray":
return_data = response_data.data
return_headers = response_data.headers
elif response_type:
return_data = self.deserialize(response_data, response_type)
return_headers = response_data.getheaders()
else:
return_data = None
return_headers = response_data.getheaders()

if _return_http_data_only:
return return_data
else:
return ApiResponse(status_code = response_data.status,
data = return_data,
headers = response_data.getheaders(),
headers = return_headers,
raw_data = response_data.data)

def sanitize_for_serialization(self, obj):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class Bird(BaseModel):
"""
size: Optional[StrictStr] = None
color: Optional[StrictStr] = None
__properties = ["size", "color"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class Category(BaseModel):
"""
id: Optional[StrictInt] = None
name: Optional[StrictStr] = None
__properties = ["id", "name"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class DataQuery(Query):
suffix: Optional[StrictStr] = Field(None, description="test suffix")
text: Optional[StrictStr] = Field(None, description="Some text containing white spaces")
var_date: Optional[datetime] = Field(None, alias="date", description="A date")
__properties = ["id", "outcomes", "suffix", "text", "date"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class DefaultValue(BaseModel):
array_string_nullable: Optional[conlist(StrictStr)] = None
array_string_extension_nullable: Optional[conlist(StrictStr)] = None
string_nullable: Optional[StrictStr] = None
__properties = ["array_string_enum_ref_default", "array_string_enum_default", "array_string_default", "array_integer_default", "array_string", "array_string_nullable", "array_string_extension_nullable", "string_nullable"]

@validator('array_string_enum_default')
def array_string_enum_default_validate_enum(cls, value):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class NumberPropertiesOnly(BaseModel):
number: Optional[Union[StrictFloat, StrictInt]] = None
float: Optional[Union[StrictFloat, StrictInt]] = None
double: Optional[Union[confloat(le=50.2, ge=0.8, strict=True), conint(le=50, ge=1, strict=True)]] = None
__properties = ["number", "float", "double"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class Pet(BaseModel):
photo_urls: conlist(StrictStr) = Field(..., alias="photoUrls")
tags: Optional[conlist(Tag)] = None
status: Optional[StrictStr] = Field(None, description="pet status in the store")
__properties = ["id", "name", "category", "photoUrls", "tags", "status"]

@validator('status')
def status_validate_enum(cls, value):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class Query(BaseModel):
"""
id: Optional[StrictInt] = Field(None, description="Query")
outcomes: Optional[conlist(StrictStr)] = None
__properties = ["id", "outcomes"]

@validator('outcomes')
def outcomes_validate_enum(cls, value):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class Tag(BaseModel):
"""
id: Optional[StrictInt] = None
name: Optional[StrictStr] = None
__properties = ["id", "name"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseMod
color: Optional[StrictStr] = None
id: Optional[StrictInt] = None
name: Optional[StrictStr] = None
__properties = ["size", "color", "id", "name"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel):
TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter
"""
values: Optional[conlist(StrictStr)] = None
__properties = ["values"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ async def __call_api(
self.last_response = response_data

return_data = None # assuming deserialization is not needed
return_headers = None
# data needs deserialization or returns HTTP data (deserialized) only
if _preload_content or _return_http_data_only:
response_type = response_types_map.get(str(response_data.status), None)
Expand All @@ -224,17 +225,20 @@ async def __call_api(
# deserialize response data
if response_type == "bytearray":
return_data = response_data.data
return_headers = response_data.headers
elif response_type:
return_data = self.deserialize(response_data, response_type)
return_headers = response_data.getheaders()
else:
return_data = None
return_headers = response_data.getheaders()

if _return_http_data_only:
return return_data
else:
return ApiResponse(status_code = response_data.status,
data = return_data,
headers = response_data.getheaders(),
headers = return_headers,
raw_data = response_data.data)

def sanitize_for_serialization(self, obj):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class AdditionalPropertiesAnyType(BaseModel):
"""
name: Optional[StrictStr] = None
additional_properties: Dict[str, Any] = {}
__properties = ["name"]

"""Pydantic configuration"""
class Config:
Expand Down Expand Up @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> AdditionalPropertiesAnyType:
})
# store additional fields in additional_properties
for _key in obj.keys():
if _key not in cls.__properties:
if _key not in ["name"]:
_obj.additional_properties[_key] = obj.get(_key)

return _obj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class AdditionalPropertiesClass(BaseModel):
"""
map_property: Optional[Dict[str, StrictStr]] = None
map_of_map_property: Optional[Dict[str, Dict[str, StrictStr]]] = None
__properties = ["map_property", "map_of_map_property"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class AdditionalPropertiesObject(BaseModel):
"""
name: Optional[StrictStr] = None
additional_properties: Dict[str, Any] = {}
__properties = ["name"]

"""Pydantic configuration"""
class Config:
Expand Down Expand Up @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> AdditionalPropertiesObject:
})
# store additional fields in additional_properties
for _key in obj.keys():
if _key not in cls.__properties:
if _key not in ["name"]:
_obj.additional_properties[_key] = obj.get(_key)

return _obj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel):
"""
name: Optional[StrictStr] = None
additional_properties: Dict[str, Any] = {}
__properties = ["name"]

"""Pydantic configuration"""
class Config:
Expand Down Expand Up @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> AdditionalPropertiesWithDescriptionOnly:
})
# store additional fields in additional_properties
for _key in obj.keys():
if _key not in cls.__properties:
if _key not in ["name"]:
_obj.additional_properties[_key] = obj.get(_key)

return _obj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class AllOfWithSingleRef(BaseModel):
"""
username: Optional[StrictStr] = None
single_ref_type: Optional[SingleRefType] = Field(None, alias="SingleRefType")
__properties = ["username", "SingleRefType"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,24 @@ class Animal(BaseModel):
"""
class_name: StrictStr = Field(..., alias="className")
color: Optional[StrictStr] = 'red'
__properties = ["className", "color"]

"""Pydantic configuration"""
class Config:
allow_population_by_field_name = True
validate_assignment = True

# JSON field name that stores the object type
__discriminator_property_name = 'className'

# discriminator mappings
__discriminator_value_class_map = {
'Cat': 'Cat',
'Dog': 'Dog'
}

@classmethod
def get_discriminator_value(cls, obj: dict) -> str:
"""Returns the discriminator value (object type) of the data"""
discriminator_value = obj[cls.__discriminator_property_name]
discriminator_value = obj['className']
discriminator_value_class_map = {
'Cat': 'Cat','Dog': 'Dog'
}

if discriminator_value:
return cls.__discriminator_value_class_map.get(discriminator_value)
return discriminator_value_class_map.get(discriminator_value)
else:
return None

Expand Down Expand Up @@ -78,15 +74,21 @@ def from_dict(cls, obj: dict) -> Union(Cat, Dog):
"""Create an instance of Animal from a dict"""
# look up the object type based on discriminator mapping
object_type = cls.get_discriminator_value(obj)
discriminator_value_class_map = {
'Cat': 'Cat','Dog': 'Dog'
}
if object_type:
klass = globals()[object_type]
return klass.from_dict(obj)
else:
raise ValueError("Animal failed to lookup discriminator value from " +
json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name +
", mapping: " + json.dumps(cls.__discriminator_value_class_map))
json.dumps(obj) + ". Discriminator property name: " + 'className' +
", mapping: " + json.dumps(discriminator_value_class_map))

from petstore_api.models.cat import Cat
from petstore_api.models.dog import Dog
Animal.update_forward_refs()
try:
Animal.update_forward_refs()
except Exception:
pass

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AnyOfColor(BaseModel):
if TYPE_CHECKING:
actual_instance: Union[List[int], str]
else:
actual_instance: Any
actual_instance: Any = None
any_of_schemas: List[str] = Field(ANYOFCOLOR_ANY_OF_SCHEMAS, const=True)

"""Pydantic configuration"""
Expand All @@ -52,8 +52,10 @@ def __init__(self, *args, **kwargs) -> None:
if kwargs:
raise ValueError("If a position argument is used, keyword arguments cannot be used.")
super().__init__(actual_instance=args[0])
else:
elif kwargs:
super().__init__(**kwargs)
else:
super().__init__(actual_instance=None)

@validator('actual_instance')
def actual_instance_must_validate_anyof(cls, v):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AnyOfPig(BaseModel):
if TYPE_CHECKING:
actual_instance: Union[BasquePig, DanishPig]
else:
actual_instance: Any
actual_instance: Any = None
any_of_schemas: List[str] = Field(ANYOFPIG_ANY_OF_SCHEMAS, const=True)

"""Pydantic configuration"""
Expand All @@ -52,25 +52,27 @@ def __init__(self, *args, **kwargs) -> None:
if kwargs:
raise ValueError("If a position argument is used, keyword arguments cannot be used.")
super().__init__(actual_instance=args[0])
else:
elif kwargs:
super().__init__(**kwargs)
else:
super().__init__(actual_instance=None)

@validator('actual_instance')
def actual_instance_must_validate_anyof(cls, v):
instance = AnyOfPig.construct()
error_messages = []
# validate data type: BasquePig
if not isinstance(v, BasquePig):
error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`")
else:
try:
instance.anyof_schema_1_validator = v
return v

except (ValidationError, ValueError) as e:
error_messages.append(str(e))
# validate data type: DanishPig
if not isinstance(v, DanishPig):
error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`")
else:
try:
instance.anyof_schema_2_validator = v
return v

except (ValidationError, ValueError) as e:
error_messages.append(str(e))
if error_messages:
# no match
raise ValueError("No match found when setting the actual_instance in AnyOfPig with anyOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class ApiResponse(BaseModel):
code: Optional[StrictInt] = None
type: Optional[StrictStr] = None
message: Optional[StrictStr] = None
__properties = ["code", "type", "message"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class ArrayOfArrayOfModel(BaseModel):
ArrayOfArrayOfModel
"""
another_property: Optional[conlist(conlist(Tag))] = None
__properties = ["another_property"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class ArrayOfArrayOfNumberOnly(BaseModel):
ArrayOfArrayOfNumberOnly
"""
array_array_number: Optional[conlist(conlist(float))] = Field(None, alias="ArrayArrayNumber")
__properties = ["ArrayArrayNumber"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class ArrayOfNumberOnly(BaseModel):
ArrayOfNumberOnly
"""
array_number: Optional[conlist(float)] = Field(None, alias="ArrayNumber")
__properties = ["ArrayNumber"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class ArrayTest(BaseModel):
array_of_string: Optional[conlist(StrictStr, max_items=3, min_items=0)] = None
array_array_of_integer: Optional[conlist(conlist(StrictInt))] = None
array_array_of_model: Optional[conlist(conlist(ReadOnlyFirst))] = None
__properties = ["array_of_string", "array_array_of_integer", "array_array_of_model"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class BasquePig(BaseModel):
"""
class_name: StrictStr = Field(..., alias="className")
color: StrictStr = Field(...)
__properties = ["className", "color"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Capitalization(BaseModel):
capital_snake: Optional[StrictStr] = Field(None, alias="Capital_Snake")
sca_eth_flow_points: Optional[StrictStr] = Field(None, alias="SCA_ETH_Flow_Points")
att_name: Optional[StrictStr] = Field(None, alias="ATT_NAME", description="Name of the pet ")
__properties = ["smallCamel", "CapitalCamel", "small_Snake", "Capital_Snake", "SCA_ETH_Flow_Points", "ATT_NAME"]

"""Pydantic configuration"""
class Config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class Cat(Animal):
Cat
"""
declawed: Optional[StrictBool] = None
__properties = ["className", "color", "declawed"]

"""Pydantic configuration"""
class Config:
Expand Down
Loading

0 comments on commit 99b39ee

Please sign in to comment.