[PYTHON] generate code based on pydantic v2 (#16685)

* [python] replace validator with field_validator

* [python] replace parse_obj with model_validate

* [python] replace dict with model_dump

* [python] replace construct with model_construct

* [python] replace __fields_set__ with model_fields_set

* [python] replace __fields_set__ in the test cases with model_fields_set

* [python] replace validate_arguments with validate_call

* [python] replace max_items, min_items with max_length, min_length

* [python] replace Config class with model_config

* [python] replace allow_population_by_field_name with populate_by_name

* [python] remove {{{classname}}}_ONE_OF_SCHEMAS

* [python] update test cases

* [python] update samples

* [python] fix typos in test cases
This commit is contained in:
ふぁ
2023-09-29 17:45:46 +09:00
committed by GitHub
parent 67b129fda9
commit e2f249ba35
177 changed files with 1774 additions and 1611 deletions

View File

@@ -17,7 +17,7 @@ import re # noqa: F401
import io
import warnings
from pydantic import validate_arguments, ValidationError
from pydantic import validate_call, ValidationError
from openapi_client.api_client import ApiClient
@@ -40,7 +40,7 @@ class AuthApi:
api_client = ApiClient.get_default()
self.api_client = api_client
@validate_arguments
@validate_call
def test_auth_http_basic(self, **kwargs) -> str: # noqa: E501
"""To test HTTP basic authentication # noqa: E501
@@ -68,7 +68,7 @@ class AuthApi:
raise ValueError(message)
return self.test_auth_http_basic_with_http_info(**kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_auth_http_basic_with_http_info(self, **kwargs) -> ApiResponse: # noqa: E501
"""To test HTTP basic authentication # noqa: E501

View File

@@ -17,7 +17,7 @@ import re # noqa: F401
import io
import warnings
from pydantic import validate_arguments, ValidationError
from pydantic import validate_call, ValidationError
from pydantic import Field
from typing_extensions import Annotated
@@ -48,7 +48,7 @@ class BodyApi:
api_client = ApiClient.get_default()
self.api_client = api_client
@validate_arguments
@validate_call
def test_binary_gif(self, **kwargs) -> bytearray: # noqa: E501
"""Test binary (gif) response body # noqa: E501
@@ -76,7 +76,7 @@ class BodyApi:
raise ValueError(message)
return self.test_binary_gif_with_http_info(**kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_binary_gif_with_http_info(self, **kwargs) -> ApiResponse: # noqa: E501
"""Test binary (gif) response body # noqa: E501
@@ -180,7 +180,7 @@ class BodyApi:
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
@validate_call
def test_body_application_octetstream_binary(self, body : Optional[Union[StrictBytes, StrictStr]] = None, **kwargs) -> str: # noqa: E501
"""Test body parameter(s) # noqa: E501
@@ -210,7 +210,7 @@ class BodyApi:
raise ValueError(message)
return self.test_body_application_octetstream_binary_with_http_info(body, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_body_application_octetstream_binary_with_http_info(self, body : Optional[Union[StrictBytes, StrictStr]] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test body parameter(s) # noqa: E501
@@ -332,7 +332,7 @@ class BodyApi:
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
@validate_call
def test_body_multipart_formdata_array_of_binary(self, files : List[Union[StrictBytes, StrictStr]], **kwargs) -> str: # noqa: E501
"""Test array of binary in multipart mime # noqa: E501
@@ -362,7 +362,7 @@ class BodyApi:
raise ValueError(message)
return self.test_body_multipart_formdata_array_of_binary_with_http_info(files, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_body_multipart_formdata_array_of_binary_with_http_info(self, files : List[Union[StrictBytes, StrictStr]], **kwargs) -> ApiResponse: # noqa: E501
"""Test array of binary in multipart mime # noqa: E501
@@ -480,7 +480,7 @@ class BodyApi:
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
@validate_call
def test_echo_body_free_form_object_response_string(self, body : Annotated[Optional[Dict[str, Any]], Field(description="Free form object")] = None, **kwargs) -> str: # noqa: E501
"""Test free form object # noqa: E501
@@ -510,7 +510,7 @@ class BodyApi:
raise ValueError(message)
return self.test_echo_body_free_form_object_response_string_with_http_info(body, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_echo_body_free_form_object_response_string_with_http_info(self, body : Annotated[Optional[Dict[str, Any]], Field(description="Free form object")] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test free form object # noqa: E501
@@ -627,7 +627,7 @@ class BodyApi:
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
@validate_call
def test_echo_body_pet(self, pet : Annotated[Optional[Pet], Field(description="Pet object that needs to be added to the store")] = None, **kwargs) -> Pet: # noqa: E501
"""Test body parameter(s) # noqa: E501
@@ -657,7 +657,7 @@ class BodyApi:
raise ValueError(message)
return self.test_echo_body_pet_with_http_info(pet, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_echo_body_pet_with_http_info(self, pet : Annotated[Optional[Pet], Field(description="Pet object that needs to be added to the store")] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test body parameter(s) # noqa: E501
@@ -774,7 +774,7 @@ class BodyApi:
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
@validate_call
def test_echo_body_pet_response_string(self, pet : Annotated[Optional[Pet], Field(description="Pet object that needs to be added to the store")] = None, **kwargs) -> str: # noqa: E501
"""Test empty response body # noqa: E501
@@ -804,7 +804,7 @@ class BodyApi:
raise ValueError(message)
return self.test_echo_body_pet_response_string_with_http_info(pet, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_echo_body_pet_response_string_with_http_info(self, pet : Annotated[Optional[Pet], Field(description="Pet object that needs to be added to the store")] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test empty response body # noqa: E501
@@ -921,7 +921,7 @@ class BodyApi:
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
@validate_call
def test_echo_body_tag_response_string(self, tag : Annotated[Optional[Tag], Field(description="Tag object")] = None, **kwargs) -> str: # noqa: E501
"""Test empty json (request body) # noqa: E501
@@ -951,7 +951,7 @@ class BodyApi:
raise ValueError(message)
return self.test_echo_body_tag_response_string_with_http_info(tag, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_echo_body_tag_response_string_with_http_info(self, tag : Annotated[Optional[Tag], Field(description="Tag object")] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test empty json (request body) # noqa: E501

View File

@@ -17,7 +17,7 @@ import re # noqa: F401
import io
import warnings
from pydantic import validate_arguments, ValidationError
from pydantic import validate_call, ValidationError
from pydantic import StrictBool, StrictInt, StrictStr
@@ -44,7 +44,7 @@ class FormApi:
api_client = ApiClient.get_default()
self.api_client = api_client
@validate_arguments
@validate_call
def test_form_integer_boolean_string(self, integer_form : Optional[StrictInt] = None, boolean_form : Optional[StrictBool] = None, string_form : Optional[StrictStr] = None, **kwargs) -> str: # noqa: E501
"""Test form parameter(s) # noqa: E501
@@ -78,7 +78,7 @@ class FormApi:
raise ValueError(message)
return self.test_form_integer_boolean_string_with_http_info(integer_form, boolean_form, string_form, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_form_integer_boolean_string_with_http_info(self, integer_form : Optional[StrictInt] = None, boolean_form : Optional[StrictBool] = None, string_form : Optional[StrictStr] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test form parameter(s) # noqa: E501
@@ -207,7 +207,7 @@ class FormApi:
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
@validate_call
def test_form_oneof(self, form1 : Optional[StrictStr] = None, form2 : Optional[StrictInt] = None, form3 : Optional[StrictStr] = None, form4 : Optional[StrictBool] = None, id : Optional[StrictInt] = None, name : Optional[StrictStr] = None, **kwargs) -> str: # noqa: E501
"""Test form parameter(s) for oneOf schema # noqa: E501
@@ -247,7 +247,7 @@ class FormApi:
raise ValueError(message)
return self.test_form_oneof_with_http_info(form1, form2, form3, form4, id, name, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_form_oneof_with_http_info(self, form1 : Optional[StrictStr] = None, form2 : Optional[StrictInt] = None, form3 : Optional[StrictStr] = None, form4 : Optional[StrictBool] = None, id : Optional[StrictInt] = None, name : Optional[StrictStr] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test form parameter(s) for oneOf schema # noqa: E501

View File

@@ -17,7 +17,7 @@ import re # noqa: F401
import io
import warnings
from pydantic import validate_arguments, ValidationError
from pydantic import validate_call, ValidationError
from pydantic import StrictBool, StrictInt, StrictStr
@@ -44,7 +44,7 @@ class HeaderApi:
api_client = ApiClient.get_default()
self.api_client = api_client
@validate_arguments
@validate_call
def test_header_integer_boolean_string(self, integer_header : Optional[StrictInt] = None, boolean_header : Optional[StrictBool] = None, string_header : Optional[StrictStr] = None, **kwargs) -> str: # noqa: E501
"""Test header parameter(s) # noqa: E501
@@ -78,7 +78,7 @@ class HeaderApi:
raise ValueError(message)
return self.test_header_integer_boolean_string_with_http_info(integer_header, boolean_header, string_header, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_header_integer_boolean_string_with_http_info(self, integer_header : Optional[StrictInt] = None, boolean_header : Optional[StrictBool] = None, string_header : Optional[StrictStr] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test header parameter(s) # noqa: E501

View File

@@ -17,7 +17,7 @@ import re # noqa: F401
import io
import warnings
from pydantic import validate_arguments, ValidationError
from pydantic import validate_call, ValidationError
from pydantic import StrictInt, StrictStr
@@ -42,7 +42,7 @@ class PathApi:
api_client = ApiClient.get_default()
self.api_client = api_client
@validate_arguments
@validate_call
def tests_path_string_path_string_integer_path_integer(self, path_string : StrictStr, path_integer : StrictInt, **kwargs) -> str: # noqa: E501
"""Test path parameter(s) # noqa: E501
@@ -74,7 +74,7 @@ class PathApi:
raise ValueError(message)
return self.tests_path_string_path_string_integer_path_integer_with_http_info(path_string, path_integer, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def tests_path_string_path_string_integer_path_integer_with_http_info(self, path_string : StrictStr, path_integer : StrictInt, **kwargs) -> ApiResponse: # noqa: E501
"""Test path parameter(s) # noqa: E501

View File

@@ -17,7 +17,7 @@ import re # noqa: F401
import io
import warnings
from pydantic import validate_arguments, ValidationError
from pydantic import validate_call, ValidationError
from datetime import date, datetime
@@ -49,7 +49,7 @@ class QueryApi:
api_client = ApiClient.get_default()
self.api_client = api_client
@validate_arguments
@validate_call
def test_enum_ref_string(self, enum_ref_string_query : Optional[StringEnumRef] = None, **kwargs) -> str: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -79,7 +79,7 @@ class QueryApi:
raise ValueError(message)
return self.test_enum_ref_string_with_http_info(enum_ref_string_query, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_enum_ref_string_with_http_info(self, enum_ref_string_query : Optional[StringEnumRef] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -189,7 +189,7 @@ class QueryApi:
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
@validate_call
def test_query_datetime_date_string(self, datetime_query : Optional[datetime] = None, date_query : Optional[date] = None, string_query : Optional[StrictStr] = None, **kwargs) -> str: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -223,7 +223,7 @@ class QueryApi:
raise ValueError(message)
return self.test_query_datetime_date_string_with_http_info(datetime_query, date_query, string_query, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_query_datetime_date_string_with_http_info(self, datetime_query : Optional[datetime] = None, date_query : Optional[date] = None, string_query : Optional[StrictStr] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -351,7 +351,7 @@ class QueryApi:
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
@validate_call
def test_query_integer_boolean_string(self, integer_query : Optional[StrictInt] = None, boolean_query : Optional[StrictBool] = None, string_query : Optional[StrictStr] = None, **kwargs) -> str: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -385,7 +385,7 @@ class QueryApi:
raise ValueError(message)
return self.test_query_integer_boolean_string_with_http_info(integer_query, boolean_query, string_query, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_query_integer_boolean_string_with_http_info(self, integer_query : Optional[StrictInt] = None, boolean_query : Optional[StrictBool] = None, string_query : Optional[StrictStr] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -507,7 +507,7 @@ class QueryApi:
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
@validate_call
def test_query_style_deep_object_explode_true_object(self, query_object : Optional[Pet] = None, **kwargs) -> str: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -537,7 +537,7 @@ class QueryApi:
raise ValueError(message)
return self.test_query_style_deep_object_explode_true_object_with_http_info(query_object, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_query_style_deep_object_explode_true_object_with_http_info(self, query_object : Optional[Pet] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -647,7 +647,7 @@ class QueryApi:
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
@validate_call
def test_query_style_deep_object_explode_true_object_all_of(self, query_object : Optional[Any] = None, **kwargs) -> str: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -677,7 +677,7 @@ class QueryApi:
raise ValueError(message)
return self.test_query_style_deep_object_explode_true_object_all_of_with_http_info(query_object, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_query_style_deep_object_explode_true_object_all_of_with_http_info(self, query_object : Optional[Any] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -787,7 +787,7 @@ class QueryApi:
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
@validate_call
def test_query_style_form_explode_true_array_string(self, query_object : Optional[TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter] = None, **kwargs) -> str: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -817,7 +817,7 @@ class QueryApi:
raise ValueError(message)
return self.test_query_style_form_explode_true_array_string_with_http_info(query_object, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_query_style_form_explode_true_array_string_with_http_info(self, query_object : Optional[TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -927,7 +927,7 @@ class QueryApi:
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
@validate_call
def test_query_style_form_explode_true_object(self, query_object : Optional[Pet] = None, **kwargs) -> str: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -957,7 +957,7 @@ class QueryApi:
raise ValueError(message)
return self.test_query_style_form_explode_true_object_with_http_info(query_object, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_query_style_form_explode_true_object_with_http_info(self, query_object : Optional[Pet] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -1067,7 +1067,7 @@ class QueryApi:
collection_formats=_collection_formats,
_request_auth=_params.get('_request_auth'))
@validate_arguments
@validate_call
def test_query_style_form_explode_true_object_all_of(self, query_object : Optional[Any] = None, **kwargs) -> str: # noqa: E501
"""Test query parameter(s) # noqa: E501
@@ -1097,7 +1097,7 @@ class QueryApi:
raise ValueError(message)
return self.test_query_style_form_explode_true_object_all_of_with_http_info(query_object, **kwargs) # noqa: E501
@validate_arguments
@validate_call
def test_query_style_form_explode_true_object_all_of_with_http_info(self, query_object : Optional[Any] = None, **kwargs) -> ApiResponse: # noqa: E501
"""Test query parameter(s) # noqa: E501

View File

@@ -30,14 +30,15 @@ class Bird(BaseModel):
color: Optional[StrictStr] = None
__properties = ["size", "color"]
class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True
model_config = {
"populate_by_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))
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
@@ -51,7 +52,7 @@ class Bird(BaseModel):
def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
_dict = self.model_dump(by_alias=True,
exclude={
},
exclude_none=True)
@@ -64,9 +65,9 @@ class Bird(BaseModel):
return None
if not isinstance(obj, dict):
return Bird.parse_obj(obj)
return Bird.model_validate(obj)
_obj = Bird.parse_obj({
_obj = Bird.model_validate({
"size": obj.get("size"),
"color": obj.get("color")
})

View File

@@ -30,14 +30,15 @@ class Category(BaseModel):
name: Optional[StrictStr] = None
__properties = ["id", "name"]
class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True
model_config = {
"populate_by_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))
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
@@ -51,7 +52,7 @@ class Category(BaseModel):
def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
_dict = self.model_dump(by_alias=True,
exclude={
},
exclude_none=True)
@@ -64,9 +65,9 @@ class Category(BaseModel):
return None
if not isinstance(obj, dict):
return Category.parse_obj(obj)
return Category.model_validate(obj)
_obj = Category.parse_obj({
_obj = Category.model_validate({
"id": obj.get("id"),
"name": obj.get("name")
})

View File

@@ -33,14 +33,15 @@ class DataQuery(Query):
var_date: Optional[datetime] = Field(default=None, description="A date", alias="date")
__properties = ["id", "outcomes", "suffix", "text", "date"]
class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True
model_config = {
"populate_by_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))
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
@@ -54,7 +55,7 @@ class DataQuery(Query):
def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
_dict = self.model_dump(by_alias=True,
exclude={
},
exclude_none=True)
@@ -67,9 +68,9 @@ class DataQuery(Query):
return None
if not isinstance(obj, dict):
return DataQuery.parse_obj(obj)
return DataQuery.model_validate(obj)
_obj = DataQuery.parse_obj({
_obj = DataQuery.model_validate({
"id": obj.get("id"),
"outcomes": obj.get("outcomes"),
"suffix": obj.get("suffix"),

View File

@@ -20,7 +20,7 @@ import json
from typing import List, Optional
from pydantic import BaseModel, StrictInt, StrictStr, validator
from pydantic import BaseModel, StrictInt, StrictStr, field_validator
from openapi_client.models.string_enum_ref import StringEnumRef
class DefaultValue(BaseModel):
@@ -37,7 +37,7 @@ class DefaultValue(BaseModel):
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')
@field_validator('array_string_enum_default')
def array_string_enum_default_validate_enum(cls, value):
"""Validates the enum"""
if value is None:
@@ -48,14 +48,15 @@ class DefaultValue(BaseModel):
raise ValueError("each list item must be one of ('success', 'failure', 'unclassified')")
return value
class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True
model_config = {
"populate_by_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))
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
@@ -69,23 +70,23 @@ class DefaultValue(BaseModel):
def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
_dict = self.model_dump(by_alias=True,
exclude={
},
exclude_none=True)
# set to None if array_string_nullable (nullable) is None
# and __fields_set__ contains the field
if self.array_string_nullable is None and "array_string_nullable" in self.__fields_set__:
# and model_fields_set contains the field
if self.array_string_nullable is None and "array_string_nullable" in self.model_fields_set:
_dict['array_string_nullable'] = None
# set to None if array_string_extension_nullable (nullable) is None
# and __fields_set__ contains the field
if self.array_string_extension_nullable is None and "array_string_extension_nullable" in self.__fields_set__:
# and model_fields_set contains the field
if self.array_string_extension_nullable is None and "array_string_extension_nullable" in self.model_fields_set:
_dict['array_string_extension_nullable'] = None
# set to None if string_nullable (nullable) is None
# and __fields_set__ contains the field
if self.string_nullable is None and "string_nullable" in self.__fields_set__:
# and model_fields_set contains the field
if self.string_nullable is None and "string_nullable" in self.model_fields_set:
_dict['string_nullable'] = None
return _dict
@@ -97,9 +98,9 @@ class DefaultValue(BaseModel):
return None
if not isinstance(obj, dict):
return DefaultValue.parse_obj(obj)
return DefaultValue.model_validate(obj)
_obj = DefaultValue.parse_obj({
_obj = DefaultValue.model_validate({
"array_string_enum_ref_default": obj.get("array_string_enum_ref_default"),
"array_string_enum_default": obj.get("array_string_enum_default"),
"array_string_default": obj.get("array_string_default"),

View File

@@ -32,14 +32,15 @@ class NumberPropertiesOnly(BaseModel):
double: Optional[Union[Annotated[float, Field(le=50.2, strict=True, ge=0.8)], Annotated[int, Field(le=50, strict=True, ge=1)]]] = None
__properties = ["number", "double"]
class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True
model_config = {
"populate_by_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))
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
@@ -53,7 +54,7 @@ class NumberPropertiesOnly(BaseModel):
def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
_dict = self.model_dump(by_alias=True,
exclude={
},
exclude_none=True)
@@ -66,9 +67,9 @@ class NumberPropertiesOnly(BaseModel):
return None
if not isinstance(obj, dict):
return NumberPropertiesOnly.parse_obj(obj)
return NumberPropertiesOnly.model_validate(obj)
_obj = NumberPropertiesOnly.parse_obj({
_obj = NumberPropertiesOnly.model_validate({
"number": obj.get("number"),
"double": obj.get("double")
})

View File

@@ -20,7 +20,7 @@ import json
from typing import List, Optional
from pydantic import BaseModel, StrictInt, StrictStr, validator
from pydantic import BaseModel, StrictInt, StrictStr, field_validator
from pydantic import Field
from openapi_client.models.category import Category
from openapi_client.models.tag import Tag
@@ -37,7 +37,7 @@ class Pet(BaseModel):
status: Optional[StrictStr] = Field(default=None, description="pet status in the store")
__properties = ["id", "name", "category", "photoUrls", "tags", "status"]
@validator('status')
@field_validator('status')
def status_validate_enum(cls, value):
"""Validates the enum"""
if value is None:
@@ -47,14 +47,15 @@ class Pet(BaseModel):
raise ValueError("must be one of enum values ('available', 'pending', 'sold')")
return value
class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True
model_config = {
"populate_by_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))
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
@@ -68,7 +69,7 @@ class Pet(BaseModel):
def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
_dict = self.model_dump(by_alias=True,
exclude={
},
exclude_none=True)
@@ -91,9 +92,9 @@ class Pet(BaseModel):
return None
if not isinstance(obj, dict):
return Pet.parse_obj(obj)
return Pet.model_validate(obj)
_obj = Pet.parse_obj({
_obj = Pet.model_validate({
"id": obj.get("id"),
"name": obj.get("name"),
"category": Category.from_dict(obj.get("category")) if obj.get("category") is not None else None,

View File

@@ -20,7 +20,7 @@ import json
from typing import List, Optional
from pydantic import BaseModel, StrictInt, StrictStr, validator
from pydantic import BaseModel, StrictInt, StrictStr, field_validator
from pydantic import Field
class Query(BaseModel):
@@ -31,7 +31,7 @@ class Query(BaseModel):
outcomes: Optional[List[StrictStr]] = None
__properties = ["id", "outcomes"]
@validator('outcomes')
@field_validator('outcomes')
def outcomes_validate_enum(cls, value):
"""Validates the enum"""
if value is None:
@@ -42,14 +42,15 @@ class Query(BaseModel):
raise ValueError("each list item must be one of ('SUCCESS', 'FAILURE', 'SKIPPED')")
return value
class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True
model_config = {
"populate_by_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))
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
@@ -63,7 +64,7 @@ class Query(BaseModel):
def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
_dict = self.model_dump(by_alias=True,
exclude={
},
exclude_none=True)

View File

@@ -30,14 +30,15 @@ class Tag(BaseModel):
name: Optional[StrictStr] = None
__properties = ["id", "name"]
class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True
model_config = {
"populate_by_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))
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
@@ -51,7 +52,7 @@ class Tag(BaseModel):
def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
_dict = self.model_dump(by_alias=True,
exclude={
},
exclude_none=True)
@@ -64,9 +65,9 @@ class Tag(BaseModel):
return None
if not isinstance(obj, dict):
return Tag.parse_obj(obj)
return Tag.model_validate(obj)
_obj = Tag.parse_obj({
_obj = Tag.model_validate({
"id": obj.get("id"),
"name": obj.get("name")
})

View File

@@ -32,14 +32,15 @@ class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseMod
name: Optional[StrictStr] = None
__properties = ["size", "color", "id", "name"]
class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True
model_config = {
"populate_by_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))
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
@@ -53,7 +54,7 @@ class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseMod
def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
_dict = self.model_dump(by_alias=True,
exclude={
},
exclude_none=True)
@@ -66,9 +67,9 @@ class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseMod
return None
if not isinstance(obj, dict):
return TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.parse_obj(obj)
return TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_validate(obj)
_obj = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.parse_obj({
_obj = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_validate({
"size": obj.get("size"),
"color": obj.get("color"),
"id": obj.get("id"),

View File

@@ -29,14 +29,15 @@ class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel):
values: Optional[List[StrictStr]] = None
__properties = ["values"]
class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True
model_config = {
"populate_by_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))
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
@@ -50,7 +51,7 @@ class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel):
def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
_dict = self.model_dump(by_alias=True,
exclude={
},
exclude_none=True)
@@ -63,9 +64,9 @@ class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel):
return None
if not isinstance(obj, dict):
return TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.parse_obj(obj)
return TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_validate(obj)
_obj = TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.parse_obj({
_obj = TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_validate({
"values": obj.get("values")
})
return _obj