From e2f249ba35e2da2f9936efaf5434068238cfc68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B5=E3=81=81?= <34892635+fa0311@users.noreply.github.com> Date: Fri, 29 Sep 2023 17:45:46 +0900 Subject: [PATCH] [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 --- .../languages/AbstractPythonCodegen.java | 14 +-- .../src/main/resources/python/api.mustache | 6 +- .../resources/python/model_anyof.mustache | 13 +-- .../resources/python/model_generic.mustache | 25 ++--- .../resources/python/model_oneof.mustache | 16 ++-- .../python/openapi_client/api/auth_api.py | 6 +- .../python/openapi_client/api/body_api.py | 30 +++--- .../python/openapi_client/api/form_api.py | 10 +- .../python/openapi_client/api/header_api.py | 6 +- .../python/openapi_client/api/path_api.py | 6 +- .../python/openapi_client/api/query_api.py | 34 +++---- .../python/openapi_client/models/bird.py | 17 ++-- .../python/openapi_client/models/category.py | 17 ++-- .../openapi_client/models/data_query.py | 17 ++-- .../openapi_client/models/default_value.py | 33 +++---- .../models/number_properties_only.py | 17 ++-- .../python/openapi_client/models/pet.py | 21 +++-- .../python/openapi_client/models/query.py | 17 ++-- .../python/openapi_client/models/tag.py | 17 ++-- ...ue_object_all_of_query_object_parameter.py | 17 ++-- ...rue_array_string_query_object_parameter.py | 17 ++-- .../petstore_api/api/another_fake_api.py | 6 +- .../petstore_api/api/default_api.py | 6 +- .../petstore_api/api/fake_api.py | 92 +++++++++---------- .../api/fake_classname_tags123_api.py | 6 +- .../petstore_api/api/pet_api.py | 40 ++++---- .../petstore_api/api/store_api.py | 18 ++-- .../petstore_api/api/user_api.py | 34 +++---- .../models/additional_properties_any_type.py | 17 ++-- .../models/additional_properties_class.py | 17 ++-- .../models/additional_properties_object.py | 17 ++-- ...tional_properties_with_description_only.py | 17 ++-- .../models/all_of_with_single_ref.py | 17 ++-- .../petstore_api/models/animal.py | 13 +-- .../petstore_api/models/any_of_color.py | 19 ++-- .../petstore_api/models/any_of_pig.py | 15 +-- .../petstore_api/models/api_response.py | 17 ++-- .../models/array_of_array_of_model.py | 17 ++-- .../models/array_of_array_of_number_only.py | 17 ++-- .../models/array_of_number_only.py | 17 ++-- .../petstore_api/models/array_test.py | 19 ++-- .../petstore_api/models/basque_pig.py | 17 ++-- .../petstore_api/models/capitalization.py | 17 ++-- .../python-aiohttp/petstore_api/models/cat.py | 17 ++-- .../petstore_api/models/category.py | 17 ++-- .../models/circular_reference_model.py | 17 ++-- .../petstore_api/models/class_model.py | 17 ++-- .../petstore_api/models/client.py | 17 ++-- .../petstore_api/models/color.py | 22 +++-- .../petstore_api/models/creature.py | 17 ++-- .../petstore_api/models/creature_info.py | 17 ++-- .../petstore_api/models/danish_pig.py | 17 ++-- .../petstore_api/models/deprecated_object.py | 17 ++-- .../python-aiohttp/petstore_api/models/dog.py | 17 ++-- .../petstore_api/models/dummy_model.py | 17 ++-- .../petstore_api/models/enum_arrays.py | 23 ++--- .../petstore_api/models/enum_test.py | 33 +++---- .../petstore_api/models/file.py | 17 ++-- .../models/file_schema_test_class.py | 17 ++-- .../petstore_api/models/first_ref.py | 17 ++-- .../python-aiohttp/petstore_api/models/foo.py | 17 ++-- .../models/foo_get_default_response.py | 17 ++-- .../petstore_api/models/format_test.py | 27 +++--- .../petstore_api/models/has_only_read_only.py | 17 ++-- .../models/health_check_result.py | 21 +++-- .../models/inner_dict_with_property.py | 17 ++-- .../petstore_api/models/int_or_string.py | 18 ++-- .../petstore_api/models/list.py | 17 ++-- .../models/map_of_array_of_model.py | 17 ++-- .../petstore_api/models/map_test.py | 21 +++-- ...perties_and_additional_properties_class.py | 17 ++-- .../petstore_api/models/model200_response.py | 17 ++-- .../petstore_api/models/model_return.py | 17 ++-- .../petstore_api/models/name.py | 17 ++-- .../petstore_api/models/nullable_class.py | 61 ++++++------ .../petstore_api/models/nullable_property.py | 25 ++--- .../petstore_api/models/number_only.py | 17 ++-- .../object_to_test_additional_properties.py | 17 ++-- .../models/object_with_deprecated_fields.py | 17 ++-- .../petstore_api/models/one_of_enum_string.py | 18 ++-- .../petstore_api/models/order.py | 21 +++-- .../petstore_api/models/outer_composite.py | 17 ++-- .../models/outer_object_with_enum_property.py | 21 +++-- .../petstore_api/models/parent.py | 17 ++-- .../models/parent_with_optional_dict.py | 17 ++-- .../python-aiohttp/petstore_api/models/pet.py | 23 ++--- .../python-aiohttp/petstore_api/models/pig.py | 18 ++-- .../models/property_name_collision.py | 17 ++-- .../petstore_api/models/read_only_first.py | 17 ++-- .../petstore_api/models/second_ref.py | 17 ++-- .../models/self_reference_model.py | 17 ++-- .../petstore_api/models/special_model_name.py | 17 ++-- .../petstore_api/models/special_name.py | 21 +++-- .../python-aiohttp/petstore_api/models/tag.py | 17 ++-- ..._freeform_additional_properties_request.py | 17 ++-- .../petstore_api/models/tiger.py | 17 ++-- .../petstore_api/models/user.py | 17 ++-- .../petstore_api/models/with_nested_one_of.py | 17 ++-- .../petstore_api/api/another_fake_api.py | 6 +- .../python/petstore_api/api/default_api.py | 6 +- .../python/petstore_api/api/fake_api.py | 92 +++++++++---------- .../api/fake_classname_tags123_api.py | 6 +- .../python/petstore_api/api/pet_api.py | 40 ++++---- .../python/petstore_api/api/store_api.py | 18 ++-- .../python/petstore_api/api/user_api.py | 34 +++---- .../models/additional_properties_any_type.py | 17 ++-- .../models/additional_properties_class.py | 17 ++-- .../models/additional_properties_object.py | 17 ++-- ...tional_properties_with_description_only.py | 17 ++-- .../models/all_of_with_single_ref.py | 17 ++-- .../python/petstore_api/models/animal.py | 13 +-- .../petstore_api/models/any_of_color.py | 19 ++-- .../python/petstore_api/models/any_of_pig.py | 15 +-- .../petstore_api/models/api_response.py | 17 ++-- .../models/array_of_array_of_model.py | 17 ++-- .../models/array_of_array_of_number_only.py | 17 ++-- .../models/array_of_number_only.py | 17 ++-- .../python/petstore_api/models/array_test.py | 19 ++-- .../python/petstore_api/models/basque_pig.py | 17 ++-- .../petstore_api/models/capitalization.py | 17 ++-- .../python/petstore_api/models/cat.py | 17 ++-- .../python/petstore_api/models/category.py | 17 ++-- .../models/circular_reference_model.py | 17 ++-- .../python/petstore_api/models/class_model.py | 17 ++-- .../python/petstore_api/models/client.py | 17 ++-- .../python/petstore_api/models/color.py | 22 +++-- .../python/petstore_api/models/creature.py | 17 ++-- .../petstore_api/models/creature_info.py | 17 ++-- .../python/petstore_api/models/danish_pig.py | 17 ++-- .../petstore_api/models/deprecated_object.py | 17 ++-- .../python/petstore_api/models/dog.py | 17 ++-- .../python/petstore_api/models/dummy_model.py | 17 ++-- .../python/petstore_api/models/enum_arrays.py | 23 ++--- .../python/petstore_api/models/enum_test.py | 33 +++---- .../python/petstore_api/models/file.py | 17 ++-- .../models/file_schema_test_class.py | 17 ++-- .../python/petstore_api/models/first_ref.py | 17 ++-- .../python/petstore_api/models/foo.py | 17 ++-- .../models/foo_get_default_response.py | 17 ++-- .../python/petstore_api/models/format_test.py | 27 +++--- .../petstore_api/models/has_only_read_only.py | 17 ++-- .../models/health_check_result.py | 21 +++-- .../models/inner_dict_with_property.py | 17 ++-- .../petstore_api/models/int_or_string.py | 18 ++-- .../python/petstore_api/models/list.py | 17 ++-- .../models/map_of_array_of_model.py | 17 ++-- .../python/petstore_api/models/map_test.py | 21 +++-- ...perties_and_additional_properties_class.py | 17 ++-- .../petstore_api/models/model200_response.py | 17 ++-- .../petstore_api/models/model_return.py | 17 ++-- .../python/petstore_api/models/name.py | 17 ++-- .../petstore_api/models/nullable_class.py | 61 ++++++------ .../petstore_api/models/nullable_property.py | 25 ++--- .../python/petstore_api/models/number_only.py | 17 ++-- .../object_to_test_additional_properties.py | 17 ++-- .../models/object_with_deprecated_fields.py | 17 ++-- .../petstore_api/models/one_of_enum_string.py | 18 ++-- .../python/petstore_api/models/order.py | 21 +++-- .../petstore_api/models/outer_composite.py | 17 ++-- .../models/outer_object_with_enum_property.py | 21 +++-- .../python/petstore_api/models/parent.py | 17 ++-- .../models/parent_with_optional_dict.py | 17 ++-- .../python/petstore_api/models/pet.py | 23 ++--- .../python/petstore_api/models/pig.py | 18 ++-- .../models/property_name_collision.py | 17 ++-- .../petstore_api/models/read_only_first.py | 17 ++-- .../python/petstore_api/models/second_ref.py | 17 ++-- .../models/self_reference_model.py | 17 ++-- .../petstore_api/models/special_model_name.py | 17 ++-- .../petstore_api/models/special_name.py | 21 +++-- .../python/petstore_api/models/tag.py | 17 ++-- ..._freeform_additional_properties_request.py | 17 ++-- .../python/petstore_api/models/tiger.py | 17 ++-- .../python/petstore_api/models/user.py | 17 ++-- .../petstore_api/models/with_nested_one_of.py | 17 ++-- .../python/tests/test_api_validation.py | 9 +- .../petstore/python/tests/test_model.py | 4 +- 177 files changed, 1774 insertions(+), 1611 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java index 15b88422fad..2b7c6b1ef1f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java @@ -911,13 +911,13 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co pydanticImports.add("Field"); pydanticImports.add("StrictStr"); pydanticImports.add("ValidationError"); - pydanticImports.add("validator"); + pydanticImports.add("field_validator"); } else if (!model.anyOf.isEmpty()) { // anyOF codegenProperties = model.getComposedSchemas().getAnyOf(); pydanticImports.add("Field"); pydanticImports.add("StrictStr"); pydanticImports.add("ValidationError"); - pydanticImports.add("validator"); + pydanticImports.add("field_validator"); } else { // typical model codegenProperties = model.vars; @@ -1768,10 +1768,10 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co private PythonType arrayType(IJsonSchemaValidationProperties cp) { PythonType pt = new PythonType(); if (cp.getMaxItems() != null) { - pt.constrain("max_items", cp.getMaxItems()); + pt.constrain("max_length", cp.getMaxItems()); } if (cp.getMinItems()!= null) { - pt.constrain("min_items", cp.getMinItems()); + pt.constrain("min_length", cp.getMinItems()); } if (cp.getUniqueItems()) { // A unique "array" is a set @@ -1807,7 +1807,7 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co } if (cp.getPattern() != null) { - pydanticImports.add("validator"); + pydanticImports.add("field_validator"); // use validator instead as regex doesn't support flags, e.g. IGNORECASE //fieldCustomization.add(Locale.ROOT, String.format(Locale.ROOT, "regex=r'%s'", cp.getPattern())); } @@ -1938,7 +1938,7 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co strt.constrain("min_length", cp.getMinLength()); } if (cp.getPattern() != null) { - pydanticImports.add("validator"); + pydanticImports.add("field_validator"); // use validator instead as regex doesn't support flags, e.g. IGNORECASE //fieldCustomization.add(Locale.ROOT, String.format(Locale.ROOT, "regex=r'%s'", cp.getPattern())); } @@ -2042,7 +2042,7 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co } if (cp.getIsEnum()) { - pydanticImports.add("validator"); + pydanticImports.add("field_validator"); } if (cp.getIsArray()) { diff --git a/modules/openapi-generator/src/main/resources/python/api.mustache b/modules/openapi-generator/src/main/resources/python/api.mustache index 38356218fc7..c8319e1a598 100644 --- a/modules/openapi-generator/src/main/resources/python/api.mustache +++ b/modules/openapi-generator/src/main/resources/python/api.mustache @@ -6,7 +6,7 @@ import re # noqa: F401 import io import warnings -from pydantic import validate_arguments, ValidationError +from pydantic import validate_call, ValidationError {{#imports}} {{import}} @@ -34,7 +34,7 @@ class {{classname}}: self.api_client = api_client {{#operation}} - @validate_arguments + @validate_call {{#asyncio}} async def {{operationId}}(self, {{#allParams}}{{paramName}} : {{{vendorExtensions.x-py-typing}}}{{^required}} = None{{/required}}, {{/allParams}}**kwargs) -> {{{returnType}}}{{^returnType}}None{{/returnType}}: # noqa: E501 {{/asyncio}} @@ -77,7 +77,7 @@ class {{classname}}: raise ValueError(message) return {{#asyncio}}await {{/asyncio}}self.{{operationId}}_with_http_info({{#allParams}}{{paramName}}, {{/allParams}}**kwargs) # noqa: E501 - @validate_arguments + @validate_call {{#asyncio}} async def {{operationId}}_with_http_info(self, {{#allParams}}{{paramName}} : {{{vendorExtensions.x-py-typing}}}{{^required}} = None{{/required}}, {{/allParams}}**kwargs) -> ApiResponse: # noqa: E501 {{/asyncio}} diff --git a/modules/openapi-generator/src/main/resources/python/model_anyof.mustache b/modules/openapi-generator/src/main/resources/python/model_anyof.mustache index c6cc86610ae..f8f3e8f10ee 100644 --- a/modules/openapi-generator/src/main/resources/python/model_anyof.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_anyof.mustache @@ -33,8 +33,9 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} actual_instance: Any = None any_of_schemas: List[str] = Literal[{{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ANY_OF_SCHEMAS] - class Config: - validate_assignment = True + model_config = { + "validate_assignment": True + } {{#discriminator}} discriminator_value_class_map: Dict[str, str] = { @@ -54,14 +55,14 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} else: super().__init__(**kwargs) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): {{#isNullable}} if v is None: return v {{/isNullable}} - instance = {{{classname}}}.construct() + instance = {{{classname}}}.model_construct() error_messages = [] {{#composedSchemas.anyOf}} # validate data type: {{{dataType}}} @@ -102,7 +103,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} @classmethod def from_json(cls, json_str: str) -> {{{classname}}}: """Returns the object represented by the json string""" - instance = {{{classname}}}.construct() + instance = {{{classname}}}.model_construct() {{#isNullable}} if json_str is None: return instance @@ -174,7 +175,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) {{#vendorExtensions.x-py-postponed-model-imports.size}} {{#vendorExtensions.x-py-postponed-model-imports}} diff --git a/modules/openapi-generator/src/main/resources/python/model_generic.mustache b/modules/openapi-generator/src/main/resources/python/model_generic.mustache index 346d24f9d0a..c8a27a42c24 100644 --- a/modules/openapi-generator/src/main/resources/python/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_generic.mustache @@ -27,7 +27,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{#vars}} {{#vendorExtensions.x-regex}} - @validator('{{{name}}}') + @field_validator('{{{name}}}') def {{{name}}}_validate_regular_expression(cls, value): """Validates the regular expression""" {{^required}} @@ -48,7 +48,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{/vendorExtensions.x-regex}} {{#isEnum}} - @validator('{{{name}}}') + @field_validator('{{{name}}}') def {{{name}}}_validate_enum(cls, value): """Validates the enum""" {{^required}} @@ -76,10 +76,11 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{/isEnum}} {{/vars}} - class Config: - """Pydantic configuration""" - allow_population_by_field_name = True - validate_assignment = True + model_config = { + "populate_by_name": True, + "validate_assignment": True + } + {{#hasChildren}} {{#discriminator}} @@ -110,7 +111,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{/hasChildren}} 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""" @@ -124,7 +125,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} 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={ {{#vendorExtensions.x-py-readonly}} "{{{.}}}", @@ -211,8 +212,8 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{#allVars}} {{#isNullable}} # set to None if {{{name}}} (nullable) is None - # and __fields_set__ contains the field - if self.{{name}} is None and "{{{name}}}" in self.__fields_set__: + # and model_fields_set contains the field + if self.{{name}} is None and "{{{name}}}" in self.model_fields_set: _dict['{{{baseName}}}'] = None {{/isNullable}} @@ -240,7 +241,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} return None if not isinstance(obj, dict): - return {{{classname}}}.parse_obj(obj) + return {{{classname}}}.model_validate(obj) {{#disallowAdditionalPropertiesIfNotPresent}} {{^isAdditionalPropertiesTrue}} @@ -251,7 +252,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{/isAdditionalPropertiesTrue}} {{/disallowAdditionalPropertiesIfNotPresent}} - _obj = {{{classname}}}.parse_obj({ + _obj = {{{classname}}}.model_validate({ {{#allVars}} {{#isContainer}} {{#isArray}} diff --git a/modules/openapi-generator/src/main/resources/python/model_oneof.mustache b/modules/openapi-generator/src/main/resources/python/model_oneof.mustache index 20d31bf8890..83b15304bd5 100644 --- a/modules/openapi-generator/src/main/resources/python/model_oneof.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_oneof.mustache @@ -27,10 +27,12 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}} {{/composedSchemas.oneOf}} actual_instance: Optional[Union[{{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}]] = None - one_of_schemas: List[str] = Literal[{{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ONE_OF_SCHEMAS] + one_of_schemas: List[str] = Literal[{{#oneOf}}"{{.}}"{{^-last}}, {{/-last}}{{/oneOf}}] + + model_config = { + "validate_assignment": True + } - class Config: - validate_assignment = True {{#discriminator}} discriminator_value_class_map: Dict[str, str] = { @@ -50,14 +52,14 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} else: super().__init__(**kwargs) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): {{#isNullable}} if v is None: return v {{/isNullable}} - instance = {{{classname}}}.construct() + instance = {{{classname}}}.model_construct() error_messages = [] match = 0 {{#composedSchemas.oneOf}} @@ -101,7 +103,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} @classmethod def from_json(cls, json_str: str) -> {{{classname}}}: """Returns the object represented by the json string""" - instance = {{{classname}}}.construct() + instance = {{{classname}}}.model_construct() {{#isNullable}} if json_str is None: return instance @@ -197,7 +199,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) {{#vendorExtensions.x-py-postponed-model-imports.size}} {{#vendorExtensions.x-py-postponed-model-imports}} diff --git a/samples/client/echo_api/python/openapi_client/api/auth_api.py b/samples/client/echo_api/python/openapi_client/api/auth_api.py index 16ee7463aad..4e7959696e7 100644 --- a/samples/client/echo_api/python/openapi_client/api/auth_api.py +++ b/samples/client/echo_api/python/openapi_client/api/auth_api.py @@ -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 diff --git a/samples/client/echo_api/python/openapi_client/api/body_api.py b/samples/client/echo_api/python/openapi_client/api/body_api.py index 6969e3bcced..e3465a71db4 100644 --- a/samples/client/echo_api/python/openapi_client/api/body_api.py +++ b/samples/client/echo_api/python/openapi_client/api/body_api.py @@ -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 diff --git a/samples/client/echo_api/python/openapi_client/api/form_api.py b/samples/client/echo_api/python/openapi_client/api/form_api.py index 7b0f9720c6c..7d92389ace7 100644 --- a/samples/client/echo_api/python/openapi_client/api/form_api.py +++ b/samples/client/echo_api/python/openapi_client/api/form_api.py @@ -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 diff --git a/samples/client/echo_api/python/openapi_client/api/header_api.py b/samples/client/echo_api/python/openapi_client/api/header_api.py index e9ebc11e9cd..5a1bef8ba30 100644 --- a/samples/client/echo_api/python/openapi_client/api/header_api.py +++ b/samples/client/echo_api/python/openapi_client/api/header_api.py @@ -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 diff --git a/samples/client/echo_api/python/openapi_client/api/path_api.py b/samples/client/echo_api/python/openapi_client/api/path_api.py index a2798c4d604..99f144742ab 100644 --- a/samples/client/echo_api/python/openapi_client/api/path_api.py +++ b/samples/client/echo_api/python/openapi_client/api/path_api.py @@ -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 diff --git a/samples/client/echo_api/python/openapi_client/api/query_api.py b/samples/client/echo_api/python/openapi_client/api/query_api.py index 09d55efd2f5..caca1968b16 100644 --- a/samples/client/echo_api/python/openapi_client/api/query_api.py +++ b/samples/client/echo_api/python/openapi_client/api/query_api.py @@ -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 diff --git a/samples/client/echo_api/python/openapi_client/models/bird.py b/samples/client/echo_api/python/openapi_client/models/bird.py index ea447caaa8e..13b67878e2e 100644 --- a/samples/client/echo_api/python/openapi_client/models/bird.py +++ b/samples/client/echo_api/python/openapi_client/models/bird.py @@ -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") }) diff --git a/samples/client/echo_api/python/openapi_client/models/category.py b/samples/client/echo_api/python/openapi_client/models/category.py index fc4d2c6983a..0d4cfdd54dc 100644 --- a/samples/client/echo_api/python/openapi_client/models/category.py +++ b/samples/client/echo_api/python/openapi_client/models/category.py @@ -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") }) diff --git a/samples/client/echo_api/python/openapi_client/models/data_query.py b/samples/client/echo_api/python/openapi_client/models/data_query.py index ae0c7e7595c..14f2288d1c0 100644 --- a/samples/client/echo_api/python/openapi_client/models/data_query.py +++ b/samples/client/echo_api/python/openapi_client/models/data_query.py @@ -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"), diff --git a/samples/client/echo_api/python/openapi_client/models/default_value.py b/samples/client/echo_api/python/openapi_client/models/default_value.py index 895349de2c4..e807e94e34c 100644 --- a/samples/client/echo_api/python/openapi_client/models/default_value.py +++ b/samples/client/echo_api/python/openapi_client/models/default_value.py @@ -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"), diff --git a/samples/client/echo_api/python/openapi_client/models/number_properties_only.py b/samples/client/echo_api/python/openapi_client/models/number_properties_only.py index e23550731d2..23a179ae2a8 100644 --- a/samples/client/echo_api/python/openapi_client/models/number_properties_only.py +++ b/samples/client/echo_api/python/openapi_client/models/number_properties_only.py @@ -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") }) diff --git a/samples/client/echo_api/python/openapi_client/models/pet.py b/samples/client/echo_api/python/openapi_client/models/pet.py index 3a955d0322c..51b1d20275a 100644 --- a/samples/client/echo_api/python/openapi_client/models/pet.py +++ b/samples/client/echo_api/python/openapi_client/models/pet.py @@ -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, diff --git a/samples/client/echo_api/python/openapi_client/models/query.py b/samples/client/echo_api/python/openapi_client/models/query.py index ba6c8b09f21..c96f723c99b 100644 --- a/samples/client/echo_api/python/openapi_client/models/query.py +++ b/samples/client/echo_api/python/openapi_client/models/query.py @@ -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) diff --git a/samples/client/echo_api/python/openapi_client/models/tag.py b/samples/client/echo_api/python/openapi_client/models/tag.py index 18e2db0c571..5e456e33d22 100644 --- a/samples/client/echo_api/python/openapi_client/models/tag.py +++ b/samples/client/echo_api/python/openapi_client/models/tag.py @@ -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") }) diff --git a/samples/client/echo_api/python/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.py b/samples/client/echo_api/python/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.py index 3ae2d2a2905..c809f92c494 100644 --- a/samples/client/echo_api/python/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.py +++ b/samples/client/echo_api/python/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.py @@ -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"), diff --git a/samples/client/echo_api/python/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.py b/samples/client/echo_api/python/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.py index ebc1612f038..1fef3569599 100644 --- a/samples/client/echo_api/python/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.py +++ b/samples/client/echo_api/python/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.py @@ -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 diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/another_fake_api.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/another_fake_api.py index 1b98cf6c66f..7ba6e9979a4 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/another_fake_api.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/another_fake_api.py @@ -16,7 +16,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 @@ -42,7 +42,7 @@ class AnotherFakeApi: api_client = ApiClient.get_default() self.api_client = api_client - @validate_arguments + @validate_call async def call_123_test_special_tags(self, client : Annotated[Client, Field(description="client model")], **kwargs) -> Client: # noqa: E501 """To test special tags # noqa: E501 @@ -65,7 +65,7 @@ class AnotherFakeApi: raise ValueError(message) return await self.call_123_test_special_tags_with_http_info(client, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def call_123_test_special_tags_with_http_info(self, client : Annotated[Client, Field(description="client model")], **kwargs) -> ApiResponse: # noqa: E501 """To test special tags # noqa: E501 diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/default_api.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/default_api.py index 048cdf7d30a..4adb84f0a25 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/default_api.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/default_api.py @@ -16,7 +16,7 @@ import re # noqa: F401 import io import warnings -from pydantic import validate_arguments, ValidationError +from pydantic import validate_call, ValidationError from petstore_api.models.foo_get_default_response import FooGetDefaultResponse @@ -40,7 +40,7 @@ class DefaultApi: api_client = ApiClient.get_default() self.api_client = api_client - @validate_arguments + @validate_call async def foo_get(self, **kwargs) -> FooGetDefaultResponse: # noqa: E501 """foo_get # noqa: E501 @@ -60,7 +60,7 @@ class DefaultApi: raise ValueError(message) return await self.foo_get_with_http_info(**kwargs) # noqa: E501 - @validate_arguments + @validate_call async def foo_get_with_http_info(self, **kwargs) -> ApiResponse: # noqa: E501 """foo_get # noqa: E501 diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/fake_api.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/fake_api.py index 01e9792aa33..31db62d60ae 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/fake_api.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/fake_api.py @@ -16,13 +16,13 @@ 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 from datetime import date, datetime -from pydantic import StrictBool, StrictBytes, StrictInt, StrictStr, validator +from pydantic import StrictBool, StrictBytes, StrictInt, StrictStr, field_validator from typing import Any, Dict, List, Optional, Union @@ -57,7 +57,7 @@ class FakeApi: api_client = ApiClient.get_default() self.api_client = api_client - @validate_arguments + @validate_call async def fake_any_type_request_body(self, body : Optional[Dict[str, Any]] = None, **kwargs) -> None: # noqa: E501 """test any type request body # noqa: E501 @@ -79,7 +79,7 @@ class FakeApi: raise ValueError(message) return await self.fake_any_type_request_body_with_http_info(body, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def fake_any_type_request_body_with_http_info(self, body : Optional[Dict[str, Any]] = None, **kwargs) -> ApiResponse: # noqa: E501 """test any type request body # noqa: E501 @@ -180,7 +180,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def fake_enum_ref_query_parameter(self, enum_ref : Annotated[Optional[EnumClass], Field(description="enum reference")] = None, **kwargs) -> None: # noqa: E501 """test enum reference query parameter # noqa: E501 @@ -202,7 +202,7 @@ class FakeApi: raise ValueError(message) return await self.fake_enum_ref_query_parameter_with_http_info(enum_ref, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def fake_enum_ref_query_parameter_with_http_info(self, enum_ref : Annotated[Optional[EnumClass], Field(description="enum reference")] = None, **kwargs) -> ApiResponse: # noqa: E501 """test enum reference query parameter # noqa: E501 @@ -296,7 +296,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def fake_health_get(self, **kwargs) -> HealthCheckResult: # noqa: E501 """Health check endpoint # noqa: E501 @@ -316,7 +316,7 @@ class FakeApi: raise ValueError(message) return await self.fake_health_get_with_http_info(**kwargs) # noqa: E501 - @validate_arguments + @validate_call async def fake_health_get_with_http_info(self, **kwargs) -> ApiResponse: # noqa: E501 """Health check endpoint # noqa: E501 @@ -410,7 +410,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def fake_http_signature_test(self, pet : Annotated[Pet, Field(description="Pet object that needs to be added to the store")], query_1 : Annotated[Optional[StrictStr], Field(description="query parameter")] = None, header_1 : Annotated[Optional[StrictStr], Field(description="header parameter")] = None, **kwargs) -> None: # noqa: E501 """test http signature authentication # noqa: E501 @@ -436,7 +436,7 @@ class FakeApi: raise ValueError(message) return await self.fake_http_signature_test_with_http_info(pet, query_1, header_1, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def fake_http_signature_test_with_http_info(self, pet : Annotated[Pet, Field(description="Pet object that needs to be added to the store")], query_1 : Annotated[Optional[StrictStr], Field(description="query parameter")] = None, header_1 : Annotated[Optional[StrictStr], Field(description="header parameter")] = None, **kwargs) -> ApiResponse: # noqa: E501 """test http signature authentication # noqa: E501 @@ -549,7 +549,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def fake_outer_boolean_serialize(self, body : Annotated[Optional[StrictBool], Field(description="Input boolean as post body")] = None, **kwargs) -> bool: # noqa: E501 """fake_outer_boolean_serialize # noqa: E501 @@ -572,7 +572,7 @@ class FakeApi: raise ValueError(message) return await self.fake_outer_boolean_serialize_with_http_info(body, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def fake_outer_boolean_serialize_with_http_info(self, body : Annotated[Optional[StrictBool], Field(description="Input boolean as post body")] = None, **kwargs) -> ApiResponse: # noqa: E501 """fake_outer_boolean_serialize # noqa: E501 @@ -680,7 +680,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def fake_outer_composite_serialize(self, outer_composite : Annotated[Optional[OuterComposite], Field(description="Input composite as post body")] = None, **kwargs) -> OuterComposite: # noqa: E501 """fake_outer_composite_serialize # noqa: E501 @@ -703,7 +703,7 @@ class FakeApi: raise ValueError(message) return await self.fake_outer_composite_serialize_with_http_info(outer_composite, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def fake_outer_composite_serialize_with_http_info(self, outer_composite : Annotated[Optional[OuterComposite], Field(description="Input composite as post body")] = None, **kwargs) -> ApiResponse: # noqa: E501 """fake_outer_composite_serialize # noqa: E501 @@ -811,7 +811,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def fake_outer_number_serialize(self, body : Annotated[Optional[float], Field(description="Input number as post body")] = None, **kwargs) -> float: # noqa: E501 """fake_outer_number_serialize # noqa: E501 @@ -834,7 +834,7 @@ class FakeApi: raise ValueError(message) return await self.fake_outer_number_serialize_with_http_info(body, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def fake_outer_number_serialize_with_http_info(self, body : Annotated[Optional[float], Field(description="Input number as post body")] = None, **kwargs) -> ApiResponse: # noqa: E501 """fake_outer_number_serialize # noqa: E501 @@ -942,7 +942,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def fake_outer_string_serialize(self, body : Annotated[Optional[StrictStr], Field(description="Input string as post body")] = None, **kwargs) -> str: # noqa: E501 """fake_outer_string_serialize # noqa: E501 @@ -965,7 +965,7 @@ class FakeApi: raise ValueError(message) return await self.fake_outer_string_serialize_with_http_info(body, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def fake_outer_string_serialize_with_http_info(self, body : Annotated[Optional[StrictStr], Field(description="Input string as post body")] = None, **kwargs) -> ApiResponse: # noqa: E501 """fake_outer_string_serialize # noqa: E501 @@ -1073,7 +1073,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def fake_property_enum_integer_serialize(self, outer_object_with_enum_property : Annotated[OuterObjectWithEnumProperty, Field(description="Input enum (int) as post body")], **kwargs) -> OuterObjectWithEnumProperty: # noqa: E501 """fake_property_enum_integer_serialize # noqa: E501 @@ -1096,7 +1096,7 @@ class FakeApi: raise ValueError(message) return await self.fake_property_enum_integer_serialize_with_http_info(outer_object_with_enum_property, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def fake_property_enum_integer_serialize_with_http_info(self, outer_object_with_enum_property : Annotated[OuterObjectWithEnumProperty, Field(description="Input enum (int) as post body")], **kwargs) -> ApiResponse: # noqa: E501 """fake_property_enum_integer_serialize # noqa: E501 @@ -1204,7 +1204,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def fake_return_list_of_objects(self, **kwargs) -> List[List[Tag]]: # noqa: E501 """test returning list of objects # noqa: E501 @@ -1224,7 +1224,7 @@ class FakeApi: raise ValueError(message) return await self.fake_return_list_of_objects_with_http_info(**kwargs) # noqa: E501 - @validate_arguments + @validate_call async def fake_return_list_of_objects_with_http_info(self, **kwargs) -> ApiResponse: # noqa: E501 """test returning list of objects # noqa: E501 @@ -1318,7 +1318,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def fake_uuid_example(self, uuid_example : Annotated[StrictStr, Field(description="uuid example")], **kwargs) -> None: # noqa: E501 """test uuid example # noqa: E501 @@ -1340,7 +1340,7 @@ class FakeApi: raise ValueError(message) return await self.fake_uuid_example_with_http_info(uuid_example, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def fake_uuid_example_with_http_info(self, uuid_example : Annotated[StrictStr, Field(description="uuid example")], **kwargs) -> ApiResponse: # noqa: E501 """test uuid example # noqa: E501 @@ -1434,7 +1434,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def test_body_with_binary(self, body : Annotated[Optional[Union[StrictBytes, StrictStr]], Field(description="image to upload")], **kwargs) -> None: # noqa: E501 """test_body_with_binary # noqa: E501 @@ -1457,7 +1457,7 @@ class FakeApi: raise ValueError(message) return await self.test_body_with_binary_with_http_info(body, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def test_body_with_binary_with_http_info(self, body : Annotated[Optional[Union[StrictBytes, StrictStr]], Field(description="image to upload")], **kwargs) -> ApiResponse: # noqa: E501 """test_body_with_binary # noqa: E501 @@ -1564,7 +1564,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def test_body_with_file_schema(self, file_schema_test_class : FileSchemaTestClass, **kwargs) -> None: # noqa: E501 """test_body_with_file_schema # noqa: E501 @@ -1587,7 +1587,7 @@ class FakeApi: raise ValueError(message) return await self.test_body_with_file_schema_with_http_info(file_schema_test_class, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def test_body_with_file_schema_with_http_info(self, file_schema_test_class : FileSchemaTestClass, **kwargs) -> ApiResponse: # noqa: E501 """test_body_with_file_schema # noqa: E501 @@ -1689,7 +1689,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def test_body_with_query_params(self, query : StrictStr, user : User, **kwargs) -> None: # noqa: E501 """test_body_with_query_params # noqa: E501 @@ -1713,7 +1713,7 @@ class FakeApi: raise ValueError(message) return await self.test_body_with_query_params_with_http_info(query, user, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def test_body_with_query_params_with_http_info(self, query : StrictStr, user : User, **kwargs) -> ApiResponse: # noqa: E501 """test_body_with_query_params # noqa: E501 @@ -1820,7 +1820,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def test_client_model(self, client : Annotated[Client, Field(description="client model")], **kwargs) -> Client: # noqa: E501 """To test \"client\" model # noqa: E501 @@ -1843,7 +1843,7 @@ class FakeApi: raise ValueError(message) return await self.test_client_model_with_http_info(client, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def test_client_model_with_http_info(self, client : Annotated[Client, Field(description="client model")], **kwargs) -> ApiResponse: # noqa: E501 """To test \"client\" model # noqa: E501 @@ -1951,7 +1951,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def test_date_time_query_parameter(self, date_time_query : datetime, str_query : StrictStr, **kwargs) -> None: # noqa: E501 """test_date_time_query_parameter # noqa: E501 @@ -1975,7 +1975,7 @@ class FakeApi: raise ValueError(message) return await self.test_date_time_query_parameter_with_http_info(date_time_query, str_query, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def test_date_time_query_parameter_with_http_info(self, date_time_query : datetime, str_query : StrictStr, **kwargs) -> ApiResponse: # noqa: E501 """test_date_time_query_parameter # noqa: E501 @@ -2078,7 +2078,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def test_endpoint_parameters(self, number : Annotated[float, Field(le=543.2, ge=32.1, description="None")], double : Annotated[float, Field(le=123.4, ge=67.8, description="None")], pattern_without_delimiter : Annotated[str, Field(strict=True, description="None")], byte : Annotated[Union[StrictBytes, StrictStr], Field(description="None")], integer : Annotated[Optional[Annotated[int, Field(le=100, strict=True, ge=10)]], Field(description="None")] = None, int32 : Annotated[Optional[Annotated[int, Field(le=200, strict=True, ge=20)]], Field(description="None")] = None, int64 : Annotated[Optional[StrictInt], Field(description="None")] = None, float : Annotated[Optional[Annotated[float, Field(le=987.6)]], Field(description="None")] = None, string : Annotated[Optional[Annotated[str, Field(strict=True)]], Field(description="None")] = None, binary : Annotated[Optional[Union[StrictBytes, StrictStr]], Field(description="None")] = None, byte_with_max_length : Annotated[Optional[Union[Annotated[bytes, Field(strict=True, max_length=64)], Annotated[str, Field(strict=True, max_length=64)]]], Field(description="None")] = None, var_date : Annotated[Optional[date], Field(description="None")] = None, date_time : Annotated[Optional[datetime], Field(description="None")] = None, password : Annotated[Optional[Annotated[str, Field(min_length=10, strict=True, max_length=64)]], Field(description="None")] = None, param_callback : Annotated[Optional[StrictStr], Field(description="None")] = None, **kwargs) -> None: # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 @@ -2129,7 +2129,7 @@ class FakeApi: raise ValueError(message) return await self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, integer, int32, int64, float, string, binary, byte_with_max_length, var_date, date_time, password, param_callback, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def test_endpoint_parameters_with_http_info(self, number : Annotated[float, Field(le=543.2, ge=32.1, description="None")], double : Annotated[float, Field(le=123.4, ge=67.8, description="None")], pattern_without_delimiter : Annotated[str, Field(strict=True, description="None")], byte : Annotated[Union[StrictBytes, StrictStr], Field(description="None")], integer : Annotated[Optional[Annotated[int, Field(le=100, strict=True, ge=10)]], Field(description="None")] = None, int32 : Annotated[Optional[Annotated[int, Field(le=200, strict=True, ge=20)]], Field(description="None")] = None, int64 : Annotated[Optional[StrictInt], Field(description="None")] = None, float : Annotated[Optional[Annotated[float, Field(le=987.6)]], Field(description="None")] = None, string : Annotated[Optional[Annotated[str, Field(strict=True)]], Field(description="None")] = None, binary : Annotated[Optional[Union[StrictBytes, StrictStr]], Field(description="None")] = None, byte_with_max_length : Annotated[Optional[Union[Annotated[bytes, Field(strict=True, max_length=64)], Annotated[str, Field(strict=True, max_length=64)]]], Field(description="None")] = None, var_date : Annotated[Optional[date], Field(description="None")] = None, date_time : Annotated[Optional[datetime], Field(description="None")] = None, password : Annotated[Optional[Annotated[str, Field(min_length=10, strict=True, max_length=64)]], Field(description="None")] = None, param_callback : Annotated[Optional[StrictStr], Field(description="None")] = None, **kwargs) -> ApiResponse: # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 @@ -2315,7 +2315,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def test_group_parameters(self, required_string_group : Annotated[StrictInt, Field(description="Required String in group parameters")], required_boolean_group : Annotated[StrictBool, Field(description="Required Boolean in group parameters")], required_int64_group : Annotated[StrictInt, Field(description="Required Integer in group parameters")], string_group : Annotated[Optional[StrictInt], Field(description="String in group parameters")] = None, boolean_group : Annotated[Optional[StrictBool], Field(description="Boolean in group parameters")] = None, int64_group : Annotated[Optional[StrictInt], Field(description="Integer in group parameters")] = None, **kwargs) -> None: # noqa: E501 """Fake endpoint to test group parameters (optional) # noqa: E501 @@ -2348,7 +2348,7 @@ class FakeApi: raise ValueError(message) return await self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, string_group, boolean_group, int64_group, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def test_group_parameters_with_http_info(self, required_string_group : Annotated[StrictInt, Field(description="Required String in group parameters")], required_boolean_group : Annotated[StrictBool, Field(description="Required Boolean in group parameters")], required_int64_group : Annotated[StrictInt, Field(description="Required Integer in group parameters")], string_group : Annotated[Optional[StrictInt], Field(description="String in group parameters")] = None, boolean_group : Annotated[Optional[StrictBool], Field(description="Boolean in group parameters")] = None, int64_group : Annotated[Optional[StrictInt], Field(description="Integer in group parameters")] = None, **kwargs) -> ApiResponse: # noqa: E501 """Fake endpoint to test group parameters (optional) # noqa: E501 @@ -2473,7 +2473,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def test_inline_additional_properties(self, request_body : Annotated[Dict[str, StrictStr], Field(description="request body")], **kwargs) -> None: # noqa: E501 """test inline additionalProperties # noqa: E501 @@ -2496,7 +2496,7 @@ class FakeApi: raise ValueError(message) return await self.test_inline_additional_properties_with_http_info(request_body, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def test_inline_additional_properties_with_http_info(self, request_body : Annotated[Dict[str, StrictStr], Field(description="request body")], **kwargs) -> ApiResponse: # noqa: E501 """test inline additionalProperties # noqa: E501 @@ -2598,7 +2598,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def test_inline_freeform_additional_properties(self, test_inline_freeform_additional_properties_request : Annotated[TestInlineFreeformAdditionalPropertiesRequest, Field(description="request body")], **kwargs) -> None: # noqa: E501 """test inline free-form additionalProperties # noqa: E501 @@ -2621,7 +2621,7 @@ class FakeApi: raise ValueError(message) return await self.test_inline_freeform_additional_properties_with_http_info(test_inline_freeform_additional_properties_request, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def test_inline_freeform_additional_properties_with_http_info(self, test_inline_freeform_additional_properties_request : Annotated[TestInlineFreeformAdditionalPropertiesRequest, Field(description="request body")], **kwargs) -> ApiResponse: # noqa: E501 """test inline free-form additionalProperties # noqa: E501 @@ -2723,7 +2723,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def test_json_form_data(self, param : Annotated[StrictStr, Field(description="field1")], param2 : Annotated[StrictStr, Field(description="field2")], **kwargs) -> None: # noqa: E501 """test json serialization of form data # noqa: E501 @@ -2748,7 +2748,7 @@ class FakeApi: raise ValueError(message) return await self.test_json_form_data_with_http_info(param, param2, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def test_json_form_data_with_http_info(self, param : Annotated[StrictStr, Field(description="field1")], param2 : Annotated[StrictStr, Field(description="field2")], **kwargs) -> ApiResponse: # noqa: E501 """test json serialization of form data # noqa: E501 @@ -2856,7 +2856,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def test_query_parameter_collection_format(self, pipe : List[StrictStr], ioutil : List[StrictStr], http : List[StrictStr], url : List[StrictStr], context : List[StrictStr], allow_empty : StrictStr, language : Optional[Dict[str, StrictStr]] = None, **kwargs) -> None: # noqa: E501 """test_query_parameter_collection_format # noqa: E501 @@ -2891,7 +2891,7 @@ class FakeApi: raise ValueError(message) return await self.test_query_parameter_collection_format_with_http_info(pipe, ioutil, http, url, context, allow_empty, language, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def test_query_parameter_collection_format_with_http_info(self, pipe : List[StrictStr], ioutil : List[StrictStr], http : List[StrictStr], url : List[StrictStr], context : List[StrictStr], allow_empty : StrictStr, language : Optional[Dict[str, StrictStr]] = None, **kwargs) -> ApiResponse: # noqa: E501 """test_query_parameter_collection_format # noqa: E501 diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/fake_classname_tags123_api.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/fake_classname_tags123_api.py index bf28c701306..1fc4e442629 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/fake_classname_tags123_api.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/fake_classname_tags123_api.py @@ -16,7 +16,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 @@ -42,7 +42,7 @@ class FakeClassnameTags123Api: api_client = ApiClient.get_default() self.api_client = api_client - @validate_arguments + @validate_call async def test_classname(self, client : Annotated[Client, Field(description="client model")], **kwargs) -> Client: # noqa: E501 """To test class name in snake case # noqa: E501 @@ -65,7 +65,7 @@ class FakeClassnameTags123Api: raise ValueError(message) return await self.test_classname_with_http_info(client, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def test_classname_with_http_info(self, client : Annotated[Client, Field(description="client model")], **kwargs) -> ApiResponse: # noqa: E501 """To test class name in snake case # noqa: E501 diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/pet_api.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/pet_api.py index 6619d616dd4..143ae485831 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/pet_api.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/pet_api.py @@ -16,11 +16,11 @@ 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 -from pydantic import StrictBytes, StrictInt, StrictStr, validator +from pydantic import StrictBytes, StrictInt, StrictStr, field_validator from typing import List, Optional, Union @@ -47,7 +47,7 @@ class PetApi: api_client = ApiClient.get_default() self.api_client = api_client - @validate_arguments + @validate_call async def add_pet(self, pet : Annotated[Pet, Field(description="Pet object that needs to be added to the store")], **kwargs) -> None: # noqa: E501 """Add a new pet to the store # noqa: E501 @@ -70,7 +70,7 @@ class PetApi: raise ValueError(message) return await self.add_pet_with_http_info(pet, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def add_pet_with_http_info(self, pet : Annotated[Pet, Field(description="Pet object that needs to be added to the store")], **kwargs) -> ApiResponse: # noqa: E501 """Add a new pet to the store # noqa: E501 @@ -172,7 +172,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def delete_pet(self, pet_id : Annotated[StrictInt, Field(description="Pet id to delete")], api_key : Optional[StrictStr] = None, **kwargs) -> None: # noqa: E501 """Deletes a pet # noqa: E501 @@ -197,7 +197,7 @@ class PetApi: raise ValueError(message) return await self.delete_pet_with_http_info(pet_id, api_key, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def delete_pet_with_http_info(self, pet_id : Annotated[StrictInt, Field(description="Pet id to delete")], api_key : Optional[StrictStr] = None, **kwargs) -> ApiResponse: # noqa: E501 """Deletes a pet # noqa: E501 @@ -298,7 +298,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def find_pets_by_status(self, status : Annotated[List[StrictStr], Field(description="Status values that need to be considered for filter")], **kwargs) -> List[Pet]: # noqa: E501 """Finds Pets by status # noqa: E501 @@ -321,7 +321,7 @@ class PetApi: raise ValueError(message) return await self.find_pets_by_status_with_http_info(status, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def find_pets_by_status_with_http_info(self, status : Annotated[List[StrictStr], Field(description="Status values that need to be considered for filter")], **kwargs) -> ApiResponse: # noqa: E501 """Finds Pets by status # noqa: E501 @@ -424,7 +424,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def find_pets_by_tags(self, tags : Annotated[List[StrictStr], Field(description="Tags to filter by")], **kwargs) -> List[Pet]: # noqa: E501 """(Deprecated) Finds Pets by tags # noqa: E501 @@ -447,7 +447,7 @@ class PetApi: raise ValueError(message) return await self.find_pets_by_tags_with_http_info(tags, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def find_pets_by_tags_with_http_info(self, tags : Annotated[List[StrictStr], Field(description="Tags to filter by")], **kwargs) -> ApiResponse: # noqa: E501 """(Deprecated) Finds Pets by tags # noqa: E501 @@ -552,7 +552,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def get_pet_by_id(self, pet_id : Annotated[StrictInt, Field(description="ID of pet to return")], **kwargs) -> Pet: # noqa: E501 """Find pet by ID # noqa: E501 @@ -575,7 +575,7 @@ class PetApi: raise ValueError(message) return await self.get_pet_by_id_with_http_info(pet_id, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def get_pet_by_id_with_http_info(self, pet_id : Annotated[StrictInt, Field(description="ID of pet to return")], **kwargs) -> ApiResponse: # noqa: E501 """Find pet by ID # noqa: E501 @@ -678,7 +678,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def update_pet(self, pet : Annotated[Pet, Field(description="Pet object that needs to be added to the store")], **kwargs) -> None: # noqa: E501 """Update an existing pet # noqa: E501 @@ -701,7 +701,7 @@ class PetApi: raise ValueError(message) return await self.update_pet_with_http_info(pet, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def update_pet_with_http_info(self, pet : Annotated[Pet, Field(description="Pet object that needs to be added to the store")], **kwargs) -> ApiResponse: # noqa: E501 """Update an existing pet # noqa: E501 @@ -803,7 +803,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def update_pet_with_form(self, pet_id : Annotated[StrictInt, Field(description="ID of pet that needs to be updated")], name : Annotated[Optional[StrictStr], Field(description="Updated name of the pet")] = None, status : Annotated[Optional[StrictStr], Field(description="Updated status of the pet")] = None, **kwargs) -> None: # noqa: E501 """Updates a pet in the store with form data # noqa: E501 @@ -830,7 +830,7 @@ class PetApi: raise ValueError(message) return await self.update_pet_with_form_with_http_info(pet_id, name, status, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def update_pet_with_form_with_http_info(self, pet_id : Annotated[StrictInt, Field(description="ID of pet that needs to be updated")], name : Annotated[Optional[StrictStr], Field(description="Updated name of the pet")] = None, status : Annotated[Optional[StrictStr], Field(description="Updated status of the pet")] = None, **kwargs) -> ApiResponse: # noqa: E501 """Updates a pet in the store with form data # noqa: E501 @@ -944,7 +944,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def upload_file(self, pet_id : Annotated[StrictInt, Field(description="ID of pet to update")], additional_metadata : Annotated[Optional[StrictStr], Field(description="Additional data to pass to server")] = None, file : Annotated[Optional[Union[StrictBytes, StrictStr]], Field(description="file to upload")] = None, **kwargs) -> ApiResponse: # noqa: E501 """uploads an image # noqa: E501 @@ -971,7 +971,7 @@ class PetApi: raise ValueError(message) return await self.upload_file_with_http_info(pet_id, additional_metadata, file, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def upload_file_with_http_info(self, pet_id : Annotated[StrictInt, Field(description="ID of pet to update")], additional_metadata : Annotated[Optional[StrictStr], Field(description="Additional data to pass to server")] = None, file : Annotated[Optional[Union[StrictBytes, StrictStr]], Field(description="file to upload")] = None, **kwargs) -> ApiResponse: # noqa: E501 """uploads an image # noqa: E501 @@ -1091,7 +1091,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def upload_file_with_required_file(self, pet_id : Annotated[StrictInt, Field(description="ID of pet to update")], required_file : Annotated[Union[StrictBytes, StrictStr], Field(description="file to upload")], additional_metadata : Annotated[Optional[StrictStr], Field(description="Additional data to pass to server")] = None, **kwargs) -> ApiResponse: # noqa: E501 """uploads an image (required) # noqa: E501 @@ -1118,7 +1118,7 @@ class PetApi: raise ValueError(message) return await self.upload_file_with_required_file_with_http_info(pet_id, required_file, additional_metadata, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def upload_file_with_required_file_with_http_info(self, pet_id : Annotated[StrictInt, Field(description="ID of pet to update")], required_file : Annotated[Union[StrictBytes, StrictStr], Field(description="file to upload")], additional_metadata : Annotated[Optional[StrictStr], Field(description="Additional data to pass to server")] = None, **kwargs) -> ApiResponse: # noqa: E501 """uploads an image (required) # noqa: E501 diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/store_api.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/store_api.py index c25fa5f697b..dd992c9f013 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/store_api.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/store_api.py @@ -16,7 +16,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 @@ -46,7 +46,7 @@ class StoreApi: api_client = ApiClient.get_default() self.api_client = api_client - @validate_arguments + @validate_call async def delete_order(self, order_id : Annotated[StrictStr, Field(description="ID of the order that needs to be deleted")], **kwargs) -> None: # noqa: E501 """Delete purchase order by ID # noqa: E501 @@ -69,7 +69,7 @@ class StoreApi: raise ValueError(message) return await self.delete_order_with_http_info(order_id, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def delete_order_with_http_info(self, order_id : Annotated[StrictStr, Field(description="ID of the order that needs to be deleted")], **kwargs) -> ApiResponse: # noqa: E501 """Delete purchase order by ID # noqa: E501 @@ -164,7 +164,7 @@ class StoreApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def get_inventory(self, **kwargs) -> Dict[str, int]: # noqa: E501 """Returns pet inventories by status # noqa: E501 @@ -185,7 +185,7 @@ class StoreApi: raise ValueError(message) return await self.get_inventory_with_http_info(**kwargs) # noqa: E501 - @validate_arguments + @validate_call async def get_inventory_with_http_info(self, **kwargs) -> ApiResponse: # noqa: E501 """Returns pet inventories by status # noqa: E501 @@ -280,7 +280,7 @@ class StoreApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def get_order_by_id(self, order_id : Annotated[int, Field(le=5, strict=True, ge=1, description="ID of pet that needs to be fetched")], **kwargs) -> Order: # noqa: E501 """Find purchase order by ID # noqa: E501 @@ -303,7 +303,7 @@ class StoreApi: raise ValueError(message) return await self.get_order_by_id_with_http_info(order_id, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def get_order_by_id_with_http_info(self, order_id : Annotated[int, Field(le=5, strict=True, ge=1, description="ID of pet that needs to be fetched")], **kwargs) -> ApiResponse: # noqa: E501 """Find purchase order by ID # noqa: E501 @@ -406,7 +406,7 @@ class StoreApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def place_order(self, order : Annotated[Order, Field(description="order placed for purchasing the pet")], **kwargs) -> Order: # noqa: E501 """Place an order for a pet # noqa: E501 @@ -429,7 +429,7 @@ class StoreApi: raise ValueError(message) return await self.place_order_with_http_info(order, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def place_order_with_http_info(self, order : Annotated[Order, Field(description="order placed for purchasing the pet")], **kwargs) -> ApiResponse: # noqa: E501 """Place an order for a pet # noqa: E501 diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/user_api.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/user_api.py index fa23d5a8fd7..00e32e0663e 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/user_api.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/user_api.py @@ -16,7 +16,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 @@ -46,7 +46,7 @@ class UserApi: api_client = ApiClient.get_default() self.api_client = api_client - @validate_arguments + @validate_call async def create_user(self, user : Annotated[User, Field(description="Created user object")], **kwargs) -> None: # noqa: E501 """Create user # noqa: E501 @@ -69,7 +69,7 @@ class UserApi: raise ValueError(message) return await self.create_user_with_http_info(user, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def create_user_with_http_info(self, user : Annotated[User, Field(description="Created user object")], **kwargs) -> ApiResponse: # noqa: E501 """Create user # noqa: E501 @@ -186,7 +186,7 @@ class UserApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def create_users_with_array_input(self, user : Annotated[List[User], Field(description="List of user object")], **kwargs) -> None: # noqa: E501 """Creates list of users with given input array # noqa: E501 @@ -209,7 +209,7 @@ class UserApi: raise ValueError(message) return await self.create_users_with_array_input_with_http_info(user, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def create_users_with_array_input_with_http_info(self, user : Annotated[List[User], Field(description="List of user object")], **kwargs) -> ApiResponse: # noqa: E501 """Creates list of users with given input array # noqa: E501 @@ -311,7 +311,7 @@ class UserApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def create_users_with_list_input(self, user : Annotated[List[User], Field(description="List of user object")], **kwargs) -> None: # noqa: E501 """Creates list of users with given input array # noqa: E501 @@ -334,7 +334,7 @@ class UserApi: raise ValueError(message) return await self.create_users_with_list_input_with_http_info(user, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def create_users_with_list_input_with_http_info(self, user : Annotated[List[User], Field(description="List of user object")], **kwargs) -> ApiResponse: # noqa: E501 """Creates list of users with given input array # noqa: E501 @@ -436,7 +436,7 @@ class UserApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def delete_user(self, username : Annotated[StrictStr, Field(description="The name that needs to be deleted")], **kwargs) -> None: # noqa: E501 """Delete user # noqa: E501 @@ -459,7 +459,7 @@ class UserApi: raise ValueError(message) return await self.delete_user_with_http_info(username, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def delete_user_with_http_info(self, username : Annotated[StrictStr, Field(description="The name that needs to be deleted")], **kwargs) -> ApiResponse: # noqa: E501 """Delete user # noqa: E501 @@ -554,7 +554,7 @@ class UserApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def get_user_by_name(self, username : Annotated[StrictStr, Field(description="The name that needs to be fetched. Use user1 for testing.")], **kwargs) -> User: # noqa: E501 """Get user by user name # noqa: E501 @@ -577,7 +577,7 @@ class UserApi: raise ValueError(message) return await self.get_user_by_name_with_http_info(username, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def get_user_by_name_with_http_info(self, username : Annotated[StrictStr, Field(description="The name that needs to be fetched. Use user1 for testing.")], **kwargs) -> ApiResponse: # noqa: E501 """Get user by user name # noqa: E501 @@ -680,7 +680,7 @@ class UserApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def login_user(self, username : Annotated[StrictStr, Field(description="The user name for login")], password : Annotated[StrictStr, Field(description="The password for login in clear text")], **kwargs) -> str: # noqa: E501 """Logs user into the system # noqa: E501 @@ -705,7 +705,7 @@ class UserApi: raise ValueError(message) return await self.login_user_with_http_info(username, password, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def login_user_with_http_info(self, username : Annotated[StrictStr, Field(description="The user name for login")], password : Annotated[StrictStr, Field(description="The password for login in clear text")], **kwargs) -> ApiResponse: # noqa: E501 """Logs user into the system # noqa: E501 @@ -813,7 +813,7 @@ class UserApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def logout_user(self, **kwargs) -> None: # noqa: E501 """Logs out current logged in user session # noqa: E501 @@ -834,7 +834,7 @@ class UserApi: raise ValueError(message) return await self.logout_user_with_http_info(**kwargs) # noqa: E501 - @validate_arguments + @validate_call async def logout_user_with_http_info(self, **kwargs) -> ApiResponse: # noqa: E501 """Logs out current logged in user session # noqa: E501 @@ -923,7 +923,7 @@ class UserApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call async def update_user(self, username : Annotated[StrictStr, Field(description="name that need to be deleted")], user : Annotated[User, Field(description="Updated user object")], **kwargs) -> None: # noqa: E501 """Updated user # noqa: E501 @@ -948,7 +948,7 @@ class UserApi: raise ValueError(message) return await self.update_user_with_http_info(username, user, **kwargs) # noqa: E501 - @validate_arguments + @validate_call async def update_user_with_http_info(self, username : Annotated[StrictStr, Field(description="name that need to be deleted")], user : Annotated[User, Field(description="Updated user object")], **kwargs) -> ApiResponse: # noqa: E501 """Updated user # noqa: E501 diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_any_type.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_any_type.py index 9c3fc032c1b..434439f1769 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_any_type.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_any_type.py @@ -29,14 +29,15 @@ class AdditionalPropertiesAnyType(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["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""" @@ -50,7 +51,7 @@ class AdditionalPropertiesAnyType(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={ "additional_properties" }, @@ -69,9 +70,9 @@ class AdditionalPropertiesAnyType(BaseModel): return None if not isinstance(obj, dict): - return AdditionalPropertiesAnyType.parse_obj(obj) + return AdditionalPropertiesAnyType.model_validate(obj) - _obj = AdditionalPropertiesAnyType.parse_obj({ + _obj = AdditionalPropertiesAnyType.model_validate({ "name": obj.get("name") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_class.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_class.py index 960d5452f78..86f52278aa1 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_class.py @@ -29,14 +29,15 @@ class AdditionalPropertiesClass(BaseModel): map_of_map_property: Optional[Dict[str, Dict[str, StrictStr]]] = None __properties = ["map_property", "map_of_map_property"] - 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 AdditionalPropertiesClass(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 AdditionalPropertiesClass(BaseModel): return None if not isinstance(obj, dict): - return AdditionalPropertiesClass.parse_obj(obj) + return AdditionalPropertiesClass.model_validate(obj) - _obj = AdditionalPropertiesClass.parse_obj({ + _obj = AdditionalPropertiesClass.model_validate({ "map_property": obj.get("map_property"), "map_of_map_property": obj.get("map_of_map_property") }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_object.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_object.py index 566643e8087..e05cd9a4752 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_object.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_object.py @@ -29,14 +29,15 @@ class AdditionalPropertiesObject(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["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""" @@ -50,7 +51,7 @@ class AdditionalPropertiesObject(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={ "additional_properties" }, @@ -69,9 +70,9 @@ class AdditionalPropertiesObject(BaseModel): return None if not isinstance(obj, dict): - return AdditionalPropertiesObject.parse_obj(obj) + return AdditionalPropertiesObject.model_validate(obj) - _obj = AdditionalPropertiesObject.parse_obj({ + _obj = AdditionalPropertiesObject.model_validate({ "name": obj.get("name") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_with_description_only.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_with_description_only.py index 79e6c925a30..10e6602941b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_with_description_only.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_with_description_only.py @@ -29,14 +29,15 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["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""" @@ -50,7 +51,7 @@ class AdditionalPropertiesWithDescriptionOnly(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={ "additional_properties" }, @@ -69,9 +70,9 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel): return None if not isinstance(obj, dict): - return AdditionalPropertiesWithDescriptionOnly.parse_obj(obj) + return AdditionalPropertiesWithDescriptionOnly.model_validate(obj) - _obj = AdditionalPropertiesWithDescriptionOnly.parse_obj({ + _obj = AdditionalPropertiesWithDescriptionOnly.model_validate({ "name": obj.get("name") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_with_single_ref.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_with_single_ref.py index 285f28670a1..302f89173e4 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_with_single_ref.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_with_single_ref.py @@ -31,14 +31,15 @@ class AllOfWithSingleRef(BaseModel): single_ref_type: Optional[SingleRefType] = Field(default=None, alias="SingleRefType") __properties = ["username", "SingleRefType"] - 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""" @@ -52,7 +53,7 @@ class AllOfWithSingleRef(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) @@ -65,9 +66,9 @@ class AllOfWithSingleRef(BaseModel): return None if not isinstance(obj, dict): - return AllOfWithSingleRef.parse_obj(obj) + return AllOfWithSingleRef.model_validate(obj) - _obj = AllOfWithSingleRef.parse_obj({ + _obj = AllOfWithSingleRef.model_validate({ "username": obj.get("username"), "SingleRefType": obj.get("SingleRefType") }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/animal.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/animal.py index 4f62093ac2c..33501c52ed0 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/animal.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/animal.py @@ -30,10 +30,11 @@ class Animal(BaseModel): color: Optional[StrictStr] = 'red' __properties = ["className", "color"] - class Config: - """Pydantic configuration""" - allow_population_by_field_name = True - validate_assignment = True + model_config = { + "populate_by_name": True, + "validate_assignment": True + } + # JSON field name that stores the object type __discriminator_property_name = 'className' @@ -55,7 +56,7 @@ class Animal(BaseModel): 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,7 +70,7 @@ class Animal(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) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py index 397956daa53..23097a49750 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py @@ -19,7 +19,7 @@ import pprint import re # noqa: F401 from typing import List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from pydantic import Field from typing_extensions import Annotated from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict @@ -34,9 +34,9 @@ class AnyOfColor(BaseModel): """ # data type: List[int] - anyof_schema_1_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_items=3, max_items=3)]] = Field(default=None, description="RGB three element array with values 0-255.") + anyof_schema_1_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_length=3, max_length=3)]] = Field(default=None, description="RGB three element array with values 0-255.") # data type: List[int] - anyof_schema_2_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_items=4, max_items=4)]] = Field(default=None, description="RGBA four element array with values 0-255.") + anyof_schema_2_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_length=4, max_length=4)]] = Field(default=None, description="RGBA four element array with values 0-255.") # data type: str anyof_schema_3_validator: Optional[Annotated[str, Field(min_length=7, strict=True, max_length=7)]] = Field(default=None, description="Hex color string, such as #00FF00.") if TYPE_CHECKING: @@ -45,8 +45,9 @@ class AnyOfColor(BaseModel): actual_instance: Any = None any_of_schemas: List[str] = Literal[ANYOFCOLOR_ANY_OF_SCHEMAS] - class Config: - validate_assignment = True + model_config = { + "validate_assignment": True + } def __init__(self, *args, **kwargs) -> None: if args: @@ -58,9 +59,9 @@ class AnyOfColor(BaseModel): else: super().__init__(**kwargs) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): - instance = AnyOfColor.construct() + instance = AnyOfColor.model_construct() error_messages = [] # validate data type: List[int] try: @@ -93,7 +94,7 @@ class AnyOfColor(BaseModel): @classmethod def from_json(cls, json_str: str) -> AnyOfColor: """Returns the object represented by the json string""" - instance = AnyOfColor.construct() + instance = AnyOfColor.model_construct() error_messages = [] # deserialize data into List[int] try: @@ -153,6 +154,6 @@ class AnyOfColor(BaseModel): def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_pig.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_pig.py index 174c3af2554..00369b878bd 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_pig.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_pig.py @@ -19,7 +19,7 @@ import pprint import re # noqa: F401 from typing import Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict @@ -43,8 +43,9 @@ class AnyOfPig(BaseModel): actual_instance: Any = None any_of_schemas: List[str] = Literal[ANYOFPIG_ANY_OF_SCHEMAS] - class Config: - validate_assignment = True + model_config = { + "validate_assignment": True + } def __init__(self, *args, **kwargs) -> None: if args: @@ -56,9 +57,9 @@ class AnyOfPig(BaseModel): else: super().__init__(**kwargs) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): - instance = AnyOfPig.construct() + instance = AnyOfPig.model_construct() error_messages = [] # validate data type: BasquePig if not isinstance(v, BasquePig): @@ -85,7 +86,7 @@ class AnyOfPig(BaseModel): @classmethod def from_json(cls, json_str: str) -> AnyOfPig: """Returns the object represented by the json string""" - instance = AnyOfPig.construct() + instance = AnyOfPig.model_construct() error_messages = [] # anyof_schema_1_validator: Optional[BasquePig] = None try: @@ -130,6 +131,6 @@ class AnyOfPig(BaseModel): def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/api_response.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/api_response.py index cd441f02a12..875a41e2aed 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/api_response.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/api_response.py @@ -30,14 +30,15 @@ class ApiResponse(BaseModel): message: Optional[StrictStr] = None __properties = ["code", "type", "message"] - 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 ApiResponse(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 ApiResponse(BaseModel): return None if not isinstance(obj, dict): - return ApiResponse.parse_obj(obj) + return ApiResponse.model_validate(obj) - _obj = ApiResponse.parse_obj({ + _obj = ApiResponse.model_validate({ "code": obj.get("code"), "type": obj.get("type"), "message": obj.get("message") diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_model.py index c2fe6a0f0a4..d798ac121c2 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_model.py @@ -29,14 +29,15 @@ class ArrayOfArrayOfModel(BaseModel): another_property: Optional[List[List[Tag]]] = None __properties = ["another_property"] - 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 ArrayOfArrayOfModel(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) @@ -72,9 +73,9 @@ class ArrayOfArrayOfModel(BaseModel): return None if not isinstance(obj, dict): - return ArrayOfArrayOfModel.parse_obj(obj) + return ArrayOfArrayOfModel.model_validate(obj) - _obj = ArrayOfArrayOfModel.parse_obj({ + _obj = ArrayOfArrayOfModel.model_validate({ "another_property": [ [Tag.from_dict(_inner_item) for _inner_item in _item] for _item in obj.get("another_property") diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_number_only.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_number_only.py index 61e443b2b9c..7b25d1d101a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_number_only.py @@ -29,14 +29,15 @@ class ArrayOfArrayOfNumberOnly(BaseModel): array_array_number: Optional[List[List[float]]] = Field(default=None, alias="ArrayArrayNumber") __properties = ["ArrayArrayNumber"] - 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 ArrayOfArrayOfNumberOnly(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 ArrayOfArrayOfNumberOnly(BaseModel): return None if not isinstance(obj, dict): - return ArrayOfArrayOfNumberOnly.parse_obj(obj) + return ArrayOfArrayOfNumberOnly.model_validate(obj) - _obj = ArrayOfArrayOfNumberOnly.parse_obj({ + _obj = ArrayOfArrayOfNumberOnly.model_validate({ "ArrayArrayNumber": obj.get("ArrayArrayNumber") }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_number_only.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_number_only.py index 4a77818138e..d4ba3bd6da1 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_number_only.py @@ -29,14 +29,15 @@ class ArrayOfNumberOnly(BaseModel): array_number: Optional[List[float]] = Field(default=None, alias="ArrayNumber") __properties = ["ArrayNumber"] - 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 ArrayOfNumberOnly(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 ArrayOfNumberOnly(BaseModel): return None if not isinstance(obj, dict): - return ArrayOfNumberOnly.parse_obj(obj) + return ArrayOfNumberOnly.model_validate(obj) - _obj = ArrayOfNumberOnly.parse_obj({ + _obj = ArrayOfNumberOnly.model_validate({ "ArrayNumber": obj.get("ArrayNumber") }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_test.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_test.py index b1d86e8ab5c..c195a37415f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_test.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_test.py @@ -28,19 +28,20 @@ class ArrayTest(BaseModel): """ ArrayTest """ - array_of_string: Optional[Annotated[List[StrictStr], Field(min_items=0, max_items=3)]] = None + array_of_string: Optional[Annotated[List[StrictStr], Field(min_length=0, max_length=3)]] = None array_array_of_integer: Optional[List[List[StrictInt]]] = None array_array_of_model: Optional[List[List[ReadOnlyFirst]]] = None __properties = ["array_of_string", "array_array_of_integer", "array_array_of_model"] - 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 ArrayTest(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) @@ -76,9 +77,9 @@ class ArrayTest(BaseModel): return None if not isinstance(obj, dict): - return ArrayTest.parse_obj(obj) + return ArrayTest.model_validate(obj) - _obj = ArrayTest.parse_obj({ + _obj = ArrayTest.model_validate({ "array_of_string": obj.get("array_of_string"), "array_array_of_integer": obj.get("array_array_of_integer"), "array_array_of_model": [ diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/basque_pig.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/basque_pig.py index 5e644b98daf..698016f3faa 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/basque_pig.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/basque_pig.py @@ -30,14 +30,15 @@ class BasquePig(BaseModel): color: StrictStr __properties = ["className", "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 BasquePig(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 BasquePig(BaseModel): return None if not isinstance(obj, dict): - return BasquePig.parse_obj(obj) + return BasquePig.model_validate(obj) - _obj = BasquePig.parse_obj({ + _obj = BasquePig.model_validate({ "className": obj.get("className"), "color": obj.get("color") }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/capitalization.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/capitalization.py index b09b8886bad..dcd0d77e7e1 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/capitalization.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/capitalization.py @@ -34,14 +34,15 @@ class Capitalization(BaseModel): att_name: Optional[StrictStr] = Field(default=None, description="Name of the pet ", alias="ATT_NAME") __properties = ["smallCamel", "CapitalCamel", "small_Snake", "Capital_Snake", "SCA_ETH_Flow_Points", "ATT_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""" @@ -55,7 +56,7 @@ class Capitalization(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) @@ -68,9 +69,9 @@ class Capitalization(BaseModel): return None if not isinstance(obj, dict): - return Capitalization.parse_obj(obj) + return Capitalization.model_validate(obj) - _obj = Capitalization.parse_obj({ + _obj = Capitalization.model_validate({ "smallCamel": obj.get("smallCamel"), "CapitalCamel": obj.get("CapitalCamel"), "small_Snake": obj.get("small_Snake"), diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/cat.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/cat.py index 31c055907f9..c716c253a47 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/cat.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/cat.py @@ -29,14 +29,15 @@ class Cat(Animal): declawed: Optional[StrictBool] = None __properties = ["className", "color", "declawed"] - 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 Cat(Animal): 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 Cat(Animal): return None if not isinstance(obj, dict): - return Cat.parse_obj(obj) + return Cat.model_validate(obj) - _obj = Cat.parse_obj({ + _obj = Cat.model_validate({ "className": obj.get("className"), "color": obj.get("color") if obj.get("color") is not None else 'red', "declawed": obj.get("declawed") diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/category.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/category.py index 2d1a5acc762..861e6e9ee07 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/category.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/category.py @@ -29,14 +29,15 @@ class Category(BaseModel): name: StrictStr __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""" @@ -50,7 +51,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) @@ -63,9 +64,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") if obj.get("name") is not None else 'default-name' }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_reference_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_reference_model.py index 806f03b7698..920a3e8135e 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_reference_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_reference_model.py @@ -29,14 +29,15 @@ class CircularReferenceModel(BaseModel): nested: Optional[FirstRef] = None __properties = ["size", "nested"] - 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 CircularReferenceModel(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 CircularReferenceModel(BaseModel): return None if not isinstance(obj, dict): - return CircularReferenceModel.parse_obj(obj) + return CircularReferenceModel.model_validate(obj) - _obj = CircularReferenceModel.parse_obj({ + _obj = CircularReferenceModel.model_validate({ "size": obj.get("size"), "nested": FirstRef.from_dict(obj.get("nested")) if obj.get("nested") is not None else None }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/class_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/class_model.py index a6ef8617c7c..c340fd7de00 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/class_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/class_model.py @@ -29,14 +29,15 @@ class ClassModel(BaseModel): var_class: Optional[StrictStr] = Field(default=None, alias="_class") __properties = ["_class"] - 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 ClassModel(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 ClassModel(BaseModel): return None if not isinstance(obj, dict): - return ClassModel.parse_obj(obj) + return ClassModel.model_validate(obj) - _obj = ClassModel.parse_obj({ + _obj = ClassModel.model_validate({ "_class": obj.get("_class") }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/client.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/client.py index 669f070d32f..1f03d4ffb57 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/client.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/client.py @@ -28,14 +28,15 @@ class Client(BaseModel): client: Optional[StrictStr] = None __properties = ["client"] - 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""" @@ -49,7 +50,7 @@ class Client(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) @@ -62,9 +63,9 @@ class Client(BaseModel): return None if not isinstance(obj, dict): - return Client.parse_obj(obj) + return Client.model_validate(obj) - _obj = Client.parse_obj({ + _obj = Client.model_validate({ "client": obj.get("client") }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py index d6b2ab8d8d7..2fdc7e8805c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py @@ -19,7 +19,7 @@ import pprint import re # noqa: F401 from typing import Any, List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from pydantic import Field from typing_extensions import Annotated from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict @@ -33,16 +33,18 @@ class Color(BaseModel): RGB array, RGBA array, or hex string. """ # data type: List[int] - oneof_schema_1_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_items=3, max_items=3)]] = Field(default=None, description="RGB three element array with values 0-255.") + oneof_schema_1_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_length=3, max_length=3)]] = Field(default=None, description="RGB three element array with values 0-255.") # data type: List[int] - oneof_schema_2_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_items=4, max_items=4)]] = Field(default=None, description="RGBA four element array with values 0-255.") + oneof_schema_2_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_length=4, max_length=4)]] = Field(default=None, description="RGBA four element array with values 0-255.") # data type: str oneof_schema_3_validator: Optional[Annotated[str, Field(min_length=7, strict=True, max_length=7)]] = Field(default=None, description="Hex color string, such as #00FF00.") actual_instance: Optional[Union[List[int], str]] = None - one_of_schemas: List[str] = Literal[COLOR_ONE_OF_SCHEMAS] + one_of_schemas: List[str] = Literal["List[int]", "str"] + + model_config = { + "validate_assignment": True + } - class Config: - validate_assignment = True def __init__(self, *args, **kwargs) -> None: if args: @@ -54,12 +56,12 @@ class Color(BaseModel): else: super().__init__(**kwargs) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): if v is None: return v - instance = Color.construct() + instance = Color.model_construct() error_messages = [] match = 0 # validate data type: List[int] @@ -96,7 +98,7 @@ class Color(BaseModel): @classmethod def from_json(cls, json_str: str) -> Color: """Returns the object represented by the json string""" - instance = Color.construct() + instance = Color.model_construct() if json_str is None: return instance @@ -165,6 +167,6 @@ class Color(BaseModel): def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature.py index ebeb3a8d489..269294aa24e 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature.py @@ -30,14 +30,15 @@ class Creature(BaseModel): type: StrictStr __properties = ["info", "type"] - 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 Creature(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) @@ -67,9 +68,9 @@ class Creature(BaseModel): return None if not isinstance(obj, dict): - return Creature.parse_obj(obj) + return Creature.model_validate(obj) - _obj = Creature.parse_obj({ + _obj = Creature.model_validate({ "info": CreatureInfo.from_dict(obj.get("info")) if obj.get("info") is not None else None, "type": obj.get("type") }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature_info.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature_info.py index e3430a519ba..fabe153f31b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature_info.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature_info.py @@ -28,14 +28,15 @@ class CreatureInfo(BaseModel): name: StrictStr __properties = ["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""" @@ -49,7 +50,7 @@ class CreatureInfo(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) @@ -62,9 +63,9 @@ class CreatureInfo(BaseModel): return None if not isinstance(obj, dict): - return CreatureInfo.parse_obj(obj) + return CreatureInfo.model_validate(obj) - _obj = CreatureInfo.parse_obj({ + _obj = CreatureInfo.model_validate({ "name": obj.get("name") }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/danish_pig.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/danish_pig.py index b481fb48b81..f1bb9dc5218 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/danish_pig.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/danish_pig.py @@ -30,14 +30,15 @@ class DanishPig(BaseModel): size: StrictInt __properties = ["className", "size"] - 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 DanishPig(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 DanishPig(BaseModel): return None if not isinstance(obj, dict): - return DanishPig.parse_obj(obj) + return DanishPig.model_validate(obj) - _obj = DanishPig.parse_obj({ + _obj = DanishPig.model_validate({ "className": obj.get("className"), "size": obj.get("size") }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/deprecated_object.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/deprecated_object.py index 0817078bb4a..d7689114dc0 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/deprecated_object.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/deprecated_object.py @@ -28,14 +28,15 @@ class DeprecatedObject(BaseModel): name: Optional[StrictStr] = None __properties = ["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""" @@ -49,7 +50,7 @@ class DeprecatedObject(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) @@ -62,9 +63,9 @@ class DeprecatedObject(BaseModel): return None if not isinstance(obj, dict): - return DeprecatedObject.parse_obj(obj) + return DeprecatedObject.model_validate(obj) - _obj = DeprecatedObject.parse_obj({ + _obj = DeprecatedObject.model_validate({ "name": obj.get("name") }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dog.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dog.py index 904f1f69eab..ca35796fb14 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dog.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dog.py @@ -29,14 +29,15 @@ class Dog(Animal): breed: Optional[StrictStr] = None __properties = ["className", "color", "breed"] - 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 Dog(Animal): 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 Dog(Animal): return None if not isinstance(obj, dict): - return Dog.parse_obj(obj) + return Dog.model_validate(obj) - _obj = Dog.parse_obj({ + _obj = Dog.model_validate({ "className": obj.get("className"), "color": obj.get("color") if obj.get("color") is not None else 'red', "breed": obj.get("breed") diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dummy_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dummy_model.py index a1340d266bc..65765b6922d 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dummy_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dummy_model.py @@ -29,14 +29,15 @@ class DummyModel(BaseModel): self_ref: Optional[SelfReferenceModel] = None __properties = ["category", "self_ref"] - 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 DummyModel(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 DummyModel(BaseModel): return None if not isinstance(obj, dict): - return DummyModel.parse_obj(obj) + return DummyModel.model_validate(obj) - _obj = DummyModel.parse_obj({ + _obj = DummyModel.model_validate({ "category": obj.get("category"), "self_ref": SelfReferenceModel.from_dict(obj.get("self_ref")) if obj.get("self_ref") is not None else None }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_arrays.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_arrays.py index d8d163362df..161fe46cc11 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_arrays.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_arrays.py @@ -19,7 +19,7 @@ import json from typing import List, Optional -from pydantic import BaseModel, StrictStr, validator +from pydantic import BaseModel, StrictStr, field_validator class EnumArrays(BaseModel): """ @@ -29,7 +29,7 @@ class EnumArrays(BaseModel): array_enum: Optional[List[StrictStr]] = None __properties = ["just_symbol", "array_enum"] - @validator('just_symbol') + @field_validator('just_symbol') def just_symbol_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -39,7 +39,7 @@ class EnumArrays(BaseModel): raise ValueError("must be one of enum values ('>=', '$')") return value - @validator('array_enum') + @field_validator('array_enum') def array_enum_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -50,14 +50,15 @@ class EnumArrays(BaseModel): raise ValueError("each list item must be one of ('fish', 'crab')") 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""" @@ -71,7 +72,7 @@ class EnumArrays(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) @@ -84,9 +85,9 @@ class EnumArrays(BaseModel): return None if not isinstance(obj, dict): - return EnumArrays.parse_obj(obj) + return EnumArrays.model_validate(obj) - _obj = EnumArrays.parse_obj({ + _obj = EnumArrays.model_validate({ "just_symbol": obj.get("just_symbol"), "array_enum": obj.get("array_enum") }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py index 1fe38fd8773..347a39e802a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py @@ -19,7 +19,7 @@ import json from typing import Optional -from pydantic import BaseModel, StrictInt, StrictStr, validator +from pydantic import BaseModel, StrictInt, StrictStr, field_validator from pydantic import Field from petstore_api.models.outer_enum import OuterEnum from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue @@ -41,7 +41,7 @@ class EnumTest(BaseModel): outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(default=None, alias="outerEnumIntegerDefaultValue") __properties = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] - @validator('enum_string') + @field_validator('enum_string') def enum_string_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -51,14 +51,14 @@ class EnumTest(BaseModel): raise ValueError("must be one of enum values ('UPPER', 'lower', '')") return value - @validator('enum_string_required') + @field_validator('enum_string_required') def enum_string_required_validate_enum(cls, value): """Validates the enum""" if value not in ('UPPER', 'lower', ''): raise ValueError("must be one of enum values ('UPPER', 'lower', '')") return value - @validator('enum_integer_default') + @field_validator('enum_integer_default') def enum_integer_default_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -68,7 +68,7 @@ class EnumTest(BaseModel): raise ValueError("must be one of enum values (1, 5, 14)") return value - @validator('enum_integer') + @field_validator('enum_integer') def enum_integer_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -78,7 +78,7 @@ class EnumTest(BaseModel): raise ValueError("must be one of enum values (1, -1)") return value - @validator('enum_number') + @field_validator('enum_number') def enum_number_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -88,14 +88,15 @@ class EnumTest(BaseModel): raise ValueError("must be one of enum values (1.1, -1.2)") 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""" @@ -109,13 +110,13 @@ class EnumTest(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 outer_enum (nullable) is None - # and __fields_set__ contains the field - if self.outer_enum is None and "outer_enum" in self.__fields_set__: + # and model_fields_set contains the field + if self.outer_enum is None and "outer_enum" in self.model_fields_set: _dict['outerEnum'] = None return _dict @@ -127,9 +128,9 @@ class EnumTest(BaseModel): return None if not isinstance(obj, dict): - return EnumTest.parse_obj(obj) + return EnumTest.model_validate(obj) - _obj = EnumTest.parse_obj({ + _obj = EnumTest.model_validate({ "enum_string": obj.get("enum_string"), "enum_string_required": obj.get("enum_string_required"), "enum_integer_default": obj.get("enum_integer_default") if obj.get("enum_integer_default") is not None else 5, diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file.py index 4bd46a8359c..4db5067c90b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file.py @@ -29,14 +29,15 @@ class File(BaseModel): source_uri: Optional[StrictStr] = Field(default=None, description="Test capitalization", alias="sourceURI") __properties = ["sourceURI"] - 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 File(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 File(BaseModel): return None if not isinstance(obj, dict): - return File.parse_obj(obj) + return File.model_validate(obj) - _obj = File.parse_obj({ + _obj = File.model_validate({ "sourceURI": obj.get("sourceURI") }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file_schema_test_class.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file_schema_test_class.py index ea8a6dbc550..cacb59dc918 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file_schema_test_class.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file_schema_test_class.py @@ -30,14 +30,15 @@ class FileSchemaTestClass(BaseModel): files: Optional[List[File]] = None __properties = ["file", "files"] - 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 FileSchemaTestClass(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) @@ -74,9 +75,9 @@ class FileSchemaTestClass(BaseModel): return None if not isinstance(obj, dict): - return FileSchemaTestClass.parse_obj(obj) + return FileSchemaTestClass.model_validate(obj) - _obj = FileSchemaTestClass.parse_obj({ + _obj = FileSchemaTestClass.model_validate({ "file": File.from_dict(obj.get("file")) if obj.get("file") is not None else None, "files": [File.from_dict(_item) for _item in obj.get("files")] if obj.get("files") is not None else None }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/first_ref.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/first_ref.py index 4807f0acec7..78dcfa435b3 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/first_ref.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/first_ref.py @@ -29,14 +29,15 @@ class FirstRef(BaseModel): self_ref: Optional[SecondRef] = None __properties = ["category", "self_ref"] - 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 FirstRef(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 FirstRef(BaseModel): return None if not isinstance(obj, dict): - return FirstRef.parse_obj(obj) + return FirstRef.model_validate(obj) - _obj = FirstRef.parse_obj({ + _obj = FirstRef.model_validate({ "category": obj.get("category"), "self_ref": SecondRef.from_dict(obj.get("self_ref")) if obj.get("self_ref") is not None else None }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo.py index 61d26e02f53..b26e388a28a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo.py @@ -28,14 +28,15 @@ class Foo(BaseModel): bar: Optional[StrictStr] = 'bar' __properties = ["bar"] - 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""" @@ -49,7 +50,7 @@ class Foo(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) @@ -62,9 +63,9 @@ class Foo(BaseModel): return None if not isinstance(obj, dict): - return Foo.parse_obj(obj) + return Foo.model_validate(obj) - _obj = Foo.parse_obj({ + _obj = Foo.model_validate({ "bar": obj.get("bar") if obj.get("bar") is not None else 'bar' }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo_get_default_response.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo_get_default_response.py index 2b4697c9e9a..8aa1c763e88 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo_get_default_response.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo_get_default_response.py @@ -29,14 +29,15 @@ class FooGetDefaultResponse(BaseModel): string: Optional[Foo] = None __properties = ["string"] - 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 FooGetDefaultResponse(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 FooGetDefaultResponse(BaseModel): return None if not isinstance(obj, dict): - return FooGetDefaultResponse.parse_obj(obj) + return FooGetDefaultResponse.model_validate(obj) - _obj = FooGetDefaultResponse.parse_obj({ + _obj = FooGetDefaultResponse.model_validate({ "string": Foo.from_dict(obj.get("string")) if obj.get("string") is not None else None }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/format_test.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/format_test.py index f2efd815cdf..69980df9fab 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/format_test.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/format_test.py @@ -19,7 +19,7 @@ import json from datetime import date, datetime from typing import Optional, Union -from pydantic import BaseModel, StrictBytes, StrictInt, StrictStr, validator +from pydantic import BaseModel, StrictBytes, StrictInt, StrictStr, field_validator from decimal import Decimal from pydantic import Field from typing_extensions import Annotated @@ -46,7 +46,7 @@ class FormatTest(BaseModel): pattern_with_digits_and_delimiter: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01.") __properties = ["integer", "int32", "int64", "number", "double", "decimal", "string", "string_with_double_quote_pattern", "byte", "binary", "date", "dateTime", "uuid", "password", "pattern_with_digits", "pattern_with_digits_and_delimiter"] - @validator('string') + @field_validator('string') def string_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -56,7 +56,7 @@ class FormatTest(BaseModel): raise ValueError(r"must validate the regular expression /[a-z]/i") return value - @validator('string_with_double_quote_pattern') + @field_validator('string_with_double_quote_pattern') def string_with_double_quote_pattern_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -66,7 +66,7 @@ class FormatTest(BaseModel): raise ValueError(r"must validate the regular expression /this is \"something\"/") return value - @validator('pattern_with_digits') + @field_validator('pattern_with_digits') def pattern_with_digits_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -76,7 +76,7 @@ class FormatTest(BaseModel): raise ValueError(r"must validate the regular expression /^\d{10}$/") return value - @validator('pattern_with_digits_and_delimiter') + @field_validator('pattern_with_digits_and_delimiter') def pattern_with_digits_and_delimiter_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -86,14 +86,15 @@ class FormatTest(BaseModel): raise ValueError(r"must validate the regular expression /^image_\d{1,3}$/i") 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""" @@ -107,7 +108,7 @@ class FormatTest(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) @@ -120,9 +121,9 @@ class FormatTest(BaseModel): return None if not isinstance(obj, dict): - return FormatTest.parse_obj(obj) + return FormatTest.model_validate(obj) - _obj = FormatTest.parse_obj({ + _obj = FormatTest.model_validate({ "integer": obj.get("integer"), "int32": obj.get("int32"), "int64": obj.get("int64"), diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/has_only_read_only.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/has_only_read_only.py index bde5806252f..bdb291e1f6a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/has_only_read_only.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/has_only_read_only.py @@ -29,14 +29,15 @@ class HasOnlyReadOnly(BaseModel): foo: Optional[StrictStr] = None __properties = ["bar", "foo"] - 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 HasOnlyReadOnly(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={ "bar", "foo", @@ -65,9 +66,9 @@ class HasOnlyReadOnly(BaseModel): return None if not isinstance(obj, dict): - return HasOnlyReadOnly.parse_obj(obj) + return HasOnlyReadOnly.model_validate(obj) - _obj = HasOnlyReadOnly.parse_obj({ + _obj = HasOnlyReadOnly.model_validate({ "bar": obj.get("bar"), "foo": obj.get("foo") }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/health_check_result.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/health_check_result.py index e8e0efdc8ee..7328147fd7a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/health_check_result.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/health_check_result.py @@ -29,14 +29,15 @@ class HealthCheckResult(BaseModel): nullable_message: Optional[StrictStr] = Field(default=None, alias="NullableMessage") __properties = ["NullableMessage"] - 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,13 +51,13 @@ class HealthCheckResult(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 nullable_message (nullable) is None - # and __fields_set__ contains the field - if self.nullable_message is None and "nullable_message" in self.__fields_set__: + # and model_fields_set contains the field + if self.nullable_message is None and "nullable_message" in self.model_fields_set: _dict['NullableMessage'] = None return _dict @@ -68,9 +69,9 @@ class HealthCheckResult(BaseModel): return None if not isinstance(obj, dict): - return HealthCheckResult.parse_obj(obj) + return HealthCheckResult.model_validate(obj) - _obj = HealthCheckResult.parse_obj({ + _obj = HealthCheckResult.model_validate({ "NullableMessage": obj.get("NullableMessage") }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/inner_dict_with_property.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/inner_dict_with_property.py index 97ee832e051..fabd6b43f09 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/inner_dict_with_property.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/inner_dict_with_property.py @@ -29,14 +29,15 @@ class InnerDictWithProperty(BaseModel): a_property: Optional[Union[str, Any]] = Field(default=None, alias="aProperty") __properties = ["aProperty"] - 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 InnerDictWithProperty(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 InnerDictWithProperty(BaseModel): return None if not isinstance(obj, dict): - return InnerDictWithProperty.parse_obj(obj) + return InnerDictWithProperty.model_validate(obj) - _obj = InnerDictWithProperty.parse_obj({ + _obj = InnerDictWithProperty.model_validate({ "aProperty": obj.get("aProperty") }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/int_or_string.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/int_or_string.py index a292b747c56..0fb43ecaebb 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/int_or_string.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/int_or_string.py @@ -19,7 +19,7 @@ import pprint import re # noqa: F401 from typing import Any, List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from pydantic import Field from typing_extensions import Annotated from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict @@ -37,10 +37,12 @@ class IntOrString(BaseModel): # data type: str oneof_schema_2_validator: Optional[StrictStr] = None actual_instance: Optional[Union[int, str]] = None - one_of_schemas: List[str] = Literal[INTORSTRING_ONE_OF_SCHEMAS] + one_of_schemas: List[str] = Literal["int", "str"] + + model_config = { + "validate_assignment": True + } - class Config: - validate_assignment = True def __init__(self, *args, **kwargs) -> None: if args: @@ -52,9 +54,9 @@ class IntOrString(BaseModel): else: super().__init__(**kwargs) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): - instance = IntOrString.construct() + instance = IntOrString.model_construct() error_messages = [] match = 0 # validate data type: int @@ -85,7 +87,7 @@ class IntOrString(BaseModel): @classmethod def from_json(cls, json_str: str) -> IntOrString: """Returns the object represented by the json string""" - instance = IntOrString.construct() + instance = IntOrString.model_construct() error_messages = [] match = 0 @@ -142,6 +144,6 @@ class IntOrString(BaseModel): def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/list.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/list.py index d6f8d8f8835..be0719de484 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/list.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/list.py @@ -29,14 +29,15 @@ class List(BaseModel): var_123_list: Optional[StrictStr] = Field(default=None, alias="123-list") __properties = ["123-list"] - 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 List(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 List(BaseModel): return None if not isinstance(obj, dict): - return List.parse_obj(obj) + return List.model_validate(obj) - _obj = List.parse_obj({ + _obj = List.model_validate({ "123-list": obj.get("123-list") }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py index 2f31f5170b9..df4f9d9c4d7 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py @@ -30,14 +30,15 @@ class MapOfArrayOfModel(BaseModel): shop_id_to_org_online_lip_map: Optional[Dict[str, List[Tag]]] = Field(default=None, alias="shopIdToOrgOnlineLipMap") __properties = ["shopIdToOrgOnlineLipMap"] - 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 MapOfArrayOfModel(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) @@ -73,9 +74,9 @@ class MapOfArrayOfModel(BaseModel): return None if not isinstance(obj, dict): - return MapOfArrayOfModel.parse_obj(obj) + return MapOfArrayOfModel.model_validate(obj) - _obj = MapOfArrayOfModel.parse_obj({ + _obj = MapOfArrayOfModel.model_validate({ "shopIdToOrgOnlineLipMap": dict( (_k, [Tag.from_dict(_item) for _item in _v] diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_test.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_test.py index 7e5de1928be..4745dbbfe80 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_test.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_test.py @@ -19,7 +19,7 @@ import json from typing import Dict, Optional -from pydantic import BaseModel, StrictBool, StrictStr, validator +from pydantic import BaseModel, StrictBool, StrictStr, field_validator class MapTest(BaseModel): """ @@ -31,7 +31,7 @@ class MapTest(BaseModel): indirect_map: Optional[Dict[str, StrictBool]] = None __properties = ["map_map_of_string", "map_of_enum_string", "direct_map", "indirect_map"] - @validator('map_of_enum_string') + @field_validator('map_of_enum_string') def map_of_enum_string_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -41,14 +41,15 @@ class MapTest(BaseModel): raise ValueError("must be one of enum values ('UPPER', 'lower')") 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""" @@ -62,7 +63,7 @@ class MapTest(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) @@ -75,9 +76,9 @@ class MapTest(BaseModel): return None if not isinstance(obj, dict): - return MapTest.parse_obj(obj) + return MapTest.model_validate(obj) - _obj = MapTest.parse_obj({ + _obj = MapTest.model_validate({ "map_map_of_string": obj.get("map_map_of_string"), "map_of_enum_string": obj.get("map_of_enum_string"), "direct_map": obj.get("direct_map"), diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py index 9e6ac0ee249..0a637426955 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -32,14 +32,15 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): map: Optional[Dict[str, Animal]] = None __properties = ["uuid", "dateTime", "map"] - 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 MixedPropertiesAndAdditionalPropertiesClass(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) @@ -73,9 +74,9 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): return None if not isinstance(obj, dict): - return MixedPropertiesAndAdditionalPropertiesClass.parse_obj(obj) + return MixedPropertiesAndAdditionalPropertiesClass.model_validate(obj) - _obj = MixedPropertiesAndAdditionalPropertiesClass.parse_obj({ + _obj = MixedPropertiesAndAdditionalPropertiesClass.model_validate({ "uuid": obj.get("uuid"), "dateTime": obj.get("dateTime"), "map": dict( diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model200_response.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model200_response.py index ded7bc23eef..fc1d271ca45 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model200_response.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model200_response.py @@ -30,14 +30,15 @@ class Model200Response(BaseModel): var_class: Optional[StrictStr] = Field(default=None, alias="class") __properties = ["name", "class"] - 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 Model200Response(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 Model200Response(BaseModel): return None if not isinstance(obj, dict): - return Model200Response.parse_obj(obj) + return Model200Response.model_validate(obj) - _obj = Model200Response.parse_obj({ + _obj = Model200Response.model_validate({ "name": obj.get("name"), "class": obj.get("class") }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_return.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_return.py index 47640cb6822..33c2edf0d81 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_return.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_return.py @@ -29,14 +29,15 @@ class ModelReturn(BaseModel): var_return: Optional[StrictInt] = Field(default=None, alias="return") __properties = ["return"] - 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 ModelReturn(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 ModelReturn(BaseModel): return None if not isinstance(obj, dict): - return ModelReturn.parse_obj(obj) + return ModelReturn.model_validate(obj) - _obj = ModelReturn.parse_obj({ + _obj = ModelReturn.model_validate({ "return": obj.get("return") }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/name.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/name.py index 863af2756db..31caeb08202 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/name.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/name.py @@ -32,14 +32,15 @@ class Name(BaseModel): var_123_number: Optional[StrictInt] = Field(default=None, alias="123Number") __properties = ["name", "snake_case", "property", "123Number"] - 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 Name(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={ "snake_case", "var_123_number", @@ -68,9 +69,9 @@ class Name(BaseModel): return None if not isinstance(obj, dict): - return Name.parse_obj(obj) + return Name.model_validate(obj) - _obj = Name.parse_obj({ + _obj = Name.model_validate({ "name": obj.get("name"), "snake_case": obj.get("snake_case"), "property": obj.get("property"), diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_class.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_class.py index f4317671731..df5f2998f01 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_class.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_class.py @@ -41,14 +41,15 @@ class NullableClass(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["required_integer_prop", "integer_prop", "number_prop", "boolean_prop", "string_prop", "date_prop", "datetime_prop", "array_nullable_prop", "array_and_items_nullable_prop", "array_items_nullable", "object_nullable_prop", "object_and_items_nullable_prop", "object_items_nullable"] - 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""" @@ -62,7 +63,7 @@ class NullableClass(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={ "additional_properties" }, @@ -73,58 +74,58 @@ class NullableClass(BaseModel): _dict[_key] = _value # set to None if required_integer_prop (nullable) is None - # and __fields_set__ contains the field - if self.required_integer_prop is None and "required_integer_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.required_integer_prop is None and "required_integer_prop" in self.model_fields_set: _dict['required_integer_prop'] = None # set to None if integer_prop (nullable) is None - # and __fields_set__ contains the field - if self.integer_prop is None and "integer_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.integer_prop is None and "integer_prop" in self.model_fields_set: _dict['integer_prop'] = None # set to None if number_prop (nullable) is None - # and __fields_set__ contains the field - if self.number_prop is None and "number_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.number_prop is None and "number_prop" in self.model_fields_set: _dict['number_prop'] = None # set to None if boolean_prop (nullable) is None - # and __fields_set__ contains the field - if self.boolean_prop is None and "boolean_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.boolean_prop is None and "boolean_prop" in self.model_fields_set: _dict['boolean_prop'] = None # set to None if string_prop (nullable) is None - # and __fields_set__ contains the field - if self.string_prop is None and "string_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.string_prop is None and "string_prop" in self.model_fields_set: _dict['string_prop'] = None # set to None if date_prop (nullable) is None - # and __fields_set__ contains the field - if self.date_prop is None and "date_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.date_prop is None and "date_prop" in self.model_fields_set: _dict['date_prop'] = None # set to None if datetime_prop (nullable) is None - # and __fields_set__ contains the field - if self.datetime_prop is None and "datetime_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.datetime_prop is None and "datetime_prop" in self.model_fields_set: _dict['datetime_prop'] = None # set to None if array_nullable_prop (nullable) is None - # and __fields_set__ contains the field - if self.array_nullable_prop is None and "array_nullable_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.array_nullable_prop is None and "array_nullable_prop" in self.model_fields_set: _dict['array_nullable_prop'] = None # set to None if array_and_items_nullable_prop (nullable) is None - # and __fields_set__ contains the field - if self.array_and_items_nullable_prop is None and "array_and_items_nullable_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.array_and_items_nullable_prop is None and "array_and_items_nullable_prop" in self.model_fields_set: _dict['array_and_items_nullable_prop'] = None # set to None if object_nullable_prop (nullable) is None - # and __fields_set__ contains the field - if self.object_nullable_prop is None and "object_nullable_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.object_nullable_prop is None and "object_nullable_prop" in self.model_fields_set: _dict['object_nullable_prop'] = None # set to None if object_and_items_nullable_prop (nullable) is None - # and __fields_set__ contains the field - if self.object_and_items_nullable_prop is None and "object_and_items_nullable_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.object_and_items_nullable_prop is None and "object_and_items_nullable_prop" in self.model_fields_set: _dict['object_and_items_nullable_prop'] = None return _dict @@ -136,9 +137,9 @@ class NullableClass(BaseModel): return None if not isinstance(obj, dict): - return NullableClass.parse_obj(obj) + return NullableClass.model_validate(obj) - _obj = NullableClass.parse_obj({ + _obj = NullableClass.model_validate({ "required_integer_prop": obj.get("required_integer_prop"), "integer_prop": obj.get("integer_prop"), "number_prop": obj.get("number_prop"), diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_property.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_property.py index 5ef7bed3503..08b1946c58f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_property.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_property.py @@ -19,7 +19,7 @@ import json from typing import Optional -from pydantic import BaseModel, StrictInt, validator +from pydantic import BaseModel, StrictInt, field_validator from pydantic import Field from typing_extensions import Annotated @@ -31,7 +31,7 @@ class NullableProperty(BaseModel): name: Optional[Annotated[str, Field(strict=True)]] __properties = ["id", "name"] - @validator('name') + @field_validator('name') def name_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -41,14 +41,15 @@ class NullableProperty(BaseModel): raise ValueError(r"must validate the regular expression /^[A-Z].*/") 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""" @@ -62,13 +63,13 @@ class NullableProperty(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 name (nullable) is None - # and __fields_set__ contains the field - if self.name is None and "name" in self.__fields_set__: + # and model_fields_set contains the field + if self.name is None and "name" in self.model_fields_set: _dict['name'] = None return _dict @@ -80,9 +81,9 @@ class NullableProperty(BaseModel): return None if not isinstance(obj, dict): - return NullableProperty.parse_obj(obj) + return NullableProperty.model_validate(obj) - _obj = NullableProperty.parse_obj({ + _obj = NullableProperty.model_validate({ "id": obj.get("id"), "name": obj.get("name") }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/number_only.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/number_only.py index fb508750586..384ba5f7aa5 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/number_only.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/number_only.py @@ -29,14 +29,15 @@ class NumberOnly(BaseModel): just_number: Optional[float] = Field(default=None, alias="JustNumber") __properties = ["JustNumber"] - 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 NumberOnly(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 NumberOnly(BaseModel): return None if not isinstance(obj, dict): - return NumberOnly.parse_obj(obj) + return NumberOnly.model_validate(obj) - _obj = NumberOnly.parse_obj({ + _obj = NumberOnly.model_validate({ "JustNumber": obj.get("JustNumber") }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_to_test_additional_properties.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_to_test_additional_properties.py index 582a0193ab9..be3a1b2ce56 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_to_test_additional_properties.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_to_test_additional_properties.py @@ -29,14 +29,15 @@ class ObjectToTestAdditionalProperties(BaseModel): var_property: Optional[StrictBool] = Field(default=False, description="Property", alias="property") __properties = ["property"] - 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 ObjectToTestAdditionalProperties(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 ObjectToTestAdditionalProperties(BaseModel): return None if not isinstance(obj, dict): - return ObjectToTestAdditionalProperties.parse_obj(obj) + return ObjectToTestAdditionalProperties.model_validate(obj) - _obj = ObjectToTestAdditionalProperties.parse_obj({ + _obj = ObjectToTestAdditionalProperties.model_validate({ "property": obj.get("property") if obj.get("property") is not None else False }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_with_deprecated_fields.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_with_deprecated_fields.py index 7e2f6c5169e..805d4ce5396 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_with_deprecated_fields.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_with_deprecated_fields.py @@ -33,14 +33,15 @@ class ObjectWithDeprecatedFields(BaseModel): bars: Optional[List[StrictStr]] = None __properties = ["uuid", "id", "deprecatedRef", "bars"] - 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 ObjectWithDeprecatedFields(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) @@ -70,9 +71,9 @@ class ObjectWithDeprecatedFields(BaseModel): return None if not isinstance(obj, dict): - return ObjectWithDeprecatedFields.parse_obj(obj) + return ObjectWithDeprecatedFields.model_validate(obj) - _obj = ObjectWithDeprecatedFields.parse_obj({ + _obj = ObjectWithDeprecatedFields.model_validate({ "uuid": obj.get("uuid"), "id": obj.get("id"), "deprecatedRef": DeprecatedObject.from_dict(obj.get("deprecatedRef")) if obj.get("deprecatedRef") is not None else None, diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/one_of_enum_string.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/one_of_enum_string.py index dfc27aa8820..65067fe7620 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/one_of_enum_string.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/one_of_enum_string.py @@ -19,7 +19,7 @@ import pprint import re # noqa: F401 from typing import Any, List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from petstore_api.models.enum_string1 import EnumString1 from petstore_api.models.enum_string2 import EnumString2 from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict @@ -37,10 +37,12 @@ class OneOfEnumString(BaseModel): # data type: EnumString2 oneof_schema_2_validator: Optional[EnumString2] = None actual_instance: Optional[Union[EnumString1, EnumString2]] = None - one_of_schemas: List[str] = Literal[ONEOFENUMSTRING_ONE_OF_SCHEMAS] + one_of_schemas: List[str] = Literal["EnumString1", "EnumString2"] + + model_config = { + "validate_assignment": True + } - class Config: - validate_assignment = True def __init__(self, *args, **kwargs) -> None: if args: @@ -52,9 +54,9 @@ class OneOfEnumString(BaseModel): else: super().__init__(**kwargs) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): - instance = OneOfEnumString.construct() + instance = OneOfEnumString.model_construct() error_messages = [] match = 0 # validate data type: EnumString1 @@ -83,7 +85,7 @@ class OneOfEnumString(BaseModel): @classmethod def from_json(cls, json_str: str) -> OneOfEnumString: """Returns the object represented by the json string""" - instance = OneOfEnumString.construct() + instance = OneOfEnumString.model_construct() error_messages = [] match = 0 @@ -134,6 +136,6 @@ class OneOfEnumString(BaseModel): def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/order.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/order.py index aae37c06e58..d44585a9dde 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/order.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/order.py @@ -19,7 +19,7 @@ import json from datetime import datetime from typing import Optional -from pydantic import BaseModel, StrictBool, StrictInt, StrictStr, validator +from pydantic import BaseModel, StrictBool, StrictInt, StrictStr, field_validator from pydantic import Field class Order(BaseModel): @@ -34,7 +34,7 @@ class Order(BaseModel): complete: Optional[StrictBool] = False __properties = ["id", "petId", "quantity", "shipDate", "status", "complete"] - @validator('status') + @field_validator('status') def status_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -44,14 +44,15 @@ class Order(BaseModel): raise ValueError("must be one of enum values ('placed', 'approved', 'delivered')") 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""" @@ -65,7 +66,7 @@ class Order(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) @@ -78,9 +79,9 @@ class Order(BaseModel): return None if not isinstance(obj, dict): - return Order.parse_obj(obj) + return Order.model_validate(obj) - _obj = Order.parse_obj({ + _obj = Order.model_validate({ "id": obj.get("id"), "petId": obj.get("petId"), "quantity": obj.get("quantity"), diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_composite.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_composite.py index 75d106c4dbf..1f6f60549ea 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_composite.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_composite.py @@ -30,14 +30,15 @@ class OuterComposite(BaseModel): my_boolean: Optional[StrictBool] = None __properties = ["my_number", "my_string", "my_boolean"] - 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 OuterComposite(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 OuterComposite(BaseModel): return None if not isinstance(obj, dict): - return OuterComposite.parse_obj(obj) + return OuterComposite.model_validate(obj) - _obj = OuterComposite.parse_obj({ + _obj = OuterComposite.model_validate({ "my_number": obj.get("my_number"), "my_string": obj.get("my_string"), "my_boolean": obj.get("my_boolean") diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_object_with_enum_property.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_object_with_enum_property.py index 4baa10251ad..6ac81887102 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_object_with_enum_property.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_object_with_enum_property.py @@ -31,14 +31,15 @@ class OuterObjectWithEnumProperty(BaseModel): value: OuterEnumInteger __properties = ["str_value", "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""" @@ -52,13 +53,13 @@ class OuterObjectWithEnumProperty(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 str_value (nullable) is None - # and __fields_set__ contains the field - if self.str_value is None and "str_value" in self.__fields_set__: + # and model_fields_set contains the field + if self.str_value is None and "str_value" in self.model_fields_set: _dict['str_value'] = None return _dict @@ -70,9 +71,9 @@ class OuterObjectWithEnumProperty(BaseModel): return None if not isinstance(obj, dict): - return OuterObjectWithEnumProperty.parse_obj(obj) + return OuterObjectWithEnumProperty.model_validate(obj) - _obj = OuterObjectWithEnumProperty.parse_obj({ + _obj = OuterObjectWithEnumProperty.model_validate({ "str_value": obj.get("str_value"), "value": obj.get("value") }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent.py index b90b8cda3cb..d31cc7b86f3 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent.py @@ -30,14 +30,15 @@ class Parent(BaseModel): optional_dict: Optional[Dict[str, InnerDictWithProperty]] = Field(default=None, alias="optionalDict") __properties = ["optionalDict"] - 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 Parent(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) @@ -71,9 +72,9 @@ class Parent(BaseModel): return None if not isinstance(obj, dict): - return Parent.parse_obj(obj) + return Parent.model_validate(obj) - _obj = Parent.parse_obj({ + _obj = Parent.model_validate({ "optionalDict": dict( (_k, InnerDictWithProperty.from_dict(_v)) for _k, _v in obj.get("optionalDict").items() diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent_with_optional_dict.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent_with_optional_dict.py index 9d606221821..c834b3d5f74 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent_with_optional_dict.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent_with_optional_dict.py @@ -30,14 +30,15 @@ class ParentWithOptionalDict(BaseModel): optional_dict: Optional[Dict[str, InnerDictWithProperty]] = Field(default=None, alias="optionalDict") __properties = ["optionalDict"] - 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 ParentWithOptionalDict(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) @@ -71,9 +72,9 @@ class ParentWithOptionalDict(BaseModel): return None if not isinstance(obj, dict): - return ParentWithOptionalDict.parse_obj(obj) + return ParentWithOptionalDict.model_validate(obj) - _obj = ParentWithOptionalDict.parse_obj({ + _obj = ParentWithOptionalDict.model_validate({ "optionalDict": dict( (_k, InnerDictWithProperty.from_dict(_v)) for _k, _v in obj.get("optionalDict").items() diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pet.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pet.py index 8aff3b94e81..c76cc47797c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pet.py @@ -19,7 +19,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 typing_extensions import Annotated from petstore_api.models.category import Category @@ -32,12 +32,12 @@ class Pet(BaseModel): id: Optional[StrictInt] = None category: Optional[Category] = None name: StrictStr - photo_urls: Annotated[List[StrictStr], Field(min_items=0)] = Field(alias="photoUrls") + photo_urls: Annotated[List[StrictStr], Field(min_length=0)] = Field(alias="photoUrls") tags: Optional[List[Tag]] = None status: Optional[StrictStr] = Field(default=None, description="pet status in the store") __properties = ["id", "category", "name", "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"), "category": Category.from_dict(obj.get("category")) if obj.get("category") is not None else None, "name": obj.get("name"), diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pig.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pig.py index 3c72f9816b8..7af8f7ee8e3 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pig.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pig.py @@ -19,7 +19,7 @@ import pprint import re # noqa: F401 from typing import Any, List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict @@ -37,10 +37,12 @@ class Pig(BaseModel): # data type: DanishPig oneof_schema_2_validator: Optional[DanishPig] = None actual_instance: Optional[Union[BasquePig, DanishPig]] = None - one_of_schemas: List[str] = Literal[PIG_ONE_OF_SCHEMAS] + one_of_schemas: List[str] = Literal["BasquePig", "DanishPig"] + + model_config = { + "validate_assignment": True + } - class Config: - validate_assignment = True discriminator_value_class_map: Dict[str, str] = { } @@ -55,9 +57,9 @@ class Pig(BaseModel): else: super().__init__(**kwargs) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): - instance = Pig.construct() + instance = Pig.model_construct() error_messages = [] match = 0 # validate data type: BasquePig @@ -86,7 +88,7 @@ class Pig(BaseModel): @classmethod def from_json(cls, json_str: str) -> Pig: """Returns the object represented by the json string""" - instance = Pig.construct() + instance = Pig.model_construct() error_messages = [] match = 0 @@ -137,6 +139,6 @@ class Pig(BaseModel): def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_name_collision.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_name_collision.py index 063376fa537..af6d6cc1906 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_name_collision.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_name_collision.py @@ -31,14 +31,15 @@ class PropertyNameCollision(BaseModel): type_: Optional[StrictStr] = None __properties = ["_type", "type", "type_"] - 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""" @@ -52,7 +53,7 @@ class PropertyNameCollision(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) @@ -65,9 +66,9 @@ class PropertyNameCollision(BaseModel): return None if not isinstance(obj, dict): - return PropertyNameCollision.parse_obj(obj) + return PropertyNameCollision.model_validate(obj) - _obj = PropertyNameCollision.parse_obj({ + _obj = PropertyNameCollision.model_validate({ "_type": obj.get("_type"), "type": obj.get("type"), "type_": obj.get("type_") diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/read_only_first.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/read_only_first.py index 6c63efe2145..8a34b0acc32 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/read_only_first.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/read_only_first.py @@ -29,14 +29,15 @@ class ReadOnlyFirst(BaseModel): baz: Optional[StrictStr] = None __properties = ["bar", "baz"] - 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 ReadOnlyFirst(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={ "bar", }, @@ -64,9 +65,9 @@ class ReadOnlyFirst(BaseModel): return None if not isinstance(obj, dict): - return ReadOnlyFirst.parse_obj(obj) + return ReadOnlyFirst.model_validate(obj) - _obj = ReadOnlyFirst.parse_obj({ + _obj = ReadOnlyFirst.model_validate({ "bar": obj.get("bar"), "baz": obj.get("baz") }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_ref.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_ref.py index f4fb35ab231..5202c14fed9 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_ref.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_ref.py @@ -29,14 +29,15 @@ class SecondRef(BaseModel): circular_ref: Optional[CircularReferenceModel] = None __properties = ["category", "circular_ref"] - 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 SecondRef(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 SecondRef(BaseModel): return None if not isinstance(obj, dict): - return SecondRef.parse_obj(obj) + return SecondRef.model_validate(obj) - _obj = SecondRef.parse_obj({ + _obj = SecondRef.model_validate({ "category": obj.get("category"), "circular_ref": CircularReferenceModel.from_dict(obj.get("circular_ref")) if obj.get("circular_ref") is not None else None }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/self_reference_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/self_reference_model.py index bf9d13067ce..b6b521e4096 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/self_reference_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/self_reference_model.py @@ -29,14 +29,15 @@ class SelfReferenceModel(BaseModel): nested: Optional[DummyModel] = None __properties = ["size", "nested"] - 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 SelfReferenceModel(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 SelfReferenceModel(BaseModel): return None if not isinstance(obj, dict): - return SelfReferenceModel.parse_obj(obj) + return SelfReferenceModel.model_validate(obj) - _obj = SelfReferenceModel.parse_obj({ + _obj = SelfReferenceModel.model_validate({ "size": obj.get("size"), "nested": DummyModel.from_dict(obj.get("nested")) if obj.get("nested") is not None else None }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_model_name.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_model_name.py index 20040798b50..e9c82e37092 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_model_name.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_model_name.py @@ -29,14 +29,15 @@ class SpecialModelName(BaseModel): special_property_name: Optional[StrictInt] = Field(default=None, alias="$special[property.name]") __properties = ["$special[property.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""" @@ -50,7 +51,7 @@ class SpecialModelName(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 SpecialModelName(BaseModel): return None if not isinstance(obj, dict): - return SpecialModelName.parse_obj(obj) + return SpecialModelName.model_validate(obj) - _obj = SpecialModelName.parse_obj({ + _obj = SpecialModelName.model_validate({ "$special[property.name]": obj.get("$special[property.name]") }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_name.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_name.py index b5c7281a347..8cbf678f3c3 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_name.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_name.py @@ -19,7 +19,7 @@ import json from typing import Optional -from pydantic import BaseModel, StrictInt, StrictStr, validator +from pydantic import BaseModel, StrictInt, StrictStr, field_validator from pydantic import Field from petstore_api.models.category import Category @@ -32,7 +32,7 @@ class SpecialName(BaseModel): var_schema: Optional[StrictStr] = Field(default=None, description="pet status in the store", alias="schema") __properties = ["property", "async", "schema"] - @validator('var_schema') + @field_validator('var_schema') def var_schema_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -42,14 +42,15 @@ class SpecialName(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""" @@ -63,7 +64,7 @@ class SpecialName(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) @@ -79,9 +80,9 @@ class SpecialName(BaseModel): return None if not isinstance(obj, dict): - return SpecialName.parse_obj(obj) + return SpecialName.model_validate(obj) - _obj = SpecialName.parse_obj({ + _obj = SpecialName.model_validate({ "property": obj.get("property"), "async": Category.from_dict(obj.get("async")) if obj.get("async") is not None else None, "schema": obj.get("schema") diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tag.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tag.py index 4a9fbc67852..8a7251eefbe 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tag.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tag.py @@ -29,14 +29,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""" @@ -50,7 +51,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) @@ -63,9 +64,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") }) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_inline_freeform_additional_properties_request.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_inline_freeform_additional_properties_request.py index 4b811a07bf9..ffda6891843 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_inline_freeform_additional_properties_request.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_inline_freeform_additional_properties_request.py @@ -30,14 +30,15 @@ class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["someProperty"] - 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 TestInlineFreeformAdditionalPropertiesRequest(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={ "additional_properties" }, @@ -70,9 +71,9 @@ class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): return None if not isinstance(obj, dict): - return TestInlineFreeformAdditionalPropertiesRequest.parse_obj(obj) + return TestInlineFreeformAdditionalPropertiesRequest.model_validate(obj) - _obj = TestInlineFreeformAdditionalPropertiesRequest.parse_obj({ + _obj = TestInlineFreeformAdditionalPropertiesRequest.model_validate({ "someProperty": obj.get("someProperty") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tiger.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tiger.py index 7a8ec99bc8f..d0678ac15d1 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tiger.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tiger.py @@ -28,14 +28,15 @@ class Tiger(BaseModel): skill: Optional[StrictStr] = None __properties = ["skill"] - 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""" @@ -49,7 +50,7 @@ class Tiger(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) @@ -62,9 +63,9 @@ class Tiger(BaseModel): return None if not isinstance(obj, dict): - return Tiger.parse_obj(obj) + return Tiger.model_validate(obj) - _obj = Tiger.parse_obj({ + _obj = Tiger.model_validate({ "skill": obj.get("skill") }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/user.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/user.py index 937221ec7a6..b2c1e3c7e3f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/user.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/user.py @@ -36,14 +36,15 @@ class User(BaseModel): user_status: Optional[StrictInt] = Field(default=None, description="User Status", alias="userStatus") __properties = ["id", "username", "firstName", "lastName", "email", "password", "phone", "userStatus"] - 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""" @@ -57,7 +58,7 @@ class User(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) @@ -70,9 +71,9 @@ class User(BaseModel): return None if not isinstance(obj, dict): - return User.parse_obj(obj) + return User.model_validate(obj) - _obj = User.parse_obj({ + _obj = User.model_validate({ "id": obj.get("id"), "username": obj.get("username"), "firstName": obj.get("firstName"), diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/with_nested_one_of.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/with_nested_one_of.py index a5f52af9e14..0d8f7616827 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/with_nested_one_of.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/with_nested_one_of.py @@ -32,14 +32,15 @@ class WithNestedOneOf(BaseModel): nested_oneof_enum_string: Optional[OneOfEnumString] = None __properties = ["size", "nested_pig", "nested_oneof_enum_string"] - 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 WithNestedOneOf(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) @@ -72,9 +73,9 @@ class WithNestedOneOf(BaseModel): return None if not isinstance(obj, dict): - return WithNestedOneOf.parse_obj(obj) + return WithNestedOneOf.model_validate(obj) - _obj = WithNestedOneOf.parse_obj({ + _obj = WithNestedOneOf.model_validate({ "size": obj.get("size"), "nested_pig": Pig.from_dict(obj.get("nested_pig")) if obj.get("nested_pig") is not None else None, "nested_oneof_enum_string": OneOfEnumString.from_dict(obj.get("nested_oneof_enum_string")) if obj.get("nested_oneof_enum_string") is not None else None diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/another_fake_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/another_fake_api.py index 9eabf5fb45b..f1e942608b7 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/api/another_fake_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/another_fake_api.py @@ -16,7 +16,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 @@ -42,7 +42,7 @@ class AnotherFakeApi: api_client = ApiClient.get_default() self.api_client = api_client - @validate_arguments + @validate_call def call_123_test_special_tags(self, client : Annotated[Client, Field(description="client model")], **kwargs) -> Client: # noqa: E501 """To test special tags # noqa: E501 @@ -72,7 +72,7 @@ class AnotherFakeApi: raise ValueError(message) return self.call_123_test_special_tags_with_http_info(client, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def call_123_test_special_tags_with_http_info(self, client : Annotated[Client, Field(description="client model")], **kwargs) -> ApiResponse: # noqa: E501 """To test special tags # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/default_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/default_api.py index b5269287737..79a8f572630 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/api/default_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/default_api.py @@ -16,7 +16,7 @@ import re # noqa: F401 import io import warnings -from pydantic import validate_arguments, ValidationError +from pydantic import validate_call, ValidationError from petstore_api.models.foo_get_default_response import FooGetDefaultResponse @@ -40,7 +40,7 @@ class DefaultApi: api_client = ApiClient.get_default() self.api_client = api_client - @validate_arguments + @validate_call def foo_get(self, **kwargs) -> FooGetDefaultResponse: # noqa: E501 """foo_get # noqa: E501 @@ -67,7 +67,7 @@ class DefaultApi: raise ValueError(message) return self.foo_get_with_http_info(**kwargs) # noqa: E501 - @validate_arguments + @validate_call def foo_get_with_http_info(self, **kwargs) -> ApiResponse: # noqa: E501 """foo_get # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py index 58460fe9112..59b139c1e67 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py @@ -16,13 +16,13 @@ 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 from datetime import date, datetime -from pydantic import StrictBool, StrictBytes, StrictFloat, StrictInt, StrictStr, validator +from pydantic import StrictBool, StrictBytes, StrictFloat, StrictInt, StrictStr, field_validator from typing import Any, Dict, List, Optional, Union @@ -57,7 +57,7 @@ class FakeApi: api_client = ApiClient.get_default() self.api_client = api_client - @validate_arguments + @validate_call def fake_any_type_request_body(self, body : Optional[Dict[str, Any]] = None, **kwargs) -> None: # noqa: E501 """test any type request body # noqa: E501 @@ -86,7 +86,7 @@ class FakeApi: raise ValueError(message) return self.fake_any_type_request_body_with_http_info(body, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def fake_any_type_request_body_with_http_info(self, body : Optional[Dict[str, Any]] = None, **kwargs) -> ApiResponse: # noqa: E501 """test any type request body # noqa: E501 @@ -196,7 +196,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def fake_enum_ref_query_parameter(self, enum_ref : Annotated[Optional[EnumClass], Field(description="enum reference")] = None, **kwargs) -> None: # noqa: E501 """test enum reference query parameter # noqa: E501 @@ -225,7 +225,7 @@ class FakeApi: raise ValueError(message) return self.fake_enum_ref_query_parameter_with_http_info(enum_ref, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def fake_enum_ref_query_parameter_with_http_info(self, enum_ref : Annotated[Optional[EnumClass], Field(description="enum reference")] = None, **kwargs) -> ApiResponse: # noqa: E501 """test enum reference query parameter # noqa: E501 @@ -328,7 +328,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def fake_health_get(self, **kwargs) -> HealthCheckResult: # noqa: E501 """Health check endpoint # noqa: E501 @@ -355,7 +355,7 @@ class FakeApi: raise ValueError(message) return self.fake_health_get_with_http_info(**kwargs) # noqa: E501 - @validate_arguments + @validate_call def fake_health_get_with_http_info(self, **kwargs) -> ApiResponse: # noqa: E501 """Health check endpoint # noqa: E501 @@ -458,7 +458,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def fake_http_signature_test(self, pet : Annotated[Pet, Field(description="Pet object that needs to be added to the store")], query_1 : Annotated[Optional[StrictStr], Field(description="query parameter")] = None, header_1 : Annotated[Optional[StrictStr], Field(description="header parameter")] = None, **kwargs) -> None: # noqa: E501 """test http signature authentication # noqa: E501 @@ -491,7 +491,7 @@ class FakeApi: raise ValueError(message) return self.fake_http_signature_test_with_http_info(pet, query_1, header_1, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def fake_http_signature_test_with_http_info(self, pet : Annotated[Pet, Field(description="Pet object that needs to be added to the store")], query_1 : Annotated[Optional[StrictStr], Field(description="query parameter")] = None, header_1 : Annotated[Optional[StrictStr], Field(description="header parameter")] = None, **kwargs) -> ApiResponse: # noqa: E501 """test http signature authentication # noqa: E501 @@ -613,7 +613,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def fake_outer_boolean_serialize(self, body : Annotated[Optional[StrictBool], Field(description="Input boolean as post body")] = None, **kwargs) -> bool: # noqa: E501 """fake_outer_boolean_serialize # noqa: E501 @@ -643,7 +643,7 @@ class FakeApi: raise ValueError(message) return self.fake_outer_boolean_serialize_with_http_info(body, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def fake_outer_boolean_serialize_with_http_info(self, body : Annotated[Optional[StrictBool], Field(description="Input boolean as post body")] = None, **kwargs) -> ApiResponse: # noqa: E501 """fake_outer_boolean_serialize # noqa: E501 @@ -760,7 +760,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def fake_outer_composite_serialize(self, outer_composite : Annotated[Optional[OuterComposite], Field(description="Input composite as post body")] = None, **kwargs) -> OuterComposite: # noqa: E501 """fake_outer_composite_serialize # noqa: E501 @@ -790,7 +790,7 @@ class FakeApi: raise ValueError(message) return self.fake_outer_composite_serialize_with_http_info(outer_composite, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def fake_outer_composite_serialize_with_http_info(self, outer_composite : Annotated[Optional[OuterComposite], Field(description="Input composite as post body")] = None, **kwargs) -> ApiResponse: # noqa: E501 """fake_outer_composite_serialize # noqa: E501 @@ -907,7 +907,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def fake_outer_number_serialize(self, body : Annotated[Optional[StrictFloat], Field(description="Input number as post body")] = None, **kwargs) -> float: # noqa: E501 """fake_outer_number_serialize # noqa: E501 @@ -937,7 +937,7 @@ class FakeApi: raise ValueError(message) return self.fake_outer_number_serialize_with_http_info(body, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def fake_outer_number_serialize_with_http_info(self, body : Annotated[Optional[StrictFloat], Field(description="Input number as post body")] = None, **kwargs) -> ApiResponse: # noqa: E501 """fake_outer_number_serialize # noqa: E501 @@ -1054,7 +1054,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def fake_outer_string_serialize(self, body : Annotated[Optional[StrictStr], Field(description="Input string as post body")] = None, **kwargs) -> str: # noqa: E501 """fake_outer_string_serialize # noqa: E501 @@ -1084,7 +1084,7 @@ class FakeApi: raise ValueError(message) return self.fake_outer_string_serialize_with_http_info(body, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def fake_outer_string_serialize_with_http_info(self, body : Annotated[Optional[StrictStr], Field(description="Input string as post body")] = None, **kwargs) -> ApiResponse: # noqa: E501 """fake_outer_string_serialize # noqa: E501 @@ -1201,7 +1201,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def fake_property_enum_integer_serialize(self, outer_object_with_enum_property : Annotated[OuterObjectWithEnumProperty, Field(description="Input enum (int) as post body")], **kwargs) -> OuterObjectWithEnumProperty: # noqa: E501 """fake_property_enum_integer_serialize # noqa: E501 @@ -1231,7 +1231,7 @@ class FakeApi: raise ValueError(message) return self.fake_property_enum_integer_serialize_with_http_info(outer_object_with_enum_property, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def fake_property_enum_integer_serialize_with_http_info(self, outer_object_with_enum_property : Annotated[OuterObjectWithEnumProperty, Field(description="Input enum (int) as post body")], **kwargs) -> ApiResponse: # noqa: E501 """fake_property_enum_integer_serialize # noqa: E501 @@ -1348,7 +1348,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def fake_return_list_of_objects(self, **kwargs) -> List[List[Tag]]: # noqa: E501 """test returning list of objects # noqa: E501 @@ -1375,7 +1375,7 @@ class FakeApi: raise ValueError(message) return self.fake_return_list_of_objects_with_http_info(**kwargs) # noqa: E501 - @validate_arguments + @validate_call def fake_return_list_of_objects_with_http_info(self, **kwargs) -> ApiResponse: # noqa: E501 """test returning list of objects # noqa: E501 @@ -1478,7 +1478,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def fake_uuid_example(self, uuid_example : Annotated[StrictStr, Field(description="uuid example")], **kwargs) -> None: # noqa: E501 """test uuid example # noqa: E501 @@ -1507,7 +1507,7 @@ class FakeApi: raise ValueError(message) return self.fake_uuid_example_with_http_info(uuid_example, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def fake_uuid_example_with_http_info(self, uuid_example : Annotated[StrictStr, Field(description="uuid example")], **kwargs) -> ApiResponse: # noqa: E501 """test uuid example # noqa: E501 @@ -1610,7 +1610,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def test_body_with_binary(self, body : Annotated[Optional[Union[StrictBytes, StrictStr]], Field(description="image to upload")], **kwargs) -> None: # noqa: E501 """test_body_with_binary # noqa: E501 @@ -1640,7 +1640,7 @@ class FakeApi: raise ValueError(message) return self.test_body_with_binary_with_http_info(body, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def test_body_with_binary_with_http_info(self, body : Annotated[Optional[Union[StrictBytes, StrictStr]], Field(description="image to upload")], **kwargs) -> ApiResponse: # noqa: E501 """test_body_with_binary # noqa: E501 @@ -1756,7 +1756,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def test_body_with_file_schema(self, file_schema_test_class : FileSchemaTestClass, **kwargs) -> None: # noqa: E501 """test_body_with_file_schema # noqa: E501 @@ -1786,7 +1786,7 @@ class FakeApi: raise ValueError(message) return self.test_body_with_file_schema_with_http_info(file_schema_test_class, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def test_body_with_file_schema_with_http_info(self, file_schema_test_class : FileSchemaTestClass, **kwargs) -> ApiResponse: # noqa: E501 """test_body_with_file_schema # noqa: E501 @@ -1897,7 +1897,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def test_body_with_query_params(self, query : StrictStr, user : User, **kwargs) -> None: # noqa: E501 """test_body_with_query_params # noqa: E501 @@ -1928,7 +1928,7 @@ class FakeApi: raise ValueError(message) return self.test_body_with_query_params_with_http_info(query, user, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def test_body_with_query_params_with_http_info(self, query : StrictStr, user : User, **kwargs) -> ApiResponse: # noqa: E501 """test_body_with_query_params # noqa: E501 @@ -2044,7 +2044,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def test_client_model(self, client : Annotated[Client, Field(description="client model")], **kwargs) -> Client: # noqa: E501 """To test \"client\" model # noqa: E501 @@ -2074,7 +2074,7 @@ class FakeApi: raise ValueError(message) return self.test_client_model_with_http_info(client, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def test_client_model_with_http_info(self, client : Annotated[Client, Field(description="client model")], **kwargs) -> ApiResponse: # noqa: E501 """To test \"client\" model # noqa: E501 @@ -2191,7 +2191,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def test_date_time_query_parameter(self, date_time_query : datetime, str_query : StrictStr, **kwargs) -> None: # noqa: E501 """test_date_time_query_parameter # noqa: E501 @@ -2222,7 +2222,7 @@ class FakeApi: raise ValueError(message) return self.test_date_time_query_parameter_with_http_info(date_time_query, str_query, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def test_date_time_query_parameter_with_http_info(self, date_time_query : datetime, str_query : StrictStr, **kwargs) -> ApiResponse: # noqa: E501 """test_date_time_query_parameter # noqa: E501 @@ -2334,7 +2334,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def test_endpoint_parameters(self, number : Annotated[float, Field(le=543.2, strict=True, ge=32.1, description="None")], double : Annotated[float, Field(le=123.4, strict=True, ge=67.8, description="None")], pattern_without_delimiter : Annotated[str, Field(strict=True, description="None")], byte : Annotated[Union[StrictBytes, StrictStr], Field(description="None")], integer : Annotated[Optional[Annotated[int, Field(le=100, strict=True, ge=10)]], Field(description="None")] = None, int32 : Annotated[Optional[Annotated[int, Field(le=200, strict=True, ge=20)]], Field(description="None")] = None, int64 : Annotated[Optional[StrictInt], Field(description="None")] = None, float : Annotated[Optional[Annotated[float, Field(le=987.6, strict=True)]], Field(description="None")] = None, string : Annotated[Optional[Annotated[str, Field(strict=True)]], Field(description="None")] = None, binary : Annotated[Optional[Union[StrictBytes, StrictStr]], Field(description="None")] = None, byte_with_max_length : Annotated[Optional[Union[Annotated[bytes, Field(strict=True, max_length=64)], Annotated[str, Field(strict=True, max_length=64)]]], Field(description="None")] = None, var_date : Annotated[Optional[date], Field(description="None")] = None, date_time : Annotated[Optional[datetime], Field(description="None")] = None, password : Annotated[Optional[Annotated[str, Field(min_length=10, strict=True, max_length=64)]], Field(description="None")] = None, param_callback : Annotated[Optional[StrictStr], Field(description="None")] = None, **kwargs) -> None: # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 @@ -2392,7 +2392,7 @@ class FakeApi: raise ValueError(message) return self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, integer, int32, int64, float, string, binary, byte_with_max_length, var_date, date_time, password, param_callback, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def test_endpoint_parameters_with_http_info(self, number : Annotated[float, Field(le=543.2, strict=True, ge=32.1, description="None")], double : Annotated[float, Field(le=123.4, strict=True, ge=67.8, description="None")], pattern_without_delimiter : Annotated[str, Field(strict=True, description="None")], byte : Annotated[Union[StrictBytes, StrictStr], Field(description="None")], integer : Annotated[Optional[Annotated[int, Field(le=100, strict=True, ge=10)]], Field(description="None")] = None, int32 : Annotated[Optional[Annotated[int, Field(le=200, strict=True, ge=20)]], Field(description="None")] = None, int64 : Annotated[Optional[StrictInt], Field(description="None")] = None, float : Annotated[Optional[Annotated[float, Field(le=987.6, strict=True)]], Field(description="None")] = None, string : Annotated[Optional[Annotated[str, Field(strict=True)]], Field(description="None")] = None, binary : Annotated[Optional[Union[StrictBytes, StrictStr]], Field(description="None")] = None, byte_with_max_length : Annotated[Optional[Union[Annotated[bytes, Field(strict=True, max_length=64)], Annotated[str, Field(strict=True, max_length=64)]]], Field(description="None")] = None, var_date : Annotated[Optional[date], Field(description="None")] = None, date_time : Annotated[Optional[datetime], Field(description="None")] = None, password : Annotated[Optional[Annotated[str, Field(min_length=10, strict=True, max_length=64)]], Field(description="None")] = None, param_callback : Annotated[Optional[StrictStr], Field(description="None")] = None, **kwargs) -> ApiResponse: # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 @@ -2587,7 +2587,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def test_group_parameters(self, required_string_group : Annotated[StrictInt, Field(description="Required String in group parameters")], required_boolean_group : Annotated[StrictBool, Field(description="Required Boolean in group parameters")], required_int64_group : Annotated[StrictInt, Field(description="Required Integer in group parameters")], string_group : Annotated[Optional[StrictInt], Field(description="String in group parameters")] = None, boolean_group : Annotated[Optional[StrictBool], Field(description="Boolean in group parameters")] = None, int64_group : Annotated[Optional[StrictInt], Field(description="Integer in group parameters")] = None, **kwargs) -> None: # noqa: E501 """Fake endpoint to test group parameters (optional) # noqa: E501 @@ -2627,7 +2627,7 @@ class FakeApi: raise ValueError(message) return self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, string_group, boolean_group, int64_group, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def test_group_parameters_with_http_info(self, required_string_group : Annotated[StrictInt, Field(description="Required String in group parameters")], required_boolean_group : Annotated[StrictBool, Field(description="Required Boolean in group parameters")], required_int64_group : Annotated[StrictInt, Field(description="Required Integer in group parameters")], string_group : Annotated[Optional[StrictInt], Field(description="String in group parameters")] = None, boolean_group : Annotated[Optional[StrictBool], Field(description="Boolean in group parameters")] = None, int64_group : Annotated[Optional[StrictInt], Field(description="Integer in group parameters")] = None, **kwargs) -> ApiResponse: # noqa: E501 """Fake endpoint to test group parameters (optional) # noqa: E501 @@ -2761,7 +2761,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def test_inline_additional_properties(self, request_body : Annotated[Dict[str, StrictStr], Field(description="request body")], **kwargs) -> None: # noqa: E501 """test inline additionalProperties # noqa: E501 @@ -2791,7 +2791,7 @@ class FakeApi: raise ValueError(message) return self.test_inline_additional_properties_with_http_info(request_body, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def test_inline_additional_properties_with_http_info(self, request_body : Annotated[Dict[str, StrictStr], Field(description="request body")], **kwargs) -> ApiResponse: # noqa: E501 """test inline additionalProperties # noqa: E501 @@ -2902,7 +2902,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def test_inline_freeform_additional_properties(self, test_inline_freeform_additional_properties_request : Annotated[TestInlineFreeformAdditionalPropertiesRequest, Field(description="request body")], **kwargs) -> None: # noqa: E501 """test inline free-form additionalProperties # noqa: E501 @@ -2932,7 +2932,7 @@ class FakeApi: raise ValueError(message) return self.test_inline_freeform_additional_properties_with_http_info(test_inline_freeform_additional_properties_request, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def test_inline_freeform_additional_properties_with_http_info(self, test_inline_freeform_additional_properties_request : Annotated[TestInlineFreeformAdditionalPropertiesRequest, Field(description="request body")], **kwargs) -> ApiResponse: # noqa: E501 """test inline free-form additionalProperties # noqa: E501 @@ -3043,7 +3043,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def test_json_form_data(self, param : Annotated[StrictStr, Field(description="field1")], param2 : Annotated[StrictStr, Field(description="field2")], **kwargs) -> None: # noqa: E501 """test json serialization of form data # noqa: E501 @@ -3075,7 +3075,7 @@ class FakeApi: raise ValueError(message) return self.test_json_form_data_with_http_info(param, param2, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def test_json_form_data_with_http_info(self, param : Annotated[StrictStr, Field(description="field1")], param2 : Annotated[StrictStr, Field(description="field2")], **kwargs) -> ApiResponse: # noqa: E501 """test json serialization of form data # noqa: E501 @@ -3192,7 +3192,7 @@ class FakeApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def test_query_parameter_collection_format(self, pipe : List[StrictStr], ioutil : List[StrictStr], http : List[StrictStr], url : List[StrictStr], context : List[StrictStr], allow_empty : StrictStr, language : Optional[Dict[str, StrictStr]] = None, **kwargs) -> None: # noqa: E501 """test_query_parameter_collection_format # noqa: E501 @@ -3234,7 +3234,7 @@ class FakeApi: raise ValueError(message) return self.test_query_parameter_collection_format_with_http_info(pipe, ioutil, http, url, context, allow_empty, language, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def test_query_parameter_collection_format_with_http_info(self, pipe : List[StrictStr], ioutil : List[StrictStr], http : List[StrictStr], url : List[StrictStr], context : List[StrictStr], allow_empty : StrictStr, language : Optional[Dict[str, StrictStr]] = None, **kwargs) -> ApiResponse: # noqa: E501 """test_query_parameter_collection_format # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/fake_classname_tags123_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/fake_classname_tags123_api.py index 342d93d861d..89b898d96e0 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/fake_classname_tags123_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/fake_classname_tags123_api.py @@ -16,7 +16,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 @@ -42,7 +42,7 @@ class FakeClassnameTags123Api: api_client = ApiClient.get_default() self.api_client = api_client - @validate_arguments + @validate_call def test_classname(self, client : Annotated[Client, Field(description="client model")], **kwargs) -> Client: # noqa: E501 """To test class name in snake case # noqa: E501 @@ -72,7 +72,7 @@ class FakeClassnameTags123Api: raise ValueError(message) return self.test_classname_with_http_info(client, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def test_classname_with_http_info(self, client : Annotated[Client, Field(description="client model")], **kwargs) -> ApiResponse: # noqa: E501 """To test class name in snake case # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/pet_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/pet_api.py index 90b585150c0..f95d2334d23 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/api/pet_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/pet_api.py @@ -16,11 +16,11 @@ 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 -from pydantic import StrictBytes, StrictInt, StrictStr, validator +from pydantic import StrictBytes, StrictInt, StrictStr, field_validator from typing import List, Optional, Union @@ -47,7 +47,7 @@ class PetApi: api_client = ApiClient.get_default() self.api_client = api_client - @validate_arguments + @validate_call def add_pet(self, pet : Annotated[Pet, Field(description="Pet object that needs to be added to the store")], **kwargs) -> None: # noqa: E501 """Add a new pet to the store # noqa: E501 @@ -77,7 +77,7 @@ class PetApi: raise ValueError(message) return self.add_pet_with_http_info(pet, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def add_pet_with_http_info(self, pet : Annotated[Pet, Field(description="Pet object that needs to be added to the store")], **kwargs) -> ApiResponse: # noqa: E501 """Add a new pet to the store # noqa: E501 @@ -188,7 +188,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def delete_pet(self, pet_id : Annotated[StrictInt, Field(description="Pet id to delete")], api_key : Optional[StrictStr] = None, **kwargs) -> None: # noqa: E501 """Deletes a pet # noqa: E501 @@ -220,7 +220,7 @@ class PetApi: raise ValueError(message) return self.delete_pet_with_http_info(pet_id, api_key, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def delete_pet_with_http_info(self, pet_id : Annotated[StrictInt, Field(description="Pet id to delete")], api_key : Optional[StrictStr] = None, **kwargs) -> ApiResponse: # noqa: E501 """Deletes a pet # noqa: E501 @@ -330,7 +330,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def find_pets_by_status(self, status : Annotated[List[StrictStr], Field(description="Status values that need to be considered for filter")], **kwargs) -> List[Pet]: # noqa: E501 """Finds Pets by status # noqa: E501 @@ -360,7 +360,7 @@ class PetApi: raise ValueError(message) return self.find_pets_by_status_with_http_info(status, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def find_pets_by_status_with_http_info(self, status : Annotated[List[StrictStr], Field(description="Status values that need to be considered for filter")], **kwargs) -> ApiResponse: # noqa: E501 """Finds Pets by status # noqa: E501 @@ -472,7 +472,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def find_pets_by_tags(self, tags : Annotated[List[StrictStr], Field(description="Tags to filter by")], **kwargs) -> List[Pet]: # noqa: E501 """(Deprecated) Finds Pets by tags # noqa: E501 @@ -502,7 +502,7 @@ class PetApi: raise ValueError(message) return self.find_pets_by_tags_with_http_info(tags, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def find_pets_by_tags_with_http_info(self, tags : Annotated[List[StrictStr], Field(description="Tags to filter by")], **kwargs) -> ApiResponse: # noqa: E501 """(Deprecated) Finds Pets by tags # noqa: E501 @@ -616,7 +616,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def get_pet_by_id(self, pet_id : Annotated[StrictInt, Field(description="ID of pet to return")], **kwargs) -> Pet: # noqa: E501 """Find pet by ID # noqa: E501 @@ -646,7 +646,7 @@ class PetApi: raise ValueError(message) return self.get_pet_by_id_with_http_info(pet_id, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def get_pet_by_id_with_http_info(self, pet_id : Annotated[StrictInt, Field(description="ID of pet to return")], **kwargs) -> ApiResponse: # noqa: E501 """Find pet by ID # noqa: E501 @@ -758,7 +758,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def update_pet(self, pet : Annotated[Pet, Field(description="Pet object that needs to be added to the store")], **kwargs) -> None: # noqa: E501 """Update an existing pet # noqa: E501 @@ -788,7 +788,7 @@ class PetApi: raise ValueError(message) return self.update_pet_with_http_info(pet, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def update_pet_with_http_info(self, pet : Annotated[Pet, Field(description="Pet object that needs to be added to the store")], **kwargs) -> ApiResponse: # noqa: E501 """Update an existing pet # noqa: E501 @@ -899,7 +899,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def update_pet_with_form(self, pet_id : Annotated[StrictInt, Field(description="ID of pet that needs to be updated")], name : Annotated[Optional[StrictStr], Field(description="Updated name of the pet")] = None, status : Annotated[Optional[StrictStr], Field(description="Updated status of the pet")] = None, **kwargs) -> None: # noqa: E501 """Updates a pet in the store with form data # noqa: E501 @@ -933,7 +933,7 @@ class PetApi: raise ValueError(message) return self.update_pet_with_form_with_http_info(pet_id, name, status, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def update_pet_with_form_with_http_info(self, pet_id : Annotated[StrictInt, Field(description="ID of pet that needs to be updated")], name : Annotated[Optional[StrictStr], Field(description="Updated name of the pet")] = None, status : Annotated[Optional[StrictStr], Field(description="Updated status of the pet")] = None, **kwargs) -> ApiResponse: # noqa: E501 """Updates a pet in the store with form data # noqa: E501 @@ -1056,7 +1056,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def upload_file(self, pet_id : Annotated[StrictInt, Field(description="ID of pet to update")], additional_metadata : Annotated[Optional[StrictStr], Field(description="Additional data to pass to server")] = None, file : Annotated[Optional[Union[StrictBytes, StrictStr]], Field(description="file to upload")] = None, **kwargs) -> ApiResponse: # noqa: E501 """uploads an image # noqa: E501 @@ -1090,7 +1090,7 @@ class PetApi: raise ValueError(message) return self.upload_file_with_http_info(pet_id, additional_metadata, file, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def upload_file_with_http_info(self, pet_id : Annotated[StrictInt, Field(description="ID of pet to update")], additional_metadata : Annotated[Optional[StrictStr], Field(description="Additional data to pass to server")] = None, file : Annotated[Optional[Union[StrictBytes, StrictStr]], Field(description="file to upload")] = None, **kwargs) -> ApiResponse: # noqa: E501 """uploads an image # noqa: E501 @@ -1219,7 +1219,7 @@ class PetApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def upload_file_with_required_file(self, pet_id : Annotated[StrictInt, Field(description="ID of pet to update")], required_file : Annotated[Union[StrictBytes, StrictStr], Field(description="file to upload")], additional_metadata : Annotated[Optional[StrictStr], Field(description="Additional data to pass to server")] = None, **kwargs) -> ApiResponse: # noqa: E501 """uploads an image (required) # noqa: E501 @@ -1253,7 +1253,7 @@ class PetApi: raise ValueError(message) return self.upload_file_with_required_file_with_http_info(pet_id, required_file, additional_metadata, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def upload_file_with_required_file_with_http_info(self, pet_id : Annotated[StrictInt, Field(description="ID of pet to update")], required_file : Annotated[Union[StrictBytes, StrictStr], Field(description="file to upload")], additional_metadata : Annotated[Optional[StrictStr], Field(description="Additional data to pass to server")] = None, **kwargs) -> ApiResponse: # noqa: E501 """uploads an image (required) # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py index 89334dee6d1..e589c590403 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py @@ -16,7 +16,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 @@ -46,7 +46,7 @@ class StoreApi: api_client = ApiClient.get_default() self.api_client = api_client - @validate_arguments + @validate_call def delete_order(self, order_id : Annotated[StrictStr, Field(description="ID of the order that needs to be deleted")], **kwargs) -> None: # noqa: E501 """Delete purchase order by ID # noqa: E501 @@ -76,7 +76,7 @@ class StoreApi: raise ValueError(message) return self.delete_order_with_http_info(order_id, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def delete_order_with_http_info(self, order_id : Annotated[StrictStr, Field(description="ID of the order that needs to be deleted")], **kwargs) -> ApiResponse: # noqa: E501 """Delete purchase order by ID # noqa: E501 @@ -180,7 +180,7 @@ class StoreApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def get_inventory(self, **kwargs) -> Dict[str, int]: # noqa: E501 """Returns pet inventories by status # noqa: E501 @@ -208,7 +208,7 @@ class StoreApi: raise ValueError(message) return self.get_inventory_with_http_info(**kwargs) # noqa: E501 - @validate_arguments + @validate_call def get_inventory_with_http_info(self, **kwargs) -> ApiResponse: # noqa: E501 """Returns pet inventories by status # noqa: E501 @@ -312,7 +312,7 @@ class StoreApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def get_order_by_id(self, order_id : Annotated[int, Field(le=5, strict=True, ge=1, description="ID of pet that needs to be fetched")], **kwargs) -> Order: # noqa: E501 """Find purchase order by ID # noqa: E501 @@ -342,7 +342,7 @@ class StoreApi: raise ValueError(message) return self.get_order_by_id_with_http_info(order_id, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def get_order_by_id_with_http_info(self, order_id : Annotated[int, Field(le=5, strict=True, ge=1, description="ID of pet that needs to be fetched")], **kwargs) -> ApiResponse: # noqa: E501 """Find purchase order by ID # noqa: E501 @@ -454,7 +454,7 @@ class StoreApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def place_order(self, order : Annotated[Order, Field(description="order placed for purchasing the pet")], **kwargs) -> Order: # noqa: E501 """Place an order for a pet # noqa: E501 @@ -484,7 +484,7 @@ class StoreApi: raise ValueError(message) return self.place_order_with_http_info(order, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def place_order_with_http_info(self, order : Annotated[Order, Field(description="order placed for purchasing the pet")], **kwargs) -> ApiResponse: # noqa: E501 """Place an order for a pet # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/user_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/user_api.py index ab1101af25c..3420f8993a1 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/api/user_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/user_api.py @@ -16,7 +16,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 @@ -46,7 +46,7 @@ class UserApi: api_client = ApiClient.get_default() self.api_client = api_client - @validate_arguments + @validate_call def create_user(self, user : Annotated[User, Field(description="Created user object")], **kwargs) -> None: # noqa: E501 """Create user # noqa: E501 @@ -76,7 +76,7 @@ class UserApi: raise ValueError(message) return self.create_user_with_http_info(user, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def create_user_with_http_info(self, user : Annotated[User, Field(description="Created user object")], **kwargs) -> ApiResponse: # noqa: E501 """Create user # noqa: E501 @@ -202,7 +202,7 @@ class UserApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def create_users_with_array_input(self, user : Annotated[List[User], Field(description="List of user object")], **kwargs) -> None: # noqa: E501 """Creates list of users with given input array # noqa: E501 @@ -232,7 +232,7 @@ class UserApi: raise ValueError(message) return self.create_users_with_array_input_with_http_info(user, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def create_users_with_array_input_with_http_info(self, user : Annotated[List[User], Field(description="List of user object")], **kwargs) -> ApiResponse: # noqa: E501 """Creates list of users with given input array # noqa: E501 @@ -343,7 +343,7 @@ class UserApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def create_users_with_list_input(self, user : Annotated[List[User], Field(description="List of user object")], **kwargs) -> None: # noqa: E501 """Creates list of users with given input array # noqa: E501 @@ -373,7 +373,7 @@ class UserApi: raise ValueError(message) return self.create_users_with_list_input_with_http_info(user, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def create_users_with_list_input_with_http_info(self, user : Annotated[List[User], Field(description="List of user object")], **kwargs) -> ApiResponse: # noqa: E501 """Creates list of users with given input array # noqa: E501 @@ -484,7 +484,7 @@ class UserApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def delete_user(self, username : Annotated[StrictStr, Field(description="The name that needs to be deleted")], **kwargs) -> None: # noqa: E501 """Delete user # noqa: E501 @@ -514,7 +514,7 @@ class UserApi: raise ValueError(message) return self.delete_user_with_http_info(username, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def delete_user_with_http_info(self, username : Annotated[StrictStr, Field(description="The name that needs to be deleted")], **kwargs) -> ApiResponse: # noqa: E501 """Delete user # noqa: E501 @@ -618,7 +618,7 @@ class UserApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def get_user_by_name(self, username : Annotated[StrictStr, Field(description="The name that needs to be fetched. Use user1 for testing.")], **kwargs) -> User: # noqa: E501 """Get user by user name # noqa: E501 @@ -648,7 +648,7 @@ class UserApi: raise ValueError(message) return self.get_user_by_name_with_http_info(username, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def get_user_by_name_with_http_info(self, username : Annotated[StrictStr, Field(description="The name that needs to be fetched. Use user1 for testing.")], **kwargs) -> ApiResponse: # noqa: E501 """Get user by user name # noqa: E501 @@ -760,7 +760,7 @@ class UserApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def login_user(self, username : Annotated[StrictStr, Field(description="The user name for login")], password : Annotated[StrictStr, Field(description="The password for login in clear text")], **kwargs) -> str: # noqa: E501 """Logs user into the system # noqa: E501 @@ -792,7 +792,7 @@ class UserApi: raise ValueError(message) return self.login_user_with_http_info(username, password, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def login_user_with_http_info(self, username : Annotated[StrictStr, Field(description="The user name for login")], password : Annotated[StrictStr, Field(description="The password for login in clear text")], **kwargs) -> ApiResponse: # noqa: E501 """Logs user into the system # noqa: E501 @@ -909,7 +909,7 @@ class UserApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def logout_user(self, **kwargs) -> None: # noqa: E501 """Logs out current logged in user session # noqa: E501 @@ -937,7 +937,7 @@ class UserApi: raise ValueError(message) return self.logout_user_with_http_info(**kwargs) # noqa: E501 - @validate_arguments + @validate_call def logout_user_with_http_info(self, **kwargs) -> ApiResponse: # noqa: E501 """Logs out current logged in user session # noqa: E501 @@ -1035,7 +1035,7 @@ class UserApi: collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) - @validate_arguments + @validate_call def update_user(self, username : Annotated[StrictStr, Field(description="name that need to be deleted")], user : Annotated[User, Field(description="Updated user object")], **kwargs) -> None: # noqa: E501 """Updated user # noqa: E501 @@ -1067,7 +1067,7 @@ class UserApi: raise ValueError(message) return self.update_user_with_http_info(username, user, **kwargs) # noqa: E501 - @validate_arguments + @validate_call def update_user_with_http_info(self, username : Annotated[StrictStr, Field(description="name that need to be deleted")], user : Annotated[User, Field(description="Updated user object")], **kwargs) -> ApiResponse: # noqa: E501 """Updated user # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_any_type.py b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_any_type.py index 28de0a95be0..1be3065d20f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_any_type.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_any_type.py @@ -29,14 +29,15 @@ class AdditionalPropertiesAnyType(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["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""" @@ -50,7 +51,7 @@ class AdditionalPropertiesAnyType(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={ "additional_properties" }, @@ -69,9 +70,9 @@ class AdditionalPropertiesAnyType(BaseModel): return None if not isinstance(obj, dict): - return AdditionalPropertiesAnyType.parse_obj(obj) + return AdditionalPropertiesAnyType.model_validate(obj) - _obj = AdditionalPropertiesAnyType.parse_obj({ + _obj = AdditionalPropertiesAnyType.model_validate({ "name": obj.get("name") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_class.py index 4ce0f54e353..70e633cdd21 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_class.py @@ -30,14 +30,15 @@ class AdditionalPropertiesClass(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["map_property", "map_of_map_property"] - 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 AdditionalPropertiesClass(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={ "additional_properties" }, @@ -70,9 +71,9 @@ class AdditionalPropertiesClass(BaseModel): return None if not isinstance(obj, dict): - return AdditionalPropertiesClass.parse_obj(obj) + return AdditionalPropertiesClass.model_validate(obj) - _obj = AdditionalPropertiesClass.parse_obj({ + _obj = AdditionalPropertiesClass.model_validate({ "map_property": obj.get("map_property"), "map_of_map_property": obj.get("map_of_map_property") }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_object.py b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_object.py index 9d9b105a931..c401cd724c5 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_object.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_object.py @@ -29,14 +29,15 @@ class AdditionalPropertiesObject(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["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""" @@ -50,7 +51,7 @@ class AdditionalPropertiesObject(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={ "additional_properties" }, @@ -69,9 +70,9 @@ class AdditionalPropertiesObject(BaseModel): return None if not isinstance(obj, dict): - return AdditionalPropertiesObject.parse_obj(obj) + return AdditionalPropertiesObject.model_validate(obj) - _obj = AdditionalPropertiesObject.parse_obj({ + _obj = AdditionalPropertiesObject.model_validate({ "name": obj.get("name") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_with_description_only.py b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_with_description_only.py index 4327f030ce2..546c5774950 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_with_description_only.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_with_description_only.py @@ -29,14 +29,15 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["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""" @@ -50,7 +51,7 @@ class AdditionalPropertiesWithDescriptionOnly(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={ "additional_properties" }, @@ -69,9 +70,9 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel): return None if not isinstance(obj, dict): - return AdditionalPropertiesWithDescriptionOnly.parse_obj(obj) + return AdditionalPropertiesWithDescriptionOnly.model_validate(obj) - _obj = AdditionalPropertiesWithDescriptionOnly.parse_obj({ + _obj = AdditionalPropertiesWithDescriptionOnly.model_validate({ "name": obj.get("name") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/all_of_with_single_ref.py b/samples/openapi3/client/petstore/python/petstore_api/models/all_of_with_single_ref.py index 91decaece89..d88e6480c91 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/all_of_with_single_ref.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/all_of_with_single_ref.py @@ -32,14 +32,15 @@ class AllOfWithSingleRef(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["username", "SingleRefType"] - 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 AllOfWithSingleRef(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={ "additional_properties" }, @@ -72,9 +73,9 @@ class AllOfWithSingleRef(BaseModel): return None if not isinstance(obj, dict): - return AllOfWithSingleRef.parse_obj(obj) + return AllOfWithSingleRef.model_validate(obj) - _obj = AllOfWithSingleRef.parse_obj({ + _obj = AllOfWithSingleRef.model_validate({ "username": obj.get("username"), "SingleRefType": obj.get("SingleRefType") }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/animal.py b/samples/openapi3/client/petstore/python/petstore_api/models/animal.py index b74a4ca73e0..e5c95fef232 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/animal.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/animal.py @@ -31,10 +31,11 @@ class Animal(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["className", "color"] - class Config: - """Pydantic configuration""" - allow_population_by_field_name = True - validate_assignment = True + model_config = { + "populate_by_name": True, + "validate_assignment": True + } + # JSON field name that stores the object type __discriminator_property_name = 'className' @@ -56,7 +57,7 @@ class Animal(BaseModel): 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""" @@ -70,7 +71,7 @@ class Animal(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={ "additional_properties" }, diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py b/samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py index 397956daa53..23097a49750 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py @@ -19,7 +19,7 @@ import pprint import re # noqa: F401 from typing import List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from pydantic import Field from typing_extensions import Annotated from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict @@ -34,9 +34,9 @@ class AnyOfColor(BaseModel): """ # data type: List[int] - anyof_schema_1_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_items=3, max_items=3)]] = Field(default=None, description="RGB three element array with values 0-255.") + anyof_schema_1_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_length=3, max_length=3)]] = Field(default=None, description="RGB three element array with values 0-255.") # data type: List[int] - anyof_schema_2_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_items=4, max_items=4)]] = Field(default=None, description="RGBA four element array with values 0-255.") + anyof_schema_2_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_length=4, max_length=4)]] = Field(default=None, description="RGBA four element array with values 0-255.") # data type: str anyof_schema_3_validator: Optional[Annotated[str, Field(min_length=7, strict=True, max_length=7)]] = Field(default=None, description="Hex color string, such as #00FF00.") if TYPE_CHECKING: @@ -45,8 +45,9 @@ class AnyOfColor(BaseModel): actual_instance: Any = None any_of_schemas: List[str] = Literal[ANYOFCOLOR_ANY_OF_SCHEMAS] - class Config: - validate_assignment = True + model_config = { + "validate_assignment": True + } def __init__(self, *args, **kwargs) -> None: if args: @@ -58,9 +59,9 @@ class AnyOfColor(BaseModel): else: super().__init__(**kwargs) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): - instance = AnyOfColor.construct() + instance = AnyOfColor.model_construct() error_messages = [] # validate data type: List[int] try: @@ -93,7 +94,7 @@ class AnyOfColor(BaseModel): @classmethod def from_json(cls, json_str: str) -> AnyOfColor: """Returns the object represented by the json string""" - instance = AnyOfColor.construct() + instance = AnyOfColor.model_construct() error_messages = [] # deserialize data into List[int] try: @@ -153,6 +154,6 @@ class AnyOfColor(BaseModel): def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/any_of_pig.py b/samples/openapi3/client/petstore/python/petstore_api/models/any_of_pig.py index 174c3af2554..00369b878bd 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/any_of_pig.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/any_of_pig.py @@ -19,7 +19,7 @@ import pprint import re # noqa: F401 from typing import Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict @@ -43,8 +43,9 @@ class AnyOfPig(BaseModel): actual_instance: Any = None any_of_schemas: List[str] = Literal[ANYOFPIG_ANY_OF_SCHEMAS] - class Config: - validate_assignment = True + model_config = { + "validate_assignment": True + } def __init__(self, *args, **kwargs) -> None: if args: @@ -56,9 +57,9 @@ class AnyOfPig(BaseModel): else: super().__init__(**kwargs) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): - instance = AnyOfPig.construct() + instance = AnyOfPig.model_construct() error_messages = [] # validate data type: BasquePig if not isinstance(v, BasquePig): @@ -85,7 +86,7 @@ class AnyOfPig(BaseModel): @classmethod def from_json(cls, json_str: str) -> AnyOfPig: """Returns the object represented by the json string""" - instance = AnyOfPig.construct() + instance = AnyOfPig.model_construct() error_messages = [] # anyof_schema_1_validator: Optional[BasquePig] = None try: @@ -130,6 +131,6 @@ class AnyOfPig(BaseModel): def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/api_response.py b/samples/openapi3/client/petstore/python/petstore_api/models/api_response.py index 36a02f575e1..a08e764c93b 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/api_response.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/api_response.py @@ -31,14 +31,15 @@ class ApiResponse(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["code", "type", "message"] - 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""" @@ -52,7 +53,7 @@ class ApiResponse(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={ "additional_properties" }, @@ -71,9 +72,9 @@ class ApiResponse(BaseModel): return None if not isinstance(obj, dict): - return ApiResponse.parse_obj(obj) + return ApiResponse.model_validate(obj) - _obj = ApiResponse.parse_obj({ + _obj = ApiResponse.model_validate({ "code": obj.get("code"), "type": obj.get("type"), "message": obj.get("message") diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_model.py index 14d0f3e597f..c242a481e59 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_model.py @@ -30,14 +30,15 @@ class ArrayOfArrayOfModel(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["another_property"] - 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 ArrayOfArrayOfModel(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={ "additional_properties" }, @@ -79,9 +80,9 @@ class ArrayOfArrayOfModel(BaseModel): return None if not isinstance(obj, dict): - return ArrayOfArrayOfModel.parse_obj(obj) + return ArrayOfArrayOfModel.model_validate(obj) - _obj = ArrayOfArrayOfModel.parse_obj({ + _obj = ArrayOfArrayOfModel.model_validate({ "another_property": [ [Tag.from_dict(_inner_item) for _inner_item in _item] for _item in obj.get("another_property") diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py index 105251703fa..d2f8b48a1b4 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py @@ -30,14 +30,15 @@ class ArrayOfArrayOfNumberOnly(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["ArrayArrayNumber"] - 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 ArrayOfArrayOfNumberOnly(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={ "additional_properties" }, @@ -70,9 +71,9 @@ class ArrayOfArrayOfNumberOnly(BaseModel): return None if not isinstance(obj, dict): - return ArrayOfArrayOfNumberOnly.parse_obj(obj) + return ArrayOfArrayOfNumberOnly.model_validate(obj) - _obj = ArrayOfArrayOfNumberOnly.parse_obj({ + _obj = ArrayOfArrayOfNumberOnly.model_validate({ "ArrayArrayNumber": obj.get("ArrayArrayNumber") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_number_only.py b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_number_only.py index 7ae38c86ee9..7b013a257cd 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_number_only.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_number_only.py @@ -30,14 +30,15 @@ class ArrayOfNumberOnly(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["ArrayNumber"] - 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 ArrayOfNumberOnly(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={ "additional_properties" }, @@ -70,9 +71,9 @@ class ArrayOfNumberOnly(BaseModel): return None if not isinstance(obj, dict): - return ArrayOfNumberOnly.parse_obj(obj) + return ArrayOfNumberOnly.model_validate(obj) - _obj = ArrayOfNumberOnly.parse_obj({ + _obj = ArrayOfNumberOnly.model_validate({ "ArrayNumber": obj.get("ArrayNumber") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py index 0e920799b48..028329d774a 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py @@ -28,20 +28,21 @@ class ArrayTest(BaseModel): """ ArrayTest """ - array_of_string: Optional[Annotated[List[StrictStr], Field(min_items=0, max_items=3)]] = None + array_of_string: Optional[Annotated[List[StrictStr], Field(min_length=0, max_length=3)]] = None array_array_of_integer: Optional[List[List[StrictInt]]] = None array_array_of_model: Optional[List[List[ReadOnlyFirst]]] = None additional_properties: Dict[str, Any] = {} __properties = ["array_of_string", "array_array_of_integer", "array_array_of_model"] - 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""" @@ -55,7 +56,7 @@ class ArrayTest(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={ "additional_properties" }, @@ -83,9 +84,9 @@ class ArrayTest(BaseModel): return None if not isinstance(obj, dict): - return ArrayTest.parse_obj(obj) + return ArrayTest.model_validate(obj) - _obj = ArrayTest.parse_obj({ + _obj = ArrayTest.model_validate({ "array_of_string": obj.get("array_of_string"), "array_array_of_integer": obj.get("array_array_of_integer"), "array_array_of_model": [ diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/basque_pig.py b/samples/openapi3/client/petstore/python/petstore_api/models/basque_pig.py index c9e9b981cc3..c107ca3b05c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/basque_pig.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/basque_pig.py @@ -31,14 +31,15 @@ class BasquePig(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["className", "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""" @@ -52,7 +53,7 @@ class BasquePig(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={ "additional_properties" }, @@ -71,9 +72,9 @@ class BasquePig(BaseModel): return None if not isinstance(obj, dict): - return BasquePig.parse_obj(obj) + return BasquePig.model_validate(obj) - _obj = BasquePig.parse_obj({ + _obj = BasquePig.model_validate({ "className": obj.get("className"), "color": obj.get("color") }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py b/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py index 9d20b2aea6a..96466c37806 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py @@ -35,14 +35,15 @@ class Capitalization(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["smallCamel", "CapitalCamel", "small_Snake", "Capital_Snake", "SCA_ETH_Flow_Points", "ATT_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""" @@ -56,7 +57,7 @@ class Capitalization(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={ "additional_properties" }, @@ -75,9 +76,9 @@ class Capitalization(BaseModel): return None if not isinstance(obj, dict): - return Capitalization.parse_obj(obj) + return Capitalization.model_validate(obj) - _obj = Capitalization.parse_obj({ + _obj = Capitalization.model_validate({ "smallCamel": obj.get("smallCamel"), "CapitalCamel": obj.get("CapitalCamel"), "small_Snake": obj.get("small_Snake"), diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/cat.py b/samples/openapi3/client/petstore/python/petstore_api/models/cat.py index 0deedf9e616..e3f7c2a6ea5 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/cat.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/cat.py @@ -30,14 +30,15 @@ class Cat(Animal): additional_properties: Dict[str, Any] = {} __properties = ["className", "color", "declawed"] - 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 Cat(Animal): 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={ "additional_properties" }, @@ -70,9 +71,9 @@ class Cat(Animal): return None if not isinstance(obj, dict): - return Cat.parse_obj(obj) + return Cat.model_validate(obj) - _obj = Cat.parse_obj({ + _obj = Cat.model_validate({ "className": obj.get("className"), "color": obj.get("color") if obj.get("color") is not None else 'red', "declawed": obj.get("declawed") diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/category.py b/samples/openapi3/client/petstore/python/petstore_api/models/category.py index ffe0ad7b577..6dcba4df529 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/category.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/category.py @@ -30,14 +30,15 @@ class Category(BaseModel): additional_properties: Dict[str, Any] = {} __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={ "additional_properties" }, @@ -70,9 +71,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") if obj.get("name") is not None else 'default-name' }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/circular_reference_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/circular_reference_model.py index f9f28e8eebe..a1e6b907549 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/circular_reference_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/circular_reference_model.py @@ -30,14 +30,15 @@ class CircularReferenceModel(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["size", "nested"] - 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 CircularReferenceModel(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={ "additional_properties" }, @@ -73,9 +74,9 @@ class CircularReferenceModel(BaseModel): return None if not isinstance(obj, dict): - return CircularReferenceModel.parse_obj(obj) + return CircularReferenceModel.model_validate(obj) - _obj = CircularReferenceModel.parse_obj({ + _obj = CircularReferenceModel.model_validate({ "size": obj.get("size"), "nested": FirstRef.from_dict(obj.get("nested")) if obj.get("nested") is not None else None }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/class_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/class_model.py index b94d9174bbb..d8e9f2252ef 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/class_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/class_model.py @@ -30,14 +30,15 @@ class ClassModel(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["_class"] - 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 ClassModel(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={ "additional_properties" }, @@ -70,9 +71,9 @@ class ClassModel(BaseModel): return None if not isinstance(obj, dict): - return ClassModel.parse_obj(obj) + return ClassModel.model_validate(obj) - _obj = ClassModel.parse_obj({ + _obj = ClassModel.model_validate({ "_class": obj.get("_class") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/client.py b/samples/openapi3/client/petstore/python/petstore_api/models/client.py index 689c62313b6..278f76d80bc 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/client.py @@ -29,14 +29,15 @@ class Client(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["client"] - 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 Client(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={ "additional_properties" }, @@ -69,9 +70,9 @@ class Client(BaseModel): return None if not isinstance(obj, dict): - return Client.parse_obj(obj) + return Client.model_validate(obj) - _obj = Client.parse_obj({ + _obj = Client.model_validate({ "client": obj.get("client") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/color.py b/samples/openapi3/client/petstore/python/petstore_api/models/color.py index d6b2ab8d8d7..2fdc7e8805c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/color.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/color.py @@ -19,7 +19,7 @@ import pprint import re # noqa: F401 from typing import Any, List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from pydantic import Field from typing_extensions import Annotated from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict @@ -33,16 +33,18 @@ class Color(BaseModel): RGB array, RGBA array, or hex string. """ # data type: List[int] - oneof_schema_1_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_items=3, max_items=3)]] = Field(default=None, description="RGB three element array with values 0-255.") + oneof_schema_1_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_length=3, max_length=3)]] = Field(default=None, description="RGB three element array with values 0-255.") # data type: List[int] - oneof_schema_2_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_items=4, max_items=4)]] = Field(default=None, description="RGBA four element array with values 0-255.") + oneof_schema_2_validator: Optional[Annotated[List[Annotated[int, Field(le=255, strict=True, ge=0)]], Field(min_length=4, max_length=4)]] = Field(default=None, description="RGBA four element array with values 0-255.") # data type: str oneof_schema_3_validator: Optional[Annotated[str, Field(min_length=7, strict=True, max_length=7)]] = Field(default=None, description="Hex color string, such as #00FF00.") actual_instance: Optional[Union[List[int], str]] = None - one_of_schemas: List[str] = Literal[COLOR_ONE_OF_SCHEMAS] + one_of_schemas: List[str] = Literal["List[int]", "str"] + + model_config = { + "validate_assignment": True + } - class Config: - validate_assignment = True def __init__(self, *args, **kwargs) -> None: if args: @@ -54,12 +56,12 @@ class Color(BaseModel): else: super().__init__(**kwargs) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): if v is None: return v - instance = Color.construct() + instance = Color.model_construct() error_messages = [] match = 0 # validate data type: List[int] @@ -96,7 +98,7 @@ class Color(BaseModel): @classmethod def from_json(cls, json_str: str) -> Color: """Returns the object represented by the json string""" - instance = Color.construct() + instance = Color.model_construct() if json_str is None: return instance @@ -165,6 +167,6 @@ class Color(BaseModel): def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/creature.py b/samples/openapi3/client/petstore/python/petstore_api/models/creature.py index 16e389db1df..1ed187ed459 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/creature.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/creature.py @@ -31,14 +31,15 @@ class Creature(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["info", "type"] - 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""" @@ -52,7 +53,7 @@ class Creature(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={ "additional_properties" }, @@ -74,9 +75,9 @@ class Creature(BaseModel): return None if not isinstance(obj, dict): - return Creature.parse_obj(obj) + return Creature.model_validate(obj) - _obj = Creature.parse_obj({ + _obj = Creature.model_validate({ "info": CreatureInfo.from_dict(obj.get("info")) if obj.get("info") is not None else None, "type": obj.get("type") }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/creature_info.py b/samples/openapi3/client/petstore/python/petstore_api/models/creature_info.py index 76afde1837c..7c8c9657254 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/creature_info.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/creature_info.py @@ -29,14 +29,15 @@ class CreatureInfo(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["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""" @@ -50,7 +51,7 @@ class CreatureInfo(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={ "additional_properties" }, @@ -69,9 +70,9 @@ class CreatureInfo(BaseModel): return None if not isinstance(obj, dict): - return CreatureInfo.parse_obj(obj) + return CreatureInfo.model_validate(obj) - _obj = CreatureInfo.parse_obj({ + _obj = CreatureInfo.model_validate({ "name": obj.get("name") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/danish_pig.py b/samples/openapi3/client/petstore/python/petstore_api/models/danish_pig.py index 3cd1f2d70a2..6ba8851e8dd 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/danish_pig.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/danish_pig.py @@ -31,14 +31,15 @@ class DanishPig(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["className", "size"] - 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""" @@ -52,7 +53,7 @@ class DanishPig(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={ "additional_properties" }, @@ -71,9 +72,9 @@ class DanishPig(BaseModel): return None if not isinstance(obj, dict): - return DanishPig.parse_obj(obj) + return DanishPig.model_validate(obj) - _obj = DanishPig.parse_obj({ + _obj = DanishPig.model_validate({ "className": obj.get("className"), "size": obj.get("size") }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/deprecated_object.py b/samples/openapi3/client/petstore/python/petstore_api/models/deprecated_object.py index ef03024d963..3a283d11bce 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/deprecated_object.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/deprecated_object.py @@ -29,14 +29,15 @@ class DeprecatedObject(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["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""" @@ -50,7 +51,7 @@ class DeprecatedObject(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={ "additional_properties" }, @@ -69,9 +70,9 @@ class DeprecatedObject(BaseModel): return None if not isinstance(obj, dict): - return DeprecatedObject.parse_obj(obj) + return DeprecatedObject.model_validate(obj) - _obj = DeprecatedObject.parse_obj({ + _obj = DeprecatedObject.model_validate({ "name": obj.get("name") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/dog.py b/samples/openapi3/client/petstore/python/petstore_api/models/dog.py index 78ae72f0403..a6f8a6d23cc 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/dog.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/dog.py @@ -30,14 +30,15 @@ class Dog(Animal): additional_properties: Dict[str, Any] = {} __properties = ["className", "color", "breed"] - 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 Dog(Animal): 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={ "additional_properties" }, @@ -70,9 +71,9 @@ class Dog(Animal): return None if not isinstance(obj, dict): - return Dog.parse_obj(obj) + return Dog.model_validate(obj) - _obj = Dog.parse_obj({ + _obj = Dog.model_validate({ "className": obj.get("className"), "color": obj.get("color") if obj.get("color") is not None else 'red', "breed": obj.get("breed") diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/dummy_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/dummy_model.py index de7b6421243..42bed2afa37 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/dummy_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/dummy_model.py @@ -30,14 +30,15 @@ class DummyModel(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["category", "self_ref"] - 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 DummyModel(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={ "additional_properties" }, @@ -73,9 +74,9 @@ class DummyModel(BaseModel): return None if not isinstance(obj, dict): - return DummyModel.parse_obj(obj) + return DummyModel.model_validate(obj) - _obj = DummyModel.parse_obj({ + _obj = DummyModel.model_validate({ "category": obj.get("category"), "self_ref": SelfReferenceModel.from_dict(obj.get("self_ref")) if obj.get("self_ref") is not None else None }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_arrays.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_arrays.py index 620c94be60b..1af1ef9c00d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_arrays.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_arrays.py @@ -19,7 +19,7 @@ import json from typing import Any, Dict, List, Optional -from pydantic import BaseModel, StrictStr, validator +from pydantic import BaseModel, StrictStr, field_validator class EnumArrays(BaseModel): """ @@ -30,7 +30,7 @@ class EnumArrays(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["just_symbol", "array_enum"] - @validator('just_symbol') + @field_validator('just_symbol') def just_symbol_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -40,7 +40,7 @@ class EnumArrays(BaseModel): raise ValueError("must be one of enum values ('>=', '$')") return value - @validator('array_enum') + @field_validator('array_enum') def array_enum_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -51,14 +51,15 @@ class EnumArrays(BaseModel): raise ValueError("each list item must be one of ('fish', 'crab')") 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""" @@ -72,7 +73,7 @@ class EnumArrays(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={ "additional_properties" }, @@ -91,9 +92,9 @@ class EnumArrays(BaseModel): return None if not isinstance(obj, dict): - return EnumArrays.parse_obj(obj) + return EnumArrays.model_validate(obj) - _obj = EnumArrays.parse_obj({ + _obj = EnumArrays.model_validate({ "just_symbol": obj.get("just_symbol"), "array_enum": obj.get("array_enum") }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py index 9398f6bbc4b..937a10fcc5e 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py @@ -19,7 +19,7 @@ import json from typing import Any, Dict, Optional -from pydantic import BaseModel, StrictFloat, StrictInt, StrictStr, validator +from pydantic import BaseModel, StrictFloat, StrictInt, StrictStr, field_validator from pydantic import Field from petstore_api.models.outer_enum import OuterEnum from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue @@ -42,7 +42,7 @@ class EnumTest(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] - @validator('enum_string') + @field_validator('enum_string') def enum_string_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -52,14 +52,14 @@ class EnumTest(BaseModel): raise ValueError("must be one of enum values ('UPPER', 'lower', '')") return value - @validator('enum_string_required') + @field_validator('enum_string_required') def enum_string_required_validate_enum(cls, value): """Validates the enum""" if value not in ('UPPER', 'lower', ''): raise ValueError("must be one of enum values ('UPPER', 'lower', '')") return value - @validator('enum_integer_default') + @field_validator('enum_integer_default') def enum_integer_default_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -69,7 +69,7 @@ class EnumTest(BaseModel): raise ValueError("must be one of enum values (1, 5, 14)") return value - @validator('enum_integer') + @field_validator('enum_integer') def enum_integer_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -79,7 +79,7 @@ class EnumTest(BaseModel): raise ValueError("must be one of enum values (1, -1)") return value - @validator('enum_number') + @field_validator('enum_number') def enum_number_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -89,14 +89,15 @@ class EnumTest(BaseModel): raise ValueError("must be one of enum values (1.1, -1.2)") 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""" @@ -110,7 +111,7 @@ class EnumTest(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={ "additional_properties" }, @@ -121,8 +122,8 @@ class EnumTest(BaseModel): _dict[_key] = _value # set to None if outer_enum (nullable) is None - # and __fields_set__ contains the field - if self.outer_enum is None and "outer_enum" in self.__fields_set__: + # and model_fields_set contains the field + if self.outer_enum is None and "outer_enum" in self.model_fields_set: _dict['outerEnum'] = None return _dict @@ -134,9 +135,9 @@ class EnumTest(BaseModel): return None if not isinstance(obj, dict): - return EnumTest.parse_obj(obj) + return EnumTest.model_validate(obj) - _obj = EnumTest.parse_obj({ + _obj = EnumTest.model_validate({ "enum_string": obj.get("enum_string"), "enum_string_required": obj.get("enum_string_required"), "enum_integer_default": obj.get("enum_integer_default") if obj.get("enum_integer_default") is not None else 5, diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/file.py b/samples/openapi3/client/petstore/python/petstore_api/models/file.py index 114b01da18f..80b1564e58f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/file.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/file.py @@ -30,14 +30,15 @@ class File(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["sourceURI"] - 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 File(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={ "additional_properties" }, @@ -70,9 +71,9 @@ class File(BaseModel): return None if not isinstance(obj, dict): - return File.parse_obj(obj) + return File.model_validate(obj) - _obj = File.parse_obj({ + _obj = File.model_validate({ "sourceURI": obj.get("sourceURI") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py index 517980f5f44..030d9f29edb 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py @@ -31,14 +31,15 @@ class FileSchemaTestClass(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["file", "files"] - 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""" @@ -52,7 +53,7 @@ class FileSchemaTestClass(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={ "additional_properties" }, @@ -81,9 +82,9 @@ class FileSchemaTestClass(BaseModel): return None if not isinstance(obj, dict): - return FileSchemaTestClass.parse_obj(obj) + return FileSchemaTestClass.model_validate(obj) - _obj = FileSchemaTestClass.parse_obj({ + _obj = FileSchemaTestClass.model_validate({ "file": File.from_dict(obj.get("file")) if obj.get("file") is not None else None, "files": [File.from_dict(_item) for _item in obj.get("files")] if obj.get("files") is not None else None }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/first_ref.py b/samples/openapi3/client/petstore/python/petstore_api/models/first_ref.py index 070aa2b5777..900034234a4 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/first_ref.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/first_ref.py @@ -30,14 +30,15 @@ class FirstRef(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["category", "self_ref"] - 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 FirstRef(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={ "additional_properties" }, @@ -73,9 +74,9 @@ class FirstRef(BaseModel): return None if not isinstance(obj, dict): - return FirstRef.parse_obj(obj) + return FirstRef.model_validate(obj) - _obj = FirstRef.parse_obj({ + _obj = FirstRef.model_validate({ "category": obj.get("category"), "self_ref": SecondRef.from_dict(obj.get("self_ref")) if obj.get("self_ref") is not None else None }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/foo.py b/samples/openapi3/client/petstore/python/petstore_api/models/foo.py index 89fede0ee27..cacb692da0c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/foo.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/foo.py @@ -29,14 +29,15 @@ class Foo(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["bar"] - 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 Foo(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={ "additional_properties" }, @@ -69,9 +70,9 @@ class Foo(BaseModel): return None if not isinstance(obj, dict): - return Foo.parse_obj(obj) + return Foo.model_validate(obj) - _obj = Foo.parse_obj({ + _obj = Foo.model_validate({ "bar": obj.get("bar") if obj.get("bar") is not None else 'bar' }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/foo_get_default_response.py b/samples/openapi3/client/petstore/python/petstore_api/models/foo_get_default_response.py index 006d85181ae..ac6ef75e60b 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/foo_get_default_response.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/foo_get_default_response.py @@ -30,14 +30,15 @@ class FooGetDefaultResponse(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["string"] - 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 FooGetDefaultResponse(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={ "additional_properties" }, @@ -73,9 +74,9 @@ class FooGetDefaultResponse(BaseModel): return None if not isinstance(obj, dict): - return FooGetDefaultResponse.parse_obj(obj) + return FooGetDefaultResponse.model_validate(obj) - _obj = FooGetDefaultResponse.parse_obj({ + _obj = FooGetDefaultResponse.model_validate({ "string": Foo.from_dict(obj.get("string")) if obj.get("string") is not None else None }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/format_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/format_test.py index 06392e44329..e383796a98f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/format_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/format_test.py @@ -19,7 +19,7 @@ import json from datetime import date, datetime from typing import Any, Dict, Optional, Union -from pydantic import BaseModel, StrictBytes, StrictInt, StrictStr, validator +from pydantic import BaseModel, StrictBytes, StrictInt, StrictStr, field_validator from decimal import Decimal from pydantic import Field from typing_extensions import Annotated @@ -47,7 +47,7 @@ class FormatTest(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["integer", "int32", "int64", "number", "double", "decimal", "string", "string_with_double_quote_pattern", "byte", "binary", "date", "dateTime", "uuid", "password", "pattern_with_digits", "pattern_with_digits_and_delimiter"] - @validator('string') + @field_validator('string') def string_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -57,7 +57,7 @@ class FormatTest(BaseModel): raise ValueError(r"must validate the regular expression /[a-z]/i") return value - @validator('string_with_double_quote_pattern') + @field_validator('string_with_double_quote_pattern') def string_with_double_quote_pattern_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -67,7 +67,7 @@ class FormatTest(BaseModel): raise ValueError(r"must validate the regular expression /this is \"something\"/") return value - @validator('pattern_with_digits') + @field_validator('pattern_with_digits') def pattern_with_digits_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -77,7 +77,7 @@ class FormatTest(BaseModel): raise ValueError(r"must validate the regular expression /^\d{10}$/") return value - @validator('pattern_with_digits_and_delimiter') + @field_validator('pattern_with_digits_and_delimiter') def pattern_with_digits_and_delimiter_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -87,14 +87,15 @@ class FormatTest(BaseModel): raise ValueError(r"must validate the regular expression /^image_\d{1,3}$/i") 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""" @@ -108,7 +109,7 @@ class FormatTest(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={ "additional_properties" }, @@ -127,9 +128,9 @@ class FormatTest(BaseModel): return None if not isinstance(obj, dict): - return FormatTest.parse_obj(obj) + return FormatTest.model_validate(obj) - _obj = FormatTest.parse_obj({ + _obj = FormatTest.model_validate({ "integer": obj.get("integer"), "int32": obj.get("int32"), "int64": obj.get("int64"), diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/has_only_read_only.py b/samples/openapi3/client/petstore/python/petstore_api/models/has_only_read_only.py index e0612dbaab2..50af5287e1a 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/has_only_read_only.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/has_only_read_only.py @@ -30,14 +30,15 @@ class HasOnlyReadOnly(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["bar", "foo"] - 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 HasOnlyReadOnly(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={ "bar", "foo", @@ -72,9 +73,9 @@ class HasOnlyReadOnly(BaseModel): return None if not isinstance(obj, dict): - return HasOnlyReadOnly.parse_obj(obj) + return HasOnlyReadOnly.model_validate(obj) - _obj = HasOnlyReadOnly.parse_obj({ + _obj = HasOnlyReadOnly.model_validate({ "bar": obj.get("bar"), "foo": obj.get("foo") }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/health_check_result.py b/samples/openapi3/client/petstore/python/petstore_api/models/health_check_result.py index 97ea8c9e8b4..bcb06ace99c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/health_check_result.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/health_check_result.py @@ -30,14 +30,15 @@ class HealthCheckResult(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["NullableMessage"] - 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 HealthCheckResult(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={ "additional_properties" }, @@ -62,8 +63,8 @@ class HealthCheckResult(BaseModel): _dict[_key] = _value # set to None if nullable_message (nullable) is None - # and __fields_set__ contains the field - if self.nullable_message is None and "nullable_message" in self.__fields_set__: + # and model_fields_set contains the field + if self.nullable_message is None and "nullable_message" in self.model_fields_set: _dict['NullableMessage'] = None return _dict @@ -75,9 +76,9 @@ class HealthCheckResult(BaseModel): return None if not isinstance(obj, dict): - return HealthCheckResult.parse_obj(obj) + return HealthCheckResult.model_validate(obj) - _obj = HealthCheckResult.parse_obj({ + _obj = HealthCheckResult.model_validate({ "NullableMessage": obj.get("NullableMessage") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/inner_dict_with_property.py b/samples/openapi3/client/petstore/python/petstore_api/models/inner_dict_with_property.py index 56ba5121158..e53b2401dd7 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/inner_dict_with_property.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/inner_dict_with_property.py @@ -30,14 +30,15 @@ class InnerDictWithProperty(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["aProperty"] - 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 InnerDictWithProperty(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={ "additional_properties" }, @@ -70,9 +71,9 @@ class InnerDictWithProperty(BaseModel): return None if not isinstance(obj, dict): - return InnerDictWithProperty.parse_obj(obj) + return InnerDictWithProperty.model_validate(obj) - _obj = InnerDictWithProperty.parse_obj({ + _obj = InnerDictWithProperty.model_validate({ "aProperty": obj.get("aProperty") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/int_or_string.py b/samples/openapi3/client/petstore/python/petstore_api/models/int_or_string.py index a292b747c56..0fb43ecaebb 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/int_or_string.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/int_or_string.py @@ -19,7 +19,7 @@ import pprint import re # noqa: F401 from typing import Any, List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from pydantic import Field from typing_extensions import Annotated from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict @@ -37,10 +37,12 @@ class IntOrString(BaseModel): # data type: str oneof_schema_2_validator: Optional[StrictStr] = None actual_instance: Optional[Union[int, str]] = None - one_of_schemas: List[str] = Literal[INTORSTRING_ONE_OF_SCHEMAS] + one_of_schemas: List[str] = Literal["int", "str"] + + model_config = { + "validate_assignment": True + } - class Config: - validate_assignment = True def __init__(self, *args, **kwargs) -> None: if args: @@ -52,9 +54,9 @@ class IntOrString(BaseModel): else: super().__init__(**kwargs) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): - instance = IntOrString.construct() + instance = IntOrString.model_construct() error_messages = [] match = 0 # validate data type: int @@ -85,7 +87,7 @@ class IntOrString(BaseModel): @classmethod def from_json(cls, json_str: str) -> IntOrString: """Returns the object represented by the json string""" - instance = IntOrString.construct() + instance = IntOrString.model_construct() error_messages = [] match = 0 @@ -142,6 +144,6 @@ class IntOrString(BaseModel): def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/list.py b/samples/openapi3/client/petstore/python/petstore_api/models/list.py index 80236c059e6..2d1ca0f6cff 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/list.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/list.py @@ -30,14 +30,15 @@ class List(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["123-list"] - 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 List(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={ "additional_properties" }, @@ -70,9 +71,9 @@ class List(BaseModel): return None if not isinstance(obj, dict): - return List.parse_obj(obj) + return List.model_validate(obj) - _obj = List.parse_obj({ + _obj = List.model_validate({ "123-list": obj.get("123-list") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py index eeece98926e..f33be2c87f4 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py @@ -31,14 +31,15 @@ class MapOfArrayOfModel(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["shopIdToOrgOnlineLipMap"] - 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""" @@ -52,7 +53,7 @@ class MapOfArrayOfModel(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={ "additional_properties" }, @@ -80,9 +81,9 @@ class MapOfArrayOfModel(BaseModel): return None if not isinstance(obj, dict): - return MapOfArrayOfModel.parse_obj(obj) + return MapOfArrayOfModel.model_validate(obj) - _obj = MapOfArrayOfModel.parse_obj({ + _obj = MapOfArrayOfModel.model_validate({ "shopIdToOrgOnlineLipMap": dict( (_k, [Tag.from_dict(_item) for _item in _v] diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py index d34257aa996..e08eb788b98 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py @@ -19,7 +19,7 @@ import json from typing import Any, Dict, Optional -from pydantic import BaseModel, StrictBool, StrictStr, validator +from pydantic import BaseModel, StrictBool, StrictStr, field_validator class MapTest(BaseModel): """ @@ -32,7 +32,7 @@ class MapTest(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["map_map_of_string", "map_of_enum_string", "direct_map", "indirect_map"] - @validator('map_of_enum_string') + @field_validator('map_of_enum_string') def map_of_enum_string_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -42,14 +42,15 @@ class MapTest(BaseModel): raise ValueError("must be one of enum values ('UPPER', 'lower')") 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 MapTest(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={ "additional_properties" }, @@ -82,9 +83,9 @@ class MapTest(BaseModel): return None if not isinstance(obj, dict): - return MapTest.parse_obj(obj) + return MapTest.model_validate(obj) - _obj = MapTest.parse_obj({ + _obj = MapTest.model_validate({ "map_map_of_string": obj.get("map_map_of_string"), "map_of_enum_string": obj.get("map_of_enum_string"), "direct_map": obj.get("direct_map"), diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py index 901935866db..fba7f02172a 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -33,14 +33,15 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["uuid", "dateTime", "map"] - 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 MixedPropertiesAndAdditionalPropertiesClass(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={ "additional_properties" }, @@ -80,9 +81,9 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): return None if not isinstance(obj, dict): - return MixedPropertiesAndAdditionalPropertiesClass.parse_obj(obj) + return MixedPropertiesAndAdditionalPropertiesClass.model_validate(obj) - _obj = MixedPropertiesAndAdditionalPropertiesClass.parse_obj({ + _obj = MixedPropertiesAndAdditionalPropertiesClass.model_validate({ "uuid": obj.get("uuid"), "dateTime": obj.get("dateTime"), "map": dict( diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/model200_response.py b/samples/openapi3/client/petstore/python/petstore_api/models/model200_response.py index ddc1f9f9619..f5818228991 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/model200_response.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/model200_response.py @@ -31,14 +31,15 @@ class Model200Response(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["name", "class"] - 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""" @@ -52,7 +53,7 @@ class Model200Response(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={ "additional_properties" }, @@ -71,9 +72,9 @@ class Model200Response(BaseModel): return None if not isinstance(obj, dict): - return Model200Response.parse_obj(obj) + return Model200Response.model_validate(obj) - _obj = Model200Response.parse_obj({ + _obj = Model200Response.model_validate({ "name": obj.get("name"), "class": obj.get("class") }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/model_return.py b/samples/openapi3/client/petstore/python/petstore_api/models/model_return.py index 3d9922adcf7..d39ad5cb6bd 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/model_return.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/model_return.py @@ -30,14 +30,15 @@ class ModelReturn(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["return"] - 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 ModelReturn(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={ "additional_properties" }, @@ -70,9 +71,9 @@ class ModelReturn(BaseModel): return None if not isinstance(obj, dict): - return ModelReturn.parse_obj(obj) + return ModelReturn.model_validate(obj) - _obj = ModelReturn.parse_obj({ + _obj = ModelReturn.model_validate({ "return": obj.get("return") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/name.py b/samples/openapi3/client/petstore/python/petstore_api/models/name.py index 8f2e407b7d1..5b473903729 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/name.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/name.py @@ -33,14 +33,15 @@ class Name(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["name", "snake_case", "property", "123Number"] - 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 Name(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={ "snake_case", "var_123_number", @@ -75,9 +76,9 @@ class Name(BaseModel): return None if not isinstance(obj, dict): - return Name.parse_obj(obj) + return Name.model_validate(obj) - _obj = Name.parse_obj({ + _obj = Name.model_validate({ "name": obj.get("name"), "snake_case": obj.get("snake_case"), "property": obj.get("property"), diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py index bc6e96d321f..4c46cc2ae23 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py @@ -41,14 +41,15 @@ class NullableClass(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["required_integer_prop", "integer_prop", "number_prop", "boolean_prop", "string_prop", "date_prop", "datetime_prop", "array_nullable_prop", "array_and_items_nullable_prop", "array_items_nullable", "object_nullable_prop", "object_and_items_nullable_prop", "object_items_nullable"] - 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""" @@ -62,7 +63,7 @@ class NullableClass(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={ "additional_properties" }, @@ -73,58 +74,58 @@ class NullableClass(BaseModel): _dict[_key] = _value # set to None if required_integer_prop (nullable) is None - # and __fields_set__ contains the field - if self.required_integer_prop is None and "required_integer_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.required_integer_prop is None and "required_integer_prop" in self.model_fields_set: _dict['required_integer_prop'] = None # set to None if integer_prop (nullable) is None - # and __fields_set__ contains the field - if self.integer_prop is None and "integer_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.integer_prop is None and "integer_prop" in self.model_fields_set: _dict['integer_prop'] = None # set to None if number_prop (nullable) is None - # and __fields_set__ contains the field - if self.number_prop is None and "number_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.number_prop is None and "number_prop" in self.model_fields_set: _dict['number_prop'] = None # set to None if boolean_prop (nullable) is None - # and __fields_set__ contains the field - if self.boolean_prop is None and "boolean_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.boolean_prop is None and "boolean_prop" in self.model_fields_set: _dict['boolean_prop'] = None # set to None if string_prop (nullable) is None - # and __fields_set__ contains the field - if self.string_prop is None and "string_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.string_prop is None and "string_prop" in self.model_fields_set: _dict['string_prop'] = None # set to None if date_prop (nullable) is None - # and __fields_set__ contains the field - if self.date_prop is None and "date_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.date_prop is None and "date_prop" in self.model_fields_set: _dict['date_prop'] = None # set to None if datetime_prop (nullable) is None - # and __fields_set__ contains the field - if self.datetime_prop is None and "datetime_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.datetime_prop is None and "datetime_prop" in self.model_fields_set: _dict['datetime_prop'] = None # set to None if array_nullable_prop (nullable) is None - # and __fields_set__ contains the field - if self.array_nullable_prop is None and "array_nullable_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.array_nullable_prop is None and "array_nullable_prop" in self.model_fields_set: _dict['array_nullable_prop'] = None # set to None if array_and_items_nullable_prop (nullable) is None - # and __fields_set__ contains the field - if self.array_and_items_nullable_prop is None and "array_and_items_nullable_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.array_and_items_nullable_prop is None and "array_and_items_nullable_prop" in self.model_fields_set: _dict['array_and_items_nullable_prop'] = None # set to None if object_nullable_prop (nullable) is None - # and __fields_set__ contains the field - if self.object_nullable_prop is None and "object_nullable_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.object_nullable_prop is None and "object_nullable_prop" in self.model_fields_set: _dict['object_nullable_prop'] = None # set to None if object_and_items_nullable_prop (nullable) is None - # and __fields_set__ contains the field - if self.object_and_items_nullable_prop is None and "object_and_items_nullable_prop" in self.__fields_set__: + # and model_fields_set contains the field + if self.object_and_items_nullable_prop is None and "object_and_items_nullable_prop" in self.model_fields_set: _dict['object_and_items_nullable_prop'] = None return _dict @@ -136,9 +137,9 @@ class NullableClass(BaseModel): return None if not isinstance(obj, dict): - return NullableClass.parse_obj(obj) + return NullableClass.model_validate(obj) - _obj = NullableClass.parse_obj({ + _obj = NullableClass.model_validate({ "required_integer_prop": obj.get("required_integer_prop"), "integer_prop": obj.get("integer_prop"), "number_prop": obj.get("number_prop"), diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/nullable_property.py b/samples/openapi3/client/petstore/python/petstore_api/models/nullable_property.py index 008daec1b4d..9feb0a3f0a0 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/nullable_property.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/nullable_property.py @@ -19,7 +19,7 @@ import json from typing import Any, Dict, Optional -from pydantic import BaseModel, StrictInt, validator +from pydantic import BaseModel, StrictInt, field_validator from pydantic import Field from typing_extensions import Annotated @@ -32,7 +32,7 @@ class NullableProperty(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["id", "name"] - @validator('name') + @field_validator('name') def name_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -42,14 +42,15 @@ class NullableProperty(BaseModel): raise ValueError(r"must validate the regular expression /^[A-Z].*/") 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 NullableProperty(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={ "additional_properties" }, @@ -74,8 +75,8 @@ class NullableProperty(BaseModel): _dict[_key] = _value # set to None if name (nullable) is None - # and __fields_set__ contains the field - if self.name is None and "name" in self.__fields_set__: + # and model_fields_set contains the field + if self.name is None and "name" in self.model_fields_set: _dict['name'] = None return _dict @@ -87,9 +88,9 @@ class NullableProperty(BaseModel): return None if not isinstance(obj, dict): - return NullableProperty.parse_obj(obj) + return NullableProperty.model_validate(obj) - _obj = NullableProperty.parse_obj({ + _obj = NullableProperty.model_validate({ "id": obj.get("id"), "name": obj.get("name") }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/number_only.py b/samples/openapi3/client/petstore/python/petstore_api/models/number_only.py index 0885acb8432..845ec245db6 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/number_only.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/number_only.py @@ -30,14 +30,15 @@ class NumberOnly(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["JustNumber"] - 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 NumberOnly(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={ "additional_properties" }, @@ -70,9 +71,9 @@ class NumberOnly(BaseModel): return None if not isinstance(obj, dict): - return NumberOnly.parse_obj(obj) + return NumberOnly.model_validate(obj) - _obj = NumberOnly.parse_obj({ + _obj = NumberOnly.model_validate({ "JustNumber": obj.get("JustNumber") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/object_to_test_additional_properties.py b/samples/openapi3/client/petstore/python/petstore_api/models/object_to_test_additional_properties.py index 2d89ae37c46..30d264be3ac 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/object_to_test_additional_properties.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/object_to_test_additional_properties.py @@ -30,14 +30,15 @@ class ObjectToTestAdditionalProperties(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["property"] - 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 ObjectToTestAdditionalProperties(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={ "additional_properties" }, @@ -70,9 +71,9 @@ class ObjectToTestAdditionalProperties(BaseModel): return None if not isinstance(obj, dict): - return ObjectToTestAdditionalProperties.parse_obj(obj) + return ObjectToTestAdditionalProperties.model_validate(obj) - _obj = ObjectToTestAdditionalProperties.parse_obj({ + _obj = ObjectToTestAdditionalProperties.model_validate({ "property": obj.get("property") if obj.get("property") is not None else False }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/object_with_deprecated_fields.py b/samples/openapi3/client/petstore/python/petstore_api/models/object_with_deprecated_fields.py index 736478dc831..a37a6415a92 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/object_with_deprecated_fields.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/object_with_deprecated_fields.py @@ -34,14 +34,15 @@ class ObjectWithDeprecatedFields(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["uuid", "id", "deprecatedRef", "bars"] - 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""" @@ -55,7 +56,7 @@ class ObjectWithDeprecatedFields(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={ "additional_properties" }, @@ -77,9 +78,9 @@ class ObjectWithDeprecatedFields(BaseModel): return None if not isinstance(obj, dict): - return ObjectWithDeprecatedFields.parse_obj(obj) + return ObjectWithDeprecatedFields.model_validate(obj) - _obj = ObjectWithDeprecatedFields.parse_obj({ + _obj = ObjectWithDeprecatedFields.model_validate({ "uuid": obj.get("uuid"), "id": obj.get("id"), "deprecatedRef": DeprecatedObject.from_dict(obj.get("deprecatedRef")) if obj.get("deprecatedRef") is not None else None, diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/one_of_enum_string.py b/samples/openapi3/client/petstore/python/petstore_api/models/one_of_enum_string.py index dfc27aa8820..65067fe7620 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/one_of_enum_string.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/one_of_enum_string.py @@ -19,7 +19,7 @@ import pprint import re # noqa: F401 from typing import Any, List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from petstore_api.models.enum_string1 import EnumString1 from petstore_api.models.enum_string2 import EnumString2 from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict @@ -37,10 +37,12 @@ class OneOfEnumString(BaseModel): # data type: EnumString2 oneof_schema_2_validator: Optional[EnumString2] = None actual_instance: Optional[Union[EnumString1, EnumString2]] = None - one_of_schemas: List[str] = Literal[ONEOFENUMSTRING_ONE_OF_SCHEMAS] + one_of_schemas: List[str] = Literal["EnumString1", "EnumString2"] + + model_config = { + "validate_assignment": True + } - class Config: - validate_assignment = True def __init__(self, *args, **kwargs) -> None: if args: @@ -52,9 +54,9 @@ class OneOfEnumString(BaseModel): else: super().__init__(**kwargs) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): - instance = OneOfEnumString.construct() + instance = OneOfEnumString.model_construct() error_messages = [] match = 0 # validate data type: EnumString1 @@ -83,7 +85,7 @@ class OneOfEnumString(BaseModel): @classmethod def from_json(cls, json_str: str) -> OneOfEnumString: """Returns the object represented by the json string""" - instance = OneOfEnumString.construct() + instance = OneOfEnumString.model_construct() error_messages = [] match = 0 @@ -134,6 +136,6 @@ class OneOfEnumString(BaseModel): def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/order.py b/samples/openapi3/client/petstore/python/petstore_api/models/order.py index e5386fd01eb..9a082803f8c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/order.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/order.py @@ -19,7 +19,7 @@ import json from datetime import datetime from typing import Any, Dict, Optional -from pydantic import BaseModel, StrictBool, StrictInt, StrictStr, validator +from pydantic import BaseModel, StrictBool, StrictInt, StrictStr, field_validator from pydantic import Field class Order(BaseModel): @@ -35,7 +35,7 @@ class Order(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["id", "petId", "quantity", "shipDate", "status", "complete"] - @validator('status') + @field_validator('status') def status_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -45,14 +45,15 @@ class Order(BaseModel): raise ValueError("must be one of enum values ('placed', 'approved', 'delivered')") 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""" @@ -66,7 +67,7 @@ class Order(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={ "additional_properties" }, @@ -85,9 +86,9 @@ class Order(BaseModel): return None if not isinstance(obj, dict): - return Order.parse_obj(obj) + return Order.model_validate(obj) - _obj = Order.parse_obj({ + _obj = Order.model_validate({ "id": obj.get("id"), "petId": obj.get("petId"), "quantity": obj.get("quantity"), diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_composite.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_composite.py index 30f3280d281..5b85be74ab9 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_composite.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_composite.py @@ -31,14 +31,15 @@ class OuterComposite(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["my_number", "my_string", "my_boolean"] - 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""" @@ -52,7 +53,7 @@ class OuterComposite(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={ "additional_properties" }, @@ -71,9 +72,9 @@ class OuterComposite(BaseModel): return None if not isinstance(obj, dict): - return OuterComposite.parse_obj(obj) + return OuterComposite.model_validate(obj) - _obj = OuterComposite.parse_obj({ + _obj = OuterComposite.model_validate({ "my_number": obj.get("my_number"), "my_string": obj.get("my_string"), "my_boolean": obj.get("my_boolean") diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_object_with_enum_property.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_object_with_enum_property.py index b8f15909e72..fe073e3cc8c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_object_with_enum_property.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_object_with_enum_property.py @@ -32,14 +32,15 @@ class OuterObjectWithEnumProperty(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["str_value", "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""" @@ -53,7 +54,7 @@ class OuterObjectWithEnumProperty(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={ "additional_properties" }, @@ -64,8 +65,8 @@ class OuterObjectWithEnumProperty(BaseModel): _dict[_key] = _value # set to None if str_value (nullable) is None - # and __fields_set__ contains the field - if self.str_value is None and "str_value" in self.__fields_set__: + # and model_fields_set contains the field + if self.str_value is None and "str_value" in self.model_fields_set: _dict['str_value'] = None return _dict @@ -77,9 +78,9 @@ class OuterObjectWithEnumProperty(BaseModel): return None if not isinstance(obj, dict): - return OuterObjectWithEnumProperty.parse_obj(obj) + return OuterObjectWithEnumProperty.model_validate(obj) - _obj = OuterObjectWithEnumProperty.parse_obj({ + _obj = OuterObjectWithEnumProperty.model_validate({ "str_value": obj.get("str_value"), "value": obj.get("value") }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/parent.py b/samples/openapi3/client/petstore/python/petstore_api/models/parent.py index 4df17374dc1..3f92a9bdc3d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/parent.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/parent.py @@ -31,14 +31,15 @@ class Parent(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["optionalDict"] - 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""" @@ -52,7 +53,7 @@ class Parent(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={ "additional_properties" }, @@ -78,9 +79,9 @@ class Parent(BaseModel): return None if not isinstance(obj, dict): - return Parent.parse_obj(obj) + return Parent.model_validate(obj) - _obj = Parent.parse_obj({ + _obj = Parent.model_validate({ "optionalDict": dict( (_k, InnerDictWithProperty.from_dict(_v)) for _k, _v in obj.get("optionalDict").items() diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/parent_with_optional_dict.py b/samples/openapi3/client/petstore/python/petstore_api/models/parent_with_optional_dict.py index 902c2558f1c..54f687f1ea2 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/parent_with_optional_dict.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/parent_with_optional_dict.py @@ -31,14 +31,15 @@ class ParentWithOptionalDict(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["optionalDict"] - 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""" @@ -52,7 +53,7 @@ class ParentWithOptionalDict(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={ "additional_properties" }, @@ -78,9 +79,9 @@ class ParentWithOptionalDict(BaseModel): return None if not isinstance(obj, dict): - return ParentWithOptionalDict.parse_obj(obj) + return ParentWithOptionalDict.model_validate(obj) - _obj = ParentWithOptionalDict.parse_obj({ + _obj = ParentWithOptionalDict.model_validate({ "optionalDict": dict( (_k, InnerDictWithProperty.from_dict(_v)) for _k, _v in obj.get("optionalDict").items() diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/pet.py b/samples/openapi3/client/petstore/python/petstore_api/models/pet.py index 6242c5ead08..d79d9c94df5 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/pet.py @@ -19,7 +19,7 @@ import json from typing import Any, Dict, List, Optional -from pydantic import BaseModel, StrictInt, StrictStr, validator +from pydantic import BaseModel, StrictInt, StrictStr, field_validator from pydantic import Field from typing_extensions import Annotated from petstore_api.models.category import Category @@ -32,13 +32,13 @@ class Pet(BaseModel): id: Optional[StrictInt] = None category: Optional[Category] = None name: StrictStr - photo_urls: Annotated[List[StrictStr], Field(min_items=0)] = Field(alias="photoUrls") + photo_urls: Annotated[List[StrictStr], Field(min_length=0)] = Field(alias="photoUrls") tags: Optional[List[Tag]] = None status: Optional[StrictStr] = Field(default=None, description="pet status in the store") additional_properties: Dict[str, Any] = {} __properties = ["id", "category", "name", "photoUrls", "tags", "status"] - @validator('status') + @field_validator('status') def status_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -48,14 +48,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""" @@ -69,7 +70,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={ "additional_properties" }, @@ -98,9 +99,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"), "category": Category.from_dict(obj.get("category")) if obj.get("category") is not None else None, "name": obj.get("name"), diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/pig.py b/samples/openapi3/client/petstore/python/petstore_api/models/pig.py index d8c2fccc909..341a4aed0f5 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/pig.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/pig.py @@ -19,7 +19,7 @@ import pprint import re # noqa: F401 from typing import Any, List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict @@ -37,10 +37,12 @@ class Pig(BaseModel): # data type: DanishPig oneof_schema_2_validator: Optional[DanishPig] = None actual_instance: Optional[Union[BasquePig, DanishPig]] = None - one_of_schemas: List[str] = Literal[PIG_ONE_OF_SCHEMAS] + one_of_schemas: List[str] = Literal["BasquePig", "DanishPig"] + + model_config = { + "validate_assignment": True + } - class Config: - validate_assignment = True discriminator_value_class_map: Dict[str, str] = { } @@ -55,9 +57,9 @@ class Pig(BaseModel): else: super().__init__(**kwargs) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): - instance = Pig.construct() + instance = Pig.model_construct() error_messages = [] match = 0 # validate data type: BasquePig @@ -86,7 +88,7 @@ class Pig(BaseModel): @classmethod def from_json(cls, json_str: str) -> Pig: """Returns the object represented by the json string""" - instance = Pig.construct() + instance = Pig.model_construct() error_messages = [] match = 0 @@ -152,6 +154,6 @@ class Pig(BaseModel): def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/property_name_collision.py b/samples/openapi3/client/petstore/python/petstore_api/models/property_name_collision.py index 96bfc4f51bd..78d9f97a026 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/property_name_collision.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/property_name_collision.py @@ -32,14 +32,15 @@ class PropertyNameCollision(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["_type", "type", "type_"] - 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 PropertyNameCollision(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={ "additional_properties" }, @@ -72,9 +73,9 @@ class PropertyNameCollision(BaseModel): return None if not isinstance(obj, dict): - return PropertyNameCollision.parse_obj(obj) + return PropertyNameCollision.model_validate(obj) - _obj = PropertyNameCollision.parse_obj({ + _obj = PropertyNameCollision.model_validate({ "_type": obj.get("_type"), "type": obj.get("type"), "type_": obj.get("type_") diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/read_only_first.py b/samples/openapi3/client/petstore/python/petstore_api/models/read_only_first.py index c5d5c86c59f..581ecdf7b54 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/read_only_first.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/read_only_first.py @@ -30,14 +30,15 @@ class ReadOnlyFirst(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["bar", "baz"] - 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 ReadOnlyFirst(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={ "bar", "additional_properties" @@ -71,9 +72,9 @@ class ReadOnlyFirst(BaseModel): return None if not isinstance(obj, dict): - return ReadOnlyFirst.parse_obj(obj) + return ReadOnlyFirst.model_validate(obj) - _obj = ReadOnlyFirst.parse_obj({ + _obj = ReadOnlyFirst.model_validate({ "bar": obj.get("bar"), "baz": obj.get("baz") }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/second_ref.py b/samples/openapi3/client/petstore/python/petstore_api/models/second_ref.py index 2ce53c5f923..286f39e4ae4 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/second_ref.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/second_ref.py @@ -30,14 +30,15 @@ class SecondRef(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["category", "circular_ref"] - 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 SecondRef(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={ "additional_properties" }, @@ -73,9 +74,9 @@ class SecondRef(BaseModel): return None if not isinstance(obj, dict): - return SecondRef.parse_obj(obj) + return SecondRef.model_validate(obj) - _obj = SecondRef.parse_obj({ + _obj = SecondRef.model_validate({ "category": obj.get("category"), "circular_ref": CircularReferenceModel.from_dict(obj.get("circular_ref")) if obj.get("circular_ref") is not None else None }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/self_reference_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/self_reference_model.py index 9c5faa62f8c..e1c51a1f23e 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/self_reference_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/self_reference_model.py @@ -30,14 +30,15 @@ class SelfReferenceModel(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["size", "nested"] - 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 SelfReferenceModel(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={ "additional_properties" }, @@ -73,9 +74,9 @@ class SelfReferenceModel(BaseModel): return None if not isinstance(obj, dict): - return SelfReferenceModel.parse_obj(obj) + return SelfReferenceModel.model_validate(obj) - _obj = SelfReferenceModel.parse_obj({ + _obj = SelfReferenceModel.model_validate({ "size": obj.get("size"), "nested": DummyModel.from_dict(obj.get("nested")) if obj.get("nested") is not None else None }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/special_model_name.py b/samples/openapi3/client/petstore/python/petstore_api/models/special_model_name.py index e2d87179a94..0cc61ec6bc3 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/special_model_name.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/special_model_name.py @@ -30,14 +30,15 @@ class SpecialModelName(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["$special[property.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 SpecialModelName(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={ "additional_properties" }, @@ -70,9 +71,9 @@ class SpecialModelName(BaseModel): return None if not isinstance(obj, dict): - return SpecialModelName.parse_obj(obj) + return SpecialModelName.model_validate(obj) - _obj = SpecialModelName.parse_obj({ + _obj = SpecialModelName.model_validate({ "$special[property.name]": obj.get("$special[property.name]") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/special_name.py b/samples/openapi3/client/petstore/python/petstore_api/models/special_name.py index 3f7f6247b0c..d44d2f4fb80 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/special_name.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/special_name.py @@ -19,7 +19,7 @@ import json from typing import Any, Dict, Optional -from pydantic import BaseModel, StrictInt, StrictStr, validator +from pydantic import BaseModel, StrictInt, StrictStr, field_validator from pydantic import Field from petstore_api.models.category import Category @@ -33,7 +33,7 @@ class SpecialName(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["property", "async", "schema"] - @validator('var_schema') + @field_validator('var_schema') def var_schema_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -43,14 +43,15 @@ class SpecialName(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""" @@ -64,7 +65,7 @@ class SpecialName(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={ "additional_properties" }, @@ -86,9 +87,9 @@ class SpecialName(BaseModel): return None if not isinstance(obj, dict): - return SpecialName.parse_obj(obj) + return SpecialName.model_validate(obj) - _obj = SpecialName.parse_obj({ + _obj = SpecialName.model_validate({ "property": obj.get("property"), "async": Category.from_dict(obj.get("async")) if obj.get("async") is not None else None, "schema": obj.get("schema") diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/tag.py b/samples/openapi3/client/petstore/python/petstore_api/models/tag.py index fcd5a0e716d..37837197808 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/tag.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/tag.py @@ -30,14 +30,15 @@ class Tag(BaseModel): additional_properties: Dict[str, Any] = {} __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={ "additional_properties" }, @@ -70,9 +71,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") }) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/test_inline_freeform_additional_properties_request.py b/samples/openapi3/client/petstore/python/petstore_api/models/test_inline_freeform_additional_properties_request.py index b7606b510af..1ced9efa5f8 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/test_inline_freeform_additional_properties_request.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/test_inline_freeform_additional_properties_request.py @@ -30,14 +30,15 @@ class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["someProperty"] - 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 TestInlineFreeformAdditionalPropertiesRequest(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={ "additional_properties" }, @@ -70,9 +71,9 @@ class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): return None if not isinstance(obj, dict): - return TestInlineFreeformAdditionalPropertiesRequest.parse_obj(obj) + return TestInlineFreeformAdditionalPropertiesRequest.model_validate(obj) - _obj = TestInlineFreeformAdditionalPropertiesRequest.parse_obj({ + _obj = TestInlineFreeformAdditionalPropertiesRequest.model_validate({ "someProperty": obj.get("someProperty") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/tiger.py b/samples/openapi3/client/petstore/python/petstore_api/models/tiger.py index 522a3c94750..647ac852dd4 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/tiger.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/tiger.py @@ -29,14 +29,15 @@ class Tiger(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["skill"] - 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 Tiger(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={ "additional_properties" }, @@ -69,9 +70,9 @@ class Tiger(BaseModel): return None if not isinstance(obj, dict): - return Tiger.parse_obj(obj) + return Tiger.model_validate(obj) - _obj = Tiger.parse_obj({ + _obj = Tiger.model_validate({ "skill": obj.get("skill") }) # store additional fields in additional_properties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/user.py b/samples/openapi3/client/petstore/python/petstore_api/models/user.py index 50df0f5072b..08330324388 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/user.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/user.py @@ -37,14 +37,15 @@ class User(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["id", "username", "firstName", "lastName", "email", "password", "phone", "userStatus"] - 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""" @@ -58,7 +59,7 @@ class User(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={ "additional_properties" }, @@ -77,9 +78,9 @@ class User(BaseModel): return None if not isinstance(obj, dict): - return User.parse_obj(obj) + return User.model_validate(obj) - _obj = User.parse_obj({ + _obj = User.model_validate({ "id": obj.get("id"), "username": obj.get("username"), "firstName": obj.get("firstName"), diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/with_nested_one_of.py b/samples/openapi3/client/petstore/python/petstore_api/models/with_nested_one_of.py index 76c78c668bd..3597922adb1 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/with_nested_one_of.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/with_nested_one_of.py @@ -33,14 +33,15 @@ class WithNestedOneOf(BaseModel): additional_properties: Dict[str, Any] = {} __properties = ["size", "nested_pig", "nested_oneof_enum_string"] - 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 WithNestedOneOf(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={ "additional_properties" }, @@ -79,9 +80,9 @@ class WithNestedOneOf(BaseModel): return None if not isinstance(obj, dict): - return WithNestedOneOf.parse_obj(obj) + return WithNestedOneOf.model_validate(obj) - _obj = WithNestedOneOf.parse_obj({ + _obj = WithNestedOneOf.model_validate({ "size": obj.get("size"), "nested_pig": Pig.from_dict(obj.get("nested_pig")) if obj.get("nested_pig") is not None else None, "nested_oneof_enum_string": OneOfEnumString.from_dict(obj.get("nested_oneof_enum_string")) if obj.get("nested_oneof_enum_string") is not None else None diff --git a/samples/openapi3/client/petstore/python/tests/test_api_validation.py b/samples/openapi3/client/petstore/python/tests/test_api_validation.py index f99df7edfc0..035d618ce05 100644 --- a/samples/openapi3/client/petstore/python/tests/test_api_validation.py +++ b/samples/openapi3/client/petstore/python/tests/test_api_validation.py @@ -49,18 +49,19 @@ class ApiExceptionTests(unittest.TestCase): def test_required_param_validation(self): try: self.pet_api.get_pet_by_id() - except TypeError as e: - self.assertIn("missing 1 required positional argument: 'pet_id'", str(e)) + except ValidationError as e: + self.assertIn("1 validation error for get_pet_by_id", str(e)) + self.assertIn("Missing required argument", str(e)) def test_integer_validation(self): try: self.pet_api.get_pet_by_id("123") except ValidationError as e: - # 1 validation error for GetPetById + # 1 validation error for get_pet_by_id # pet_id # Input should be a valid integer [type=int_type, input_value='123', input_type=str] # For further information visit https://errors.pydantic.dev/2.3/v/int_type - self.assertIn("1 validation error for GetPetById", str(e)) + self.assertIn("1 validation error for get_pet_by_id", str(e)) self.assertIn("Input should be a valid integer", str(e)) def test_string_enum_validation(self): diff --git a/samples/openapi3/client/petstore/python/tests/test_model.py b/samples/openapi3/client/petstore/python/tests/test_model.py index d04fd36c442..4ec36ff8d9f 100644 --- a/samples/openapi3/client/petstore/python/tests/test_model.py +++ b/samples/openapi3/client/petstore/python/tests/test_model.py @@ -367,9 +367,9 @@ class ModelTests(unittest.TestCase): d4 = petstore_api.OuterObjectWithEnumProperty(value=petstore_api.OuterEnumInteger.NUMBER_1, str_value=None) self.assertEqual(d4.to_json(), '{"value": 1, "str_value": null}') d5 = petstore_api.OuterObjectWithEnumProperty(value=petstore_api.OuterEnumInteger.NUMBER_1) - self.assertEqual(d5.__fields_set__, {'value'}) + self.assertEqual(d5.model_fields_set, {'value'}) d5.str_value = None # set None explicitly - self.assertEqual(d5.__fields_set__, {'value', 'str_value'}) + self.assertEqual(d5.model_fields_set, {'value', 'str_value'}) self.assertEqual(d5.to_json(), '{"value": 1, "str_value": null}') def test_valdiator(self):