diff --git a/modules/openapi-generator/src/main/resources/python/api.mustache b/modules/openapi-generator/src/main/resources/python/api.mustache index 2f1478a7a94e..3dde3f1dd0b3 100644 --- a/modules/openapi-generator/src/main/resources/python/api.mustache +++ b/modules/openapi-generator/src/main/resources/python/api.mustache @@ -5,7 +5,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated {{#imports}} {{import}} diff --git a/modules/openapi-generator/src/main/resources/python/api_client.mustache b/modules/openapi-generator/src/main/resources/python/api_client.mustache index ffbea33fe354..4386a99cc6a7 100644 --- a/modules/openapi-generator/src/main/resources/python/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/python/api_client.mustache @@ -321,7 +321,7 @@ class ApiClient: return_data = self.__deserialize_file(response_data) elif response_type is not None: match = None - content_type = response_data.headers.get('content-type') + content_type = response_data.getheader('content-type') if content_type is not None: match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type) encoding = match.group(1) if match else "utf-8" @@ -338,7 +338,7 @@ class ApiClient: return ApiResponse( status_code = response_data.status, data = return_data, - headers = response_data.headers, + headers = response_data.getheaders(), raw_data = response_data.data ) @@ -389,13 +389,10 @@ class ApiClient: # and attributes which value is not None. # Convert attribute name to json key in # model definition for request. - if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')): - obj_dict = obj.to_dict() - else: - obj_dict = obj.__dict__ + obj_dict = obj.model_dump(by_alias=True, exclude_none=True) if isinstance(obj_dict, list): - # here we handle instances that can either be a list or something else, and only became a real list by calling to_dict() + # here we handle instances that can either be a list or something else, and only became a real list by calling model_dump(by_alias=True) return self.sanitize_for_serialization(obj_dict) return { @@ -719,7 +716,7 @@ class ApiClient: os.close(fd) os.remove(path) - content_disposition = response.headers.get("Content-Disposition") + content_disposition = response.getheader("Content-Disposition") if content_disposition: m = re.search( r'filename=[\'"]?([^\'"\s]+)[\'"]?', @@ -819,4 +816,4 @@ class ApiClient: :return: model object. """ - return klass.from_dict(data) + return klass.model_validate(data) diff --git a/modules/openapi-generator/src/main/resources/python/configuration.mustache b/modules/openapi-generator/src/main/resources/python/configuration.mustache index 039b2a85519f..62af726c21a1 100644 --- a/modules/openapi-generator/src/main/resources/python/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/python/configuration.mustache @@ -14,8 +14,7 @@ from logging import FileHandler import multiprocessing {{/async}} import sys -from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union -from typing_extensions import NotRequired, Self +from typing import Any, ClassVar, Dict, List, Literal, NotRequired, Optional, TypedDict, Union, Self {{^async}} import urllib3 diff --git a/modules/openapi-generator/src/main/resources/python/exceptions.mustache b/modules/openapi-generator/src/main/resources/python/exceptions.mustache index 6b93b1cb9638..b9eb827113f9 100644 --- a/modules/openapi-generator/src/main/resources/python/exceptions.mustache +++ b/modules/openapi-generator/src/main/resources/python/exceptions.mustache @@ -1,9 +1,6 @@ -# coding: utf-8 - {{>partial_header}} -from typing import Any, Optional -from typing_extensions import Self +from typing import Any, Optional, Self class OpenApiException(Exception): """The base exception class for all OpenAPIExceptions""" @@ -95,9 +92,9 @@ class ApiKeyError(OpenApiException, KeyError): class ApiException(OpenApiException): def __init__( - self, - status=None, - reason=None, + self, + status=None, + reason=None, http_resp=None, *, body: Optional[str] = None, @@ -119,14 +116,14 @@ class ApiException(OpenApiException): self.body = http_resp.data.decode('utf-8') except Exception: pass - self.headers = http_resp.headers + self.headers = http_resp.getheaders() @classmethod def from_response( - cls, - *, - http_resp, - body: Optional[str], + cls, + *, + http_resp, + body: Optional[str], data: Optional[Any], ) -> Self: if http_resp.status == 400: @@ -160,11 +157,8 @@ class ApiException(OpenApiException): error_message += "HTTP response headers: {0}\n".format( self.headers) - if self.body: - error_message += "HTTP response body: {0}\n".format(self.body) - - if self.data: - error_message += "HTTP response data: {0}\n".format(self.data) + if self.data or self.body: + error_message += "HTTP response body: {0}\n".format(self.data or self.body) return error_message 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 e035e4829b6f..52faca49b6dd 100644 --- a/modules/openapi-generator/src/main/resources/python/model_anyof.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_anyof.mustache @@ -9,169 +9,31 @@ import re # noqa: F401 {{#vendorExtensions.x-py-model-imports}} {{{.}}} {{/vendorExtensions.x-py-model-imports}} -from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict -from typing_extensions import Literal, Self -from pydantic import Field +from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict, Literal, Self +from pydantic import Field, RootModel {{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ANY_OF_SCHEMAS = [{{#anyOf}}"{{.}}"{{^-last}}, {{/-last}}{{/anyOf}}] -class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}): + +class {{classname}}(RootModel[Union[{{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}]]): """ {{{description}}}{{^description}}{{{classname}}}{{/description}} """ -{{#composedSchemas.anyOf}} - # data type: {{{dataType}}} - {{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}} -{{/composedSchemas.anyOf}} - if TYPE_CHECKING: - actual_instance: Optional[Union[{{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}]] = None - else: - actual_instance: Any = None - any_of_schemas: Set[str] = { {{#anyOf}}"{{.}}"{{^-last}}, {{/-last}}{{/anyOf}} } - - model_config = { - "validate_assignment": True, - "protected_namespaces": (), - } -{{#discriminator}} - - discriminator_value_class_map: Dict[str, str] = { -{{#children}} - '{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}': '{{{classname}}}'{{^-last}},{{/-last}} -{{/children}} - } -{{/discriminator}} - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_anyof(cls, v): - {{#isNullable}} - if v is None: - return v - - {{/isNullable}} - instance = {{{classname}}}.model_construct() - error_messages = [] - {{#composedSchemas.anyOf}} - # validate data type: {{{dataType}}} - {{#isContainer}} - try: - instance.{{vendorExtensions.x-py-name}} = v - return v - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - {{/isContainer}} - {{^isContainer}} - {{#isPrimitiveType}} - try: - instance.{{vendorExtensions.x-py-name}} = v - return v - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - {{/isPrimitiveType}} - {{^isPrimitiveType}} - if not isinstance(v, {{{dataType}}}): - error_messages.append(f"Error! Input type `{type(v)}` is not `{{{dataType}}}`") - else: - return v - - {{/isPrimitiveType}} - {{/isContainer}} - {{/composedSchemas.anyOf}} - if error_messages: - # no match - raise ValueError("No match found when setting the actual_instance in {{{classname}}} with anyOf schemas: {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - {{#isNullable}} - if json_str is None: - return instance - - {{/isNullable}} - error_messages = [] - {{#composedSchemas.anyOf}} - {{#isContainer}} - # deserialize data into {{{dataType}}} - try: - # validation - instance.{{vendorExtensions.x-py-name}} = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.{{vendorExtensions.x-py-name}} - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - {{/isContainer}} - {{^isContainer}} - {{#isPrimitiveType}} - # deserialize data into {{{dataType}}} - try: - # validation - instance.{{vendorExtensions.x-py-name}} = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.{{vendorExtensions.x-py-name}} - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - {{/isPrimitiveType}} - {{^isPrimitiveType}} - # {{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}} - try: - instance.actual_instance = {{{dataType}}}.from_json(json_str) - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - {{/isPrimitiveType}} - {{/isContainer}} - {{/composedSchemas.anyOf}} - - if error_messages: - # no match - raise ValueError("No match found when deserializing the JSON string into {{{classname}}} with anyOf schemas: {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], {{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + root: Union[{{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}] = Field( + ...{{#discriminator}}, discriminator="{{discriminatorName}}"{{/discriminator}} + ) + + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") {{#vendorExtensions.x-py-postponed-model-imports.size}} {{#vendorExtensions.x-py-postponed-model-imports}} diff --git a/modules/openapi-generator/src/main/resources/python/model_doc.mustache b/modules/openapi-generator/src/main/resources/python/model_doc.mustache index 98d50cf8e6ea..b499f149d6b3 100644 --- a/modules/openapi-generator/src/main/resources/python/model_doc.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_doc.mustache @@ -19,14 +19,14 @@ from {{modelPackage}}.{{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}} im # TODO update the JSON string below json = "{}" # create an instance of {{classname}} from a JSON string -{{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_instance = {{classname}}.from_json(json) +{{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_instance = {{classname}}.model_validate_json(json) # print the JSON string representation of the object -print({{classname}}.to_json()) +print({{classname}}.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -{{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_dict = {{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_instance.to_dict() +{{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_dict = {{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_instance.model_dump(by_alias=True) # create an instance of {{classname}} from a dict -{{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_from_dict = {{classname}}.from_dict({{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_dict) +{{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_from_dict = {{classname}}.model_validate({{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_dict) ``` {{/isEnum}} {{#isEnum}} diff --git a/modules/openapi-generator/src/main/resources/python/model_enum.mustache b/modules/openapi-generator/src/main/resources/python/model_enum.mustache index 3f449b121a33..4f57a60e3422 100644 --- a/modules/openapi-generator/src/main/resources/python/model_enum.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_enum.mustache @@ -1,36 +1,32 @@ from __future__ import annotations import json -from enum import Enum +from enum import Enum, StrEnum, IntEnum +from typing import Self {{#vendorExtensions.x-py-other-imports}} {{{.}}} {{/vendorExtensions.x-py-other-imports}} -from typing_extensions import Self - -class {{classname}}({{vendorExtensions.x-py-enum-type}}, Enum): +{{#isString}} +class {{classname}}(StrEnum): +{{/isString}} +{{#isInteger}} +class {{classname}}(IntEnum): +{{/isInteger}} +{{^isString}}{{^isInteger}} +class {{classname}}(Enum): +{{/isInteger}}{{/isString}} """ {{{description}}}{{^description}}{{{classname}}}{{/description}} """ - """ - allowed enum values - """ {{#allowableValues}} + # Allowed enum values {{#enumVars}} - {{{name}}} = {{{value}}} + {{name}} = {{{value}}} {{/enumVars}} @classmethod def from_json(cls, json_str: str) -> Self: """Create an instance of {{classname}} from a JSON string""" return cls(json.loads(json_str)) - - {{#defaultValue}} - - # - @classmethod - def _missing_value_(cls, value): - if value is no_arg: - return cls.{{{.}}} - {{/defaultValue}} {{/allowableValues}} 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 70804d448de0..3e7036f4e384 100644 --- a/modules/openapi-generator/src/main/resources/python/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_generic.mustache @@ -9,8 +9,8 @@ import json {{#vendorExtensions.x-py-model-imports}} {{{.}}} {{/vendorExtensions.x-py-model-imports}} -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field {{#hasChildren}} {{#discriminator}} @@ -28,7 +28,33 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{#description}}{{{description}}}{{/description}}{{^description}}{{{classname}}}{{/description}} """ # noqa: E501 {{#vars}} + {{#isEnum}} + {{#allowableValues}} + {{^isArray}} + {{#values}} + {{#-first}} + {{#-last}} + {{! Single value enum - use Literal }} + {{name}}: Literal['{{{.}}}'] = Field( + {{#required}}...{{/required}}{{^required}}None{{/required}}, + description="{{description}}{{^description}}{{{name}}} of the {{classname}}{{/description}}" + ) + {{/-last}} + {{^-last}} + {{! Multiple value enum - use enum class }} + {{name}}: {{#required}}{{datatypeWithEnum}}{{/required}}{{^required}}Optional[{{datatypeWithEnum}}]{{/required}} = Field( + {{#required}}...{{/required}}{{^required}}None{{/required}}, + description="{{description}}{{^description}}{{{name}}} of the {{classname}}{{/description}}" + ) + {{/-last}} + {{/-first}} + {{/values}} + {{/isArray}} + {{/allowableValues}} + {{/isEnum}} + {{^isEnum}} {{name}}: {{{vendorExtensions.x-py-typing}}} + {{/isEnum}} {{/vars}} {{#isAdditionalPropertiesTrue}} additional_properties: Dict[str, Any] = {} @@ -125,274 +151,6 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[{{^hasChildren}}Self{{/hasChildren}}{{#hasChildren}}{{#discriminator}}Union[{{#mappedModels}}{{{modelName}}}{{^-last}}, {{/-last}}{{/mappedModels}}]{{/discriminator}}{{^discriminator}}Self{{/discriminator}}{{/hasChildren}}]: - """Create an instance of {{{classname}}} from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - {{#vendorExtensions.x-py-readonly}} - * OpenAPI `readOnly` fields are excluded. - {{/vendorExtensions.x-py-readonly}} - {{#isAdditionalPropertiesTrue}} - * Fields in `self.additional_properties` are added to the output dict. - {{/isAdditionalPropertiesTrue}} - """ - excluded_fields: Set[str] = set([ - {{#vendorExtensions.x-py-readonly}} - "{{{.}}}", - {{/vendorExtensions.x-py-readonly}} - {{#isAdditionalPropertiesTrue}} - "additional_properties", - {{/isAdditionalPropertiesTrue}} - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - {{#allVars}} - {{#isContainer}} - {{#isArray}} - {{#items.isArray}} - {{^items.items.isPrimitiveType}} - # override the default output from pydantic by calling `to_dict()` of each item in {{{name}}} (list of list) - _items = [] - if self.{{{name}}}: - for _item_{{{name}}} in self.{{{name}}}: - if _item_{{{name}}}: - _items.append( - [_inner_item.to_dict() for _inner_item in _item_{{{name}}} if _inner_item is not None] - ) - _dict['{{{baseName}}}'] = _items - {{/items.items.isPrimitiveType}} - {{/items.isArray}} - {{^items.isArray}} - {{^items.isPrimitiveType}} - {{^items.isEnumOrRef}} - # override the default output from pydantic by calling `to_dict()` of each item in {{{name}}} (list) - _items = [] - if self.{{{name}}}: - for _item_{{{name}}} in self.{{{name}}}: - if _item_{{{name}}}: - _items.append(_item_{{{name}}}.to_dict()) - _dict['{{{baseName}}}'] = _items - {{/items.isEnumOrRef}} - {{/items.isPrimitiveType}} - {{/items.isArray}} - {{/isArray}} - {{#isMap}} - {{#items.isArray}} - {{^items.items.isPrimitiveType}} - # override the default output from pydantic by calling `to_dict()` of each value in {{{name}}} (dict of array) - _field_dict_of_array = {} - if self.{{{name}}}: - for _key_{{{name}}} in self.{{{name}}}: - if self.{{{name}}}[_key_{{{name}}}] is not None: - _field_dict_of_array[_key_{{{name}}}] = [ - _item.to_dict() for _item in self.{{{name}}}[_key_{{{name}}}] - ] - _dict['{{{baseName}}}'] = _field_dict_of_array - {{/items.items.isPrimitiveType}} - {{/items.isArray}} - {{^items.isArray}} - {{^items.isPrimitiveType}} - {{^items.isEnumOrRef}} - # override the default output from pydantic by calling `to_dict()` of each value in {{{name}}} (dict) - _field_dict = {} - if self.{{{name}}}: - for _key_{{{name}}} in self.{{{name}}}: - if self.{{{name}}}[_key_{{{name}}}]: - _field_dict[_key_{{{name}}}] = self.{{{name}}}[_key_{{{name}}}].to_dict() - _dict['{{{baseName}}}'] = _field_dict - {{/items.isEnumOrRef}} - {{/items.isPrimitiveType}} - {{/items.isArray}} - {{/isMap}} - {{/isContainer}} - {{^isContainer}} - {{^isPrimitiveType}} - {{^isEnumOrRef}} - # override the default output from pydantic by calling `to_dict()` of {{{name}}} - if self.{{{name}}}: - _dict['{{{baseName}}}'] = self.{{{name}}}.to_dict() - {{/isEnumOrRef}} - {{/isPrimitiveType}} - {{/isContainer}} - {{/allVars}} - {{#isAdditionalPropertiesTrue}} - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - {{/isAdditionalPropertiesTrue}} - {{#allVars}} - {{#isNullable}} - # set to None if {{{name}}} (nullable) is None - # and model_fields_set contains the field - if self.{{name}} is None and "{{{name}}}" in self.model_fields_set: - _dict['{{{baseName}}}'] = None - - {{/isNullable}} - {{/allVars}} - return _dict - - {{#hasChildren}} - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[{{#discriminator}}Union[{{#mappedModels}}{{{modelName}}}{{^-last}}, {{/-last}}{{/mappedModels}}]{{/discriminator}}{{^discriminator}}Self{{/discriminator}}]: - """Create an instance of {{{classname}}} from a dict""" - {{#discriminator}} - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - {{#mappedModels}} - if object_type == '{{{modelName}}}': - return import_module("{{packageName}}.models.{{model.classFilename}}").{{modelName}}.from_dict(obj) - {{/mappedModels}} - - raise ValueError("{{{classname}}} failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) - {{/discriminator}} - {{/hasChildren}} - {{^hasChildren}} - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of {{{classname}}} from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - {{#disallowAdditionalPropertiesIfNotPresent}} - {{^isAdditionalPropertiesTrue}} - # raise errors for additional fields in the input - for _key in obj.keys(): - if _key not in cls.__properties: - raise ValueError("Error due to additional fields (not defined in {{classname}}) in the input: " + _key) - - {{/isAdditionalPropertiesTrue}} - {{/disallowAdditionalPropertiesIfNotPresent}} - _obj = cls.model_validate({ - {{#allVars}} - {{#isContainer}} - {{#isArray}} - {{#items.isArray}} - {{#items.items.isPrimitiveType}} - "{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}} - {{/items.items.isPrimitiveType}} - {{^items.items.isPrimitiveType}} - "{{{baseName}}}": [ - [{{{items.items.dataType}}}.from_dict(_inner_item) for _inner_item in _item] - for _item in obj["{{{baseName}}}"] - ] if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}} - {{/items.items.isPrimitiveType}} - {{/items.isArray}} - {{^items.isArray}} - {{^items.isPrimitiveType}} - {{#items.isEnumOrRef}} - "{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}} - {{/items.isEnumOrRef}} - {{^items.isEnumOrRef}} - "{{{baseName}}}": [{{{items.dataType}}}.from_dict(_item) for _item in obj["{{{baseName}}}"]] if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}} - {{/items.isEnumOrRef}} - {{/items.isPrimitiveType}} - {{#items.isPrimitiveType}} - "{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}} - {{/items.isPrimitiveType}} - {{/items.isArray}} - {{/isArray}} - {{#isMap}} - {{^items.isPrimitiveType}} - {{^items.isEnumOrRef}} - {{#items.isContainer}} - {{#items.isMap}} - "{{{baseName}}}": dict( - (_k, dict( - (_ik, {{{items.items.dataType}}}.from_dict(_iv)) - for _ik, _iv in _v.items() - ) - if _v is not None - else None - ) - for _k, _v in obj.get("{{{baseName}}}").items() - ) - if obj.get("{{{baseName}}}") is not None - else None{{^-last}},{{/-last}} - {{/items.isMap}} - {{#items.isArray}} - "{{{baseName}}}": dict( - (_k, - [{{{items.items.dataType}}}.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("{{{baseName}}}", {}).items() - ){{^-last}},{{/-last}} - {{/items.isArray}} - {{/items.isContainer}} - {{^items.isContainer}} - "{{{baseName}}}": dict( - (_k, {{{items.dataType}}}.from_dict(_v)) - for _k, _v in obj["{{{baseName}}}"].items() - ) - if obj.get("{{{baseName}}}") is not None - else None{{^-last}},{{/-last}} - {{/items.isContainer}} - {{/items.isEnumOrRef}} - {{#items.isEnumOrRef}} - "{{{baseName}}}": dict((_k, _v) for _k, _v in obj.get("{{{baseName}}}").items()) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}} - {{/items.isEnumOrRef}} - {{/items.isPrimitiveType}} - {{#items.isPrimitiveType}} - "{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}} - {{/items.isPrimitiveType}} - {{/isMap}} - {{/isContainer}} - {{^isContainer}} - {{^isPrimitiveType}} - {{^isEnumOrRef}} - "{{{baseName}}}": {{{dataType}}}.from_dict(obj["{{{baseName}}}"]) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}} - {{/isEnumOrRef}} - {{#isEnumOrRef}} - "{{{baseName}}}": obj.get("{{{baseName}}}"){{#defaultValue}} if obj.get("{{baseName}}") is not None else {{{defaultValue}}}{{/defaultValue}}{{^-last}},{{/-last}} - {{/isEnumOrRef}} - {{/isPrimitiveType}} - {{#isPrimitiveType}} - {{#defaultValue}} - "{{{baseName}}}": obj.get("{{{baseName}}}") if obj.get("{{{baseName}}}") is not None else {{{defaultValue}}}{{^-last}},{{/-last}} - {{/defaultValue}} - {{^defaultValue}} - "{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}} - {{/defaultValue}} - {{/isPrimitiveType}} - {{/isContainer}} - {{/allVars}} - }) - {{#isAdditionalPropertiesTrue}} - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - {{/isAdditionalPropertiesTrue}} - return _obj - {{/hasChildren}} {{#vendorExtensions.x-py-postponed-model-imports.size}} {{#vendorExtensions.x-py-postponed-model-imports}} 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 07a4d93f9ddf..3c4e4e0d7bec 100644 --- a/modules/openapi-generator/src/main/resources/python/model_oneof.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_oneof.mustache @@ -7,203 +7,26 @@ import pprint {{#vendorExtensions.x-py-model-imports}} {{{.}}} {{/vendorExtensions.x-py-model-imports}} -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self {{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ONE_OF_SCHEMAS = [{{#oneOf}}"{{.}}"{{^-last}}, {{/-last}}{{/oneOf}}] -class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}): +class {{classname}}(RootModel[Union[{{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}]]): """ {{{description}}}{{^description}}{{{classname}}}{{/description}} """ -{{#composedSchemas.oneOf}} - # data type: {{{dataType}}} - {{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}} -{{/composedSchemas.oneOf}} - actual_instance: Optional[Union[{{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}]] = None - one_of_schemas: Set[str] = { {{#oneOf}}"{{.}}"{{^-last}}, {{/-last}}{{/oneOf}} } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[{{#oneOf}}{{.}}{{^-last}}, {{/-last}}{{/oneOf}}] = Field( + ...{{#discriminator}}, discriminator="{{discriminatorName}}"{{/discriminator}} ) -{{#discriminator}} - - discriminator_value_class_map: Dict[str, str] = { -{{#children}} - '{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}': '{{{classname}}}'{{^-last}},{{/-last}} -{{/children}} - } -{{/discriminator}} - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - {{#isNullable}} - if v is None: - return v - - {{/isNullable}} - instance = {{{classname}}}.model_construct() - error_messages = [] - match = 0 - {{#composedSchemas.oneOf}} - # validate data type: {{{dataType}}} - {{#isContainer}} - try: - instance.{{vendorExtensions.x-py-name}} = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - {{/isContainer}} - {{^isContainer}} - {{#isPrimitiveType}} - try: - instance.{{vendorExtensions.x-py-name}} = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - {{/isPrimitiveType}} - {{^isPrimitiveType}} - if not isinstance(v, {{{dataType}}}): - error_messages.append(f"Error! Input type `{type(v)}` is not `{{{dataType}}}`") - else: - match += 1 - {{/isPrimitiveType}} - {{/isContainer}} - {{/composedSchemas.oneOf}} - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - {{#isNullable}} - def from_json(cls, json_str: Optional[str]) -> Self: - {{/isNullable}} - {{^isNullable}} - def from_json(cls, json_str: str) -> Self: - {{/isNullable}} - """Returns the object represented by the json string""" - instance = cls.model_construct() - {{#isNullable}} - if json_str is None: - return instance - - {{/isNullable}} - error_messages = [] - match = 0 - - {{#useOneOfDiscriminatorLookup}} - {{#discriminator}} - {{#mappedModels}} - {{#-first}} - # use oneOf discriminator to lookup the data type - _data_type = json.loads(json_str).get("{{{propertyBaseName}}}") - if not _data_type: - raise ValueError("Failed to lookup data type from the field `{{{propertyBaseName}}}` in the input.") - - {{/-first}} - # check if data type is `{{{modelName}}}` - if _data_type == "{{{mappingName}}}": - instance.actual_instance = {{{modelName}}}.from_json(json_str) - return instance - - {{/mappedModels}} - {{/discriminator}} - {{/useOneOfDiscriminatorLookup}} - {{#composedSchemas.oneOf}} - {{#isContainer}} - # deserialize data into {{{dataType}}} - try: - # validation - instance.{{vendorExtensions.x-py-name}} = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.{{vendorExtensions.x-py-name}} - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - {{/isContainer}} - {{^isContainer}} - {{#isPrimitiveType}} - # deserialize data into {{{dataType}}} - try: - # validation - instance.{{vendorExtensions.x-py-name}} = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.{{vendorExtensions.x-py-name}} - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - {{/isPrimitiveType}} - {{^isPrimitiveType}} - # deserialize data into {{{dataType}}} - try: - instance.actual_instance = {{{dataType}}}.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - {{/isPrimitiveType}} - {{/isContainer}} - {{/composedSchemas.oneOf}} - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - -{{#vendorExtensions.x-py-postponed-model-imports.size}} -{{#vendorExtensions.x-py-postponed-model-imports}} -{{{.}}} -{{/vendorExtensions.x-py-postponed-model-imports}} -# TODO: Rewrite to not use raise_errors -{{classname}}.model_rebuild(raise_errors=False) -{{/vendorExtensions.x-py-postponed-model-imports.size}} + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/modules/openapi-generator/src/main/resources/python/pyproject.mustache b/modules/openapi-generator/src/main/resources/python/pyproject.mustache index 7eed997a3f43..0493229f4d8f 100644 --- a/modules/openapi-generator/src/main/resources/python/pyproject.mustache +++ b/modules/openapi-generator/src/main/resources/python/pyproject.mustache @@ -32,10 +32,8 @@ keywords = ["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"] include = ["{{packageName}}/py.typed"] [tool.poetry.dependencies] -python = "^3.9" -{{^async}} +python = "^3.11" urllib3 = ">= 2.1.0, < 3.0.0" -{{/async}} python-dateutil = ">= 2.8.2" {{#asyncio}} aiohttp = ">= 3.8.4" @@ -58,20 +56,15 @@ lazy-imports = ">= 1, < 2" {{/lazyImports}} {{/poetry1}} {{^poetry1}} -requires-python = ">=3.9" +requires-python = ">=3.11" dependencies = [ -{{^async}} "urllib3 (>=2.1.0,<3.0.0)", -{{/async}} "python-dateutil (>=2.8.2)", -{{#httpx}} - "httpx (>=0.28.1)", -{{/httpx}} -{{#asyncio}} +{{#async}} "aiohttp (>=3.8.4)", "aiohttp-retry (>=2.8.3)", -{{/asyncio}} +{{/async}} {{#tornado}} "tornado (>=4.2,<5)", {{/tornado}} diff --git a/modules/openapi-generator/src/main/resources/python/setup.mustache b/modules/openapi-generator/src/main/resources/python/setup.mustache index d65485b42f90..998ae2e29b50 100644 --- a/modules/openapi-generator/src/main/resources/python/setup.mustache +++ b/modules/openapi-generator/src/main/resources/python/setup.mustache @@ -1,5 +1,3 @@ -# coding: utf-8 - {{>partial_header}} @@ -13,11 +11,9 @@ from setuptools import setup, find_packages # noqa: H301 # http://pypi.python.org/pypi/setuptools NAME = "{{{projectName}}}" VERSION = "{{packageVersion}}" -PYTHON_REQUIRES = ">= 3.9" +PYTHON_REQUIRES = ">= 3.11" REQUIRES = [ -{{^async}} "urllib3 >= 2.1.0, < 3.0.0", -{{/async}} "python-dateutil >= 2.8.2", {{#asyncio}} "aiohttp >= 3.8.4", diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Bird.md b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Bird.md index e61d8458c978..aaa366493692 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Bird.md +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Bird.md @@ -16,14 +16,14 @@ from openapi_client.models.bird import Bird # TODO update the JSON string below json = "{}" # create an instance of Bird from a JSON string -bird_instance = Bird.from_json(json) +bird_instance = Bird.model_validate_json(json) # print the JSON string representation of the object -print(Bird.to_json()) +print(Bird.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -bird_dict = bird_instance.to_dict() +bird_dict = bird_instance.model_dump(by_alias=True) # create an instance of Bird from a dict -bird_from_dict = Bird.from_dict(bird_dict) +bird_from_dict = Bird.model_validate(bird_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Category.md b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Category.md index 9a807466f62a..081573acca81 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Category.md +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Category.md @@ -16,14 +16,14 @@ from openapi_client.models.category import Category # TODO update the JSON string below json = "{}" # create an instance of Category from a JSON string -category_instance = Category.from_json(json) +category_instance = Category.model_validate_json(json) # print the JSON string representation of the object -print(Category.to_json()) +print(Category.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -category_dict = category_instance.to_dict() +category_dict = category_instance.model_dump(by_alias=True) # create an instance of Category from a dict -category_from_dict = Category.from_dict(category_dict) +category_from_dict = Category.model_validate(category_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DataQuery.md b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DataQuery.md index 7ea37bfd23e1..93df45d19273 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DataQuery.md +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DataQuery.md @@ -17,14 +17,14 @@ from openapi_client.models.data_query import DataQuery # TODO update the JSON string below json = "{}" # create an instance of DataQuery from a JSON string -data_query_instance = DataQuery.from_json(json) +data_query_instance = DataQuery.model_validate_json(json) # print the JSON string representation of the object -print(DataQuery.to_json()) +print(DataQuery.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -data_query_dict = data_query_instance.to_dict() +data_query_dict = data_query_instance.model_dump(by_alias=True) # create an instance of DataQuery from a dict -data_query_from_dict = DataQuery.from_dict(data_query_dict) +data_query_from_dict = DataQuery.model_validate(data_query_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DefaultValue.md b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DefaultValue.md index 7c1668c0d6c6..40271096be2e 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DefaultValue.md +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/DefaultValue.md @@ -23,14 +23,14 @@ from openapi_client.models.default_value import DefaultValue # TODO update the JSON string below json = "{}" # create an instance of DefaultValue from a JSON string -default_value_instance = DefaultValue.from_json(json) +default_value_instance = DefaultValue.model_validate_json(json) # print the JSON string representation of the object -print(DefaultValue.to_json()) +print(DefaultValue.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -default_value_dict = default_value_instance.to_dict() +default_value_dict = default_value_instance.model_dump(by_alias=True) # create an instance of DefaultValue from a dict -default_value_from_dict = DefaultValue.from_dict(default_value_dict) +default_value_from_dict = DefaultValue.model_validate(default_value_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/NumberPropertiesOnly.md b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/NumberPropertiesOnly.md index 1f9cb5a1f634..95825bc16c1d 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/NumberPropertiesOnly.md +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/NumberPropertiesOnly.md @@ -17,14 +17,14 @@ from openapi_client.models.number_properties_only import NumberPropertiesOnly # TODO update the JSON string below json = "{}" # create an instance of NumberPropertiesOnly from a JSON string -number_properties_only_instance = NumberPropertiesOnly.from_json(json) +number_properties_only_instance = NumberPropertiesOnly.model_validate_json(json) # print the JSON string representation of the object -print(NumberPropertiesOnly.to_json()) +print(NumberPropertiesOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -number_properties_only_dict = number_properties_only_instance.to_dict() +number_properties_only_dict = number_properties_only_instance.model_dump(by_alias=True) # create an instance of NumberPropertiesOnly from a dict -number_properties_only_from_dict = NumberPropertiesOnly.from_dict(number_properties_only_dict) +number_properties_only_from_dict = NumberPropertiesOnly.model_validate(number_properties_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Pet.md b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Pet.md index 99b4bf3ab010..c2707006974b 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Pet.md +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Pet.md @@ -20,14 +20,14 @@ from openapi_client.models.pet import Pet # TODO update the JSON string below json = "{}" # create an instance of Pet from a JSON string -pet_instance = Pet.from_json(json) +pet_instance = Pet.model_validate_json(json) # print the JSON string representation of the object -print(Pet.to_json()) +print(Pet.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -pet_dict = pet_instance.to_dict() +pet_dict = pet_instance.model_dump(by_alias=True) # create an instance of Pet from a dict -pet_from_dict = Pet.from_dict(pet_dict) +pet_from_dict = Pet.model_validate(pet_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Query.md b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Query.md index d39693eb5b93..131b995205b4 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Query.md +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Query.md @@ -16,14 +16,14 @@ from openapi_client.models.query import Query # TODO update the JSON string below json = "{}" # create an instance of Query from a JSON string -query_instance = Query.from_json(json) +query_instance = Query.model_validate_json(json) # print the JSON string representation of the object -print(Query.to_json()) +print(Query.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -query_dict = query_instance.to_dict() +query_dict = query_instance.model_dump(by_alias=True) # create an instance of Query from a dict -query_from_dict = Query.from_dict(query_dict) +query_from_dict = Query.model_validate(query_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Tag.md b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Tag.md index 21314992cf43..cbb7c7cf7290 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Tag.md +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Tag.md @@ -16,14 +16,14 @@ from openapi_client.models.tag import Tag # TODO update the JSON string below json = "{}" # create an instance of Tag from a JSON string -tag_instance = Tag.from_json(json) +tag_instance = Tag.model_validate_json(json) # print the JSON string representation of the object -print(Tag.to_json()) +print(Tag.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -tag_dict = tag_instance.to_dict() +tag_dict = tag_instance.model_dump(by_alias=True) # create an instance of Tag from a dict -tag_from_dict = Tag.from_dict(tag_dict) +tag_from_dict = Tag.model_validate(tag_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestFormObjectMultipartRequestMarker.md b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestFormObjectMultipartRequestMarker.md index bf4046eb4648..aa6304c08de9 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestFormObjectMultipartRequestMarker.md +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestFormObjectMultipartRequestMarker.md @@ -15,14 +15,14 @@ from openapi_client.models.test_form_object_multipart_request_marker import Test # TODO update the JSON string below json = "{}" # create an instance of TestFormObjectMultipartRequestMarker from a JSON string -test_form_object_multipart_request_marker_instance = TestFormObjectMultipartRequestMarker.from_json(json) +test_form_object_multipart_request_marker_instance = TestFormObjectMultipartRequestMarker.model_validate_json(json) # print the JSON string representation of the object -print(TestFormObjectMultipartRequestMarker.to_json()) +print(TestFormObjectMultipartRequestMarker.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_form_object_multipart_request_marker_dict = test_form_object_multipart_request_marker_instance.to_dict() +test_form_object_multipart_request_marker_dict = test_form_object_multipart_request_marker_instance.model_dump(by_alias=True) # create an instance of TestFormObjectMultipartRequestMarker from a dict -test_form_object_multipart_request_marker_from_dict = TestFormObjectMultipartRequestMarker.from_dict(test_form_object_multipart_request_marker_dict) +test_form_object_multipart_request_marker_from_dict = TestFormObjectMultipartRequestMarker.model_validate(test_form_object_multipart_request_marker_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md index 96c36ca12e0f..1b237131c19b 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md @@ -18,14 +18,14 @@ from openapi_client.models.test_query_style_deep_object_explode_true_object_all_ # TODO update the JSON string below json = "{}" # create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a JSON string -test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.from_json(json) +test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_validate_json(json) # print the JSON string representation of the object -print(TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.to_json()) +print(TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_dict = test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance.to_dict() +test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_dict = test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance.model_dump(by_alias=True) # create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a dict -test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_from_dict = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.from_dict(test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_dict) +test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_from_dict = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_validate(test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md index 846a0941a09c..c45189c5e271 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md @@ -15,14 +15,14 @@ from openapi_client.models.test_query_style_form_explode_true_array_string_query # TODO update the JSON string below json = "{}" # create an instance of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter from a JSON string -test_query_style_form_explode_true_array_string_query_object_parameter_instance = TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.from_json(json) +test_query_style_form_explode_true_array_string_query_object_parameter_instance = TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_validate_json(json) # print the JSON string representation of the object -print(TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.to_json()) +print(TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_query_style_form_explode_true_array_string_query_object_parameter_dict = test_query_style_form_explode_true_array_string_query_object_parameter_instance.to_dict() +test_query_style_form_explode_true_array_string_query_object_parameter_dict = test_query_style_form_explode_true_array_string_query_object_parameter_instance.model_dump(by_alias=True) # create an instance of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter from a dict -test_query_style_form_explode_true_array_string_query_object_parameter_from_dict = TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.from_dict(test_query_style_form_explode_true_array_string_query_object_parameter_dict) +test_query_style_form_explode_true_array_string_query_object_parameter_from_dict = TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_validate(test_query_style_form_explode_true_array_string_query_object_parameter_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/auth_api.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/auth_api.py index 2f3e9dfcdb63..c9a8552ff76f 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/auth_api.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/auth_api.py @@ -15,7 +15,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import StrictStr diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/body_api.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/body_api.py index 33aba2cbd446..f70ceeffddc5 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/body_api.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/body_api.py @@ -15,7 +15,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field, StrictBytes, StrictStr from typing import Any, Dict, List, Optional, Tuple, Union diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/form_api.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/form_api.py index 3353457f7ee8..19a216188386 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/form_api.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/form_api.py @@ -15,7 +15,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import StrictBool, StrictInt, StrictStr from typing import Optional diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/header_api.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/header_api.py index 5c1cd1b540dd..85e88dead22d 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/header_api.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/header_api.py @@ -15,7 +15,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import StrictBool, StrictInt, StrictStr, field_validator from typing import Optional diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/path_api.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/path_api.py index d2ba4662c21a..c34887fda5d3 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/path_api.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/path_api.py @@ -15,7 +15,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import StrictInt, StrictStr, field_validator from openapi_client.models.string_enum_ref import StringEnumRef diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/query_api.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/query_api.py index 44955f205678..da67b25c2b35 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/query_api.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/query_api.py @@ -15,7 +15,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from datetime import date, datetime from pydantic import StrictBool, StrictInt, StrictStr, field_validator diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py index 0fab29669922..80f90def42f0 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py @@ -313,7 +313,7 @@ def response_deserialize( return_data = self.__deserialize_file(response_data) elif response_type is not None: match = None - content_type = response_data.headers.get('content-type') + content_type = response_data.getheader('content-type') if content_type is not None: match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type) encoding = match.group(1) if match else "utf-8" @@ -330,7 +330,7 @@ def response_deserialize( return ApiResponse( status_code = response_data.status, data = return_data, - headers = response_data.headers, + headers = response_data.getheaders(), raw_data = response_data.data ) @@ -381,13 +381,10 @@ def sanitize_for_serialization(self, obj): # and attributes which value is not None. # Convert attribute name to json key in # model definition for request. - if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')): - obj_dict = obj.to_dict() - else: - obj_dict = obj.__dict__ + obj_dict = obj.model_dump(by_alias=True, exclude_none=True) if isinstance(obj_dict, list): - # here we handle instances that can either be a list or something else, and only became a real list by calling to_dict() + # here we handle instances that can either be a list or something else, and only became a real list by calling model_dump(by_alias=True) return self.sanitize_for_serialization(obj_dict) return { @@ -702,7 +699,7 @@ def __deserialize_file(self, response): os.close(fd) os.remove(path) - content_disposition = response.headers.get("Content-Disposition") + content_disposition = response.getheader("Content-Disposition") if content_disposition: m = re.search( r'filename=[\'"]?([^\'"\s]+)[\'"]?', @@ -802,4 +799,4 @@ def __deserialize_model(self, data, klass): :return: model object. """ - return klass.from_dict(data) + return klass.model_validate(data) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py index bc8fb73562ff..dd3d712a41df 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py @@ -19,8 +19,7 @@ from logging import FileHandler import multiprocessing import sys -from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union -from typing_extensions import NotRequired, Self +from typing import Any, ClassVar, Dict, List, Literal, NotRequired, Optional, TypedDict, Union, Self import urllib3 diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/exceptions.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/exceptions.py index 1d08908dfb60..0ae1b3ff81f7 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/exceptions.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/exceptions.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """ Echo Server API @@ -12,8 +10,8 @@ Do not edit the class manually. """ # noqa: E501 -from typing import Any, Optional -from typing_extensions import Self + +from typing import Any, Optional, Self class OpenApiException(Exception): """The base exception class for all OpenAPIExceptions""" @@ -105,9 +103,9 @@ def __init__(self, msg, path_to_item=None) -> None: class ApiException(OpenApiException): def __init__( - self, - status=None, - reason=None, + self, + status=None, + reason=None, http_resp=None, *, body: Optional[str] = None, @@ -129,14 +127,14 @@ def __init__( self.body = http_resp.data.decode('utf-8') except Exception: pass - self.headers = http_resp.headers + self.headers = http_resp.getheaders() @classmethod def from_response( - cls, - *, - http_resp, - body: Optional[str], + cls, + *, + http_resp, + body: Optional[str], data: Optional[Any], ) -> Self: if http_resp.status == 400: @@ -170,11 +168,8 @@ def __str__(self): error_message += "HTTP response headers: {0}\n".format( self.headers) - if self.body: - error_message += "HTTP response body: {0}\n".format(self.body) - - if self.data: - error_message += "HTTP response data: {0}\n".format(self.data) + if self.data or self.body: + error_message += "HTTP response body: {0}\n".format(self.data or self.body) return error_message diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/bird.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/bird.py index 9bb24b9e6d80..738e59b9f5c1 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/bird.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/bird.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Bird(BaseModel): """ @@ -42,54 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Bird from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Bird from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - # raise errors for additional fields in the input - for _key in obj.keys(): - if _key not in cls.__properties: - raise ValueError("Error due to additional fields (not defined in Bird) in the input: " + _key) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "color": obj.get("color") - }) - return _obj diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/category.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/category.py index c8e9bb709fd1..b097d9ac4bea 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/category.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/category.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Category(BaseModel): """ @@ -42,54 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Category from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Category from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - # raise errors for additional fields in the input - for _key in obj.keys(): - if _key not in cls.__properties: - raise ValueError("Error due to additional fields (not defined in Category) in the input: " + _key) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") - }) - return _obj diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/data_query.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/data_query.py index 255a5ab7f422..9d16f06cc7c2 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/data_query.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/data_query.py @@ -22,8 +22,8 @@ from pydantic import ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional from openapi_client.models.query import Query -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DataQuery(Query): """ @@ -45,57 +45,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DataQuery from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DataQuery from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - # raise errors for additional fields in the input - for _key in obj.keys(): - if _key not in cls.__properties: - raise ValueError("Error due to additional fields (not defined in DataQuery) in the input: " + _key) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "outcomes": obj.get("outcomes"), - "suffix": obj.get("suffix"), - "text": obj.get("text"), - "date": obj.get("date") - }) - return _obj diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py index 8dceac31e3d5..d60615645132 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py @@ -21,15 +21,14 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional from openapi_client.models.string_enum_ref import StringEnumRef -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DefaultValue(BaseModel): """ to test the default value of properties """ # noqa: E501 array_string_enum_ref_default: Optional[List[StringEnumRef]] = None - array_string_enum_default: Optional[List[StrictStr]] = None array_string_default: Optional[List[StrictStr]] = None array_integer_default: Optional[List[StrictInt]] = None array_string: Optional[List[StrictStr]] = None @@ -60,75 +59,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DefaultValue from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # set to None if array_string_nullable (nullable) is None - # 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 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 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DefaultValue from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - # raise errors for additional fields in the input - for _key in obj.keys(): - if _key not in cls.__properties: - raise ValueError("Error due to additional fields (not defined in DefaultValue) in the input: " + _key) - - _obj = cls.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"), - "array_integer_default": obj.get("array_integer_default"), - "array_string": obj.get("array_string"), - "array_string_nullable": obj.get("array_string_nullable"), - "array_string_extension_nullable": obj.get("array_string_extension_nullable"), - "string_nullable": obj.get("string_nullable") - }) - return _obj diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/number_properties_only.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/number_properties_only.py index d089c9775ace..e2222747eca6 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/number_properties_only.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/number_properties_only.py @@ -21,8 +21,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt from typing import Any, ClassVar, Dict, List, Optional, Union from typing_extensions import Annotated -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class NumberPropertiesOnly(BaseModel): """ @@ -44,55 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of NumberPropertiesOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of NumberPropertiesOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - # raise errors for additional fields in the input - for _key in obj.keys(): - if _key not in cls.__properties: - raise ValueError("Error due to additional fields (not defined in NumberPropertiesOnly) in the input: " + _key) - - _obj = cls.model_validate({ - "number": obj.get("number"), - "float": obj.get("float"), - "double": obj.get("double") - }) - return _obj diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py index bfe90956d977..4ab26ed170c8 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py @@ -22,8 +22,8 @@ from typing import Any, ClassVar, Dict, List, Optional from openapi_client.models.category import Category from openapi_client.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Pet(BaseModel): """ @@ -34,7 +34,10 @@ class Pet(BaseModel): category: Optional[Category] = None photo_urls: List[StrictStr] = Field(alias="photoUrls") tags: Optional[List[Tag]] = None - status: Optional[StrictStr] = Field(default=None, description="pet status in the store") + status: Optional[StatusEnum] = Field( + None, + description="pet status in the store" + ) __properties: ClassVar[List[str]] = ["id", "name", "category", "photoUrls", "tags", "status"] @field_validator('status') @@ -58,68 +61,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Pet from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of category - if self.category: - _dict['category'] = self.category.to_dict() - # override the default output from pydantic by calling `to_dict()` of each item in tags (list) - _items = [] - if self.tags: - for _item_tags in self.tags: - if _item_tags: - _items.append(_item_tags.to_dict()) - _dict['tags'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Pet from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - # raise errors for additional fields in the input - for _key in obj.keys(): - if _key not in cls.__properties: - raise ValueError("Error due to additional fields (not defined in Pet) in the input: " + _key) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name"), - "category": Category.from_dict(obj["category"]) if obj.get("category") is not None else None, - "photoUrls": obj.get("photoUrls"), - "tags": [Tag.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None, - "status": obj.get("status") - }) - return _obj diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py index 97199fb7fd95..064036ff3e1e 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py @@ -20,15 +20,14 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Query(BaseModel): """ Query """ # noqa: E501 id: Optional[StrictInt] = Field(default=None, description="Query") - outcomes: Optional[List[StrictStr]] = None __properties: ClassVar[List[str]] = ["id", "outcomes"] @field_validator('outcomes') @@ -53,38 +52,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Query from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Self]: - """Create an instance of Query from a dict""" diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/string_enum_ref.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/string_enum_ref.py index 90328aea76dd..e853e6df8b97 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/string_enum_ref.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/string_enum_ref.py @@ -15,18 +15,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class StringEnumRef(StrEnum): -class StringEnumRef(str, Enum): """ StringEnumRef """ - """ - allowed enum values - """ + # Allowed enum values SUCCESS = 'success' FAILURE = 'failure' UNCLASSIFIED = 'unclassified' @@ -36,4 +34,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of StringEnumRef from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/tag.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/tag.py index 5ec177ca73ae..17e7a3c39bcf 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/tag.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/tag.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Tag(BaseModel): """ @@ -42,54 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Tag from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Tag from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - # raise errors for additional fields in the input - for _key in obj.keys(): - if _key not in cls.__properties: - raise ValueError("Error due to additional fields (not defined in Tag) in the input: " + _key) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") - }) - return _obj diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/test_form_object_multipart_request_marker.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/test_form_object_multipart_request_marker.py index 9fab70ea178d..51c2fcc79e8d 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/test_form_object_multipart_request_marker.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/test_form_object_multipart_request_marker.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestFormObjectMultipartRequestMarker(BaseModel): """ @@ -41,53 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestFormObjectMultipartRequestMarker from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestFormObjectMultipartRequestMarker from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - # raise errors for additional fields in the input - for _key in obj.keys(): - if _key not in cls.__properties: - raise ValueError("Error due to additional fields (not defined in TestFormObjectMultipartRequestMarker) in the input: " + _key) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - return _obj diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.py index 8cf292b6a90b..cd3cbb8d7fd6 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseModel): """ @@ -44,56 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - # raise errors for additional fields in the input - for _key in obj.keys(): - if _key not in cls.__properties: - raise ValueError("Error due to additional fields (not defined in TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter) in the input: " + _key) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "color": obj.get("color"), - "id": obj.get("id"), - "name": obj.get("name") - }) - return _obj diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.py index 726b427743ca..a4963abb60de 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel): """ @@ -41,53 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - # raise errors for additional fields in the input - for _key in obj.keys(): - if _key not in cls.__properties: - raise ValueError("Error due to additional fields (not defined in TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter) in the input: " + _key) - - _obj = cls.model_validate({ - "values": obj.get("values") - }) - return _obj diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml index 84c2c75e9f88..5a646fca20fb 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml @@ -8,7 +8,7 @@ authors = [ license = { text = "Apache 2.0" } readme = "README.md" keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"] -requires-python = ">=3.9" +requires-python = ">=3.11" dependencies = [ "urllib3 (>=2.1.0,<3.0.0)", diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/setup.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/setup.py index 5527d5073fe1..e15d7d113db4 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/setup.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/setup.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """ Echo Server API @@ -13,6 +11,7 @@ """ # noqa: E501 + from setuptools import setup, find_packages # noqa: H301 # To install the library, run the following @@ -23,7 +22,7 @@ # http://pypi.python.org/pypi/setuptools NAME = "openapi-client" VERSION = "1.0.0" -PYTHON_REQUIRES = ">= 3.9" +PYTHON_REQUIRES = ">= 3.11" REQUIRES = [ "urllib3 >= 2.1.0, < 3.0.0", "python-dateutil >= 2.8.2", diff --git a/samples/client/echo_api/python/docs/Bird.md b/samples/client/echo_api/python/docs/Bird.md index e61d8458c978..aaa366493692 100644 --- a/samples/client/echo_api/python/docs/Bird.md +++ b/samples/client/echo_api/python/docs/Bird.md @@ -16,14 +16,14 @@ from openapi_client.models.bird import Bird # TODO update the JSON string below json = "{}" # create an instance of Bird from a JSON string -bird_instance = Bird.from_json(json) +bird_instance = Bird.model_validate_json(json) # print the JSON string representation of the object -print(Bird.to_json()) +print(Bird.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -bird_dict = bird_instance.to_dict() +bird_dict = bird_instance.model_dump(by_alias=True) # create an instance of Bird from a dict -bird_from_dict = Bird.from_dict(bird_dict) +bird_from_dict = Bird.model_validate(bird_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python/docs/Category.md b/samples/client/echo_api/python/docs/Category.md index 9a807466f62a..081573acca81 100644 --- a/samples/client/echo_api/python/docs/Category.md +++ b/samples/client/echo_api/python/docs/Category.md @@ -16,14 +16,14 @@ from openapi_client.models.category import Category # TODO update the JSON string below json = "{}" # create an instance of Category from a JSON string -category_instance = Category.from_json(json) +category_instance = Category.model_validate_json(json) # print the JSON string representation of the object -print(Category.to_json()) +print(Category.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -category_dict = category_instance.to_dict() +category_dict = category_instance.model_dump(by_alias=True) # create an instance of Category from a dict -category_from_dict = Category.from_dict(category_dict) +category_from_dict = Category.model_validate(category_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python/docs/DataQuery.md b/samples/client/echo_api/python/docs/DataQuery.md index 7ea37bfd23e1..93df45d19273 100644 --- a/samples/client/echo_api/python/docs/DataQuery.md +++ b/samples/client/echo_api/python/docs/DataQuery.md @@ -17,14 +17,14 @@ from openapi_client.models.data_query import DataQuery # TODO update the JSON string below json = "{}" # create an instance of DataQuery from a JSON string -data_query_instance = DataQuery.from_json(json) +data_query_instance = DataQuery.model_validate_json(json) # print the JSON string representation of the object -print(DataQuery.to_json()) +print(DataQuery.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -data_query_dict = data_query_instance.to_dict() +data_query_dict = data_query_instance.model_dump(by_alias=True) # create an instance of DataQuery from a dict -data_query_from_dict = DataQuery.from_dict(data_query_dict) +data_query_from_dict = DataQuery.model_validate(data_query_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python/docs/DefaultValue.md b/samples/client/echo_api/python/docs/DefaultValue.md index 7c1668c0d6c6..40271096be2e 100644 --- a/samples/client/echo_api/python/docs/DefaultValue.md +++ b/samples/client/echo_api/python/docs/DefaultValue.md @@ -23,14 +23,14 @@ from openapi_client.models.default_value import DefaultValue # TODO update the JSON string below json = "{}" # create an instance of DefaultValue from a JSON string -default_value_instance = DefaultValue.from_json(json) +default_value_instance = DefaultValue.model_validate_json(json) # print the JSON string representation of the object -print(DefaultValue.to_json()) +print(DefaultValue.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -default_value_dict = default_value_instance.to_dict() +default_value_dict = default_value_instance.model_dump(by_alias=True) # create an instance of DefaultValue from a dict -default_value_from_dict = DefaultValue.from_dict(default_value_dict) +default_value_from_dict = DefaultValue.model_validate(default_value_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python/docs/NumberPropertiesOnly.md b/samples/client/echo_api/python/docs/NumberPropertiesOnly.md index 1f9cb5a1f634..95825bc16c1d 100644 --- a/samples/client/echo_api/python/docs/NumberPropertiesOnly.md +++ b/samples/client/echo_api/python/docs/NumberPropertiesOnly.md @@ -17,14 +17,14 @@ from openapi_client.models.number_properties_only import NumberPropertiesOnly # TODO update the JSON string below json = "{}" # create an instance of NumberPropertiesOnly from a JSON string -number_properties_only_instance = NumberPropertiesOnly.from_json(json) +number_properties_only_instance = NumberPropertiesOnly.model_validate_json(json) # print the JSON string representation of the object -print(NumberPropertiesOnly.to_json()) +print(NumberPropertiesOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -number_properties_only_dict = number_properties_only_instance.to_dict() +number_properties_only_dict = number_properties_only_instance.model_dump(by_alias=True) # create an instance of NumberPropertiesOnly from a dict -number_properties_only_from_dict = NumberPropertiesOnly.from_dict(number_properties_only_dict) +number_properties_only_from_dict = NumberPropertiesOnly.model_validate(number_properties_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python/docs/Pet.md b/samples/client/echo_api/python/docs/Pet.md index 99b4bf3ab010..c2707006974b 100644 --- a/samples/client/echo_api/python/docs/Pet.md +++ b/samples/client/echo_api/python/docs/Pet.md @@ -20,14 +20,14 @@ from openapi_client.models.pet import Pet # TODO update the JSON string below json = "{}" # create an instance of Pet from a JSON string -pet_instance = Pet.from_json(json) +pet_instance = Pet.model_validate_json(json) # print the JSON string representation of the object -print(Pet.to_json()) +print(Pet.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -pet_dict = pet_instance.to_dict() +pet_dict = pet_instance.model_dump(by_alias=True) # create an instance of Pet from a dict -pet_from_dict = Pet.from_dict(pet_dict) +pet_from_dict = Pet.model_validate(pet_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python/docs/Query.md b/samples/client/echo_api/python/docs/Query.md index d39693eb5b93..131b995205b4 100644 --- a/samples/client/echo_api/python/docs/Query.md +++ b/samples/client/echo_api/python/docs/Query.md @@ -16,14 +16,14 @@ from openapi_client.models.query import Query # TODO update the JSON string below json = "{}" # create an instance of Query from a JSON string -query_instance = Query.from_json(json) +query_instance = Query.model_validate_json(json) # print the JSON string representation of the object -print(Query.to_json()) +print(Query.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -query_dict = query_instance.to_dict() +query_dict = query_instance.model_dump(by_alias=True) # create an instance of Query from a dict -query_from_dict = Query.from_dict(query_dict) +query_from_dict = Query.model_validate(query_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python/docs/Tag.md b/samples/client/echo_api/python/docs/Tag.md index 21314992cf43..cbb7c7cf7290 100644 --- a/samples/client/echo_api/python/docs/Tag.md +++ b/samples/client/echo_api/python/docs/Tag.md @@ -16,14 +16,14 @@ from openapi_client.models.tag import Tag # TODO update the JSON string below json = "{}" # create an instance of Tag from a JSON string -tag_instance = Tag.from_json(json) +tag_instance = Tag.model_validate_json(json) # print the JSON string representation of the object -print(Tag.to_json()) +print(Tag.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -tag_dict = tag_instance.to_dict() +tag_dict = tag_instance.model_dump(by_alias=True) # create an instance of Tag from a dict -tag_from_dict = Tag.from_dict(tag_dict) +tag_from_dict = Tag.model_validate(tag_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python/docs/TestFormObjectMultipartRequestMarker.md b/samples/client/echo_api/python/docs/TestFormObjectMultipartRequestMarker.md index bf4046eb4648..aa6304c08de9 100644 --- a/samples/client/echo_api/python/docs/TestFormObjectMultipartRequestMarker.md +++ b/samples/client/echo_api/python/docs/TestFormObjectMultipartRequestMarker.md @@ -15,14 +15,14 @@ from openapi_client.models.test_form_object_multipart_request_marker import Test # TODO update the JSON string below json = "{}" # create an instance of TestFormObjectMultipartRequestMarker from a JSON string -test_form_object_multipart_request_marker_instance = TestFormObjectMultipartRequestMarker.from_json(json) +test_form_object_multipart_request_marker_instance = TestFormObjectMultipartRequestMarker.model_validate_json(json) # print the JSON string representation of the object -print(TestFormObjectMultipartRequestMarker.to_json()) +print(TestFormObjectMultipartRequestMarker.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_form_object_multipart_request_marker_dict = test_form_object_multipart_request_marker_instance.to_dict() +test_form_object_multipart_request_marker_dict = test_form_object_multipart_request_marker_instance.model_dump(by_alias=True) # create an instance of TestFormObjectMultipartRequestMarker from a dict -test_form_object_multipart_request_marker_from_dict = TestFormObjectMultipartRequestMarker.from_dict(test_form_object_multipart_request_marker_dict) +test_form_object_multipart_request_marker_from_dict = TestFormObjectMultipartRequestMarker.model_validate(test_form_object_multipart_request_marker_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python/docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md b/samples/client/echo_api/python/docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md index 96c36ca12e0f..1b237131c19b 100644 --- a/samples/client/echo_api/python/docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md +++ b/samples/client/echo_api/python/docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md @@ -18,14 +18,14 @@ from openapi_client.models.test_query_style_deep_object_explode_true_object_all_ # TODO update the JSON string below json = "{}" # create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a JSON string -test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.from_json(json) +test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_validate_json(json) # print the JSON string representation of the object -print(TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.to_json()) +print(TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_dict = test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance.to_dict() +test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_dict = test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance.model_dump(by_alias=True) # create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a dict -test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_from_dict = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.from_dict(test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_dict) +test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_from_dict = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_validate(test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/echo_api/python/docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md b/samples/client/echo_api/python/docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md index 846a0941a09c..c45189c5e271 100644 --- a/samples/client/echo_api/python/docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md +++ b/samples/client/echo_api/python/docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md @@ -15,14 +15,14 @@ from openapi_client.models.test_query_style_form_explode_true_array_string_query # TODO update the JSON string below json = "{}" # create an instance of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter from a JSON string -test_query_style_form_explode_true_array_string_query_object_parameter_instance = TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.from_json(json) +test_query_style_form_explode_true_array_string_query_object_parameter_instance = TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_validate_json(json) # print the JSON string representation of the object -print(TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.to_json()) +print(TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_query_style_form_explode_true_array_string_query_object_parameter_dict = test_query_style_form_explode_true_array_string_query_object_parameter_instance.to_dict() +test_query_style_form_explode_true_array_string_query_object_parameter_dict = test_query_style_form_explode_true_array_string_query_object_parameter_instance.model_dump(by_alias=True) # create an instance of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter from a dict -test_query_style_form_explode_true_array_string_query_object_parameter_from_dict = TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.from_dict(test_query_style_form_explode_true_array_string_query_object_parameter_dict) +test_query_style_form_explode_true_array_string_query_object_parameter_from_dict = TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_validate(test_query_style_form_explode_true_array_string_query_object_parameter_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 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 2f3e9dfcdb63..c9a8552ff76f 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 @@ -15,7 +15,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import StrictStr 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 33aba2cbd446..f70ceeffddc5 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 @@ -15,7 +15,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field, StrictBytes, StrictStr from typing import Any, Dict, List, Optional, Tuple, Union 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 3353457f7ee8..19a216188386 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 @@ -15,7 +15,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import StrictBool, StrictInt, StrictStr from typing import Optional 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 5c1cd1b540dd..85e88dead22d 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 @@ -15,7 +15,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import StrictBool, StrictInt, StrictStr, field_validator from typing import Optional 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 d2ba4662c21a..c34887fda5d3 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 @@ -15,7 +15,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import StrictInt, StrictStr, field_validator from openapi_client.models.string_enum_ref import StringEnumRef 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 44955f205678..da67b25c2b35 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 @@ -15,7 +15,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from datetime import date, datetime from pydantic import StrictBool, StrictInt, StrictStr, field_validator diff --git a/samples/client/echo_api/python/openapi_client/api_client.py b/samples/client/echo_api/python/openapi_client/api_client.py index 0fab29669922..80f90def42f0 100644 --- a/samples/client/echo_api/python/openapi_client/api_client.py +++ b/samples/client/echo_api/python/openapi_client/api_client.py @@ -313,7 +313,7 @@ def response_deserialize( return_data = self.__deserialize_file(response_data) elif response_type is not None: match = None - content_type = response_data.headers.get('content-type') + content_type = response_data.getheader('content-type') if content_type is not None: match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type) encoding = match.group(1) if match else "utf-8" @@ -330,7 +330,7 @@ def response_deserialize( return ApiResponse( status_code = response_data.status, data = return_data, - headers = response_data.headers, + headers = response_data.getheaders(), raw_data = response_data.data ) @@ -381,13 +381,10 @@ def sanitize_for_serialization(self, obj): # and attributes which value is not None. # Convert attribute name to json key in # model definition for request. - if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')): - obj_dict = obj.to_dict() - else: - obj_dict = obj.__dict__ + obj_dict = obj.model_dump(by_alias=True, exclude_none=True) if isinstance(obj_dict, list): - # here we handle instances that can either be a list or something else, and only became a real list by calling to_dict() + # here we handle instances that can either be a list or something else, and only became a real list by calling model_dump(by_alias=True) return self.sanitize_for_serialization(obj_dict) return { @@ -702,7 +699,7 @@ def __deserialize_file(self, response): os.close(fd) os.remove(path) - content_disposition = response.headers.get("Content-Disposition") + content_disposition = response.getheader("Content-Disposition") if content_disposition: m = re.search( r'filename=[\'"]?([^\'"\s]+)[\'"]?', @@ -802,4 +799,4 @@ def __deserialize_model(self, data, klass): :return: model object. """ - return klass.from_dict(data) + return klass.model_validate(data) diff --git a/samples/client/echo_api/python/openapi_client/configuration.py b/samples/client/echo_api/python/openapi_client/configuration.py index bc8fb73562ff..dd3d712a41df 100644 --- a/samples/client/echo_api/python/openapi_client/configuration.py +++ b/samples/client/echo_api/python/openapi_client/configuration.py @@ -19,8 +19,7 @@ from logging import FileHandler import multiprocessing import sys -from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union -from typing_extensions import NotRequired, Self +from typing import Any, ClassVar, Dict, List, Literal, NotRequired, Optional, TypedDict, Union, Self import urllib3 diff --git a/samples/client/echo_api/python/openapi_client/exceptions.py b/samples/client/echo_api/python/openapi_client/exceptions.py index 1d08908dfb60..0ae1b3ff81f7 100644 --- a/samples/client/echo_api/python/openapi_client/exceptions.py +++ b/samples/client/echo_api/python/openapi_client/exceptions.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """ Echo Server API @@ -12,8 +10,8 @@ Do not edit the class manually. """ # noqa: E501 -from typing import Any, Optional -from typing_extensions import Self + +from typing import Any, Optional, Self class OpenApiException(Exception): """The base exception class for all OpenAPIExceptions""" @@ -105,9 +103,9 @@ def __init__(self, msg, path_to_item=None) -> None: class ApiException(OpenApiException): def __init__( - self, - status=None, - reason=None, + self, + status=None, + reason=None, http_resp=None, *, body: Optional[str] = None, @@ -129,14 +127,14 @@ def __init__( self.body = http_resp.data.decode('utf-8') except Exception: pass - self.headers = http_resp.headers + self.headers = http_resp.getheaders() @classmethod def from_response( - cls, - *, - http_resp, - body: Optional[str], + cls, + *, + http_resp, + body: Optional[str], data: Optional[Any], ) -> Self: if http_resp.status == 400: @@ -170,11 +168,8 @@ def __str__(self): error_message += "HTTP response headers: {0}\n".format( self.headers) - if self.body: - error_message += "HTTP response body: {0}\n".format(self.body) - - if self.data: - error_message += "HTTP response data: {0}\n".format(self.data) + if self.data or self.body: + error_message += "HTTP response body: {0}\n".format(self.data or self.body) return error_message 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 9f0dd625119d..738e59b9f5c1 100644 --- a/samples/client/echo_api/python/openapi_client/models/bird.py +++ b/samples/client/echo_api/python/openapi_client/models/bird.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Bird(BaseModel): """ @@ -42,49 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Bird from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Bird from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "color": obj.get("color") - }) - return _obj 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 d81b92c0f6e3..b097d9ac4bea 100644 --- a/samples/client/echo_api/python/openapi_client/models/category.py +++ b/samples/client/echo_api/python/openapi_client/models/category.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Category(BaseModel): """ @@ -42,49 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Category from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Category from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") - }) - return _obj 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 dc9a58598e63..9d16f06cc7c2 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 @@ -22,8 +22,8 @@ from pydantic import ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional from openapi_client.models.query import Query -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DataQuery(Query): """ @@ -45,52 +45,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DataQuery from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DataQuery from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "outcomes": obj.get("outcomes"), - "suffix": obj.get("suffix"), - "text": obj.get("text"), - "date": obj.get("date") - }) - return _obj 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 feee1843319f..d60615645132 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 @@ -21,15 +21,14 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional from openapi_client.models.string_enum_ref import StringEnumRef -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DefaultValue(BaseModel): """ to test the default value of properties """ # noqa: E501 array_string_enum_ref_default: Optional[List[StringEnumRef]] = None - array_string_enum_default: Optional[List[StrictStr]] = None array_string_default: Optional[List[StrictStr]] = None array_integer_default: Optional[List[StrictInt]] = None array_string: Optional[List[StrictStr]] = None @@ -60,70 +59,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DefaultValue from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # set to None if array_string_nullable (nullable) is None - # 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 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 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DefaultValue from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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"), - "array_integer_default": obj.get("array_integer_default"), - "array_string": obj.get("array_string"), - "array_string_nullable": obj.get("array_string_nullable"), - "array_string_extension_nullable": obj.get("array_string_extension_nullable"), - "string_nullable": obj.get("string_nullable") - }) - return _obj 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 08b3d5600ffa..e2222747eca6 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 @@ -21,8 +21,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt from typing import Any, ClassVar, Dict, List, Optional, Union from typing_extensions import Annotated -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class NumberPropertiesOnly(BaseModel): """ @@ -44,50 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of NumberPropertiesOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of NumberPropertiesOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "number": obj.get("number"), - "float": obj.get("float"), - "double": obj.get("double") - }) - return _obj 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 0a0ae74d1155..4ab26ed170c8 100644 --- a/samples/client/echo_api/python/openapi_client/models/pet.py +++ b/samples/client/echo_api/python/openapi_client/models/pet.py @@ -22,8 +22,8 @@ from typing import Any, ClassVar, Dict, List, Optional from openapi_client.models.category import Category from openapi_client.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Pet(BaseModel): """ @@ -34,7 +34,10 @@ class Pet(BaseModel): category: Optional[Category] = None photo_urls: List[StrictStr] = Field(alias="photoUrls") tags: Optional[List[Tag]] = None - status: Optional[StrictStr] = Field(default=None, description="pet status in the store") + status: Optional[StatusEnum] = Field( + None, + description="pet status in the store" + ) __properties: ClassVar[List[str]] = ["id", "name", "category", "photoUrls", "tags", "status"] @field_validator('status') @@ -58,63 +61,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Pet from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of category - if self.category: - _dict['category'] = self.category.to_dict() - # override the default output from pydantic by calling `to_dict()` of each item in tags (list) - _items = [] - if self.tags: - for _item_tags in self.tags: - if _item_tags: - _items.append(_item_tags.to_dict()) - _dict['tags'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Pet from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name"), - "category": Category.from_dict(obj["category"]) if obj.get("category") is not None else None, - "photoUrls": obj.get("photoUrls"), - "tags": [Tag.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None, - "status": obj.get("status") - }) - return _obj 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 97199fb7fd95..064036ff3e1e 100644 --- a/samples/client/echo_api/python/openapi_client/models/query.py +++ b/samples/client/echo_api/python/openapi_client/models/query.py @@ -20,15 +20,14 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Query(BaseModel): """ Query """ # noqa: E501 id: Optional[StrictInt] = Field(default=None, description="Query") - outcomes: Optional[List[StrictStr]] = None __properties: ClassVar[List[str]] = ["id", "outcomes"] @field_validator('outcomes') @@ -53,38 +52,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Query from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Self]: - """Create an instance of Query from a dict""" diff --git a/samples/client/echo_api/python/openapi_client/models/string_enum_ref.py b/samples/client/echo_api/python/openapi_client/models/string_enum_ref.py index 90328aea76dd..e853e6df8b97 100644 --- a/samples/client/echo_api/python/openapi_client/models/string_enum_ref.py +++ b/samples/client/echo_api/python/openapi_client/models/string_enum_ref.py @@ -15,18 +15,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class StringEnumRef(StrEnum): -class StringEnumRef(str, Enum): """ StringEnumRef """ - """ - allowed enum values - """ + # Allowed enum values SUCCESS = 'success' FAILURE = 'failure' UNCLASSIFIED = 'unclassified' @@ -36,4 +34,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of StringEnumRef from a JSON string""" return cls(json.loads(json_str)) - 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 feec4b3f31cc..17e7a3c39bcf 100644 --- a/samples/client/echo_api/python/openapi_client/models/tag.py +++ b/samples/client/echo_api/python/openapi_client/models/tag.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Tag(BaseModel): """ @@ -42,49 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Tag from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Tag from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") - }) - return _obj diff --git a/samples/client/echo_api/python/openapi_client/models/test_form_object_multipart_request_marker.py b/samples/client/echo_api/python/openapi_client/models/test_form_object_multipart_request_marker.py index 9f7747151bd5..51c2fcc79e8d 100644 --- a/samples/client/echo_api/python/openapi_client/models/test_form_object_multipart_request_marker.py +++ b/samples/client/echo_api/python/openapi_client/models/test_form_object_multipart_request_marker.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestFormObjectMultipartRequestMarker(BaseModel): """ @@ -41,48 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestFormObjectMultipartRequestMarker from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestFormObjectMultipartRequestMarker from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - return _obj 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 8ed0f58c990b..cd3cbb8d7fd6 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseModel): """ @@ -44,51 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "color": obj.get("color"), - "id": obj.get("id"), - "name": obj.get("name") - }) - return _obj 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 a9a7a5929f2e..a4963abb60de 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel): """ @@ -41,48 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "values": obj.get("values") - }) - return _obj diff --git a/samples/client/echo_api/python/pyproject.toml b/samples/client/echo_api/python/pyproject.toml index 84c2c75e9f88..5a646fca20fb 100644 --- a/samples/client/echo_api/python/pyproject.toml +++ b/samples/client/echo_api/python/pyproject.toml @@ -8,7 +8,7 @@ authors = [ license = { text = "Apache 2.0" } readme = "README.md" keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"] -requires-python = ">=3.9" +requires-python = ">=3.11" dependencies = [ "urllib3 (>=2.1.0,<3.0.0)", diff --git a/samples/client/echo_api/python/setup.py b/samples/client/echo_api/python/setup.py index 5527d5073fe1..e15d7d113db4 100644 --- a/samples/client/echo_api/python/setup.py +++ b/samples/client/echo_api/python/setup.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """ Echo Server API @@ -13,6 +11,7 @@ """ # noqa: E501 + from setuptools import setup, find_packages # noqa: H301 # To install the library, run the following @@ -23,7 +22,7 @@ # http://pypi.python.org/pypi/setuptools NAME = "openapi-client" VERSION = "1.0.0" -PYTHON_REQUIRES = ">= 3.9" +PYTHON_REQUIRES = ">= 3.11" REQUIRES = [ "urllib3 >= 2.1.0, < 3.0.0", "python-dateutil >= 2.8.2", diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesAnyType.md b/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesAnyType.md index 314cba3a614c..6491c95beba5 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesAnyType.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesAnyType.md @@ -15,14 +15,14 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesAnyType from a JSON string -additional_properties_any_type_instance = AdditionalPropertiesAnyType.from_json(json) +additional_properties_any_type_instance = AdditionalPropertiesAnyType.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesAnyType.to_json()) +print(AdditionalPropertiesAnyType.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_any_type_dict = additional_properties_any_type_instance.to_dict() +additional_properties_any_type_dict = additional_properties_any_type_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesAnyType from a dict -additional_properties_any_type_from_dict = AdditionalPropertiesAnyType.from_dict(additional_properties_any_type_dict) +additional_properties_any_type_from_dict = AdditionalPropertiesAnyType.model_validate(additional_properties_any_type_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesClass.md b/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesClass.md index 8d4c08707f55..2a618964bc5c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesClass.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesClass.md @@ -16,14 +16,14 @@ from petstore_api.models.additional_properties_class import AdditionalProperties # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesClass from a JSON string -additional_properties_class_instance = AdditionalPropertiesClass.from_json(json) +additional_properties_class_instance = AdditionalPropertiesClass.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesClass.to_json()) +print(AdditionalPropertiesClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_class_dict = additional_properties_class_instance.to_dict() +additional_properties_class_dict = additional_properties_class_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesClass from a dict -additional_properties_class_from_dict = AdditionalPropertiesClass.from_dict(additional_properties_class_dict) +additional_properties_class_from_dict = AdditionalPropertiesClass.model_validate(additional_properties_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesObject.md b/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesObject.md index d647ec64896f..1c66f8e5d29a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesObject.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesObject.md @@ -15,14 +15,14 @@ from petstore_api.models.additional_properties_object import AdditionalPropertie # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesObject from a JSON string -additional_properties_object_instance = AdditionalPropertiesObject.from_json(json) +additional_properties_object_instance = AdditionalPropertiesObject.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesObject.to_json()) +print(AdditionalPropertiesObject.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_object_dict = additional_properties_object_instance.to_dict() +additional_properties_object_dict = additional_properties_object_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesObject from a dict -additional_properties_object_from_dict = AdditionalPropertiesObject.from_dict(additional_properties_object_dict) +additional_properties_object_from_dict = AdditionalPropertiesObject.model_validate(additional_properties_object_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesWithDescriptionOnly.md b/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesWithDescriptionOnly.md index 061f5524872b..88d66f028a2b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesWithDescriptionOnly.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesWithDescriptionOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.additional_properties_with_description_only import Addi # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesWithDescriptionOnly from a JSON string -additional_properties_with_description_only_instance = AdditionalPropertiesWithDescriptionOnly.from_json(json) +additional_properties_with_description_only_instance = AdditionalPropertiesWithDescriptionOnly.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesWithDescriptionOnly.to_json()) +print(AdditionalPropertiesWithDescriptionOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_with_description_only_dict = additional_properties_with_description_only_instance.to_dict() +additional_properties_with_description_only_dict = additional_properties_with_description_only_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesWithDescriptionOnly from a dict -additional_properties_with_description_only_from_dict = AdditionalPropertiesWithDescriptionOnly.from_dict(additional_properties_with_description_only_dict) +additional_properties_with_description_only_from_dict = AdditionalPropertiesWithDescriptionOnly.model_validate(additional_properties_with_description_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/AllOfSuperModel.md b/samples/openapi3/client/petstore/python-aiohttp/docs/AllOfSuperModel.md index 421a1527f1ef..bec62554ebf0 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/AllOfSuperModel.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/AllOfSuperModel.md @@ -15,14 +15,14 @@ from petstore_api.models.all_of_super_model import AllOfSuperModel # TODO update the JSON string below json = "{}" # create an instance of AllOfSuperModel from a JSON string -all_of_super_model_instance = AllOfSuperModel.from_json(json) +all_of_super_model_instance = AllOfSuperModel.model_validate_json(json) # print the JSON string representation of the object -print(AllOfSuperModel.to_json()) +print(AllOfSuperModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -all_of_super_model_dict = all_of_super_model_instance.to_dict() +all_of_super_model_dict = all_of_super_model_instance.model_dump(by_alias=True) # create an instance of AllOfSuperModel from a dict -all_of_super_model_from_dict = AllOfSuperModel.from_dict(all_of_super_model_dict) +all_of_super_model_from_dict = AllOfSuperModel.model_validate(all_of_super_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/AllOfWithSingleRef.md b/samples/openapi3/client/petstore/python-aiohttp/docs/AllOfWithSingleRef.md index 203a4b5da3d5..05ae8a658ab3 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/AllOfWithSingleRef.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/AllOfWithSingleRef.md @@ -16,14 +16,14 @@ from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef # TODO update the JSON string below json = "{}" # create an instance of AllOfWithSingleRef from a JSON string -all_of_with_single_ref_instance = AllOfWithSingleRef.from_json(json) +all_of_with_single_ref_instance = AllOfWithSingleRef.model_validate_json(json) # print the JSON string representation of the object -print(AllOfWithSingleRef.to_json()) +print(AllOfWithSingleRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -all_of_with_single_ref_dict = all_of_with_single_ref_instance.to_dict() +all_of_with_single_ref_dict = all_of_with_single_ref_instance.model_dump(by_alias=True) # create an instance of AllOfWithSingleRef from a dict -all_of_with_single_ref_from_dict = AllOfWithSingleRef.from_dict(all_of_with_single_ref_dict) +all_of_with_single_ref_from_dict = AllOfWithSingleRef.model_validate(all_of_with_single_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Animal.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Animal.md index 381d27b66e44..eb20439f3782 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Animal.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Animal.md @@ -16,14 +16,14 @@ from petstore_api.models.animal import Animal # TODO update the JSON string below json = "{}" # create an instance of Animal from a JSON string -animal_instance = Animal.from_json(json) +animal_instance = Animal.model_validate_json(json) # print the JSON string representation of the object -print(Animal.to_json()) +print(Animal.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -animal_dict = animal_instance.to_dict() +animal_dict = animal_instance.model_dump(by_alias=True) # create an instance of Animal from a dict -animal_from_dict = Animal.from_dict(animal_dict) +animal_from_dict = Animal.model_validate(animal_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/AnyOfColor.md b/samples/openapi3/client/petstore/python-aiohttp/docs/AnyOfColor.md index 6ed75dd7b48a..c656fdbbae05 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/AnyOfColor.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/AnyOfColor.md @@ -15,14 +15,14 @@ from petstore_api.models.any_of_color import AnyOfColor # TODO update the JSON string below json = "{}" # create an instance of AnyOfColor from a JSON string -any_of_color_instance = AnyOfColor.from_json(json) +any_of_color_instance = AnyOfColor.model_validate_json(json) # print the JSON string representation of the object -print(AnyOfColor.to_json()) +print(AnyOfColor.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -any_of_color_dict = any_of_color_instance.to_dict() +any_of_color_dict = any_of_color_instance.model_dump(by_alias=True) # create an instance of AnyOfColor from a dict -any_of_color_from_dict = AnyOfColor.from_dict(any_of_color_dict) +any_of_color_from_dict = AnyOfColor.model_validate(any_of_color_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/AnyOfPig.md b/samples/openapi3/client/petstore/python-aiohttp/docs/AnyOfPig.md index 9367e2261898..0c273f175319 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/AnyOfPig.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/AnyOfPig.md @@ -17,14 +17,14 @@ from petstore_api.models.any_of_pig import AnyOfPig # TODO update the JSON string below json = "{}" # create an instance of AnyOfPig from a JSON string -any_of_pig_instance = AnyOfPig.from_json(json) +any_of_pig_instance = AnyOfPig.model_validate_json(json) # print the JSON string representation of the object -print(AnyOfPig.to_json()) +print(AnyOfPig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -any_of_pig_dict = any_of_pig_instance.to_dict() +any_of_pig_dict = any_of_pig_instance.model_dump(by_alias=True) # create an instance of AnyOfPig from a dict -any_of_pig_from_dict = AnyOfPig.from_dict(any_of_pig_dict) +any_of_pig_from_dict = AnyOfPig.model_validate(any_of_pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayOfArrayOfModel.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayOfArrayOfModel.md index f866863d53f9..83505f6eb05b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayOfArrayOfModel.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayOfArrayOfModel.md @@ -15,14 +15,14 @@ from petstore_api.models.array_of_array_of_model import ArrayOfArrayOfModel # TODO update the JSON string below json = "{}" # create an instance of ArrayOfArrayOfModel from a JSON string -array_of_array_of_model_instance = ArrayOfArrayOfModel.from_json(json) +array_of_array_of_model_instance = ArrayOfArrayOfModel.model_validate_json(json) # print the JSON string representation of the object -print(ArrayOfArrayOfModel.to_json()) +print(ArrayOfArrayOfModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_of_array_of_model_dict = array_of_array_of_model_instance.to_dict() +array_of_array_of_model_dict = array_of_array_of_model_instance.model_dump(by_alias=True) # create an instance of ArrayOfArrayOfModel from a dict -array_of_array_of_model_from_dict = ArrayOfArrayOfModel.from_dict(array_of_array_of_model_dict) +array_of_array_of_model_from_dict = ArrayOfArrayOfModel.model_validate(array_of_array_of_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayOfArrayOfNumberOnly.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayOfArrayOfNumberOnly.md index 32bd2dfbf1e2..0027448edc27 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayOfArrayOfNumberOnly.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayOfArrayOfNumberOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumb # TODO update the JSON string below json = "{}" # create an instance of ArrayOfArrayOfNumberOnly from a JSON string -array_of_array_of_number_only_instance = ArrayOfArrayOfNumberOnly.from_json(json) +array_of_array_of_number_only_instance = ArrayOfArrayOfNumberOnly.model_validate_json(json) # print the JSON string representation of the object -print(ArrayOfArrayOfNumberOnly.to_json()) +print(ArrayOfArrayOfNumberOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_of_array_of_number_only_dict = array_of_array_of_number_only_instance.to_dict() +array_of_array_of_number_only_dict = array_of_array_of_number_only_instance.model_dump(by_alias=True) # create an instance of ArrayOfArrayOfNumberOnly from a dict -array_of_array_of_number_only_from_dict = ArrayOfArrayOfNumberOnly.from_dict(array_of_array_of_number_only_dict) +array_of_array_of_number_only_from_dict = ArrayOfArrayOfNumberOnly.model_validate(array_of_array_of_number_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayOfNumberOnly.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayOfNumberOnly.md index b814d7594942..81aeee6c1add 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayOfNumberOnly.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayOfNumberOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.array_of_number_only import ArrayOfNumberOnly # TODO update the JSON string below json = "{}" # create an instance of ArrayOfNumberOnly from a JSON string -array_of_number_only_instance = ArrayOfNumberOnly.from_json(json) +array_of_number_only_instance = ArrayOfNumberOnly.model_validate_json(json) # print the JSON string representation of the object -print(ArrayOfNumberOnly.to_json()) +print(ArrayOfNumberOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_of_number_only_dict = array_of_number_only_instance.to_dict() +array_of_number_only_dict = array_of_number_only_instance.model_dump(by_alias=True) # create an instance of ArrayOfNumberOnly from a dict -array_of_number_only_from_dict = ArrayOfNumberOnly.from_dict(array_of_number_only_dict) +array_of_number_only_from_dict = ArrayOfNumberOnly.model_validate(array_of_number_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayTest.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayTest.md index ed871fae662d..62b868a02c64 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayTest.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ArrayTest.md @@ -18,14 +18,14 @@ from petstore_api.models.array_test import ArrayTest # TODO update the JSON string below json = "{}" # create an instance of ArrayTest from a JSON string -array_test_instance = ArrayTest.from_json(json) +array_test_instance = ArrayTest.model_validate_json(json) # print the JSON string representation of the object -print(ArrayTest.to_json()) +print(ArrayTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_test_dict = array_test_instance.to_dict() +array_test_dict = array_test_instance.model_dump(by_alias=True) # create an instance of ArrayTest from a dict -array_test_from_dict = ArrayTest.from_dict(array_test_dict) +array_test_from_dict = ArrayTest.model_validate(array_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/BaseDiscriminator.md b/samples/openapi3/client/petstore/python-aiohttp/docs/BaseDiscriminator.md index fcdbeb032e68..a317fc0421fe 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/BaseDiscriminator.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/BaseDiscriminator.md @@ -15,14 +15,14 @@ from petstore_api.models.base_discriminator import BaseDiscriminator # TODO update the JSON string below json = "{}" # create an instance of BaseDiscriminator from a JSON string -base_discriminator_instance = BaseDiscriminator.from_json(json) +base_discriminator_instance = BaseDiscriminator.model_validate_json(json) # print the JSON string representation of the object -print(BaseDiscriminator.to_json()) +print(BaseDiscriminator.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -base_discriminator_dict = base_discriminator_instance.to_dict() +base_discriminator_dict = base_discriminator_instance.model_dump(by_alias=True) # create an instance of BaseDiscriminator from a dict -base_discriminator_from_dict = BaseDiscriminator.from_dict(base_discriminator_dict) +base_discriminator_from_dict = BaseDiscriminator.model_validate(base_discriminator_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/BasquePig.md b/samples/openapi3/client/petstore/python-aiohttp/docs/BasquePig.md index ee28d628722f..8af258aa7901 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/BasquePig.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/BasquePig.md @@ -16,14 +16,14 @@ from petstore_api.models.basque_pig import BasquePig # TODO update the JSON string below json = "{}" # create an instance of BasquePig from a JSON string -basque_pig_instance = BasquePig.from_json(json) +basque_pig_instance = BasquePig.model_validate_json(json) # print the JSON string representation of the object -print(BasquePig.to_json()) +print(BasquePig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -basque_pig_dict = basque_pig_instance.to_dict() +basque_pig_dict = basque_pig_instance.model_dump(by_alias=True) # create an instance of BasquePig from a dict -basque_pig_from_dict = BasquePig.from_dict(basque_pig_dict) +basque_pig_from_dict = BasquePig.model_validate(basque_pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Bathing.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Bathing.md index 6ad70e2f67cc..5365c9614d17 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Bathing.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Bathing.md @@ -17,14 +17,14 @@ from petstore_api.models.bathing import Bathing # TODO update the JSON string below json = "{}" # create an instance of Bathing from a JSON string -bathing_instance = Bathing.from_json(json) +bathing_instance = Bathing.model_validate_json(json) # print the JSON string representation of the object -print(Bathing.to_json()) +print(Bathing.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -bathing_dict = bathing_instance.to_dict() +bathing_dict = bathing_instance.model_dump(by_alias=True) # create an instance of Bathing from a dict -bathing_from_dict = Bathing.from_dict(bathing_dict) +bathing_from_dict = Bathing.model_validate(bathing_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Capitalization.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Capitalization.md index 6f564a8ed8c9..efbf7520b692 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Capitalization.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Capitalization.md @@ -20,14 +20,14 @@ from petstore_api.models.capitalization import Capitalization # TODO update the JSON string below json = "{}" # create an instance of Capitalization from a JSON string -capitalization_instance = Capitalization.from_json(json) +capitalization_instance = Capitalization.model_validate_json(json) # print the JSON string representation of the object -print(Capitalization.to_json()) +print(Capitalization.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -capitalization_dict = capitalization_instance.to_dict() +capitalization_dict = capitalization_instance.model_dump(by_alias=True) # create an instance of Capitalization from a dict -capitalization_from_dict = Capitalization.from_dict(capitalization_dict) +capitalization_from_dict = Capitalization.model_validate(capitalization_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Cat.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Cat.md index d0e39efdb33e..2940176bb9b8 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Cat.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Cat.md @@ -15,14 +15,14 @@ from petstore_api.models.cat import Cat # TODO update the JSON string below json = "{}" # create an instance of Cat from a JSON string -cat_instance = Cat.from_json(json) +cat_instance = Cat.model_validate_json(json) # print the JSON string representation of the object -print(Cat.to_json()) +print(Cat.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -cat_dict = cat_instance.to_dict() +cat_dict = cat_instance.model_dump(by_alias=True) # create an instance of Cat from a dict -cat_from_dict = Cat.from_dict(cat_dict) +cat_from_dict = Cat.model_validate(cat_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Category.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Category.md index dbde14b7344c..a1509b71308f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Category.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Category.md @@ -16,14 +16,14 @@ from petstore_api.models.category import Category # TODO update the JSON string below json = "{}" # create an instance of Category from a JSON string -category_instance = Category.from_json(json) +category_instance = Category.model_validate_json(json) # print the JSON string representation of the object -print(Category.to_json()) +print(Category.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -category_dict = category_instance.to_dict() +category_dict = category_instance.model_dump(by_alias=True) # create an instance of Category from a dict -category_from_dict = Category.from_dict(category_dict) +category_from_dict = Category.model_validate(category_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/CircularAllOfRef.md b/samples/openapi3/client/petstore/python-aiohttp/docs/CircularAllOfRef.md index 65b171177e58..aaab0079b3f4 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/CircularAllOfRef.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/CircularAllOfRef.md @@ -16,14 +16,14 @@ from petstore_api.models.circular_all_of_ref import CircularAllOfRef # TODO update the JSON string below json = "{}" # create an instance of CircularAllOfRef from a JSON string -circular_all_of_ref_instance = CircularAllOfRef.from_json(json) +circular_all_of_ref_instance = CircularAllOfRef.model_validate_json(json) # print the JSON string representation of the object -print(CircularAllOfRef.to_json()) +print(CircularAllOfRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -circular_all_of_ref_dict = circular_all_of_ref_instance.to_dict() +circular_all_of_ref_dict = circular_all_of_ref_instance.model_dump(by_alias=True) # create an instance of CircularAllOfRef from a dict -circular_all_of_ref_from_dict = CircularAllOfRef.from_dict(circular_all_of_ref_dict) +circular_all_of_ref_from_dict = CircularAllOfRef.model_validate(circular_all_of_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/CircularReferenceModel.md b/samples/openapi3/client/petstore/python-aiohttp/docs/CircularReferenceModel.md index 87216f7273ab..33ec5e9b09bf 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/CircularReferenceModel.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/CircularReferenceModel.md @@ -16,14 +16,14 @@ from petstore_api.models.circular_reference_model import CircularReferenceModel # TODO update the JSON string below json = "{}" # create an instance of CircularReferenceModel from a JSON string -circular_reference_model_instance = CircularReferenceModel.from_json(json) +circular_reference_model_instance = CircularReferenceModel.model_validate_json(json) # print the JSON string representation of the object -print(CircularReferenceModel.to_json()) +print(CircularReferenceModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -circular_reference_model_dict = circular_reference_model_instance.to_dict() +circular_reference_model_dict = circular_reference_model_instance.model_dump(by_alias=True) # create an instance of CircularReferenceModel from a dict -circular_reference_model_from_dict = CircularReferenceModel.from_dict(circular_reference_model_dict) +circular_reference_model_from_dict = CircularReferenceModel.model_validate(circular_reference_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ClassModel.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ClassModel.md index ea76a5c157bf..9e69a69b5c27 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/ClassModel.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ClassModel.md @@ -16,14 +16,14 @@ from petstore_api.models.class_model import ClassModel # TODO update the JSON string below json = "{}" # create an instance of ClassModel from a JSON string -class_model_instance = ClassModel.from_json(json) +class_model_instance = ClassModel.model_validate_json(json) # print the JSON string representation of the object -print(ClassModel.to_json()) +print(ClassModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -class_model_dict = class_model_instance.to_dict() +class_model_dict = class_model_instance.model_dump(by_alias=True) # create an instance of ClassModel from a dict -class_model_from_dict = ClassModel.from_dict(class_model_dict) +class_model_from_dict = ClassModel.model_validate(class_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Client.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Client.md index 22321c189150..6a9b3d800434 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Client.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Client.md @@ -15,14 +15,14 @@ from petstore_api.models.client import Client # TODO update the JSON string below json = "{}" # create an instance of Client from a JSON string -client_instance = Client.from_json(json) +client_instance = Client.model_validate_json(json) # print the JSON string representation of the object -print(Client.to_json()) +print(Client.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -client_dict = client_instance.to_dict() +client_dict = client_instance.model_dump(by_alias=True) # create an instance of Client from a dict -client_from_dict = Client.from_dict(client_dict) +client_from_dict = Client.model_validate(client_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Color.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Color.md index 9ac3ab2e91f4..088998e89af9 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Color.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Color.md @@ -15,14 +15,14 @@ from petstore_api.models.color import Color # TODO update the JSON string below json = "{}" # create an instance of Color from a JSON string -color_instance = Color.from_json(json) +color_instance = Color.model_validate_json(json) # print the JSON string representation of the object -print(Color.to_json()) +print(Color.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -color_dict = color_instance.to_dict() +color_dict = color_instance.model_dump(by_alias=True) # create an instance of Color from a dict -color_from_dict = Color.from_dict(color_dict) +color_from_dict = Color.model_validate(color_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Creature.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Creature.md index a4710214c198..bc746b2856e9 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Creature.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Creature.md @@ -16,14 +16,14 @@ from petstore_api.models.creature import Creature # TODO update the JSON string below json = "{}" # create an instance of Creature from a JSON string -creature_instance = Creature.from_json(json) +creature_instance = Creature.model_validate_json(json) # print the JSON string representation of the object -print(Creature.to_json()) +print(Creature.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -creature_dict = creature_instance.to_dict() +creature_dict = creature_instance.model_dump(by_alias=True) # create an instance of Creature from a dict -creature_from_dict = Creature.from_dict(creature_dict) +creature_from_dict = Creature.model_validate(creature_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/CreatureInfo.md b/samples/openapi3/client/petstore/python-aiohttp/docs/CreatureInfo.md index db3b82bb9ff5..a355b9e52802 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/CreatureInfo.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/CreatureInfo.md @@ -15,14 +15,14 @@ from petstore_api.models.creature_info import CreatureInfo # TODO update the JSON string below json = "{}" # create an instance of CreatureInfo from a JSON string -creature_info_instance = CreatureInfo.from_json(json) +creature_info_instance = CreatureInfo.model_validate_json(json) # print the JSON string representation of the object -print(CreatureInfo.to_json()) +print(CreatureInfo.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -creature_info_dict = creature_info_instance.to_dict() +creature_info_dict = creature_info_instance.model_dump(by_alias=True) # create an instance of CreatureInfo from a dict -creature_info_from_dict = CreatureInfo.from_dict(creature_info_dict) +creature_info_from_dict = CreatureInfo.model_validate(creature_info_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/DanishPig.md b/samples/openapi3/client/petstore/python-aiohttp/docs/DanishPig.md index 16941388832a..58902d70f7bd 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/DanishPig.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/DanishPig.md @@ -16,14 +16,14 @@ from petstore_api.models.danish_pig import DanishPig # TODO update the JSON string below json = "{}" # create an instance of DanishPig from a JSON string -danish_pig_instance = DanishPig.from_json(json) +danish_pig_instance = DanishPig.model_validate_json(json) # print the JSON string representation of the object -print(DanishPig.to_json()) +print(DanishPig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -danish_pig_dict = danish_pig_instance.to_dict() +danish_pig_dict = danish_pig_instance.model_dump(by_alias=True) # create an instance of DanishPig from a dict -danish_pig_from_dict = DanishPig.from_dict(danish_pig_dict) +danish_pig_from_dict = DanishPig.model_validate(danish_pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/DeprecatedObject.md b/samples/openapi3/client/petstore/python-aiohttp/docs/DeprecatedObject.md index 6b362f379ba4..55abc18b24d6 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/DeprecatedObject.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/DeprecatedObject.md @@ -15,14 +15,14 @@ from petstore_api.models.deprecated_object import DeprecatedObject # TODO update the JSON string below json = "{}" # create an instance of DeprecatedObject from a JSON string -deprecated_object_instance = DeprecatedObject.from_json(json) +deprecated_object_instance = DeprecatedObject.model_validate_json(json) # print the JSON string representation of the object -print(DeprecatedObject.to_json()) +print(DeprecatedObject.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -deprecated_object_dict = deprecated_object_instance.to_dict() +deprecated_object_dict = deprecated_object_instance.model_dump(by_alias=True) # create an instance of DeprecatedObject from a dict -deprecated_object_from_dict = DeprecatedObject.from_dict(deprecated_object_dict) +deprecated_object_from_dict = DeprecatedObject.model_validate(deprecated_object_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/DiscriminatorAllOfSub.md b/samples/openapi3/client/petstore/python-aiohttp/docs/DiscriminatorAllOfSub.md index f72b6e8e68ca..9453c541c53a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/DiscriminatorAllOfSub.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/DiscriminatorAllOfSub.md @@ -14,14 +14,14 @@ from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub # TODO update the JSON string below json = "{}" # create an instance of DiscriminatorAllOfSub from a JSON string -discriminator_all_of_sub_instance = DiscriminatorAllOfSub.from_json(json) +discriminator_all_of_sub_instance = DiscriminatorAllOfSub.model_validate_json(json) # print the JSON string representation of the object -print(DiscriminatorAllOfSub.to_json()) +print(DiscriminatorAllOfSub.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -discriminator_all_of_sub_dict = discriminator_all_of_sub_instance.to_dict() +discriminator_all_of_sub_dict = discriminator_all_of_sub_instance.model_dump(by_alias=True) # create an instance of DiscriminatorAllOfSub from a dict -discriminator_all_of_sub_from_dict = DiscriminatorAllOfSub.from_dict(discriminator_all_of_sub_dict) +discriminator_all_of_sub_from_dict = DiscriminatorAllOfSub.model_validate(discriminator_all_of_sub_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/DiscriminatorAllOfSuper.md b/samples/openapi3/client/petstore/python-aiohttp/docs/DiscriminatorAllOfSuper.md index 477c05bfc446..c83f6792acab 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/DiscriminatorAllOfSuper.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/DiscriminatorAllOfSuper.md @@ -15,14 +15,14 @@ from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSup # TODO update the JSON string below json = "{}" # create an instance of DiscriminatorAllOfSuper from a JSON string -discriminator_all_of_super_instance = DiscriminatorAllOfSuper.from_json(json) +discriminator_all_of_super_instance = DiscriminatorAllOfSuper.model_validate_json(json) # print the JSON string representation of the object -print(DiscriminatorAllOfSuper.to_json()) +print(DiscriminatorAllOfSuper.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -discriminator_all_of_super_dict = discriminator_all_of_super_instance.to_dict() +discriminator_all_of_super_dict = discriminator_all_of_super_instance.model_dump(by_alias=True) # create an instance of DiscriminatorAllOfSuper from a dict -discriminator_all_of_super_from_dict = DiscriminatorAllOfSuper.from_dict(discriminator_all_of_super_dict) +discriminator_all_of_super_from_dict = DiscriminatorAllOfSuper.model_validate(discriminator_all_of_super_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Dog.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Dog.md index ed23f613d01d..099b3f781b4b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Dog.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Dog.md @@ -15,14 +15,14 @@ from petstore_api.models.dog import Dog # TODO update the JSON string below json = "{}" # create an instance of Dog from a JSON string -dog_instance = Dog.from_json(json) +dog_instance = Dog.model_validate_json(json) # print the JSON string representation of the object -print(Dog.to_json()) +print(Dog.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -dog_dict = dog_instance.to_dict() +dog_dict = dog_instance.model_dump(by_alias=True) # create an instance of Dog from a dict -dog_from_dict = Dog.from_dict(dog_dict) +dog_from_dict = Dog.model_validate(dog_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/DummyModel.md b/samples/openapi3/client/petstore/python-aiohttp/docs/DummyModel.md index 01b675977f58..bf4ef8ec2b03 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/DummyModel.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/DummyModel.md @@ -16,14 +16,14 @@ from petstore_api.models.dummy_model import DummyModel # TODO update the JSON string below json = "{}" # create an instance of DummyModel from a JSON string -dummy_model_instance = DummyModel.from_json(json) +dummy_model_instance = DummyModel.model_validate_json(json) # print the JSON string representation of the object -print(DummyModel.to_json()) +print(DummyModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -dummy_model_dict = dummy_model_instance.to_dict() +dummy_model_dict = dummy_model_instance.model_dump(by_alias=True) # create an instance of DummyModel from a dict -dummy_model_from_dict = DummyModel.from_dict(dummy_model_dict) +dummy_model_from_dict = DummyModel.model_validate(dummy_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/EnumArrays.md b/samples/openapi3/client/petstore/python-aiohttp/docs/EnumArrays.md index f44617497bce..fa9dc0d523a9 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/EnumArrays.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/EnumArrays.md @@ -16,14 +16,14 @@ from petstore_api.models.enum_arrays import EnumArrays # TODO update the JSON string below json = "{}" # create an instance of EnumArrays from a JSON string -enum_arrays_instance = EnumArrays.from_json(json) +enum_arrays_instance = EnumArrays.model_validate_json(json) # print the JSON string representation of the object -print(EnumArrays.to_json()) +print(EnumArrays.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -enum_arrays_dict = enum_arrays_instance.to_dict() +enum_arrays_dict = enum_arrays_instance.model_dump(by_alias=True) # create an instance of EnumArrays from a dict -enum_arrays_from_dict = EnumArrays.from_dict(enum_arrays_dict) +enum_arrays_from_dict = EnumArrays.model_validate(enum_arrays_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/EnumRefWithDefaultValue.md b/samples/openapi3/client/petstore/python-aiohttp/docs/EnumRefWithDefaultValue.md index eeb0dc66969f..89bfb7c31366 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/EnumRefWithDefaultValue.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/EnumRefWithDefaultValue.md @@ -15,14 +15,14 @@ from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultVa # TODO update the JSON string below json = "{}" # create an instance of EnumRefWithDefaultValue from a JSON string -enum_ref_with_default_value_instance = EnumRefWithDefaultValue.from_json(json) +enum_ref_with_default_value_instance = EnumRefWithDefaultValue.model_validate_json(json) # print the JSON string representation of the object -print(EnumRefWithDefaultValue.to_json()) +print(EnumRefWithDefaultValue.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -enum_ref_with_default_value_dict = enum_ref_with_default_value_instance.to_dict() +enum_ref_with_default_value_dict = enum_ref_with_default_value_instance.model_dump(by_alias=True) # create an instance of EnumRefWithDefaultValue from a dict -enum_ref_with_default_value_from_dict = EnumRefWithDefaultValue.from_dict(enum_ref_with_default_value_dict) +enum_ref_with_default_value_from_dict = EnumRefWithDefaultValue.model_validate(enum_ref_with_default_value_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/EnumTest.md b/samples/openapi3/client/petstore/python-aiohttp/docs/EnumTest.md index 9f96c605d888..c6127df54638 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/EnumTest.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/EnumTest.md @@ -27,14 +27,14 @@ from petstore_api.models.enum_test import EnumTest # TODO update the JSON string below json = "{}" # create an instance of EnumTest from a JSON string -enum_test_instance = EnumTest.from_json(json) +enum_test_instance = EnumTest.model_validate_json(json) # print the JSON string representation of the object -print(EnumTest.to_json()) +print(EnumTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -enum_test_dict = enum_test_instance.to_dict() +enum_test_dict = enum_test_instance.model_dump(by_alias=True) # create an instance of EnumTest from a dict -enum_test_from_dict = EnumTest.from_dict(enum_test_dict) +enum_test_from_dict = EnumTest.model_validate(enum_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Feeding.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Feeding.md index 9f92b5d964d3..177cae170e77 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Feeding.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Feeding.md @@ -17,14 +17,14 @@ from petstore_api.models.feeding import Feeding # TODO update the JSON string below json = "{}" # create an instance of Feeding from a JSON string -feeding_instance = Feeding.from_json(json) +feeding_instance = Feeding.model_validate_json(json) # print the JSON string representation of the object -print(Feeding.to_json()) +print(Feeding.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -feeding_dict = feeding_instance.to_dict() +feeding_dict = feeding_instance.model_dump(by_alias=True) # create an instance of Feeding from a dict -feeding_from_dict = Feeding.from_dict(feeding_dict) +feeding_from_dict = Feeding.model_validate(feeding_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/File.md b/samples/openapi3/client/petstore/python-aiohttp/docs/File.md index 23f0567411ce..0b5942557efe 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/File.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/File.md @@ -16,14 +16,14 @@ from petstore_api.models.file import File # TODO update the JSON string below json = "{}" # create an instance of File from a JSON string -file_instance = File.from_json(json) +file_instance = File.model_validate_json(json) # print the JSON string representation of the object -print(File.to_json()) +print(File.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -file_dict = file_instance.to_dict() +file_dict = file_instance.model_dump(by_alias=True) # create an instance of File from a dict -file_from_dict = File.from_dict(file_dict) +file_from_dict = File.model_validate(file_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/FileSchemaTestClass.md b/samples/openapi3/client/petstore/python-aiohttp/docs/FileSchemaTestClass.md index e1118042a8ec..917f4ce73382 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/FileSchemaTestClass.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/FileSchemaTestClass.md @@ -16,14 +16,14 @@ from petstore_api.models.file_schema_test_class import FileSchemaTestClass # TODO update the JSON string below json = "{}" # create an instance of FileSchemaTestClass from a JSON string -file_schema_test_class_instance = FileSchemaTestClass.from_json(json) +file_schema_test_class_instance = FileSchemaTestClass.model_validate_json(json) # print the JSON string representation of the object -print(FileSchemaTestClass.to_json()) +print(FileSchemaTestClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -file_schema_test_class_dict = file_schema_test_class_instance.to_dict() +file_schema_test_class_dict = file_schema_test_class_instance.model_dump(by_alias=True) # create an instance of FileSchemaTestClass from a dict -file_schema_test_class_from_dict = FileSchemaTestClass.from_dict(file_schema_test_class_dict) +file_schema_test_class_from_dict = FileSchemaTestClass.model_validate(file_schema_test_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/FirstRef.md b/samples/openapi3/client/petstore/python-aiohttp/docs/FirstRef.md index 94b8ddc5ac22..51617b213a4f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/FirstRef.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/FirstRef.md @@ -16,14 +16,14 @@ from petstore_api.models.first_ref import FirstRef # TODO update the JSON string below json = "{}" # create an instance of FirstRef from a JSON string -first_ref_instance = FirstRef.from_json(json) +first_ref_instance = FirstRef.model_validate_json(json) # print the JSON string representation of the object -print(FirstRef.to_json()) +print(FirstRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -first_ref_dict = first_ref_instance.to_dict() +first_ref_dict = first_ref_instance.model_dump(by_alias=True) # create an instance of FirstRef from a dict -first_ref_from_dict = FirstRef.from_dict(first_ref_dict) +first_ref_from_dict = FirstRef.model_validate(first_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Foo.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Foo.md index f635b0daa6db..e25a5a16bac5 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Foo.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Foo.md @@ -15,14 +15,14 @@ from petstore_api.models.foo import Foo # TODO update the JSON string below json = "{}" # create an instance of Foo from a JSON string -foo_instance = Foo.from_json(json) +foo_instance = Foo.model_validate_json(json) # print the JSON string representation of the object -print(Foo.to_json()) +print(Foo.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -foo_dict = foo_instance.to_dict() +foo_dict = foo_instance.model_dump(by_alias=True) # create an instance of Foo from a dict -foo_from_dict = Foo.from_dict(foo_dict) +foo_from_dict = Foo.model_validate(foo_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/FooGetDefaultResponse.md b/samples/openapi3/client/petstore/python-aiohttp/docs/FooGetDefaultResponse.md index 8d84f795b00a..dab8d870b496 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/FooGetDefaultResponse.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/FooGetDefaultResponse.md @@ -15,14 +15,14 @@ from petstore_api.models.foo_get_default_response import FooGetDefaultResponse # TODO update the JSON string below json = "{}" # create an instance of FooGetDefaultResponse from a JSON string -foo_get_default_response_instance = FooGetDefaultResponse.from_json(json) +foo_get_default_response_instance = FooGetDefaultResponse.model_validate_json(json) # print the JSON string representation of the object -print(FooGetDefaultResponse.to_json()) +print(FooGetDefaultResponse.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -foo_get_default_response_dict = foo_get_default_response_instance.to_dict() +foo_get_default_response_dict = foo_get_default_response_instance.model_dump(by_alias=True) # create an instance of FooGetDefaultResponse from a dict -foo_get_default_response_from_dict = FooGetDefaultResponse.from_dict(foo_get_default_response_dict) +foo_get_default_response_from_dict = FooGetDefaultResponse.model_validate(foo_get_default_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/FormatTest.md b/samples/openapi3/client/petstore/python-aiohttp/docs/FormatTest.md index 714d2401bbae..7b4bcb6513f8 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/FormatTest.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/FormatTest.md @@ -31,14 +31,14 @@ from petstore_api.models.format_test import FormatTest # TODO update the JSON string below json = "{}" # create an instance of FormatTest from a JSON string -format_test_instance = FormatTest.from_json(json) +format_test_instance = FormatTest.model_validate_json(json) # print the JSON string representation of the object -print(FormatTest.to_json()) +print(FormatTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -format_test_dict = format_test_instance.to_dict() +format_test_dict = format_test_instance.model_dump(by_alias=True) # create an instance of FormatTest from a dict -format_test_from_dict = FormatTest.from_dict(format_test_dict) +format_test_from_dict = FormatTest.model_validate(format_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/HasOnlyReadOnly.md b/samples/openapi3/client/petstore/python-aiohttp/docs/HasOnlyReadOnly.md index fdc48781b15a..a2d020b6a2cb 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/HasOnlyReadOnly.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/HasOnlyReadOnly.md @@ -16,14 +16,14 @@ from petstore_api.models.has_only_read_only import HasOnlyReadOnly # TODO update the JSON string below json = "{}" # create an instance of HasOnlyReadOnly from a JSON string -has_only_read_only_instance = HasOnlyReadOnly.from_json(json) +has_only_read_only_instance = HasOnlyReadOnly.model_validate_json(json) # print the JSON string representation of the object -print(HasOnlyReadOnly.to_json()) +print(HasOnlyReadOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -has_only_read_only_dict = has_only_read_only_instance.to_dict() +has_only_read_only_dict = has_only_read_only_instance.model_dump(by_alias=True) # create an instance of HasOnlyReadOnly from a dict -has_only_read_only_from_dict = HasOnlyReadOnly.from_dict(has_only_read_only_dict) +has_only_read_only_from_dict = HasOnlyReadOnly.model_validate(has_only_read_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/HealthCheckResult.md b/samples/openapi3/client/petstore/python-aiohttp/docs/HealthCheckResult.md index d4a2b187167f..49c69cf1d84b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/HealthCheckResult.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/HealthCheckResult.md @@ -16,14 +16,14 @@ from petstore_api.models.health_check_result import HealthCheckResult # TODO update the JSON string below json = "{}" # create an instance of HealthCheckResult from a JSON string -health_check_result_instance = HealthCheckResult.from_json(json) +health_check_result_instance = HealthCheckResult.model_validate_json(json) # print the JSON string representation of the object -print(HealthCheckResult.to_json()) +print(HealthCheckResult.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -health_check_result_dict = health_check_result_instance.to_dict() +health_check_result_dict = health_check_result_instance.model_dump(by_alias=True) # create an instance of HealthCheckResult from a dict -health_check_result_from_dict = HealthCheckResult.from_dict(health_check_result_dict) +health_check_result_from_dict = HealthCheckResult.model_validate(health_check_result_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/HuntingDog.md b/samples/openapi3/client/petstore/python-aiohttp/docs/HuntingDog.md index 6db6745dd022..a3a905d84550 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/HuntingDog.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/HuntingDog.md @@ -15,14 +15,14 @@ from petstore_api.models.hunting_dog import HuntingDog # TODO update the JSON string below json = "{}" # create an instance of HuntingDog from a JSON string -hunting_dog_instance = HuntingDog.from_json(json) +hunting_dog_instance = HuntingDog.model_validate_json(json) # print the JSON string representation of the object -print(HuntingDog.to_json()) +print(HuntingDog.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -hunting_dog_dict = hunting_dog_instance.to_dict() +hunting_dog_dict = hunting_dog_instance.model_dump(by_alias=True) # create an instance of HuntingDog from a dict -hunting_dog_from_dict = HuntingDog.from_dict(hunting_dog_dict) +hunting_dog_from_dict = HuntingDog.model_validate(hunting_dog_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Info.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Info.md index db88778a9143..753e1d770730 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Info.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Info.md @@ -15,14 +15,14 @@ from petstore_api.models.info import Info # TODO update the JSON string below json = "{}" # create an instance of Info from a JSON string -info_instance = Info.from_json(json) +info_instance = Info.model_validate_json(json) # print the JSON string representation of the object -print(Info.to_json()) +print(Info.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -info_dict = info_instance.to_dict() +info_dict = info_instance.model_dump(by_alias=True) # create an instance of Info from a dict -info_from_dict = Info.from_dict(info_dict) +info_from_dict = Info.model_validate(info_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/InnerDictWithProperty.md b/samples/openapi3/client/petstore/python-aiohttp/docs/InnerDictWithProperty.md index 7b82ebb770b8..2a922855b34f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/InnerDictWithProperty.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/InnerDictWithProperty.md @@ -15,14 +15,14 @@ from petstore_api.models.inner_dict_with_property import InnerDictWithProperty # TODO update the JSON string below json = "{}" # create an instance of InnerDictWithProperty from a JSON string -inner_dict_with_property_instance = InnerDictWithProperty.from_json(json) +inner_dict_with_property_instance = InnerDictWithProperty.model_validate_json(json) # print the JSON string representation of the object -print(InnerDictWithProperty.to_json()) +print(InnerDictWithProperty.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -inner_dict_with_property_dict = inner_dict_with_property_instance.to_dict() +inner_dict_with_property_dict = inner_dict_with_property_instance.model_dump(by_alias=True) # create an instance of InnerDictWithProperty from a dict -inner_dict_with_property_from_dict = InnerDictWithProperty.from_dict(inner_dict_with_property_dict) +inner_dict_with_property_from_dict = InnerDictWithProperty.model_validate(inner_dict_with_property_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/InputAllOf.md b/samples/openapi3/client/petstore/python-aiohttp/docs/InputAllOf.md index 45298f5308fc..ee77a141784a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/InputAllOf.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/InputAllOf.md @@ -15,14 +15,14 @@ from petstore_api.models.input_all_of import InputAllOf # TODO update the JSON string below json = "{}" # create an instance of InputAllOf from a JSON string -input_all_of_instance = InputAllOf.from_json(json) +input_all_of_instance = InputAllOf.model_validate_json(json) # print the JSON string representation of the object -print(InputAllOf.to_json()) +print(InputAllOf.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -input_all_of_dict = input_all_of_instance.to_dict() +input_all_of_dict = input_all_of_instance.model_dump(by_alias=True) # create an instance of InputAllOf from a dict -input_all_of_from_dict = InputAllOf.from_dict(input_all_of_dict) +input_all_of_from_dict = InputAllOf.model_validate(input_all_of_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/IntOrString.md b/samples/openapi3/client/petstore/python-aiohttp/docs/IntOrString.md index b4070b9a8c79..6274e6fbc696 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/IntOrString.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/IntOrString.md @@ -14,14 +14,14 @@ from petstore_api.models.int_or_string import IntOrString # TODO update the JSON string below json = "{}" # create an instance of IntOrString from a JSON string -int_or_string_instance = IntOrString.from_json(json) +int_or_string_instance = IntOrString.model_validate_json(json) # print the JSON string representation of the object -print(IntOrString.to_json()) +print(IntOrString.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -int_or_string_dict = int_or_string_instance.to_dict() +int_or_string_dict = int_or_string_instance.model_dump(by_alias=True) # create an instance of IntOrString from a dict -int_or_string_from_dict = IntOrString.from_dict(int_or_string_dict) +int_or_string_from_dict = IntOrString.model_validate(int_or_string_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ListClass.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ListClass.md index 01068b7d22c3..00e12b663833 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/ListClass.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ListClass.md @@ -15,14 +15,14 @@ from petstore_api.models.list_class import ListClass # TODO update the JSON string below json = "{}" # create an instance of ListClass from a JSON string -list_class_instance = ListClass.from_json(json) +list_class_instance = ListClass.model_validate_json(json) # print the JSON string representation of the object -print(ListClass.to_json()) +print(ListClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -list_class_dict = list_class_instance.to_dict() +list_class_dict = list_class_instance.model_dump(by_alias=True) # create an instance of ListClass from a dict -list_class_from_dict = ListClass.from_dict(list_class_dict) +list_class_from_dict = ListClass.model_validate(list_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/MapOfArrayOfModel.md b/samples/openapi3/client/petstore/python-aiohttp/docs/MapOfArrayOfModel.md index 71a4ef66b682..dbfba20ac23b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/MapOfArrayOfModel.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/MapOfArrayOfModel.md @@ -15,14 +15,14 @@ from petstore_api.models.map_of_array_of_model import MapOfArrayOfModel # TODO update the JSON string below json = "{}" # create an instance of MapOfArrayOfModel from a JSON string -map_of_array_of_model_instance = MapOfArrayOfModel.from_json(json) +map_of_array_of_model_instance = MapOfArrayOfModel.model_validate_json(json) # print the JSON string representation of the object -print(MapOfArrayOfModel.to_json()) +print(MapOfArrayOfModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -map_of_array_of_model_dict = map_of_array_of_model_instance.to_dict() +map_of_array_of_model_dict = map_of_array_of_model_instance.model_dump(by_alias=True) # create an instance of MapOfArrayOfModel from a dict -map_of_array_of_model_from_dict = MapOfArrayOfModel.from_dict(map_of_array_of_model_dict) +map_of_array_of_model_from_dict = MapOfArrayOfModel.model_validate(map_of_array_of_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/MapTest.md b/samples/openapi3/client/petstore/python-aiohttp/docs/MapTest.md index d04b82e9378c..61382a4e3cd8 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/MapTest.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/MapTest.md @@ -18,14 +18,14 @@ from petstore_api.models.map_test import MapTest # TODO update the JSON string below json = "{}" # create an instance of MapTest from a JSON string -map_test_instance = MapTest.from_json(json) +map_test_instance = MapTest.model_validate_json(json) # print the JSON string representation of the object -print(MapTest.to_json()) +print(MapTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -map_test_dict = map_test_instance.to_dict() +map_test_dict = map_test_instance.model_dump(by_alias=True) # create an instance of MapTest from a dict -map_test_from_dict = MapTest.from_dict(map_test_dict) +map_test_from_dict = MapTest.model_validate(map_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/openapi3/client/petstore/python-aiohttp/docs/MixedPropertiesAndAdditionalPropertiesClass.md index 84134317aefc..41ef9465d498 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -17,14 +17,14 @@ from petstore_api.models.mixed_properties_and_additional_properties_class import # TODO update the JSON string below json = "{}" # create an instance of MixedPropertiesAndAdditionalPropertiesClass from a JSON string -mixed_properties_and_additional_properties_class_instance = MixedPropertiesAndAdditionalPropertiesClass.from_json(json) +mixed_properties_and_additional_properties_class_instance = MixedPropertiesAndAdditionalPropertiesClass.model_validate_json(json) # print the JSON string representation of the object -print(MixedPropertiesAndAdditionalPropertiesClass.to_json()) +print(MixedPropertiesAndAdditionalPropertiesClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -mixed_properties_and_additional_properties_class_dict = mixed_properties_and_additional_properties_class_instance.to_dict() +mixed_properties_and_additional_properties_class_dict = mixed_properties_and_additional_properties_class_instance.model_dump(by_alias=True) # create an instance of MixedPropertiesAndAdditionalPropertiesClass from a dict -mixed_properties_and_additional_properties_class_from_dict = MixedPropertiesAndAdditionalPropertiesClass.from_dict(mixed_properties_and_additional_properties_class_dict) +mixed_properties_and_additional_properties_class_from_dict = MixedPropertiesAndAdditionalPropertiesClass.model_validate(mixed_properties_and_additional_properties_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Model200Response.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Model200Response.md index 7fdbdefc6cec..56b765c788de 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Model200Response.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Model200Response.md @@ -17,14 +17,14 @@ from petstore_api.models.model200_response import Model200Response # TODO update the JSON string below json = "{}" # create an instance of Model200Response from a JSON string -model200_response_instance = Model200Response.from_json(json) +model200_response_instance = Model200Response.model_validate_json(json) # print the JSON string representation of the object -print(Model200Response.to_json()) +print(Model200Response.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model200_response_dict = model200_response_instance.to_dict() +model200_response_dict = model200_response_instance.model_dump(by_alias=True) # create an instance of Model200Response from a dict -model200_response_from_dict = Model200Response.from_dict(model200_response_dict) +model200_response_from_dict = Model200Response.model_validate(model200_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ModelApiResponse.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ModelApiResponse.md index 5ddc0db2a0f3..1fe361910ecb 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/ModelApiResponse.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ModelApiResponse.md @@ -17,14 +17,14 @@ from petstore_api.models.model_api_response import ModelApiResponse # TODO update the JSON string below json = "{}" # create an instance of ModelApiResponse from a JSON string -model_api_response_instance = ModelApiResponse.from_json(json) +model_api_response_instance = ModelApiResponse.model_validate_json(json) # print the JSON string representation of the object -print(ModelApiResponse.to_json()) +print(ModelApiResponse.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model_api_response_dict = model_api_response_instance.to_dict() +model_api_response_dict = model_api_response_instance.model_dump(by_alias=True) # create an instance of ModelApiResponse from a dict -model_api_response_from_dict = ModelApiResponse.from_dict(model_api_response_dict) +model_api_response_from_dict = ModelApiResponse.model_validate(model_api_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ModelField.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ModelField.md index 9073b5dbdb00..8fa1be583ae3 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/ModelField.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ModelField.md @@ -15,14 +15,14 @@ from petstore_api.models.model_field import ModelField # TODO update the JSON string below json = "{}" # create an instance of ModelField from a JSON string -model_field_instance = ModelField.from_json(json) +model_field_instance = ModelField.model_validate_json(json) # print the JSON string representation of the object -print(ModelField.to_json()) +print(ModelField.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model_field_dict = model_field_instance.to_dict() +model_field_dict = model_field_instance.model_dump(by_alias=True) # create an instance of ModelField from a dict -model_field_from_dict = ModelField.from_dict(model_field_dict) +model_field_from_dict = ModelField.model_validate(model_field_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ModelReturn.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ModelReturn.md index 7d327053b0c3..fbda0142410b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/ModelReturn.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ModelReturn.md @@ -16,14 +16,14 @@ from petstore_api.models.model_return import ModelReturn # TODO update the JSON string below json = "{}" # create an instance of ModelReturn from a JSON string -model_return_instance = ModelReturn.from_json(json) +model_return_instance = ModelReturn.model_validate_json(json) # print the JSON string representation of the object -print(ModelReturn.to_json()) +print(ModelReturn.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model_return_dict = model_return_instance.to_dict() +model_return_dict = model_return_instance.model_dump(by_alias=True) # create an instance of ModelReturn from a dict -model_return_from_dict = ModelReturn.from_dict(model_return_dict) +model_return_from_dict = ModelReturn.model_validate(model_return_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/MultiArrays.md b/samples/openapi3/client/petstore/python-aiohttp/docs/MultiArrays.md index fea5139e7e73..5feb5eb83587 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/MultiArrays.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/MultiArrays.md @@ -16,14 +16,14 @@ from petstore_api.models.multi_arrays import MultiArrays # TODO update the JSON string below json = "{}" # create an instance of MultiArrays from a JSON string -multi_arrays_instance = MultiArrays.from_json(json) +multi_arrays_instance = MultiArrays.model_validate_json(json) # print the JSON string representation of the object -print(MultiArrays.to_json()) +print(MultiArrays.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -multi_arrays_dict = multi_arrays_instance.to_dict() +multi_arrays_dict = multi_arrays_instance.model_dump(by_alias=True) # create an instance of MultiArrays from a dict -multi_arrays_from_dict = MultiArrays.from_dict(multi_arrays_dict) +multi_arrays_from_dict = MultiArrays.model_validate(multi_arrays_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Name.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Name.md index 5a04ec1ada06..fe30c2a76d97 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Name.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Name.md @@ -19,14 +19,14 @@ from petstore_api.models.name import Name # TODO update the JSON string below json = "{}" # create an instance of Name from a JSON string -name_instance = Name.from_json(json) +name_instance = Name.model_validate_json(json) # print the JSON string representation of the object -print(Name.to_json()) +print(Name.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -name_dict = name_instance.to_dict() +name_dict = name_instance.model_dump(by_alias=True) # create an instance of Name from a dict -name_from_dict = Name.from_dict(name_dict) +name_from_dict = Name.model_validate(name_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/NullableClass.md b/samples/openapi3/client/petstore/python-aiohttp/docs/NullableClass.md index 0387dcc2c67a..fafc21b70778 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/NullableClass.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/NullableClass.md @@ -27,14 +27,14 @@ from petstore_api.models.nullable_class import NullableClass # TODO update the JSON string below json = "{}" # create an instance of NullableClass from a JSON string -nullable_class_instance = NullableClass.from_json(json) +nullable_class_instance = NullableClass.model_validate_json(json) # print the JSON string representation of the object -print(NullableClass.to_json()) +print(NullableClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -nullable_class_dict = nullable_class_instance.to_dict() +nullable_class_dict = nullable_class_instance.model_dump(by_alias=True) # create an instance of NullableClass from a dict -nullable_class_from_dict = NullableClass.from_dict(nullable_class_dict) +nullable_class_from_dict = NullableClass.model_validate(nullable_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/NullableProperty.md b/samples/openapi3/client/petstore/python-aiohttp/docs/NullableProperty.md index 30edaf4844b2..1738420f6e1c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/NullableProperty.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/NullableProperty.md @@ -16,14 +16,14 @@ from petstore_api.models.nullable_property import NullableProperty # TODO update the JSON string below json = "{}" # create an instance of NullableProperty from a JSON string -nullable_property_instance = NullableProperty.from_json(json) +nullable_property_instance = NullableProperty.model_validate_json(json) # print the JSON string representation of the object -print(NullableProperty.to_json()) +print(NullableProperty.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -nullable_property_dict = nullable_property_instance.to_dict() +nullable_property_dict = nullable_property_instance.model_dump(by_alias=True) # create an instance of NullableProperty from a dict -nullable_property_from_dict = NullableProperty.from_dict(nullable_property_dict) +nullable_property_from_dict = NullableProperty.model_validate(nullable_property_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/NumberOnly.md b/samples/openapi3/client/petstore/python-aiohttp/docs/NumberOnly.md index 415dd25585d4..739426b7c295 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/NumberOnly.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/NumberOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.number_only import NumberOnly # TODO update the JSON string below json = "{}" # create an instance of NumberOnly from a JSON string -number_only_instance = NumberOnly.from_json(json) +number_only_instance = NumberOnly.model_validate_json(json) # print the JSON string representation of the object -print(NumberOnly.to_json()) +print(NumberOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -number_only_dict = number_only_instance.to_dict() +number_only_dict = number_only_instance.model_dump(by_alias=True) # create an instance of NumberOnly from a dict -number_only_from_dict = NumberOnly.from_dict(number_only_dict) +number_only_from_dict = NumberOnly.model_validate(number_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ObjectToTestAdditionalProperties.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ObjectToTestAdditionalProperties.md index f6bc34c98e65..eec52f82c2ca 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/ObjectToTestAdditionalProperties.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ObjectToTestAdditionalProperties.md @@ -16,14 +16,14 @@ from petstore_api.models.object_to_test_additional_properties import ObjectToTes # TODO update the JSON string below json = "{}" # create an instance of ObjectToTestAdditionalProperties from a JSON string -object_to_test_additional_properties_instance = ObjectToTestAdditionalProperties.from_json(json) +object_to_test_additional_properties_instance = ObjectToTestAdditionalProperties.model_validate_json(json) # print the JSON string representation of the object -print(ObjectToTestAdditionalProperties.to_json()) +print(ObjectToTestAdditionalProperties.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -object_to_test_additional_properties_dict = object_to_test_additional_properties_instance.to_dict() +object_to_test_additional_properties_dict = object_to_test_additional_properties_instance.model_dump(by_alias=True) # create an instance of ObjectToTestAdditionalProperties from a dict -object_to_test_additional_properties_from_dict = ObjectToTestAdditionalProperties.from_dict(object_to_test_additional_properties_dict) +object_to_test_additional_properties_from_dict = ObjectToTestAdditionalProperties.model_validate(object_to_test_additional_properties_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ObjectWithDeprecatedFields.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ObjectWithDeprecatedFields.md index 6dbd2ace04f1..6329b1899970 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/ObjectWithDeprecatedFields.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ObjectWithDeprecatedFields.md @@ -18,14 +18,14 @@ from petstore_api.models.object_with_deprecated_fields import ObjectWithDeprecat # TODO update the JSON string below json = "{}" # create an instance of ObjectWithDeprecatedFields from a JSON string -object_with_deprecated_fields_instance = ObjectWithDeprecatedFields.from_json(json) +object_with_deprecated_fields_instance = ObjectWithDeprecatedFields.model_validate_json(json) # print the JSON string representation of the object -print(ObjectWithDeprecatedFields.to_json()) +print(ObjectWithDeprecatedFields.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -object_with_deprecated_fields_dict = object_with_deprecated_fields_instance.to_dict() +object_with_deprecated_fields_dict = object_with_deprecated_fields_instance.model_dump(by_alias=True) # create an instance of ObjectWithDeprecatedFields from a dict -object_with_deprecated_fields_from_dict = ObjectWithDeprecatedFields.from_dict(object_with_deprecated_fields_dict) +object_with_deprecated_fields_from_dict = ObjectWithDeprecatedFields.model_validate(object_with_deprecated_fields_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Order.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Order.md index 00526b8d04b9..8d4b8ac2983f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Order.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Order.md @@ -20,14 +20,14 @@ from petstore_api.models.order import Order # TODO update the JSON string below json = "{}" # create an instance of Order from a JSON string -order_instance = Order.from_json(json) +order_instance = Order.model_validate_json(json) # print the JSON string representation of the object -print(Order.to_json()) +print(Order.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -order_dict = order_instance.to_dict() +order_dict = order_instance.model_dump(by_alias=True) # create an instance of Order from a dict -order_from_dict = Order.from_dict(order_dict) +order_from_dict = Order.model_validate(order_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/OuterComposite.md b/samples/openapi3/client/petstore/python-aiohttp/docs/OuterComposite.md index c8242c2d2653..bff67df11388 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/OuterComposite.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/OuterComposite.md @@ -17,14 +17,14 @@ from petstore_api.models.outer_composite import OuterComposite # TODO update the JSON string below json = "{}" # create an instance of OuterComposite from a JSON string -outer_composite_instance = OuterComposite.from_json(json) +outer_composite_instance = OuterComposite.model_validate_json(json) # print the JSON string representation of the object -print(OuterComposite.to_json()) +print(OuterComposite.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -outer_composite_dict = outer_composite_instance.to_dict() +outer_composite_dict = outer_composite_instance.model_dump(by_alias=True) # create an instance of OuterComposite from a dict -outer_composite_from_dict = OuterComposite.from_dict(outer_composite_dict) +outer_composite_from_dict = OuterComposite.model_validate(outer_composite_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/OuterObjectWithEnumProperty.md b/samples/openapi3/client/petstore/python-aiohttp/docs/OuterObjectWithEnumProperty.md index 6137dbd98da6..39611a8868a7 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/OuterObjectWithEnumProperty.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/OuterObjectWithEnumProperty.md @@ -16,14 +16,14 @@ from petstore_api.models.outer_object_with_enum_property import OuterObjectWithE # TODO update the JSON string below json = "{}" # create an instance of OuterObjectWithEnumProperty from a JSON string -outer_object_with_enum_property_instance = OuterObjectWithEnumProperty.from_json(json) +outer_object_with_enum_property_instance = OuterObjectWithEnumProperty.model_validate_json(json) # print the JSON string representation of the object -print(OuterObjectWithEnumProperty.to_json()) +print(OuterObjectWithEnumProperty.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -outer_object_with_enum_property_dict = outer_object_with_enum_property_instance.to_dict() +outer_object_with_enum_property_dict = outer_object_with_enum_property_instance.model_dump(by_alias=True) # create an instance of OuterObjectWithEnumProperty from a dict -outer_object_with_enum_property_from_dict = OuterObjectWithEnumProperty.from_dict(outer_object_with_enum_property_dict) +outer_object_with_enum_property_from_dict = OuterObjectWithEnumProperty.model_validate(outer_object_with_enum_property_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Parent.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Parent.md index 7387f9250aad..700d8446226c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Parent.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Parent.md @@ -15,14 +15,14 @@ from petstore_api.models.parent import Parent # TODO update the JSON string below json = "{}" # create an instance of Parent from a JSON string -parent_instance = Parent.from_json(json) +parent_instance = Parent.model_validate_json(json) # print the JSON string representation of the object -print(Parent.to_json()) +print(Parent.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -parent_dict = parent_instance.to_dict() +parent_dict = parent_instance.model_dump(by_alias=True) # create an instance of Parent from a dict -parent_from_dict = Parent.from_dict(parent_dict) +parent_from_dict = Parent.model_validate(parent_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ParentWithOptionalDict.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ParentWithOptionalDict.md index bfc8688ea26f..7af4744a1016 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/ParentWithOptionalDict.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ParentWithOptionalDict.md @@ -15,14 +15,14 @@ from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict # TODO update the JSON string below json = "{}" # create an instance of ParentWithOptionalDict from a JSON string -parent_with_optional_dict_instance = ParentWithOptionalDict.from_json(json) +parent_with_optional_dict_instance = ParentWithOptionalDict.model_validate_json(json) # print the JSON string representation of the object -print(ParentWithOptionalDict.to_json()) +print(ParentWithOptionalDict.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -parent_with_optional_dict_dict = parent_with_optional_dict_instance.to_dict() +parent_with_optional_dict_dict = parent_with_optional_dict_instance.model_dump(by_alias=True) # create an instance of ParentWithOptionalDict from a dict -parent_with_optional_dict_from_dict = ParentWithOptionalDict.from_dict(parent_with_optional_dict_dict) +parent_with_optional_dict_from_dict = ParentWithOptionalDict.model_validate(parent_with_optional_dict_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Pet.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Pet.md index 5329cf2fb925..e09f1b8b22ff 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Pet.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Pet.md @@ -20,14 +20,14 @@ from petstore_api.models.pet import Pet # TODO update the JSON string below json = "{}" # create an instance of Pet from a JSON string -pet_instance = Pet.from_json(json) +pet_instance = Pet.model_validate_json(json) # print the JSON string representation of the object -print(Pet.to_json()) +print(Pet.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -pet_dict = pet_instance.to_dict() +pet_dict = pet_instance.model_dump(by_alias=True) # create an instance of Pet from a dict -pet_from_dict = Pet.from_dict(pet_dict) +pet_from_dict = Pet.model_validate(pet_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Pig.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Pig.md index 625930676083..8c9de7a86c8a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Pig.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Pig.md @@ -17,14 +17,14 @@ from petstore_api.models.pig import Pig # TODO update the JSON string below json = "{}" # create an instance of Pig from a JSON string -pig_instance = Pig.from_json(json) +pig_instance = Pig.model_validate_json(json) # print the JSON string representation of the object -print(Pig.to_json()) +print(Pig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -pig_dict = pig_instance.to_dict() +pig_dict = pig_instance.model_dump(by_alias=True) # create an instance of Pig from a dict -pig_from_dict = Pig.from_dict(pig_dict) +pig_from_dict = Pig.model_validate(pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/PonySizes.md b/samples/openapi3/client/petstore/python-aiohttp/docs/PonySizes.md index ced44c872060..03af5df5ed23 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/PonySizes.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/PonySizes.md @@ -15,14 +15,14 @@ from petstore_api.models.pony_sizes import PonySizes # TODO update the JSON string below json = "{}" # create an instance of PonySizes from a JSON string -pony_sizes_instance = PonySizes.from_json(json) +pony_sizes_instance = PonySizes.model_validate_json(json) # print the JSON string representation of the object -print(PonySizes.to_json()) +print(PonySizes.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -pony_sizes_dict = pony_sizes_instance.to_dict() +pony_sizes_dict = pony_sizes_instance.model_dump(by_alias=True) # create an instance of PonySizes from a dict -pony_sizes_from_dict = PonySizes.from_dict(pony_sizes_dict) +pony_sizes_from_dict = PonySizes.model_validate(pony_sizes_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/PoopCleaning.md b/samples/openapi3/client/petstore/python-aiohttp/docs/PoopCleaning.md index 8f9c25e08316..b58624f40112 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/PoopCleaning.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/PoopCleaning.md @@ -17,14 +17,14 @@ from petstore_api.models.poop_cleaning import PoopCleaning # TODO update the JSON string below json = "{}" # create an instance of PoopCleaning from a JSON string -poop_cleaning_instance = PoopCleaning.from_json(json) +poop_cleaning_instance = PoopCleaning.model_validate_json(json) # print the JSON string representation of the object -print(PoopCleaning.to_json()) +print(PoopCleaning.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -poop_cleaning_dict = poop_cleaning_instance.to_dict() +poop_cleaning_dict = poop_cleaning_instance.model_dump(by_alias=True) # create an instance of PoopCleaning from a dict -poop_cleaning_from_dict = PoopCleaning.from_dict(poop_cleaning_dict) +poop_cleaning_from_dict = PoopCleaning.model_validate(poop_cleaning_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/PrimitiveString.md b/samples/openapi3/client/petstore/python-aiohttp/docs/PrimitiveString.md index 85ceb632e167..c2296ead4a1a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/PrimitiveString.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/PrimitiveString.md @@ -15,14 +15,14 @@ from petstore_api.models.primitive_string import PrimitiveString # TODO update the JSON string below json = "{}" # create an instance of PrimitiveString from a JSON string -primitive_string_instance = PrimitiveString.from_json(json) +primitive_string_instance = PrimitiveString.model_validate_json(json) # print the JSON string representation of the object -print(PrimitiveString.to_json()) +print(PrimitiveString.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -primitive_string_dict = primitive_string_instance.to_dict() +primitive_string_dict = primitive_string_instance.model_dump(by_alias=True) # create an instance of PrimitiveString from a dict -primitive_string_from_dict = PrimitiveString.from_dict(primitive_string_dict) +primitive_string_from_dict = PrimitiveString.model_validate(primitive_string_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/PropertyMap.md b/samples/openapi3/client/petstore/python-aiohttp/docs/PropertyMap.md index a55a0e5c6f01..3982b35d5724 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/PropertyMap.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/PropertyMap.md @@ -15,14 +15,14 @@ from petstore_api.models.property_map import PropertyMap # TODO update the JSON string below json = "{}" # create an instance of PropertyMap from a JSON string -property_map_instance = PropertyMap.from_json(json) +property_map_instance = PropertyMap.model_validate_json(json) # print the JSON string representation of the object -print(PropertyMap.to_json()) +print(PropertyMap.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -property_map_dict = property_map_instance.to_dict() +property_map_dict = property_map_instance.model_dump(by_alias=True) # create an instance of PropertyMap from a dict -property_map_from_dict = PropertyMap.from_dict(property_map_dict) +property_map_from_dict = PropertyMap.model_validate(property_map_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/PropertyNameCollision.md b/samples/openapi3/client/petstore/python-aiohttp/docs/PropertyNameCollision.md index 40c233670dd0..e98d6ad2aa59 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/PropertyNameCollision.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/PropertyNameCollision.md @@ -17,14 +17,14 @@ from petstore_api.models.property_name_collision import PropertyNameCollision # TODO update the JSON string below json = "{}" # create an instance of PropertyNameCollision from a JSON string -property_name_collision_instance = PropertyNameCollision.from_json(json) +property_name_collision_instance = PropertyNameCollision.model_validate_json(json) # print the JSON string representation of the object -print(PropertyNameCollision.to_json()) +print(PropertyNameCollision.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -property_name_collision_dict = property_name_collision_instance.to_dict() +property_name_collision_dict = property_name_collision_instance.model_dump(by_alias=True) # create an instance of PropertyNameCollision from a dict -property_name_collision_from_dict = PropertyNameCollision.from_dict(property_name_collision_dict) +property_name_collision_from_dict = PropertyNameCollision.model_validate(property_name_collision_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ReadOnlyFirst.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ReadOnlyFirst.md index 686ec5da41c9..51831854b601 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/ReadOnlyFirst.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ReadOnlyFirst.md @@ -16,14 +16,14 @@ from petstore_api.models.read_only_first import ReadOnlyFirst # TODO update the JSON string below json = "{}" # create an instance of ReadOnlyFirst from a JSON string -read_only_first_instance = ReadOnlyFirst.from_json(json) +read_only_first_instance = ReadOnlyFirst.model_validate_json(json) # print the JSON string representation of the object -print(ReadOnlyFirst.to_json()) +print(ReadOnlyFirst.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -read_only_first_dict = read_only_first_instance.to_dict() +read_only_first_dict = read_only_first_instance.model_dump(by_alias=True) # create an instance of ReadOnlyFirst from a dict -read_only_first_from_dict = ReadOnlyFirst.from_dict(read_only_first_dict) +read_only_first_from_dict = ReadOnlyFirst.model_validate(read_only_first_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/SecondCircularAllOfRef.md b/samples/openapi3/client/petstore/python-aiohttp/docs/SecondCircularAllOfRef.md index 65ebdd4c7e1d..173a4eb5fd68 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/SecondCircularAllOfRef.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/SecondCircularAllOfRef.md @@ -16,14 +16,14 @@ from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRe # TODO update the JSON string below json = "{}" # create an instance of SecondCircularAllOfRef from a JSON string -second_circular_all_of_ref_instance = SecondCircularAllOfRef.from_json(json) +second_circular_all_of_ref_instance = SecondCircularAllOfRef.model_validate_json(json) # print the JSON string representation of the object -print(SecondCircularAllOfRef.to_json()) +print(SecondCircularAllOfRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -second_circular_all_of_ref_dict = second_circular_all_of_ref_instance.to_dict() +second_circular_all_of_ref_dict = second_circular_all_of_ref_instance.model_dump(by_alias=True) # create an instance of SecondCircularAllOfRef from a dict -second_circular_all_of_ref_from_dict = SecondCircularAllOfRef.from_dict(second_circular_all_of_ref_dict) +second_circular_all_of_ref_from_dict = SecondCircularAllOfRef.model_validate(second_circular_all_of_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/SecondRef.md b/samples/openapi3/client/petstore/python-aiohttp/docs/SecondRef.md index dfb1a0ac6db5..87c1e1d4bb3a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/SecondRef.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/SecondRef.md @@ -16,14 +16,14 @@ from petstore_api.models.second_ref import SecondRef # TODO update the JSON string below json = "{}" # create an instance of SecondRef from a JSON string -second_ref_instance = SecondRef.from_json(json) +second_ref_instance = SecondRef.model_validate_json(json) # print the JSON string representation of the object -print(SecondRef.to_json()) +print(SecondRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -second_ref_dict = second_ref_instance.to_dict() +second_ref_dict = second_ref_instance.model_dump(by_alias=True) # create an instance of SecondRef from a dict -second_ref_from_dict = SecondRef.from_dict(second_ref_dict) +second_ref_from_dict = SecondRef.model_validate(second_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/SelfReferenceModel.md b/samples/openapi3/client/petstore/python-aiohttp/docs/SelfReferenceModel.md index 208cdac04b6f..68c6e661ac94 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/SelfReferenceModel.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/SelfReferenceModel.md @@ -16,14 +16,14 @@ from petstore_api.models.self_reference_model import SelfReferenceModel # TODO update the JSON string below json = "{}" # create an instance of SelfReferenceModel from a JSON string -self_reference_model_instance = SelfReferenceModel.from_json(json) +self_reference_model_instance = SelfReferenceModel.model_validate_json(json) # print the JSON string representation of the object -print(SelfReferenceModel.to_json()) +print(SelfReferenceModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -self_reference_model_dict = self_reference_model_instance.to_dict() +self_reference_model_dict = self_reference_model_instance.model_dump(by_alias=True) # create an instance of SelfReferenceModel from a dict -self_reference_model_from_dict = SelfReferenceModel.from_dict(self_reference_model_dict) +self_reference_model_from_dict = SelfReferenceModel.model_validate(self_reference_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/SpecialModelName.md b/samples/openapi3/client/petstore/python-aiohttp/docs/SpecialModelName.md index 35303f34efd2..0e99036d92f4 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/SpecialModelName.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/SpecialModelName.md @@ -15,14 +15,14 @@ from petstore_api.models.special_model_name import SpecialModelName # TODO update the JSON string below json = "{}" # create an instance of SpecialModelName from a JSON string -special_model_name_instance = SpecialModelName.from_json(json) +special_model_name_instance = SpecialModelName.model_validate_json(json) # print the JSON string representation of the object -print(SpecialModelName.to_json()) +print(SpecialModelName.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -special_model_name_dict = special_model_name_instance.to_dict() +special_model_name_dict = special_model_name_instance.model_dump(by_alias=True) # create an instance of SpecialModelName from a dict -special_model_name_from_dict = SpecialModelName.from_dict(special_model_name_dict) +special_model_name_from_dict = SpecialModelName.model_validate(special_model_name_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/SpecialName.md b/samples/openapi3/client/petstore/python-aiohttp/docs/SpecialName.md index ccc550b16e33..5d00c8517aaa 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/SpecialName.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/SpecialName.md @@ -17,14 +17,14 @@ from petstore_api.models.special_name import SpecialName # TODO update the JSON string below json = "{}" # create an instance of SpecialName from a JSON string -special_name_instance = SpecialName.from_json(json) +special_name_instance = SpecialName.model_validate_json(json) # print the JSON string representation of the object -print(SpecialName.to_json()) +print(SpecialName.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -special_name_dict = special_name_instance.to_dict() +special_name_dict = special_name_instance.model_dump(by_alias=True) # create an instance of SpecialName from a dict -special_name_from_dict = SpecialName.from_dict(special_name_dict) +special_name_from_dict = SpecialName.model_validate(special_name_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Tag.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Tag.md index 4106d9cfe5db..98068caba254 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Tag.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Tag.md @@ -16,14 +16,14 @@ from petstore_api.models.tag import Tag # TODO update the JSON string below json = "{}" # create an instance of Tag from a JSON string -tag_instance = Tag.from_json(json) +tag_instance = Tag.model_validate_json(json) # print the JSON string representation of the object -print(Tag.to_json()) +print(Tag.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -tag_dict = tag_instance.to_dict() +tag_dict = tag_instance.model_dump(by_alias=True) # create an instance of Tag from a dict -tag_from_dict = Tag.from_dict(tag_dict) +tag_from_dict = Tag.model_validate(tag_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Task.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Task.md index 85fa2776a059..92aed88f998b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Task.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Task.md @@ -17,14 +17,14 @@ from petstore_api.models.task import Task # TODO update the JSON string below json = "{}" # create an instance of Task from a JSON string -task_instance = Task.from_json(json) +task_instance = Task.model_validate_json(json) # print the JSON string representation of the object -print(Task.to_json()) +print(Task.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -task_dict = task_instance.to_dict() +task_dict = task_instance.model_dump(by_alias=True) # create an instance of Task from a dict -task_from_dict = Task.from_dict(task_dict) +task_from_dict = Task.model_validate(task_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/TaskActivity.md b/samples/openapi3/client/petstore/python-aiohttp/docs/TaskActivity.md index e905a477292d..3f8e10cf7ae5 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/TaskActivity.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/TaskActivity.md @@ -17,14 +17,14 @@ from petstore_api.models.task_activity import TaskActivity # TODO update the JSON string below json = "{}" # create an instance of TaskActivity from a JSON string -task_activity_instance = TaskActivity.from_json(json) +task_activity_instance = TaskActivity.model_validate_json(json) # print the JSON string representation of the object -print(TaskActivity.to_json()) +print(TaskActivity.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -task_activity_dict = task_activity_instance.to_dict() +task_activity_dict = task_activity_instance.model_dump(by_alias=True) # create an instance of TaskActivity from a dict -task_activity_from_dict = TaskActivity.from_dict(task_activity_dict) +task_activity_from_dict = TaskActivity.model_validate(task_activity_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/TestErrorResponsesWithModel400Response.md b/samples/openapi3/client/petstore/python-aiohttp/docs/TestErrorResponsesWithModel400Response.md index be416bbad0f7..ba20c0666f90 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/TestErrorResponsesWithModel400Response.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/TestErrorResponsesWithModel400Response.md @@ -15,14 +15,14 @@ from petstore_api.models.test_error_responses_with_model400_response import Test # TODO update the JSON string below json = "{}" # create an instance of TestErrorResponsesWithModel400Response from a JSON string -test_error_responses_with_model400_response_instance = TestErrorResponsesWithModel400Response.from_json(json) +test_error_responses_with_model400_response_instance = TestErrorResponsesWithModel400Response.model_validate_json(json) # print the JSON string representation of the object -print(TestErrorResponsesWithModel400Response.to_json()) +print(TestErrorResponsesWithModel400Response.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_error_responses_with_model400_response_dict = test_error_responses_with_model400_response_instance.to_dict() +test_error_responses_with_model400_response_dict = test_error_responses_with_model400_response_instance.model_dump(by_alias=True) # create an instance of TestErrorResponsesWithModel400Response from a dict -test_error_responses_with_model400_response_from_dict = TestErrorResponsesWithModel400Response.from_dict(test_error_responses_with_model400_response_dict) +test_error_responses_with_model400_response_from_dict = TestErrorResponsesWithModel400Response.model_validate(test_error_responses_with_model400_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/TestErrorResponsesWithModel404Response.md b/samples/openapi3/client/petstore/python-aiohttp/docs/TestErrorResponsesWithModel404Response.md index 1c984f847bf1..d229d30e7b39 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/TestErrorResponsesWithModel404Response.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/TestErrorResponsesWithModel404Response.md @@ -15,14 +15,14 @@ from petstore_api.models.test_error_responses_with_model404_response import Test # TODO update the JSON string below json = "{}" # create an instance of TestErrorResponsesWithModel404Response from a JSON string -test_error_responses_with_model404_response_instance = TestErrorResponsesWithModel404Response.from_json(json) +test_error_responses_with_model404_response_instance = TestErrorResponsesWithModel404Response.model_validate_json(json) # print the JSON string representation of the object -print(TestErrorResponsesWithModel404Response.to_json()) +print(TestErrorResponsesWithModel404Response.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_error_responses_with_model404_response_dict = test_error_responses_with_model404_response_instance.to_dict() +test_error_responses_with_model404_response_dict = test_error_responses_with_model404_response_instance.model_dump(by_alias=True) # create an instance of TestErrorResponsesWithModel404Response from a dict -test_error_responses_with_model404_response_from_dict = TestErrorResponsesWithModel404Response.from_dict(test_error_responses_with_model404_response_dict) +test_error_responses_with_model404_response_from_dict = TestErrorResponsesWithModel404Response.model_validate(test_error_responses_with_model404_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/TestInlineFreeformAdditionalPropertiesRequest.md b/samples/openapi3/client/petstore/python-aiohttp/docs/TestInlineFreeformAdditionalPropertiesRequest.md index 511132d689be..6fd235e60800 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/TestInlineFreeformAdditionalPropertiesRequest.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/TestInlineFreeformAdditionalPropertiesRequest.md @@ -15,14 +15,14 @@ from petstore_api.models.test_inline_freeform_additional_properties_request impo # TODO update the JSON string below json = "{}" # create an instance of TestInlineFreeformAdditionalPropertiesRequest from a JSON string -test_inline_freeform_additional_properties_request_instance = TestInlineFreeformAdditionalPropertiesRequest.from_json(json) +test_inline_freeform_additional_properties_request_instance = TestInlineFreeformAdditionalPropertiesRequest.model_validate_json(json) # print the JSON string representation of the object -print(TestInlineFreeformAdditionalPropertiesRequest.to_json()) +print(TestInlineFreeformAdditionalPropertiesRequest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_inline_freeform_additional_properties_request_dict = test_inline_freeform_additional_properties_request_instance.to_dict() +test_inline_freeform_additional_properties_request_dict = test_inline_freeform_additional_properties_request_instance.model_dump(by_alias=True) # create an instance of TestInlineFreeformAdditionalPropertiesRequest from a dict -test_inline_freeform_additional_properties_request_from_dict = TestInlineFreeformAdditionalPropertiesRequest.from_dict(test_inline_freeform_additional_properties_request_dict) +test_inline_freeform_additional_properties_request_from_dict = TestInlineFreeformAdditionalPropertiesRequest.model_validate(test_inline_freeform_additional_properties_request_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/TestModelWithEnumDefault.md b/samples/openapi3/client/petstore/python-aiohttp/docs/TestModelWithEnumDefault.md index 7d46e86deba4..d98d6ad35cb3 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/TestModelWithEnumDefault.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/TestModelWithEnumDefault.md @@ -19,14 +19,14 @@ from petstore_api.models.test_model_with_enum_default import TestModelWithEnumDe # TODO update the JSON string below json = "{}" # create an instance of TestModelWithEnumDefault from a JSON string -test_model_with_enum_default_instance = TestModelWithEnumDefault.from_json(json) +test_model_with_enum_default_instance = TestModelWithEnumDefault.model_validate_json(json) # print the JSON string representation of the object -print(TestModelWithEnumDefault.to_json()) +print(TestModelWithEnumDefault.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_model_with_enum_default_dict = test_model_with_enum_default_instance.to_dict() +test_model_with_enum_default_dict = test_model_with_enum_default_instance.model_dump(by_alias=True) # create an instance of TestModelWithEnumDefault from a dict -test_model_with_enum_default_from_dict = TestModelWithEnumDefault.from_dict(test_model_with_enum_default_dict) +test_model_with_enum_default_from_dict = TestModelWithEnumDefault.model_validate(test_model_with_enum_default_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/TestObjectForMultipartRequestsRequestMarker.md b/samples/openapi3/client/petstore/python-aiohttp/docs/TestObjectForMultipartRequestsRequestMarker.md index ff0ca9ee00ac..4ef346d455be 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/TestObjectForMultipartRequestsRequestMarker.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/TestObjectForMultipartRequestsRequestMarker.md @@ -15,14 +15,14 @@ from petstore_api.models.test_object_for_multipart_requests_request_marker impor # TODO update the JSON string below json = "{}" # create an instance of TestObjectForMultipartRequestsRequestMarker from a JSON string -test_object_for_multipart_requests_request_marker_instance = TestObjectForMultipartRequestsRequestMarker.from_json(json) +test_object_for_multipart_requests_request_marker_instance = TestObjectForMultipartRequestsRequestMarker.model_validate_json(json) # print the JSON string representation of the object -print(TestObjectForMultipartRequestsRequestMarker.to_json()) +print(TestObjectForMultipartRequestsRequestMarker.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_object_for_multipart_requests_request_marker_dict = test_object_for_multipart_requests_request_marker_instance.to_dict() +test_object_for_multipart_requests_request_marker_dict = test_object_for_multipart_requests_request_marker_instance.model_dump(by_alias=True) # create an instance of TestObjectForMultipartRequestsRequestMarker from a dict -test_object_for_multipart_requests_request_marker_from_dict = TestObjectForMultipartRequestsRequestMarker.from_dict(test_object_for_multipart_requests_request_marker_dict) +test_object_for_multipart_requests_request_marker_from_dict = TestObjectForMultipartRequestsRequestMarker.model_validate(test_object_for_multipart_requests_request_marker_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/Tiger.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Tiger.md index f1cf2133f0f7..bf096ee0be68 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/Tiger.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Tiger.md @@ -15,14 +15,14 @@ from petstore_api.models.tiger import Tiger # TODO update the JSON string below json = "{}" # create an instance of Tiger from a JSON string -tiger_instance = Tiger.from_json(json) +tiger_instance = Tiger.model_validate_json(json) # print the JSON string representation of the object -print(Tiger.to_json()) +print(Tiger.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -tiger_dict = tiger_instance.to_dict() +tiger_dict = tiger_instance.model_dump(by_alias=True) # create an instance of Tiger from a dict -tiger_from_dict = Tiger.from_dict(tiger_dict) +tiger_from_dict = Tiger.model_validate(tiger_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/UnnamedDictWithAdditionalModelListProperties.md b/samples/openapi3/client/petstore/python-aiohttp/docs/UnnamedDictWithAdditionalModelListProperties.md index 68cd00ab0a7a..a8d992c4e033 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/UnnamedDictWithAdditionalModelListProperties.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/UnnamedDictWithAdditionalModelListProperties.md @@ -15,14 +15,14 @@ from petstore_api.models.unnamed_dict_with_additional_model_list_properties impo # TODO update the JSON string below json = "{}" # create an instance of UnnamedDictWithAdditionalModelListProperties from a JSON string -unnamed_dict_with_additional_model_list_properties_instance = UnnamedDictWithAdditionalModelListProperties.from_json(json) +unnamed_dict_with_additional_model_list_properties_instance = UnnamedDictWithAdditionalModelListProperties.model_validate_json(json) # print the JSON string representation of the object -print(UnnamedDictWithAdditionalModelListProperties.to_json()) +print(UnnamedDictWithAdditionalModelListProperties.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -unnamed_dict_with_additional_model_list_properties_dict = unnamed_dict_with_additional_model_list_properties_instance.to_dict() +unnamed_dict_with_additional_model_list_properties_dict = unnamed_dict_with_additional_model_list_properties_instance.model_dump(by_alias=True) # create an instance of UnnamedDictWithAdditionalModelListProperties from a dict -unnamed_dict_with_additional_model_list_properties_from_dict = UnnamedDictWithAdditionalModelListProperties.from_dict(unnamed_dict_with_additional_model_list_properties_dict) +unnamed_dict_with_additional_model_list_properties_from_dict = UnnamedDictWithAdditionalModelListProperties.model_validate(unnamed_dict_with_additional_model_list_properties_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/UnnamedDictWithAdditionalStringListProperties.md b/samples/openapi3/client/petstore/python-aiohttp/docs/UnnamedDictWithAdditionalStringListProperties.md index 045b0e22ad09..44aa893d69a7 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/UnnamedDictWithAdditionalStringListProperties.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/UnnamedDictWithAdditionalStringListProperties.md @@ -15,14 +15,14 @@ from petstore_api.models.unnamed_dict_with_additional_string_list_properties imp # TODO update the JSON string below json = "{}" # create an instance of UnnamedDictWithAdditionalStringListProperties from a JSON string -unnamed_dict_with_additional_string_list_properties_instance = UnnamedDictWithAdditionalStringListProperties.from_json(json) +unnamed_dict_with_additional_string_list_properties_instance = UnnamedDictWithAdditionalStringListProperties.model_validate_json(json) # print the JSON string representation of the object -print(UnnamedDictWithAdditionalStringListProperties.to_json()) +print(UnnamedDictWithAdditionalStringListProperties.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -unnamed_dict_with_additional_string_list_properties_dict = unnamed_dict_with_additional_string_list_properties_instance.to_dict() +unnamed_dict_with_additional_string_list_properties_dict = unnamed_dict_with_additional_string_list_properties_instance.model_dump(by_alias=True) # create an instance of UnnamedDictWithAdditionalStringListProperties from a dict -unnamed_dict_with_additional_string_list_properties_from_dict = UnnamedDictWithAdditionalStringListProperties.from_dict(unnamed_dict_with_additional_string_list_properties_dict) +unnamed_dict_with_additional_string_list_properties_from_dict = UnnamedDictWithAdditionalStringListProperties.model_validate(unnamed_dict_with_additional_string_list_properties_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/UploadFileWithAdditionalPropertiesRequestObject.md b/samples/openapi3/client/petstore/python-aiohttp/docs/UploadFileWithAdditionalPropertiesRequestObject.md index 141027780371..096740ca96c2 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/UploadFileWithAdditionalPropertiesRequestObject.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/UploadFileWithAdditionalPropertiesRequestObject.md @@ -16,14 +16,14 @@ from petstore_api.models.upload_file_with_additional_properties_request_object i # TODO update the JSON string below json = "{}" # create an instance of UploadFileWithAdditionalPropertiesRequestObject from a JSON string -upload_file_with_additional_properties_request_object_instance = UploadFileWithAdditionalPropertiesRequestObject.from_json(json) +upload_file_with_additional_properties_request_object_instance = UploadFileWithAdditionalPropertiesRequestObject.model_validate_json(json) # print the JSON string representation of the object -print(UploadFileWithAdditionalPropertiesRequestObject.to_json()) +print(UploadFileWithAdditionalPropertiesRequestObject.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -upload_file_with_additional_properties_request_object_dict = upload_file_with_additional_properties_request_object_instance.to_dict() +upload_file_with_additional_properties_request_object_dict = upload_file_with_additional_properties_request_object_instance.model_dump(by_alias=True) # create an instance of UploadFileWithAdditionalPropertiesRequestObject from a dict -upload_file_with_additional_properties_request_object_from_dict = UploadFileWithAdditionalPropertiesRequestObject.from_dict(upload_file_with_additional_properties_request_object_dict) +upload_file_with_additional_properties_request_object_from_dict = UploadFileWithAdditionalPropertiesRequestObject.model_validate(upload_file_with_additional_properties_request_object_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/User.md b/samples/openapi3/client/petstore/python-aiohttp/docs/User.md index c45d26d27043..1986137ecc70 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/User.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/User.md @@ -22,14 +22,14 @@ from petstore_api.models.user import User # TODO update the JSON string below json = "{}" # create an instance of User from a JSON string -user_instance = User.from_json(json) +user_instance = User.model_validate_json(json) # print the JSON string representation of the object -print(User.to_json()) +print(User.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -user_dict = user_instance.to_dict() +user_dict = user_instance.model_dump(by_alias=True) # create an instance of User from a dict -user_from_dict = User.from_dict(user_dict) +user_from_dict = User.model_validate(user_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/WithNestedOneOf.md b/samples/openapi3/client/petstore/python-aiohttp/docs/WithNestedOneOf.md index e7bbbc28fc2d..63b0f83540d1 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/WithNestedOneOf.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/WithNestedOneOf.md @@ -17,14 +17,14 @@ from petstore_api.models.with_nested_one_of import WithNestedOneOf # TODO update the JSON string below json = "{}" # create an instance of WithNestedOneOf from a JSON string -with_nested_one_of_instance = WithNestedOneOf.from_json(json) +with_nested_one_of_instance = WithNestedOneOf.model_validate_json(json) # print the JSON string representation of the object -print(WithNestedOneOf.to_json()) +print(WithNestedOneOf.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -with_nested_one_of_dict = with_nested_one_of_instance.to_dict() +with_nested_one_of_dict = with_nested_one_of_instance.model_dump(by_alias=True) # create an instance of WithNestedOneOf from a dict -with_nested_one_of_from_dict = WithNestedOneOf.from_dict(with_nested_one_of_dict) +with_nested_one_of_from_dict = WithNestedOneOf.model_validate(with_nested_one_of_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 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 b1d830a31eef..0d456a35c3a4 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 @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field from typing_extensions import Annotated 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 bf2c62a53aed..4bca18df4343 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 @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from petstore_api.models.foo_get_default_response import FooGetDefaultResponse 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 3bb7f0218ef8..04b92f2c140d 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 @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from datetime import date, datetime from pydantic import Field, StrictBool, StrictBytes, StrictInt, StrictStr, field_validator 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 58c76f1daaf3..53fb3b184e87 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 @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field from typing_extensions import Annotated diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/import_test_datetime_api.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/import_test_datetime_api.py index bb82beefad78..bf38df779595 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/import_test_datetime_api.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/import_test_datetime_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from datetime import datetime 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 6f4f8092ea56..f4058216394b 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 @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field, StrictBytes, StrictInt, StrictStr, field_validator from typing import List, Optional, Tuple, Union 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 dc8d8de5c645..48eedc258b3d 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 @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field, StrictInt, StrictStr from typing import Dict 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 4e6d222045bf..683dfadd5e3b 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 @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field, StrictStr from typing import List diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py index de233385434d..a0054a46fbdf 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py @@ -315,7 +315,7 @@ def response_deserialize( return_data = self.__deserialize_file(response_data) elif response_type is not None: match = None - content_type = response_data.headers.get('content-type') + content_type = response_data.getheader('content-type') if content_type is not None: match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type) encoding = match.group(1) if match else "utf-8" @@ -332,7 +332,7 @@ def response_deserialize( return ApiResponse( status_code = response_data.status, data = return_data, - headers = response_data.headers, + headers = response_data.getheaders(), raw_data = response_data.data ) @@ -383,13 +383,10 @@ def sanitize_for_serialization(self, obj): # and attributes which value is not None. # Convert attribute name to json key in # model definition for request. - if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')): - obj_dict = obj.to_dict() - else: - obj_dict = obj.__dict__ + obj_dict = obj.model_dump(by_alias=True, exclude_none=True) if isinstance(obj_dict, list): - # here we handle instances that can either be a list or something else, and only became a real list by calling to_dict() + # here we handle instances that can either be a list or something else, and only became a real list by calling model_dump(by_alias=True) return self.sanitize_for_serialization(obj_dict) return { @@ -711,7 +708,7 @@ def __deserialize_file(self, response): os.close(fd) os.remove(path) - content_disposition = response.headers.get("Content-Disposition") + content_disposition = response.getheader("Content-Disposition") if content_disposition: m = re.search( r'filename=[\'"]?([^\'"\s]+)[\'"]?', @@ -811,4 +808,4 @@ def __deserialize_model(self, data, klass): :return: model object. """ - return klass.from_dict(data) + return klass.model_validate(data) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py index 8a5ebdc1143f..b136a2a6d1a7 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/configuration.py @@ -18,8 +18,7 @@ import logging from logging import FileHandler import sys -from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union -from typing_extensions import NotRequired, Self +from typing import Any, ClassVar, Dict, List, Literal, NotRequired, Optional, TypedDict, Union, Self from petstore_api.signing import HttpSigningConfiguration diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/exceptions.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/exceptions.py index cb0ecfbf7018..a5d2c10c55be 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/exceptions.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/exceptions.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """ OpenAPI Petstore @@ -11,8 +9,8 @@ Do not edit the class manually. """ # noqa: E501 -from typing import Any, Optional -from typing_extensions import Self + +from typing import Any, Optional, Self class OpenApiException(Exception): """The base exception class for all OpenAPIExceptions""" @@ -104,9 +102,9 @@ def __init__(self, msg, path_to_item=None) -> None: class ApiException(OpenApiException): def __init__( - self, - status=None, - reason=None, + self, + status=None, + reason=None, http_resp=None, *, body: Optional[str] = None, @@ -128,14 +126,14 @@ def __init__( self.body = http_resp.data.decode('utf-8') except Exception: pass - self.headers = http_resp.headers + self.headers = http_resp.getheaders() @classmethod def from_response( - cls, - *, - http_resp, - body: Optional[str], + cls, + *, + http_resp, + body: Optional[str], data: Optional[Any], ) -> Self: if http_resp.status == 400: @@ -169,11 +167,8 @@ def __str__(self): error_message += "HTTP response headers: {0}\n".format( self.headers) - if self.body: - error_message += "HTTP response body: {0}\n".format(self.body) - - if self.data: - error_message += "HTTP response data: {0}\n".format(self.data) + if self.data or self.body: + error_message += "HTTP response body: {0}\n".format(self.data or self.body) return error_message 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 291b5e55e353..9986695fc1ec 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesAnyType(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesAnyType from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesAnyType from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 4b2cc457e499..8b59d27c9ff6 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesClass(BaseModel): """ @@ -41,49 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "map_property": obj.get("map_property"), - "map_of_map_property": obj.get("map_of_map_property") - }) - return _obj 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 00707c3c4818..a514124192f5 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesObject(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesObject from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesObject from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 d8049b519ed0..a01f7169f6a4 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesWithDescriptionOnly(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesWithDescriptionOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesWithDescriptionOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_super_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_super_model.py index 03f554592935..e14106518d97 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_super_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_super_model.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AllOfSuperModel(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AllOfSuperModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AllOfSuperModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_name": obj.get("_name") - }) - return _obj 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 44c7da9114a8..223e5c6a765d 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.single_ref_type import SingleRefType -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AllOfWithSingleRef(BaseModel): """ @@ -42,49 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AllOfWithSingleRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AllOfWithSingleRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "username": obj.get("username"), - "SingleRefType": obj.get("SingleRefType") - }) - return _obj 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 56bec73a9ccd..9646242f3df6 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 @@ -20,8 +20,8 @@ from importlib import import_module from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional, Union -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -64,48 +64,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[Cat, Dog]]: - """Create an instance of Animal from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[Cat, Dog]]: - """Create an instance of Animal from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'Cat': - return import_module("petstore_api.models.cat").Cat.from_dict(obj) - if object_type == 'Dog': - return import_module("petstore_api.models.dog").Dog.from_dict(obj) - - raise ValueError("Animal failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) 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 f6d277e79498..8e0c6051da74 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 @@ -20,137 +20,30 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import List, Optional from typing_extensions import Annotated -from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict -from typing_extensions import Literal, Self -from pydantic import Field +from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict, Literal, Self +from pydantic import Field, RootModel ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"] -class AnyOfColor(BaseModel): + +class AnyOfColor(RootModel[Union[List[int], str]]): """ Any of RGB array, RGBA array, or hex string. """ - # data type: List[int] - 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_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: - actual_instance: Optional[Union[List[int], str]] = None - else: - actual_instance: Any = None - any_of_schemas: Set[str] = { "List[int]", "str" } - - model_config = { - "validate_assignment": True, - "protected_namespaces": (), - } - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_anyof(cls, v): - instance = AnyOfColor.model_construct() - error_messages = [] - # validate data type: List[int] - try: - instance.anyof_schema_1_validator = v - return v - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: List[int] - try: - instance.anyof_schema_2_validator = v - return v - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: str - try: - instance.anyof_schema_3_validator = v - return v - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - if error_messages: - # no match - raise ValueError("No match found when setting the actual_instance in AnyOfColor with anyOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - # deserialize data into List[int] - try: - # validation - instance.anyof_schema_1_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.anyof_schema_1_validator - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into List[int] - try: - # validation - instance.anyof_schema_2_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.anyof_schema_2_validator - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into str - try: - # validation - instance.anyof_schema_3_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.anyof_schema_3_validator - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if error_messages: - # no match - raise ValueError("No match found when deserializing the JSON string into AnyOfColor with anyOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + root: Union[List[int], str] = Field( + ... + ) + + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") 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 c949e136f415..df3bae10d3a6 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 @@ -21,114 +21,30 @@ from typing import Optional from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig -from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict -from typing_extensions import Literal, Self -from pydantic import Field +from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict, Literal, Self +from pydantic import Field, RootModel ANYOFPIG_ANY_OF_SCHEMAS = ["BasquePig", "DanishPig"] -class AnyOfPig(BaseModel): + +class AnyOfPig(RootModel[Union[BasquePig, DanishPig]]): """ AnyOfPig """ - # data type: BasquePig - anyof_schema_1_validator: Optional[BasquePig] = None - # data type: DanishPig - anyof_schema_2_validator: Optional[DanishPig] = None - if TYPE_CHECKING: - actual_instance: Optional[Union[BasquePig, DanishPig]] = None - else: - actual_instance: Any = None - any_of_schemas: Set[str] = { "BasquePig", "DanishPig" } - - model_config = { - "validate_assignment": True, - "protected_namespaces": (), - } - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_anyof(cls, v): - instance = AnyOfPig.model_construct() - error_messages = [] - # validate data type: BasquePig - if not isinstance(v, BasquePig): - error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`") - else: - return v - - # validate data type: DanishPig - if not isinstance(v, DanishPig): - error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`") - else: - return v - - if error_messages: - # no match - raise ValueError("No match found when setting the actual_instance in AnyOfPig with anyOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - # anyof_schema_1_validator: Optional[BasquePig] = None - try: - instance.actual_instance = BasquePig.from_json(json_str) - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # anyof_schema_2_validator: Optional[DanishPig] = None - try: - instance.actual_instance = DanishPig.from_json(json_str) - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if error_messages: - # no match - raise ValueError("No match found when deserializing the JSON string into AnyOfPig with anyOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], BasquePig, DanishPig]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + root: Union[BasquePig, DanishPig] = Field( + ... + ) + + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") 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 4f8eeda66c30..c5204e2fb306 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayOfArrayOfModel(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in another_property (list of list) - _items = [] - if self.another_property: - for _item_another_property in self.another_property: - if _item_another_property: - _items.append( - [_inner_item.to_dict() for _inner_item in _item_another_property if _inner_item is not None] - ) - _dict['another_property'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "another_property": [ - [Tag.from_dict(_inner_item) for _inner_item in _item] - for _item in obj["another_property"] - ] if obj.get("another_property") is not None else None - }) - return _obj 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 02b0f6d657f4..2374c09d8bf0 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayOfArrayOfNumberOnly(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfNumberOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfNumberOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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 b22632b0ce4d..16545c13d9f2 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayOfNumberOnly(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayOfNumberOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayOfNumberOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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 e8f8acf67cc0..61b4fb891399 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 @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from typing_extensions import Annotated from petstore_api.models.read_only_first import ReadOnlyFirst -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayTest(BaseModel): """ @@ -45,63 +45,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in array_array_of_model (list of list) - _items = [] - if self.array_array_of_model: - for _item_array_array_of_model in self.array_array_of_model: - if _item_array_array_of_model: - _items.append( - [_inner_item.to_dict() for _inner_item in _item_array_array_of_model if _inner_item is not None] - ) - _dict['array_array_of_model'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "array_of_string": obj.get("array_of_string"), - "array_of_nullable_float": obj.get("array_of_nullable_float"), - "array_array_of_integer": obj.get("array_array_of_integer"), - "array_array_of_model": [ - [ReadOnlyFirst.from_dict(_inner_item) for _inner_item in _item] - for _item in obj["array_array_of_model"] - ] if obj.get("array_array_of_model") is not None else None - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/base_discriminator.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/base_discriminator.py index f13c270b56b5..b0a9914bb2bf 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/base_discriminator.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/base_discriminator.py @@ -20,8 +20,8 @@ from importlib import import_module from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional, Union -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -63,48 +63,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[PrimitiveString, Info]]: - """Create an instance of BaseDiscriminator from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[PrimitiveString, Info]]: - """Create an instance of BaseDiscriminator from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'PrimitiveString': - return import_module("petstore_api.models.primitive_string").PrimitiveString.from_dict(obj) - if object_type == 'Info': - return import_module("petstore_api.models.info").Info.from_dict(obj) - - raise ValueError("BaseDiscriminator failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) 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 a1f32a6edcfc..78b6e31c6313 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class BasquePig(BaseModel): """ @@ -41,49 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of BasquePig from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of BasquePig from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "color": obj.get("color") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/bathing.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/bathing.py index 088e6ad3b873..f6336229e61a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/bathing.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/bathing.py @@ -19,15 +19,21 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Bathing(BaseModel): """ Bathing """ # noqa: E501 - task_name: StrictStr - function_name: StrictStr + task_name: Literal['cleaning_deep'] = Field( + ..., + description="task_name of the Bathing" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Bathing" + ) content: StrictStr __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -56,50 +62,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Bathing from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Bathing from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "task_name": obj.get("task_name"), - "function_name": obj.get("function_name"), - "content": obj.get("content") - }) - return _obj 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 b3c20af54440..0145e1b19bea 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Capitalization(BaseModel): """ @@ -45,53 +45,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Capitalization from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Capitalization from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "smallCamel": obj.get("smallCamel"), - "CapitalCamel": obj.get("CapitalCamel"), - "small_Snake": obj.get("small_Snake"), - "Capital_Snake": obj.get("Capital_Snake"), - "SCA_ETH_Flow_Points": obj.get("SCA_ETH_Flow_Points"), - "ATT_NAME": obj.get("ATT_NAME") - }) - return _obj 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 0c2c9788dca3..77ec7bf1e9a7 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 @@ -20,8 +20,8 @@ from pydantic import ConfigDict, StrictBool from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.animal import Animal -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Cat(Animal): """ @@ -41,50 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Cat from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Cat from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "color": obj.get("color") if obj.get("color") is not None else 'red', - "declawed": obj.get("declawed") - }) - return _obj 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 dcc6247b5ac7..9e05503386fc 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Category(BaseModel): """ @@ -41,49 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Category from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Category from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") if obj.get("name") is not None else 'default-name' - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_all_of_ref.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_all_of_ref.py index f98247ae0fb5..b3805c6c0a72 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_all_of_ref.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_all_of_ref.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class CircularAllOfRef(BaseModel): """ @@ -41,57 +41,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of CircularAllOfRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in second_circular_all_of_ref (list) - _items = [] - if self.second_circular_all_of_ref: - for _item_second_circular_all_of_ref in self.second_circular_all_of_ref: - if _item_second_circular_all_of_ref: - _items.append(_item_second_circular_all_of_ref.to_dict()) - _dict['secondCircularAllOfRef'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of CircularAllOfRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_name": obj.get("_name"), - "secondCircularAllOfRef": [SecondCircularAllOfRef.from_dict(_item) for _item in obj["secondCircularAllOfRef"]] if obj.get("secondCircularAllOfRef") is not None else None - }) - return _obj from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef # TODO: Rewrite to not use raise_errors 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 3b2854caaac2..ef203d8a9bb9 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class CircularReferenceModel(BaseModel): """ @@ -41,53 +41,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of CircularReferenceModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of nested - if self.nested: - _dict['nested'] = self.nested.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of CircularReferenceModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "nested": FirstRef.from_dict(obj["nested"]) if obj.get("nested") is not None else None - }) - return _obj from petstore_api.models.first_ref import FirstRef # TODO: Rewrite to not use raise_errors 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 6def0e52d146..b6e82dcd7a53 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ClassModel(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ClassModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ClassModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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 1c12c9a145c8..2bd0f1eb7995 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Client(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Client from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Client from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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 bb740fb597d4..7fe333c7a3b9 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 @@ -18,150 +18,27 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Any, List, Optional from typing_extensions import Annotated -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self COLOR_ONE_OF_SCHEMAS = ["List[int]", "str"] -class Color(BaseModel): +class Color(RootModel[Union[List[int], str]]): """ 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_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_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: Set[str] = { "List[int]", "str" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[List[int], str] = Field( + ... ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - if v is None: - return v - - instance = Color.model_construct() - error_messages = [] - match = 0 - # validate data type: List[int] - try: - instance.oneof_schema_1_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: List[int] - try: - instance.oneof_schema_2_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: str - try: - instance.oneof_schema_3_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: Optional[str]) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - if json_str is None: - return instance - - error_messages = [] - match = 0 - - # deserialize data into List[int] - try: - # validation - instance.oneof_schema_1_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_1_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into List[int] - try: - # validation - instance.oneof_schema_2_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_2_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into str - try: - # validation - instance.oneof_schema_3_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_3_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") 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 2ed3aa42bf99..304672d67040 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 @@ -21,8 +21,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Union from petstore_api.models.creature_info import CreatureInfo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -64,49 +64,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[HuntingDog]]: - """Create an instance of Creature from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of info - if self.info: - _dict['info'] = self.info.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[HuntingDog]]: - """Create an instance of Creature from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'HuntingDog': - return import_module("petstore_api.models.hunting_dog").HuntingDog.from_dict(obj) - - raise ValueError("Creature failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) 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 e7927446c238..2d81c0654e7b 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class CreatureInfo(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of CreatureInfo from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of CreatureInfo from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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 061e16a486a5..1f1abc8848a4 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DanishPig(BaseModel): """ @@ -41,49 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DanishPig from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DanishPig from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "size": obj.get("size") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/data_output_format.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/data_output_format.py index ee3df76c5169..e32ebe9a5ee4 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/data_output_format.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/data_output_format.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class DataOutputFormat(StrEnum): -class DataOutputFormat(str, Enum): """ DataOutputFormat """ - """ - allowed enum values - """ + # Allowed enum values JSON = 'JSON' CSV = 'CSV' XML = 'XML' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of DataOutputFormat from a JSON string""" return cls(json.loads(json_str)) - 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 bb4747a1e18c..f76e4520350b 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DeprecatedObject(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DeprecatedObject from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DeprecatedObject from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/discriminator_all_of_sub.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/discriminator_all_of_sub.py index 2e8d4a6d7633..a7c1d0abd705 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/discriminator_all_of_sub.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/discriminator_all_of_sub.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict from typing import Any, ClassVar, Dict, List from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DiscriminatorAllOfSub(DiscriminatorAllOfSuper): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DiscriminatorAllOfSub from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DiscriminatorAllOfSub from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "elementType": obj.get("elementType") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/discriminator_all_of_super.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/discriminator_all_of_super.py index ee910f90ea69..44b5ac27198f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/discriminator_all_of_super.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/discriminator_all_of_super.py @@ -20,8 +20,8 @@ from importlib import import_module from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Union -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -62,46 +62,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[DiscriminatorAllOfSub]]: - """Create an instance of DiscriminatorAllOfSuper from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[DiscriminatorAllOfSub]]: - """Create an instance of DiscriminatorAllOfSuper from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'DiscriminatorAllOfSub': - return import_module("petstore_api.models.discriminator_all_of_sub").DiscriminatorAllOfSub.from_dict(obj) - - raise ValueError("DiscriminatorAllOfSuper failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) 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 a0f4ed786b4e..036575e157f3 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 @@ -20,8 +20,8 @@ from pydantic import ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.animal import Animal -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Dog(Animal): """ @@ -41,50 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Dog from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Dog from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "color": obj.get("color") if obj.get("color") is not None else 'red', - "breed": obj.get("breed") - }) - return _obj 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 3050cbf66dc4..82fd4e04c987 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DummyModel(BaseModel): """ @@ -41,53 +41,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DummyModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of self_ref - if self.self_ref: - _dict['self_ref'] = self.self_ref.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DummyModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "category": obj.get("category"), - "self_ref": SelfReferenceModel.from_dict(obj["self_ref"]) if obj.get("self_ref") is not None else None - }) - return _obj from petstore_api.models.self_reference_model import SelfReferenceModel # TODO: Rewrite to not use raise_errors 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 68ceb962b03e..9df2ad1d4957 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,15 +19,17 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class EnumArrays(BaseModel): """ EnumArrays """ # noqa: E501 - just_symbol: Optional[StrictStr] = None - array_enum: Optional[List[StrictStr]] = None + just_symbol: Optional[Just_symbolEnum] = Field( + None, + description="just_symbol of the EnumArrays" + ) __properties: ClassVar[List[str]] = ["just_symbol", "array_enum"] @field_validator('just_symbol') @@ -62,49 +64,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of EnumArrays from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of EnumArrays from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "just_symbol": obj.get("just_symbol"), - "array_enum": obj.get("array_enum") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_class.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_class.py index 1ba5af8036df..b4e61d237db8 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_class.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_class.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumClass(StrEnum): -class EnumClass(str, Enum): """ EnumClass """ - """ - allowed enum values - """ + # Allowed enum values ABC = '_abc' MINUS_EFG = '-efg' LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS = '(xyz)' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumClass from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_number_vendor_ext.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_number_vendor_ext.py index 5588de5c7043..91d2161cbc6d 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_number_vendor_ext.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_number_vendor_ext.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumNumberVendorExt(IntEnum): -class EnumNumberVendorExt(int, Enum): """ EnumNumberVendorExt """ - """ - allowed enum values - """ + # Allowed enum values FortyTwo = 42 Eigtheen = 18 FiftySix = 56 @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumNumberVendorExt from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_ref_with_default_value.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_ref_with_default_value.py index 9d97e3fd16d4..84065f0b77dd 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_ref_with_default_value.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_ref_with_default_value.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.data_output_format import DataOutputFormat -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class EnumRefWithDefaultValue(BaseModel): """ @@ -41,48 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of EnumRefWithDefaultValue from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of EnumRefWithDefaultValue from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "report_format": obj.get("report_format") if obj.get("report_format") is not None else DataOutputFormat.JSON - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_string1.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_string1.py index 678b4e12661f..d6970ff8346f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_string1.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_string1.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumString1(StrEnum): -class EnumString1(str, Enum): """ EnumString1 """ - """ - allowed enum values - """ + # Allowed enum values A = 'a' B = 'b' @@ -34,4 +32,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumString1 from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_string2.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_string2.py index a959f554e0af..c4fc722f826a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_string2.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_string2.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumString2(StrEnum): -class EnumString2(str, Enum): """ EnumString2 """ - """ - allowed enum values - """ + # Allowed enum values C = 'c' D = 'd' @@ -34,4 +32,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumString2 from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_string_vendor_ext.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_string_vendor_ext.py index 821812e9b088..175ace79326f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_string_vendor_ext.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_string_vendor_ext.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumStringVendorExt(StrEnum): -class EnumStringVendorExt(str, Enum): """ EnumStringVendorExt """ - """ - allowed enum values - """ + # Allowed enum values FOO_XEnumVarname = 'FOO' BarVar_XEnumVarname = 'Bar' bazVar_XEnumVarname = 'baz' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumStringVendorExt from a JSON string""" return cls(json.loads(json_str)) - 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 b7e6ec36230f..b37d73101dc6 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 @@ -25,20 +25,41 @@ from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue from petstore_api.models.outer_enum_integer import OuterEnumInteger from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntegerDefaultValue -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class EnumTest(BaseModel): """ EnumTest """ # noqa: E501 - enum_string: Optional[StrictStr] = None - enum_string_required: StrictStr - enum_integer_default: Optional[StrictInt] = 5 - enum_integer: Optional[StrictInt] = None - enum_number: Optional[float] = None - enum_string_single_member: Optional[StrictStr] = None - enum_integer_single_member: Optional[StrictInt] = None + enum_string: Optional[Enum_stringEnum] = Field( + None, + description="enum_string of the EnumTest" + ) + enum_string_required: Enum_string_requiredEnum = Field( + ..., + description="enum_string_required of the EnumTest" + ) + enum_integer_default: Optional[Enum_integer_defaultEnum] = Field( + None, + description="enum_integer_default of the EnumTest" + ) + enum_integer: Optional[Enum_integerEnum] = Field( + None, + description="enum_integer of the EnumTest" + ) + enum_number: Optional[Enum_numberEnum] = Field( + None, + description="enum_number of the EnumTest" + ) + enum_string_single_member: Literal['abc'] = Field( + None, + description="enum_string_single_member of the EnumTest" + ) + enum_integer_single_member: Literal['100'] = Field( + None, + description="enum_integer_single_member of the EnumTest" + ) outer_enum: Optional[OuterEnum] = Field(default=None, alias="outerEnum") outer_enum_integer: Optional[OuterEnumInteger] = Field(default=None, alias="outerEnumInteger") outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=OuterEnumDefaultValue.PLACED, alias="outerEnumDefaultValue") @@ -125,65 +146,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of EnumTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # set to None if outer_enum (nullable) is None - # 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of EnumTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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, - "enum_integer": obj.get("enum_integer"), - "enum_number": obj.get("enum_number"), - "enum_string_single_member": obj.get("enum_string_single_member"), - "enum_integer_single_member": obj.get("enum_integer_single_member"), - "outerEnum": obj.get("outerEnum"), - "outerEnumInteger": obj.get("outerEnumInteger"), - "outerEnumDefaultValue": obj.get("outerEnumDefaultValue") if obj.get("outerEnumDefaultValue") is not None else OuterEnumDefaultValue.PLACED, - "outerEnumIntegerDefaultValue": obj.get("outerEnumIntegerDefaultValue") if obj.get("outerEnumIntegerDefaultValue") is not None else OuterEnumIntegerDefaultValue.NUMBER_0, - "enumNumberVendorExt": obj.get("enumNumberVendorExt"), - "enumStringVendorExt": obj.get("enumStringVendorExt") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/feeding.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/feeding.py index 1183b314fdd0..6064c0ac4b80 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/feeding.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/feeding.py @@ -19,15 +19,21 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Feeding(BaseModel): """ Feeding """ # noqa: E501 - task_name: StrictStr - function_name: StrictStr + task_name: Literal['cleaning'] = Field( + ..., + description="task_name of the Feeding" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Feeding" + ) content: StrictStr __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -56,50 +62,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Feeding from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Feeding from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "task_name": obj.get("task_name"), - "function_name": obj.get("function_name"), - "content": obj.get("content") - }) - return _obj 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 0ecacf44bb8e..f433bf9d4fe0 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class File(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of File from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of File from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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 c533c0777b24..98039554d624 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.file import File -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FileSchemaTestClass(BaseModel): """ @@ -42,59 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FileSchemaTestClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of file - if self.file: - _dict['file'] = self.file.to_dict() - # override the default output from pydantic by calling `to_dict()` of each item in files (list) - _items = [] - if self.files: - for _item_files in self.files: - if _item_files: - _items.append(_item_files.to_dict()) - _dict['files'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FileSchemaTestClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "file": File.from_dict(obj["file"]) if obj.get("file") is not None else None, - "files": [File.from_dict(_item) for _item in obj["files"]] if obj.get("files") is not None else None - }) - return _obj 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 6aa0f722d874..07dd1a27b6b6 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FirstRef(BaseModel): """ @@ -41,53 +41,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FirstRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of self_ref - if self.self_ref: - _dict['self_ref'] = self.self_ref.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FirstRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "category": obj.get("category"), - "self_ref": SecondRef.from_dict(obj["self_ref"]) if obj.get("self_ref") is not None else None - }) - return _obj from petstore_api.models.second_ref import SecondRef # TODO: Rewrite to not use raise_errors 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 67b29f1ab87c..2e09049eba3a 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Foo(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Foo from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Foo from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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 ae191aad80a8..8303a4f631a5 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.foo import Foo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FooGetDefaultResponse(BaseModel): """ @@ -41,51 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FooGetDefaultResponse from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of string - if self.string: - _dict['string'] = self.string.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FooGetDefaultResponse from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "string": Foo.from_dict(obj["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 8d70a96f3a7c..421e8b67b534 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 @@ -23,8 +23,8 @@ from typing import Any, ClassVar, Dict, List, Optional, Tuple, Union from typing_extensions import Annotated from uuid import UUID -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FormatTest(BaseModel): """ @@ -100,64 +100,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FormatTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FormatTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "integer": obj.get("integer"), - "int32": obj.get("int32"), - "int64": obj.get("int64"), - "number": obj.get("number"), - "float": obj.get("float"), - "double": obj.get("double"), - "decimal": obj.get("decimal"), - "string": obj.get("string"), - "string_with_double_quote_pattern": obj.get("string_with_double_quote_pattern"), - "byte": obj.get("byte"), - "binary": obj.get("binary"), - "date": obj.get("date"), - "dateTime": obj.get("dateTime"), - "uuid": obj.get("uuid"), - "password": obj.get("password"), - "pattern_with_digits": obj.get("pattern_with_digits"), - "pattern_with_digits_and_delimiter": obj.get("pattern_with_digits_and_delimiter") - }) - return _obj 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 2137bc880484..957a9bd0d924 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class HasOnlyReadOnly(BaseModel): """ @@ -41,53 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of HasOnlyReadOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * OpenAPI `readOnly` fields are excluded. - * OpenAPI `readOnly` fields are excluded. - """ - excluded_fields: Set[str] = set([ - "bar", - "foo", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of HasOnlyReadOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "bar": obj.get("bar"), - "foo": obj.get("foo") - }) - return _obj 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 4dbdd852097f..914aea7237e6 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class HealthCheckResult(BaseModel): """ @@ -40,53 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of HealthCheckResult from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # set to None if nullable_message (nullable) is None - # 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of HealthCheckResult from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "NullableMessage": obj.get("NullableMessage") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/hunting_dog.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/hunting_dog.py index cd678616f62f..f699b1197d7d 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/hunting_dog.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/hunting_dog.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.creature import Creature from petstore_api.models.creature_info import CreatureInfo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class HuntingDog(Creature): """ @@ -42,53 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of HuntingDog from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of info - if self.info: - _dict['info'] = self.info.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of HuntingDog from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "info": CreatureInfo.from_dict(obj["info"]) if obj.get("info") is not None else None, - "type": obj.get("type"), - "isTrained": obj.get("isTrained") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/info.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/info.py index 5a15b5f9f52f..342c71caf992 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/info.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/info.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.base_discriminator import BaseDiscriminator -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Info(BaseDiscriminator): """ @@ -41,52 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Info from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of val - if self.val: - _dict['val'] = self.val.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Info from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_typeName": obj.get("_typeName"), - "val": BaseDiscriminator.from_dict(obj["val"]) if obj.get("val") is not None else None - }) - 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 27816b995f53..67a9824abe1d 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class InnerDictWithProperty(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of InnerDictWithProperty from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of InnerDictWithProperty from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "aProperty": obj.get("aProperty") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/input_all_of.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/input_all_of.py index 63870cca83ed..1e2a992990c2 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/input_all_of.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/input_all_of.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class InputAllOf(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of InputAllOf from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in some_data (dict) - _field_dict = {} - if self.some_data: - for _key_some_data in self.some_data: - if self.some_data[_key_some_data]: - _field_dict[_key_some_data] = self.some_data[_key_some_data].to_dict() - _dict['some_data'] = _field_dict - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of InputAllOf from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "some_data": dict( - (_k, Tag.from_dict(_v)) - for _k, _v in obj["some_data"].items() - ) - if obj.get("some_data") is not None - else None - }) - 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 f2a5a0a2d4a3..63f94b788677 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 @@ -18,127 +18,27 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Any, List, Optional from typing_extensions import Annotated -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self INTORSTRING_ONE_OF_SCHEMAS = ["int", "str"] -class IntOrString(BaseModel): +class IntOrString(RootModel[Union[int, str]]): """ IntOrString """ - # data type: int - oneof_schema_1_validator: Optional[Annotated[int, Field(strict=True, ge=10)]] = None - # data type: str - oneof_schema_2_validator: Optional[StrictStr] = None - actual_instance: Optional[Union[int, str]] = None - one_of_schemas: Set[str] = { "int", "str" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[int, str] = Field( + ... ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - instance = IntOrString.model_construct() - error_messages = [] - match = 0 - # validate data type: int - try: - instance.oneof_schema_1_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: str - try: - instance.oneof_schema_2_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # deserialize data into int - try: - # validation - instance.oneof_schema_1_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_1_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into str - try: - # validation - instance.oneof_schema_2_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_2_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], int, str]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/list_class.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/list_class.py index ab12a7fac521..74d6399aeb7f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/list_class.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/list_class.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ListClass(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ListClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ListClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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 a9bd000ad9ba..0f339a87cf07 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MapOfArrayOfModel(BaseModel): """ @@ -41,64 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MapOfArrayOfModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in shop_id_to_org_online_lip_map (dict of array) - _field_dict_of_array = {} - if self.shop_id_to_org_online_lip_map: - for _key_shop_id_to_org_online_lip_map in self.shop_id_to_org_online_lip_map: - if self.shop_id_to_org_online_lip_map[_key_shop_id_to_org_online_lip_map] is not None: - _field_dict_of_array[_key_shop_id_to_org_online_lip_map] = [ - _item.to_dict() for _item in self.shop_id_to_org_online_lip_map[_key_shop_id_to_org_online_lip_map] - ] - _dict['shopIdToOrgOnlineLipMap'] = _field_dict_of_array - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MapOfArrayOfModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "shopIdToOrgOnlineLipMap": dict( - (_k, - [Tag.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("shopIdToOrgOnlineLipMap", {}).items() - ) - }) - return _obj 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 2a056ab5532a..516c89c56ee6 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,15 +19,18 @@ from pydantic import BaseModel, ConfigDict, StrictBool, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MapTest(BaseModel): """ MapTest """ # noqa: E501 map_map_of_string: Optional[Dict[str, Dict[str, StrictStr]]] = None - map_of_enum_string: Optional[Dict[str, StrictStr]] = None + map_of_enum_string: Optional[Dict[str, str]] = Field( + None, + description="map_of_enum_string of the MapTest" + ) direct_map: Optional[Dict[str, StrictBool]] = None indirect_map: Optional[Dict[str, StrictBool]] = None __properties: ClassVar[List[str]] = ["map_map_of_string", "map_of_enum_string", "direct_map", "indirect_map"] @@ -54,51 +57,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MapTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MapTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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"), - "indirect_map": obj.get("indirect_map") - }) - return _obj 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 46998dfb5c68..42de85aa28f7 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 @@ -22,8 +22,8 @@ from typing import Any, ClassVar, Dict, List, Optional from uuid import UUID from petstore_api.models.animal import Animal -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): """ @@ -45,62 +45,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MixedPropertiesAndAdditionalPropertiesClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in map (dict) - _field_dict = {} - if self.map: - for _key_map in self.map: - if self.map[_key_map]: - _field_dict[_key_map] = self.map[_key_map].to_dict() - _dict['map'] = _field_dict - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MixedPropertiesAndAdditionalPropertiesClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "uuid": obj.get("uuid"), - "dateTime": obj.get("dateTime"), - "map": dict( - (_k, Animal.from_dict(_v)) - for _k, _v in obj["map"].items() - ) - if obj.get("map") is not None - else None - }) - return _obj 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 d6012c57fbd7..b65f251b4ac2 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Model200Response(BaseModel): """ @@ -41,49 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Model200Response from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Model200Response from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name"), - "class": obj.get("class") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_api_response.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_api_response.py index 005c77823bef..5e061c8596eb 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_api_response.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_api_response.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ModelApiResponse(BaseModel): """ @@ -42,50 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ModelApiResponse from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ModelApiResponse from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "code": obj.get("code"), - "type": obj.get("type"), - "message": obj.get("message") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_field.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_field.py index 9e36a6ac7e48..9f7ec1d8e8f6 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_field.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_field.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ModelField(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ModelField from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ModelField from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "field": obj.get("field") - }) - return _obj 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 a8c0f53f6c19..fcb4326a6d21 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ModelReturn(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ModelReturn from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ModelReturn from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "return": obj.get("return") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/multi_arrays.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/multi_arrays.py index 177a8359468f..4bc0deaa6875 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/multi_arrays.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/multi_arrays.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.file import File from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MultiArrays(BaseModel): """ @@ -43,63 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MultiArrays from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in tags (list) - _items = [] - if self.tags: - for _item_tags in self.tags: - if _item_tags: - _items.append(_item_tags.to_dict()) - _dict['tags'] = _items - # override the default output from pydantic by calling `to_dict()` of each item in files (list) - _items = [] - if self.files: - for _item_files in self.files: - if _item_files: - _items.append(_item_files.to_dict()) - _dict['files'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MultiArrays from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "tags": [Tag.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None, - "files": [File.from_dict(_item) for _item in obj["files"]] if obj.get("files") is not None else None - }) - 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 f33b2ecb18be..3c663054f54e 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Name(BaseModel): """ @@ -43,55 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Name from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * OpenAPI `readOnly` fields are excluded. - * OpenAPI `readOnly` fields are excluded. - """ - excluded_fields: Set[str] = set([ - "snake_case", - "var_123_number", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Name from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name"), - "snake_case": obj.get("snake_case"), - "property": obj.get("property"), - "123Number": obj.get("123Number") - }) - return _obj 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 9d1414954830..3d3d9df95b29 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 @@ -20,8 +20,8 @@ from datetime import date, datetime from pydantic import BaseModel, ConfigDict, StrictBool, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class NullableClass(BaseModel): """ @@ -54,127 +54,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of NullableClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - # set to None if required_integer_prop (nullable) is None - # 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 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 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 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 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 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 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 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 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 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 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of NullableClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "required_integer_prop": obj.get("required_integer_prop"), - "integer_prop": obj.get("integer_prop"), - "number_prop": obj.get("number_prop"), - "boolean_prop": obj.get("boolean_prop"), - "string_prop": obj.get("string_prop"), - "date_prop": obj.get("date_prop"), - "datetime_prop": obj.get("datetime_prop"), - "array_nullable_prop": obj.get("array_nullable_prop"), - "array_and_items_nullable_prop": obj.get("array_and_items_nullable_prop"), - "array_items_nullable": obj.get("array_items_nullable"), - "object_nullable_prop": obj.get("object_nullable_prop"), - "object_and_items_nullable_prop": obj.get("object_and_items_nullable_prop"), - "object_items_nullable": obj.get("object_items_nullable") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 2324745d7dd1..6ec823c425f3 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, field_validator from typing import Any, ClassVar, Dict, List, Optional from typing_extensions import Annotated -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class NullableProperty(BaseModel): """ @@ -52,54 +52,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of NullableProperty from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # set to None if name (nullable) is None - # and model_fields_set contains the field - if self.name is None and "name" in self.model_fields_set: - _dict['name'] = None - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of NullableProperty from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") - }) - return _obj 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 18c3ec953080..567c5c62453b 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class NumberOnly(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of NumberOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of NumberOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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 22b8bd401a1c..2335de5cc99f 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictBool from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ObjectToTestAdditionalProperties(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ObjectToTestAdditionalProperties from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ObjectToTestAdditionalProperties from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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 4d76d9f5fc72..7f7bc9cfd6ce 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.deprecated_object import DeprecatedObject -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ObjectWithDeprecatedFields(BaseModel): """ @@ -44,54 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ObjectWithDeprecatedFields from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of deprecated_ref - if self.deprecated_ref: - _dict['deprecatedRef'] = self.deprecated_ref.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ObjectWithDeprecatedFields from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "uuid": obj.get("uuid"), - "id": obj.get("id"), - "deprecatedRef": DeprecatedObject.from_dict(obj["deprecatedRef"]) if obj.get("deprecatedRef") is not None else None, - "bars": obj.get("bars") - }) - return _obj 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 53101c37cc8b..eff2055e8a61 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 @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OneOfEnumString(StrEnum): -class OneOfEnumString(str, Enum): """ oneOf enum strings """ - """ - allowed enum values - """ + # Allowed enum values A = 'a' B = 'b' C = 'c' @@ -36,4 +34,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OneOfEnumString from a JSON string""" return cls(json.loads(json_str)) - 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 f742027e088a..95127b5d93d2 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 @@ -20,8 +20,8 @@ from datetime import datetime from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Order(BaseModel): """ @@ -31,7 +31,10 @@ class Order(BaseModel): pet_id: Optional[StrictInt] = Field(default=None, alias="petId") quantity: Optional[StrictInt] = None ship_date: Optional[datetime] = Field(default=None, alias="shipDate") - status: Optional[StrictStr] = Field(default=None, description="Order Status") + status: Optional[StatusEnum] = Field( + None, + description="Order Status" + ) complete: Optional[StrictBool] = False __properties: ClassVar[List[str]] = ["id", "petId", "quantity", "shipDate", "status", "complete"] @@ -56,53 +59,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Order from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Order from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "petId": obj.get("petId"), - "quantity": obj.get("quantity"), - "shipDate": obj.get("shipDate"), - "status": obj.get("status"), - "complete": obj.get("complete") if obj.get("complete") is not None else False - }) - return _obj 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 6a82d49970cb..92ad3b493d46 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictBool, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class OuterComposite(BaseModel): """ @@ -42,50 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of OuterComposite from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of OuterComposite from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "my_number": obj.get("my_number"), - "my_string": obj.get("my_string"), - "my_boolean": obj.get("my_boolean") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum.py index ac48cc0dc4d8..ee5753ebef43 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnum(StrEnum): -class OuterEnum(str, Enum): """ OuterEnum """ - """ - allowed enum values - """ + # Allowed enum values PLACED = 'placed' APPROVED = 'approved' DELIVERED = 'delivered' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnum from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum_default_value.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum_default_value.py index 99d6fd5fc042..7b013c460e2b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum_default_value.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum_default_value.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnumDefaultValue(StrEnum): -class OuterEnumDefaultValue(str, Enum): """ OuterEnumDefaultValue """ - """ - allowed enum values - """ + # Allowed enum values PLACED = 'placed' APPROVED = 'approved' DELIVERED = 'delivered' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnumDefaultValue from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum_integer.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum_integer.py index b771b7a61f55..03ee644405ed 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum_integer.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum_integer.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnumInteger(IntEnum): -class OuterEnumInteger(int, Enum): """ OuterEnumInteger """ - """ - allowed enum values - """ + # Allowed enum values NUMBER_0 = 0 NUMBER_1 = 1 NUMBER_2 = 2 @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnumInteger from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum_integer_default_value.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum_integer_default_value.py index 8df41b2bd320..55735ba9b13f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum_integer_default_value.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_enum_integer_default_value.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnumIntegerDefaultValue(IntEnum): -class OuterEnumIntegerDefaultValue(int, Enum): """ OuterEnumIntegerDefaultValue """ - """ - allowed enum values - """ + # Allowed enum values NUMBER_MINUS_1 = -1 NUMBER_0 = 0 NUMBER_1 = 1 @@ -36,4 +34,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnumIntegerDefaultValue from a JSON string""" return cls(json.loads(json_str)) - 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 4f453c2a8d0c..b46c7db60925 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 @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.outer_enum import OuterEnum from petstore_api.models.outer_enum_integer import OuterEnumInteger -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class OuterObjectWithEnumProperty(BaseModel): """ @@ -43,54 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of OuterObjectWithEnumProperty from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # set to None if str_value (nullable) is None - # 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of OuterObjectWithEnumProperty from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "str_value": obj.get("str_value"), - "value": obj.get("value") - }) - return _obj 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 5986da45ab04..6dfd21dee63f 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.inner_dict_with_property import InnerDictWithProperty -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Parent(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Parent from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in optional_dict (dict) - _field_dict = {} - if self.optional_dict: - for _key_optional_dict in self.optional_dict: - if self.optional_dict[_key_optional_dict]: - _field_dict[_key_optional_dict] = self.optional_dict[_key_optional_dict].to_dict() - _dict['optionalDict'] = _field_dict - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Parent from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "optionalDict": dict( - (_k, InnerDictWithProperty.from_dict(_v)) - for _k, _v in obj["optionalDict"].items() - ) - if obj.get("optionalDict") is not None - else None - }) - return _obj 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 84445b64043a..2e81abb75704 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.inner_dict_with_property import InnerDictWithProperty -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ParentWithOptionalDict(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ParentWithOptionalDict from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in optional_dict (dict) - _field_dict = {} - if self.optional_dict: - for _key_optional_dict in self.optional_dict: - if self.optional_dict[_key_optional_dict]: - _field_dict[_key_optional_dict] = self.optional_dict[_key_optional_dict].to_dict() - _dict['optionalDict'] = _field_dict - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ParentWithOptionalDict from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "optionalDict": dict( - (_k, InnerDictWithProperty.from_dict(_v)) - for _k, _v in obj["optionalDict"].items() - ) - if obj.get("optionalDict") is not None - else None - }) - return _obj 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 be47c3b1a894..4988087c1e98 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 @@ -22,8 +22,8 @@ from typing_extensions import Annotated from petstore_api.models.category import Category from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Pet(BaseModel): """ @@ -34,7 +34,10 @@ class Pet(BaseModel): name: StrictStr 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") + status: Optional[StatusEnum] = Field( + None, + description="pet status in the store" + ) __properties: ClassVar[List[str]] = ["id", "category", "name", "photoUrls", "tags", "status"] @field_validator('status') @@ -58,63 +61,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Pet from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of category - if self.category: - _dict['category'] = self.category.to_dict() - # override the default output from pydantic by calling `to_dict()` of each item in tags (list) - _items = [] - if self.tags: - for _item_tags in self.tags: - if _item_tags: - _items.append(_item_tags.to_dict()) - _dict['tags'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Pet from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "category": Category.from_dict(obj["category"]) if obj.get("category") is not None else None, - "name": obj.get("name"), - "photoUrls": obj.get("photoUrls"), - "tags": [Tag.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None, - "status": obj.get("status") - }) - return _obj 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 b3a759e89b7b..5daca5745f89 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,122 +19,27 @@ from typing import Any, List, Optional from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self PIG_ONE_OF_SCHEMAS = ["BasquePig", "DanishPig"] -class Pig(BaseModel): +class Pig(RootModel[Union[BasquePig, DanishPig]]): """ Pig """ - # data type: BasquePig - oneof_schema_1_validator: Optional[BasquePig] = None - # data type: DanishPig - oneof_schema_2_validator: Optional[DanishPig] = None - actual_instance: Optional[Union[BasquePig, DanishPig]] = None - one_of_schemas: Set[str] = { "BasquePig", "DanishPig" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[BasquePig, DanishPig] = Field( + ..., discriminator="class_name" ) - - discriminator_value_class_map: Dict[str, str] = { - } - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - instance = Pig.model_construct() - error_messages = [] - match = 0 - # validate data type: BasquePig - if not isinstance(v, BasquePig): - error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`") - else: - match += 1 - # validate data type: DanishPig - if not isinstance(v, DanishPig): - error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`") - else: - match += 1 - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # deserialize data into BasquePig - try: - instance.actual_instance = BasquePig.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into DanishPig - try: - instance.actual_instance = DanishPig.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], BasquePig, DanishPig]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pony_sizes.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pony_sizes.py index 00bd38659577..07fad564629c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pony_sizes.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pony_sizes.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.type import Type -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PonySizes(BaseModel): """ @@ -41,48 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PonySizes from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PonySizes from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "type": obj.get("type") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/poop_cleaning.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/poop_cleaning.py index 047cf0d481a9..c651907e168f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/poop_cleaning.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/poop_cleaning.py @@ -19,15 +19,21 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PoopCleaning(BaseModel): """ PoopCleaning """ # noqa: E501 - task_name: StrictStr - function_name: StrictStr + task_name: Literal['cleaning'] = Field( + ..., + description="task_name of the PoopCleaning" + ) + function_name: Literal['care'] = Field( + ..., + description="function_name of the PoopCleaning" + ) content: StrictStr __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -56,50 +62,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PoopCleaning from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PoopCleaning from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "task_name": obj.get("task_name"), - "function_name": obj.get("function_name"), - "content": obj.get("content") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/primitive_string.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/primitive_string.py index 5a7065597861..47f666784246 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/primitive_string.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/primitive_string.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.base_discriminator import BaseDiscriminator -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PrimitiveString(BaseDiscriminator): """ @@ -41,49 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PrimitiveString from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PrimitiveString from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_typeName": obj.get("_typeName"), - "_value": obj.get("_value") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_map.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_map.py index 940016a86a72..60fe171e2156 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_map.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_map.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PropertyMap(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PropertyMap from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in some_data (dict) - _field_dict = {} - if self.some_data: - for _key_some_data in self.some_data: - if self.some_data[_key_some_data]: - _field_dict[_key_some_data] = self.some_data[_key_some_data].to_dict() - _dict['some_data'] = _field_dict - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PropertyMap from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "some_data": dict( - (_k, Tag.from_dict(_v)) - for _k, _v in obj["some_data"].items() - ) - if obj.get("some_data") is not None - else None - }) - return _obj 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 0eb56422b648..5ed85fc37ac0 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PropertyNameCollision(BaseModel): """ @@ -42,50 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PropertyNameCollision from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PropertyNameCollision from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_type": obj.get("_type"), - "type": obj.get("type"), - "type_": obj.get("type_") - }) - return _obj 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 c9f4fc6c0df9..d6dd229d91cf 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ReadOnlyFirst(BaseModel): """ @@ -41,51 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ReadOnlyFirst from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * OpenAPI `readOnly` fields are excluded. - """ - excluded_fields: Set[str] = set([ - "bar", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ReadOnlyFirst from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "bar": obj.get("bar"), - "baz": obj.get("baz") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_circular_all_of_ref.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_circular_all_of_ref.py index 854749b4fb13..b4959634120d 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_circular_all_of_ref.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_circular_all_of_ref.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SecondCircularAllOfRef(BaseModel): """ @@ -41,57 +41,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SecondCircularAllOfRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in circular_all_of_ref (list) - _items = [] - if self.circular_all_of_ref: - for _item_circular_all_of_ref in self.circular_all_of_ref: - if _item_circular_all_of_ref: - _items.append(_item_circular_all_of_ref.to_dict()) - _dict['circularAllOfRef'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SecondCircularAllOfRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_name": obj.get("_name"), - "circularAllOfRef": [CircularAllOfRef.from_dict(_item) for _item in obj["circularAllOfRef"]] if obj.get("circularAllOfRef") is not None else None - }) - return _obj from petstore_api.models.circular_all_of_ref import CircularAllOfRef # TODO: Rewrite to not use raise_errors 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 c6627cf0ba63..01a112e0d179 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SecondRef(BaseModel): """ @@ -41,53 +41,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SecondRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of circular_ref - if self.circular_ref: - _dict['circular_ref'] = self.circular_ref.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SecondRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "category": obj.get("category"), - "circular_ref": CircularReferenceModel.from_dict(obj["circular_ref"]) if obj.get("circular_ref") is not None else None - }) - return _obj from petstore_api.models.circular_reference_model import CircularReferenceModel # TODO: Rewrite to not use raise_errors 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 7c145db0d3ae..9810032e9801 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SelfReferenceModel(BaseModel): """ @@ -41,53 +41,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SelfReferenceModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of nested - if self.nested: - _dict['nested'] = self.nested.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SelfReferenceModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "nested": DummyModel.from_dict(obj["nested"]) if obj.get("nested") is not None else None - }) - return _obj from petstore_api.models.dummy_model import DummyModel # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/single_ref_type.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/single_ref_type.py index 91ab07e2535c..32b33b2271fe 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/single_ref_type.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/single_ref_type.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class SingleRefType(StrEnum): -class SingleRefType(str, Enum): """ SingleRefType """ - """ - allowed enum values - """ + # Allowed enum values ADMIN = 'admin' USER = 'user' @@ -34,4 +32,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of SingleRefType from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_character_enum.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_character_enum.py index 1d85fd148d4b..bf8d0a25df90 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_character_enum.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_character_enum.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class SpecialCharacterEnum(StrEnum): -class SpecialCharacterEnum(str, Enum): """ SpecialCharacterEnum """ - """ - allowed enum values - """ + # Allowed enum values ENUM_456 = '456' ENUM_123ABC = '123abc' UNDERSCORE = '_' @@ -42,4 +40,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of SpecialCharacterEnum from a JSON string""" return cls(json.loads(json_str)) - 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 0336e24d17da..945d996f5c15 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SpecialModelName(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SpecialModelName from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SpecialModelName from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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 d3c8f6185683..b9022dde3cbf 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.category import Category -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SpecialName(BaseModel): """ @@ -29,7 +29,10 @@ class SpecialName(BaseModel): """ # noqa: E501 var_property: Optional[StrictInt] = Field(default=None, alias="property") var_async: Optional[Category] = Field(default=None, alias="async") - var_schema: Optional[StrictStr] = Field(default=None, description="pet status in the store", alias="schema") + var_schema: Optional[Var_schemaEnum] = Field( + None, + description="pet status in the store" + ) __properties: ClassVar[List[str]] = ["property", "async", "schema"] @field_validator('var_schema') @@ -53,53 +56,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SpecialName from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of var_async - if self.var_async: - _dict['async'] = self.var_async.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SpecialName from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "property": obj.get("property"), - "async": Category.from_dict(obj["async"]) if obj.get("async") is not None else None, - "schema": obj.get("schema") - }) - return _obj 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 e5ddcbcd4a74..0c7f9d698ace 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Tag(BaseModel): """ @@ -41,49 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Tag from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Tag from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/task.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/task.py index 312b2c8ee473..c8864c78e282 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/task.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/task.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List from uuid import UUID from petstore_api.models.task_activity import TaskActivity -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Task(BaseModel): """ @@ -43,52 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Task from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of activity - if self.activity: - _dict['activity'] = self.activity.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Task from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "activity": TaskActivity.from_dict(obj["activity"]) if obj.get("activity") is not None else None - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/task_activity.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/task_activity.py index cc1e1fc5a60f..d7b8b1e71af3 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/task_activity.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/task_activity.py @@ -20,132 +20,27 @@ from petstore_api.models.bathing import Bathing from petstore_api.models.feeding import Feeding from petstore_api.models.poop_cleaning import PoopCleaning -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self TASKACTIVITY_ONE_OF_SCHEMAS = ["Bathing", "Feeding", "PoopCleaning"] -class TaskActivity(BaseModel): +class TaskActivity(RootModel[Union[Bathing, Feeding, PoopCleaning]]): """ TaskActivity """ - # data type: PoopCleaning - oneof_schema_1_validator: Optional[PoopCleaning] = None - # data type: Feeding - oneof_schema_2_validator: Optional[Feeding] = None - # data type: Bathing - oneof_schema_3_validator: Optional[Bathing] = None - actual_instance: Optional[Union[Bathing, Feeding, PoopCleaning]] = None - one_of_schemas: Set[str] = { "Bathing", "Feeding", "PoopCleaning" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[Bathing, Feeding, PoopCleaning] = Field( + ... ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - instance = TaskActivity.model_construct() - error_messages = [] - match = 0 - # validate data type: PoopCleaning - if not isinstance(v, PoopCleaning): - error_messages.append(f"Error! Input type `{type(v)}` is not `PoopCleaning`") - else: - match += 1 - # validate data type: Feeding - if not isinstance(v, Feeding): - error_messages.append(f"Error! Input type `{type(v)}` is not `Feeding`") - else: - match += 1 - # validate data type: Bathing - if not isinstance(v, Bathing): - error_messages.append(f"Error! Input type `{type(v)}` is not `Bathing`") - else: - match += 1 - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # deserialize data into PoopCleaning - try: - instance.actual_instance = PoopCleaning.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into Feeding - try: - instance.actual_instance = Feeding.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into Bathing - try: - instance.actual_instance = Bathing.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], Bathing, Feeding, PoopCleaning]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum.py index 8eae227a84e9..331f0fd597bd 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class TestEnum(StrEnum): -class TestEnum(str, Enum): """ TestEnum """ - """ - allowed enum values - """ + # Allowed enum values ONE = 'ONE' TWO = 'TWO' THREE = 'THREE' @@ -36,4 +34,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of TestEnum from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum_with_default.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum_with_default.py index 9304d3ab8497..0f3d74610b96 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum_with_default.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum_with_default.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class TestEnumWithDefault(StrEnum): -class TestEnumWithDefault(str, Enum): """ TestEnumWithDefault """ - """ - allowed enum values - """ + # Allowed enum values EIN = 'EIN' ZWEI = 'ZWEI' DREI = 'DREI' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of TestEnumWithDefault from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_error_responses_with_model400_response.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_error_responses_with_model400_response.py index cba4ab845e5e..15bb872e0575 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_error_responses_with_model400_response.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_error_responses_with_model400_response.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestErrorResponsesWithModel400Response(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel400Response from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel400Response from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "reason400": obj.get("reason400") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_error_responses_with_model404_response.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_error_responses_with_model404_response.py index 787ca11942ab..a124d7230c5d 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_error_responses_with_model404_response.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_error_responses_with_model404_response.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestErrorResponsesWithModel404Response(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel404Response from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel404Response from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "reason404": obj.get("reason404") - }) - return _obj 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 7b93d84864f2..ef3e742d900f 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestInlineFreeformAdditionalPropertiesRequest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestInlineFreeformAdditionalPropertiesRequest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "someProperty": obj.get("someProperty") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_model_with_enum_default.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_model_with_enum_default.py index 218fa8f16d22..ac8b4f6c0cdd 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_model_with_enum_default.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_model_with_enum_default.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.test_enum import TestEnum from petstore_api.models.test_enum_with_default import TestEnumWithDefault -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestModelWithEnumDefault(BaseModel): """ @@ -32,7 +32,10 @@ class TestModelWithEnumDefault(BaseModel): test_string: Optional[StrictStr] = None test_enum_with_default: Optional[TestEnumWithDefault] = TestEnumWithDefault.ZWEI test_string_with_default: Optional[StrictStr] = 'ahoy matey' - test_inline_defined_enum_with_default: Optional[StrictStr] = 'B' + test_inline_defined_enum_with_default: Optional[Test_inline_defined_enum_with_defaultEnum] = Field( + None, + description="test_inline_defined_enum_with_default of the TestModelWithEnumDefault" + ) __properties: ClassVar[List[str]] = ["test_enum", "test_string", "test_enum_with_default", "test_string_with_default", "test_inline_defined_enum_with_default"] @field_validator('test_inline_defined_enum_with_default') @@ -56,52 +59,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestModelWithEnumDefault from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestModelWithEnumDefault from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "test_enum": obj.get("test_enum"), - "test_string": obj.get("test_string"), - "test_enum_with_default": obj.get("test_enum_with_default") if obj.get("test_enum_with_default") is not None else TestEnumWithDefault.ZWEI, - "test_string_with_default": obj.get("test_string_with_default") if obj.get("test_string_with_default") is not None else 'ahoy matey', - "test_inline_defined_enum_with_default": obj.get("test_inline_defined_enum_with_default") if obj.get("test_inline_defined_enum_with_default") is not None else 'B' - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_object_for_multipart_requests_request_marker.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_object_for_multipart_requests_request_marker.py index a5c3bfdbb1b5..4d2abed68fea 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_object_for_multipart_requests_request_marker.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_object_for_multipart_requests_request_marker.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestObjectForMultipartRequestsRequestMarker(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestObjectForMultipartRequestsRequestMarker from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestObjectForMultipartRequestsRequestMarker from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - return _obj 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 bf8cbf0596ae..60baf0a7da5e 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Tiger(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Tiger from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Tiger from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "skill": obj.get("skill") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/type.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/type.py index 35a847de894f..3ab767b6125b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/type.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/type.py @@ -14,18 +14,17 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self -class Type(int, Enum): +class Type(Enum): + """ Type """ - """ - allowed enum values - """ + # Allowed enum values NUMBER_2_DOT_0 = 2.0 NUMBER_1_DOT_0 = 1.0 NUMBER_0_DOT_5 = 0.5 @@ -36,4 +35,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of Type from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py index e50edf2efa85..65dd088726a3 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.creature_info import CreatureInfo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class UnnamedDictWithAdditionalModelListProperties(BaseModel): """ @@ -41,64 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalModelListProperties from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in dict_property (dict of array) - _field_dict_of_array = {} - if self.dict_property: - for _key_dict_property in self.dict_property: - if self.dict_property[_key_dict_property] is not None: - _field_dict_of_array[_key_dict_property] = [ - _item.to_dict() for _item in self.dict_property[_key_dict_property] - ] - _dict['dictProperty'] = _field_dict_of_array - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalModelListProperties from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "dictProperty": dict( - (_k, - [CreatureInfo.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("dictProperty", {}).items() - ) - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py index 477dcae27c7c..8cb9fb502b34 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class UnnamedDictWithAdditionalStringListProperties(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalStringListProperties from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalStringListProperties from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "dictProperty": obj.get("dictProperty") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/upload_file_with_additional_properties_request_object.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/upload_file_with_additional_properties_request_object.py index 9040618ac0d7..935ac02add3a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/upload_file_with_additional_properties_request_object.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/upload_file_with_additional_properties_request_object.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class UploadFileWithAdditionalPropertiesRequestObject(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of UploadFileWithAdditionalPropertiesRequestObject from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of UploadFileWithAdditionalPropertiesRequestObject from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - 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 45e0a66f89dd..833099b0f43b 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class User(BaseModel): """ @@ -47,55 +47,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of User from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of User from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "username": obj.get("username"), - "firstName": obj.get("firstName"), - "lastName": obj.get("lastName"), - "email": obj.get("email"), - "password": obj.get("password"), - "phone": obj.get("phone"), - "userStatus": obj.get("userStatus") - }) - return _obj 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 f2cd8b7a3a30..37e9ab665d40 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 @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.one_of_enum_string import OneOfEnumString from petstore_api.models.pig import Pig -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class WithNestedOneOf(BaseModel): """ @@ -44,53 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of WithNestedOneOf from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of nested_pig - if self.nested_pig: - _dict['nested_pig'] = self.nested_pig.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of WithNestedOneOf from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "nested_pig": Pig.from_dict(obj["nested_pig"]) if obj.get("nested_pig") is not None else None, - "nested_oneof_enum_string": obj.get("nested_oneof_enum_string") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/pyproject.toml b/samples/openapi3/client/petstore/python-aiohttp/pyproject.toml index 8e03a6c82feb..767476a884d0 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/pyproject.toml +++ b/samples/openapi3/client/petstore/python-aiohttp/pyproject.toml @@ -10,7 +10,8 @@ keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"] include = ["petstore_api/py.typed"] [tool.poetry.dependencies] -python = "^3.9" +python = "^3.11" +urllib3 = ">= 2.1.0, < 3.0.0" python-dateutil = ">= 2.8.2" aiohttp = ">= 3.8.4" aiohttp-retry = ">= 2.8.3" diff --git a/samples/openapi3/client/petstore/python-aiohttp/setup.py b/samples/openapi3/client/petstore/python-aiohttp/setup.py index 93a557bdcaa9..986bb4a5b3af 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/setup.py +++ b/samples/openapi3/client/petstore/python-aiohttp/setup.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """ OpenAPI Petstore @@ -12,6 +10,7 @@ """ # noqa: E501 + from setuptools import setup, find_packages # noqa: H301 # To install the library, run the following @@ -22,8 +21,9 @@ # http://pypi.python.org/pypi/setuptools NAME = "petstore-api" VERSION = "1.0.0" -PYTHON_REQUIRES = ">= 3.9" +PYTHON_REQUIRES = ">= 3.11" REQUIRES = [ + "urllib3 >= 2.1.0, < 3.0.0", "python-dateutil >= 2.8.2", "aiohttp >= 3.8.4", "aiohttp-retry >= 2.8.3", diff --git a/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesAnyType.md b/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesAnyType.md index 314cba3a614c..6491c95beba5 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesAnyType.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesAnyType.md @@ -15,14 +15,14 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesAnyType from a JSON string -additional_properties_any_type_instance = AdditionalPropertiesAnyType.from_json(json) +additional_properties_any_type_instance = AdditionalPropertiesAnyType.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesAnyType.to_json()) +print(AdditionalPropertiesAnyType.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_any_type_dict = additional_properties_any_type_instance.to_dict() +additional_properties_any_type_dict = additional_properties_any_type_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesAnyType from a dict -additional_properties_any_type_from_dict = AdditionalPropertiesAnyType.from_dict(additional_properties_any_type_dict) +additional_properties_any_type_from_dict = AdditionalPropertiesAnyType.model_validate(additional_properties_any_type_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesClass.md b/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesClass.md index 8d4c08707f55..2a618964bc5c 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesClass.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesClass.md @@ -16,14 +16,14 @@ from petstore_api.models.additional_properties_class import AdditionalProperties # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesClass from a JSON string -additional_properties_class_instance = AdditionalPropertiesClass.from_json(json) +additional_properties_class_instance = AdditionalPropertiesClass.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesClass.to_json()) +print(AdditionalPropertiesClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_class_dict = additional_properties_class_instance.to_dict() +additional_properties_class_dict = additional_properties_class_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesClass from a dict -additional_properties_class_from_dict = AdditionalPropertiesClass.from_dict(additional_properties_class_dict) +additional_properties_class_from_dict = AdditionalPropertiesClass.model_validate(additional_properties_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesObject.md b/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesObject.md index d647ec64896f..1c66f8e5d29a 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesObject.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesObject.md @@ -15,14 +15,14 @@ from petstore_api.models.additional_properties_object import AdditionalPropertie # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesObject from a JSON string -additional_properties_object_instance = AdditionalPropertiesObject.from_json(json) +additional_properties_object_instance = AdditionalPropertiesObject.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesObject.to_json()) +print(AdditionalPropertiesObject.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_object_dict = additional_properties_object_instance.to_dict() +additional_properties_object_dict = additional_properties_object_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesObject from a dict -additional_properties_object_from_dict = AdditionalPropertiesObject.from_dict(additional_properties_object_dict) +additional_properties_object_from_dict = AdditionalPropertiesObject.model_validate(additional_properties_object_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesWithDescriptionOnly.md b/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesWithDescriptionOnly.md index 061f5524872b..88d66f028a2b 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesWithDescriptionOnly.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesWithDescriptionOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.additional_properties_with_description_only import Addi # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesWithDescriptionOnly from a JSON string -additional_properties_with_description_only_instance = AdditionalPropertiesWithDescriptionOnly.from_json(json) +additional_properties_with_description_only_instance = AdditionalPropertiesWithDescriptionOnly.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesWithDescriptionOnly.to_json()) +print(AdditionalPropertiesWithDescriptionOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_with_description_only_dict = additional_properties_with_description_only_instance.to_dict() +additional_properties_with_description_only_dict = additional_properties_with_description_only_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesWithDescriptionOnly from a dict -additional_properties_with_description_only_from_dict = AdditionalPropertiesWithDescriptionOnly.from_dict(additional_properties_with_description_only_dict) +additional_properties_with_description_only_from_dict = AdditionalPropertiesWithDescriptionOnly.model_validate(additional_properties_with_description_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/AllOfSuperModel.md b/samples/openapi3/client/petstore/python-httpx/docs/AllOfSuperModel.md index 421a1527f1ef..bec62554ebf0 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/AllOfSuperModel.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/AllOfSuperModel.md @@ -15,14 +15,14 @@ from petstore_api.models.all_of_super_model import AllOfSuperModel # TODO update the JSON string below json = "{}" # create an instance of AllOfSuperModel from a JSON string -all_of_super_model_instance = AllOfSuperModel.from_json(json) +all_of_super_model_instance = AllOfSuperModel.model_validate_json(json) # print the JSON string representation of the object -print(AllOfSuperModel.to_json()) +print(AllOfSuperModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -all_of_super_model_dict = all_of_super_model_instance.to_dict() +all_of_super_model_dict = all_of_super_model_instance.model_dump(by_alias=True) # create an instance of AllOfSuperModel from a dict -all_of_super_model_from_dict = AllOfSuperModel.from_dict(all_of_super_model_dict) +all_of_super_model_from_dict = AllOfSuperModel.model_validate(all_of_super_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/AllOfWithSingleRef.md b/samples/openapi3/client/petstore/python-httpx/docs/AllOfWithSingleRef.md index 203a4b5da3d5..05ae8a658ab3 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/AllOfWithSingleRef.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/AllOfWithSingleRef.md @@ -16,14 +16,14 @@ from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef # TODO update the JSON string below json = "{}" # create an instance of AllOfWithSingleRef from a JSON string -all_of_with_single_ref_instance = AllOfWithSingleRef.from_json(json) +all_of_with_single_ref_instance = AllOfWithSingleRef.model_validate_json(json) # print the JSON string representation of the object -print(AllOfWithSingleRef.to_json()) +print(AllOfWithSingleRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -all_of_with_single_ref_dict = all_of_with_single_ref_instance.to_dict() +all_of_with_single_ref_dict = all_of_with_single_ref_instance.model_dump(by_alias=True) # create an instance of AllOfWithSingleRef from a dict -all_of_with_single_ref_from_dict = AllOfWithSingleRef.from_dict(all_of_with_single_ref_dict) +all_of_with_single_ref_from_dict = AllOfWithSingleRef.model_validate(all_of_with_single_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Animal.md b/samples/openapi3/client/petstore/python-httpx/docs/Animal.md index 381d27b66e44..eb20439f3782 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Animal.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Animal.md @@ -16,14 +16,14 @@ from petstore_api.models.animal import Animal # TODO update the JSON string below json = "{}" # create an instance of Animal from a JSON string -animal_instance = Animal.from_json(json) +animal_instance = Animal.model_validate_json(json) # print the JSON string representation of the object -print(Animal.to_json()) +print(Animal.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -animal_dict = animal_instance.to_dict() +animal_dict = animal_instance.model_dump(by_alias=True) # create an instance of Animal from a dict -animal_from_dict = Animal.from_dict(animal_dict) +animal_from_dict = Animal.model_validate(animal_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/AnyOfColor.md b/samples/openapi3/client/petstore/python-httpx/docs/AnyOfColor.md index 6ed75dd7b48a..c656fdbbae05 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/AnyOfColor.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/AnyOfColor.md @@ -15,14 +15,14 @@ from petstore_api.models.any_of_color import AnyOfColor # TODO update the JSON string below json = "{}" # create an instance of AnyOfColor from a JSON string -any_of_color_instance = AnyOfColor.from_json(json) +any_of_color_instance = AnyOfColor.model_validate_json(json) # print the JSON string representation of the object -print(AnyOfColor.to_json()) +print(AnyOfColor.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -any_of_color_dict = any_of_color_instance.to_dict() +any_of_color_dict = any_of_color_instance.model_dump(by_alias=True) # create an instance of AnyOfColor from a dict -any_of_color_from_dict = AnyOfColor.from_dict(any_of_color_dict) +any_of_color_from_dict = AnyOfColor.model_validate(any_of_color_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/AnyOfPig.md b/samples/openapi3/client/petstore/python-httpx/docs/AnyOfPig.md index 9367e2261898..0c273f175319 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/AnyOfPig.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/AnyOfPig.md @@ -17,14 +17,14 @@ from petstore_api.models.any_of_pig import AnyOfPig # TODO update the JSON string below json = "{}" # create an instance of AnyOfPig from a JSON string -any_of_pig_instance = AnyOfPig.from_json(json) +any_of_pig_instance = AnyOfPig.model_validate_json(json) # print the JSON string representation of the object -print(AnyOfPig.to_json()) +print(AnyOfPig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -any_of_pig_dict = any_of_pig_instance.to_dict() +any_of_pig_dict = any_of_pig_instance.model_dump(by_alias=True) # create an instance of AnyOfPig from a dict -any_of_pig_from_dict = AnyOfPig.from_dict(any_of_pig_dict) +any_of_pig_from_dict = AnyOfPig.model_validate(any_of_pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/ArrayOfArrayOfModel.md b/samples/openapi3/client/petstore/python-httpx/docs/ArrayOfArrayOfModel.md index f866863d53f9..83505f6eb05b 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/ArrayOfArrayOfModel.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/ArrayOfArrayOfModel.md @@ -15,14 +15,14 @@ from petstore_api.models.array_of_array_of_model import ArrayOfArrayOfModel # TODO update the JSON string below json = "{}" # create an instance of ArrayOfArrayOfModel from a JSON string -array_of_array_of_model_instance = ArrayOfArrayOfModel.from_json(json) +array_of_array_of_model_instance = ArrayOfArrayOfModel.model_validate_json(json) # print the JSON string representation of the object -print(ArrayOfArrayOfModel.to_json()) +print(ArrayOfArrayOfModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_of_array_of_model_dict = array_of_array_of_model_instance.to_dict() +array_of_array_of_model_dict = array_of_array_of_model_instance.model_dump(by_alias=True) # create an instance of ArrayOfArrayOfModel from a dict -array_of_array_of_model_from_dict = ArrayOfArrayOfModel.from_dict(array_of_array_of_model_dict) +array_of_array_of_model_from_dict = ArrayOfArrayOfModel.model_validate(array_of_array_of_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/ArrayOfArrayOfNumberOnly.md b/samples/openapi3/client/petstore/python-httpx/docs/ArrayOfArrayOfNumberOnly.md index 32bd2dfbf1e2..0027448edc27 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/ArrayOfArrayOfNumberOnly.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/ArrayOfArrayOfNumberOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumb # TODO update the JSON string below json = "{}" # create an instance of ArrayOfArrayOfNumberOnly from a JSON string -array_of_array_of_number_only_instance = ArrayOfArrayOfNumberOnly.from_json(json) +array_of_array_of_number_only_instance = ArrayOfArrayOfNumberOnly.model_validate_json(json) # print the JSON string representation of the object -print(ArrayOfArrayOfNumberOnly.to_json()) +print(ArrayOfArrayOfNumberOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_of_array_of_number_only_dict = array_of_array_of_number_only_instance.to_dict() +array_of_array_of_number_only_dict = array_of_array_of_number_only_instance.model_dump(by_alias=True) # create an instance of ArrayOfArrayOfNumberOnly from a dict -array_of_array_of_number_only_from_dict = ArrayOfArrayOfNumberOnly.from_dict(array_of_array_of_number_only_dict) +array_of_array_of_number_only_from_dict = ArrayOfArrayOfNumberOnly.model_validate(array_of_array_of_number_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/ArrayOfNumberOnly.md b/samples/openapi3/client/petstore/python-httpx/docs/ArrayOfNumberOnly.md index b814d7594942..81aeee6c1add 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/ArrayOfNumberOnly.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/ArrayOfNumberOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.array_of_number_only import ArrayOfNumberOnly # TODO update the JSON string below json = "{}" # create an instance of ArrayOfNumberOnly from a JSON string -array_of_number_only_instance = ArrayOfNumberOnly.from_json(json) +array_of_number_only_instance = ArrayOfNumberOnly.model_validate_json(json) # print the JSON string representation of the object -print(ArrayOfNumberOnly.to_json()) +print(ArrayOfNumberOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_of_number_only_dict = array_of_number_only_instance.to_dict() +array_of_number_only_dict = array_of_number_only_instance.model_dump(by_alias=True) # create an instance of ArrayOfNumberOnly from a dict -array_of_number_only_from_dict = ArrayOfNumberOnly.from_dict(array_of_number_only_dict) +array_of_number_only_from_dict = ArrayOfNumberOnly.model_validate(array_of_number_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/ArrayTest.md b/samples/openapi3/client/petstore/python-httpx/docs/ArrayTest.md index ed871fae662d..62b868a02c64 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/ArrayTest.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/ArrayTest.md @@ -18,14 +18,14 @@ from petstore_api.models.array_test import ArrayTest # TODO update the JSON string below json = "{}" # create an instance of ArrayTest from a JSON string -array_test_instance = ArrayTest.from_json(json) +array_test_instance = ArrayTest.model_validate_json(json) # print the JSON string representation of the object -print(ArrayTest.to_json()) +print(ArrayTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_test_dict = array_test_instance.to_dict() +array_test_dict = array_test_instance.model_dump(by_alias=True) # create an instance of ArrayTest from a dict -array_test_from_dict = ArrayTest.from_dict(array_test_dict) +array_test_from_dict = ArrayTest.model_validate(array_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/BaseDiscriminator.md b/samples/openapi3/client/petstore/python-httpx/docs/BaseDiscriminator.md index fcdbeb032e68..a317fc0421fe 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/BaseDiscriminator.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/BaseDiscriminator.md @@ -15,14 +15,14 @@ from petstore_api.models.base_discriminator import BaseDiscriminator # TODO update the JSON string below json = "{}" # create an instance of BaseDiscriminator from a JSON string -base_discriminator_instance = BaseDiscriminator.from_json(json) +base_discriminator_instance = BaseDiscriminator.model_validate_json(json) # print the JSON string representation of the object -print(BaseDiscriminator.to_json()) +print(BaseDiscriminator.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -base_discriminator_dict = base_discriminator_instance.to_dict() +base_discriminator_dict = base_discriminator_instance.model_dump(by_alias=True) # create an instance of BaseDiscriminator from a dict -base_discriminator_from_dict = BaseDiscriminator.from_dict(base_discriminator_dict) +base_discriminator_from_dict = BaseDiscriminator.model_validate(base_discriminator_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/BasquePig.md b/samples/openapi3/client/petstore/python-httpx/docs/BasquePig.md index ee28d628722f..8af258aa7901 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/BasquePig.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/BasquePig.md @@ -16,14 +16,14 @@ from petstore_api.models.basque_pig import BasquePig # TODO update the JSON string below json = "{}" # create an instance of BasquePig from a JSON string -basque_pig_instance = BasquePig.from_json(json) +basque_pig_instance = BasquePig.model_validate_json(json) # print the JSON string representation of the object -print(BasquePig.to_json()) +print(BasquePig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -basque_pig_dict = basque_pig_instance.to_dict() +basque_pig_dict = basque_pig_instance.model_dump(by_alias=True) # create an instance of BasquePig from a dict -basque_pig_from_dict = BasquePig.from_dict(basque_pig_dict) +basque_pig_from_dict = BasquePig.model_validate(basque_pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Bathing.md b/samples/openapi3/client/petstore/python-httpx/docs/Bathing.md index 6ad70e2f67cc..5365c9614d17 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Bathing.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Bathing.md @@ -17,14 +17,14 @@ from petstore_api.models.bathing import Bathing # TODO update the JSON string below json = "{}" # create an instance of Bathing from a JSON string -bathing_instance = Bathing.from_json(json) +bathing_instance = Bathing.model_validate_json(json) # print the JSON string representation of the object -print(Bathing.to_json()) +print(Bathing.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -bathing_dict = bathing_instance.to_dict() +bathing_dict = bathing_instance.model_dump(by_alias=True) # create an instance of Bathing from a dict -bathing_from_dict = Bathing.from_dict(bathing_dict) +bathing_from_dict = Bathing.model_validate(bathing_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Capitalization.md b/samples/openapi3/client/petstore/python-httpx/docs/Capitalization.md index 6f564a8ed8c9..efbf7520b692 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Capitalization.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Capitalization.md @@ -20,14 +20,14 @@ from petstore_api.models.capitalization import Capitalization # TODO update the JSON string below json = "{}" # create an instance of Capitalization from a JSON string -capitalization_instance = Capitalization.from_json(json) +capitalization_instance = Capitalization.model_validate_json(json) # print the JSON string representation of the object -print(Capitalization.to_json()) +print(Capitalization.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -capitalization_dict = capitalization_instance.to_dict() +capitalization_dict = capitalization_instance.model_dump(by_alias=True) # create an instance of Capitalization from a dict -capitalization_from_dict = Capitalization.from_dict(capitalization_dict) +capitalization_from_dict = Capitalization.model_validate(capitalization_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Cat.md b/samples/openapi3/client/petstore/python-httpx/docs/Cat.md index d0e39efdb33e..2940176bb9b8 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Cat.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Cat.md @@ -15,14 +15,14 @@ from petstore_api.models.cat import Cat # TODO update the JSON string below json = "{}" # create an instance of Cat from a JSON string -cat_instance = Cat.from_json(json) +cat_instance = Cat.model_validate_json(json) # print the JSON string representation of the object -print(Cat.to_json()) +print(Cat.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -cat_dict = cat_instance.to_dict() +cat_dict = cat_instance.model_dump(by_alias=True) # create an instance of Cat from a dict -cat_from_dict = Cat.from_dict(cat_dict) +cat_from_dict = Cat.model_validate(cat_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Category.md b/samples/openapi3/client/petstore/python-httpx/docs/Category.md index dbde14b7344c..a1509b71308f 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Category.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Category.md @@ -16,14 +16,14 @@ from petstore_api.models.category import Category # TODO update the JSON string below json = "{}" # create an instance of Category from a JSON string -category_instance = Category.from_json(json) +category_instance = Category.model_validate_json(json) # print the JSON string representation of the object -print(Category.to_json()) +print(Category.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -category_dict = category_instance.to_dict() +category_dict = category_instance.model_dump(by_alias=True) # create an instance of Category from a dict -category_from_dict = Category.from_dict(category_dict) +category_from_dict = Category.model_validate(category_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/CircularAllOfRef.md b/samples/openapi3/client/petstore/python-httpx/docs/CircularAllOfRef.md index 65b171177e58..aaab0079b3f4 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/CircularAllOfRef.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/CircularAllOfRef.md @@ -16,14 +16,14 @@ from petstore_api.models.circular_all_of_ref import CircularAllOfRef # TODO update the JSON string below json = "{}" # create an instance of CircularAllOfRef from a JSON string -circular_all_of_ref_instance = CircularAllOfRef.from_json(json) +circular_all_of_ref_instance = CircularAllOfRef.model_validate_json(json) # print the JSON string representation of the object -print(CircularAllOfRef.to_json()) +print(CircularAllOfRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -circular_all_of_ref_dict = circular_all_of_ref_instance.to_dict() +circular_all_of_ref_dict = circular_all_of_ref_instance.model_dump(by_alias=True) # create an instance of CircularAllOfRef from a dict -circular_all_of_ref_from_dict = CircularAllOfRef.from_dict(circular_all_of_ref_dict) +circular_all_of_ref_from_dict = CircularAllOfRef.model_validate(circular_all_of_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/CircularReferenceModel.md b/samples/openapi3/client/petstore/python-httpx/docs/CircularReferenceModel.md index 87216f7273ab..33ec5e9b09bf 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/CircularReferenceModel.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/CircularReferenceModel.md @@ -16,14 +16,14 @@ from petstore_api.models.circular_reference_model import CircularReferenceModel # TODO update the JSON string below json = "{}" # create an instance of CircularReferenceModel from a JSON string -circular_reference_model_instance = CircularReferenceModel.from_json(json) +circular_reference_model_instance = CircularReferenceModel.model_validate_json(json) # print the JSON string representation of the object -print(CircularReferenceModel.to_json()) +print(CircularReferenceModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -circular_reference_model_dict = circular_reference_model_instance.to_dict() +circular_reference_model_dict = circular_reference_model_instance.model_dump(by_alias=True) # create an instance of CircularReferenceModel from a dict -circular_reference_model_from_dict = CircularReferenceModel.from_dict(circular_reference_model_dict) +circular_reference_model_from_dict = CircularReferenceModel.model_validate(circular_reference_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/ClassModel.md b/samples/openapi3/client/petstore/python-httpx/docs/ClassModel.md index ea76a5c157bf..9e69a69b5c27 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/ClassModel.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/ClassModel.md @@ -16,14 +16,14 @@ from petstore_api.models.class_model import ClassModel # TODO update the JSON string below json = "{}" # create an instance of ClassModel from a JSON string -class_model_instance = ClassModel.from_json(json) +class_model_instance = ClassModel.model_validate_json(json) # print the JSON string representation of the object -print(ClassModel.to_json()) +print(ClassModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -class_model_dict = class_model_instance.to_dict() +class_model_dict = class_model_instance.model_dump(by_alias=True) # create an instance of ClassModel from a dict -class_model_from_dict = ClassModel.from_dict(class_model_dict) +class_model_from_dict = ClassModel.model_validate(class_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Client.md b/samples/openapi3/client/petstore/python-httpx/docs/Client.md index 22321c189150..6a9b3d800434 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Client.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Client.md @@ -15,14 +15,14 @@ from petstore_api.models.client import Client # TODO update the JSON string below json = "{}" # create an instance of Client from a JSON string -client_instance = Client.from_json(json) +client_instance = Client.model_validate_json(json) # print the JSON string representation of the object -print(Client.to_json()) +print(Client.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -client_dict = client_instance.to_dict() +client_dict = client_instance.model_dump(by_alias=True) # create an instance of Client from a dict -client_from_dict = Client.from_dict(client_dict) +client_from_dict = Client.model_validate(client_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Color.md b/samples/openapi3/client/petstore/python-httpx/docs/Color.md index 9ac3ab2e91f4..088998e89af9 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Color.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Color.md @@ -15,14 +15,14 @@ from petstore_api.models.color import Color # TODO update the JSON string below json = "{}" # create an instance of Color from a JSON string -color_instance = Color.from_json(json) +color_instance = Color.model_validate_json(json) # print the JSON string representation of the object -print(Color.to_json()) +print(Color.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -color_dict = color_instance.to_dict() +color_dict = color_instance.model_dump(by_alias=True) # create an instance of Color from a dict -color_from_dict = Color.from_dict(color_dict) +color_from_dict = Color.model_validate(color_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Creature.md b/samples/openapi3/client/petstore/python-httpx/docs/Creature.md index a4710214c198..bc746b2856e9 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Creature.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Creature.md @@ -16,14 +16,14 @@ from petstore_api.models.creature import Creature # TODO update the JSON string below json = "{}" # create an instance of Creature from a JSON string -creature_instance = Creature.from_json(json) +creature_instance = Creature.model_validate_json(json) # print the JSON string representation of the object -print(Creature.to_json()) +print(Creature.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -creature_dict = creature_instance.to_dict() +creature_dict = creature_instance.model_dump(by_alias=True) # create an instance of Creature from a dict -creature_from_dict = Creature.from_dict(creature_dict) +creature_from_dict = Creature.model_validate(creature_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/CreatureInfo.md b/samples/openapi3/client/petstore/python-httpx/docs/CreatureInfo.md index db3b82bb9ff5..a355b9e52802 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/CreatureInfo.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/CreatureInfo.md @@ -15,14 +15,14 @@ from petstore_api.models.creature_info import CreatureInfo # TODO update the JSON string below json = "{}" # create an instance of CreatureInfo from a JSON string -creature_info_instance = CreatureInfo.from_json(json) +creature_info_instance = CreatureInfo.model_validate_json(json) # print the JSON string representation of the object -print(CreatureInfo.to_json()) +print(CreatureInfo.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -creature_info_dict = creature_info_instance.to_dict() +creature_info_dict = creature_info_instance.model_dump(by_alias=True) # create an instance of CreatureInfo from a dict -creature_info_from_dict = CreatureInfo.from_dict(creature_info_dict) +creature_info_from_dict = CreatureInfo.model_validate(creature_info_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/DanishPig.md b/samples/openapi3/client/petstore/python-httpx/docs/DanishPig.md index 16941388832a..58902d70f7bd 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/DanishPig.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/DanishPig.md @@ -16,14 +16,14 @@ from petstore_api.models.danish_pig import DanishPig # TODO update the JSON string below json = "{}" # create an instance of DanishPig from a JSON string -danish_pig_instance = DanishPig.from_json(json) +danish_pig_instance = DanishPig.model_validate_json(json) # print the JSON string representation of the object -print(DanishPig.to_json()) +print(DanishPig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -danish_pig_dict = danish_pig_instance.to_dict() +danish_pig_dict = danish_pig_instance.model_dump(by_alias=True) # create an instance of DanishPig from a dict -danish_pig_from_dict = DanishPig.from_dict(danish_pig_dict) +danish_pig_from_dict = DanishPig.model_validate(danish_pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/DeprecatedObject.md b/samples/openapi3/client/petstore/python-httpx/docs/DeprecatedObject.md index 6b362f379ba4..55abc18b24d6 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/DeprecatedObject.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/DeprecatedObject.md @@ -15,14 +15,14 @@ from petstore_api.models.deprecated_object import DeprecatedObject # TODO update the JSON string below json = "{}" # create an instance of DeprecatedObject from a JSON string -deprecated_object_instance = DeprecatedObject.from_json(json) +deprecated_object_instance = DeprecatedObject.model_validate_json(json) # print the JSON string representation of the object -print(DeprecatedObject.to_json()) +print(DeprecatedObject.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -deprecated_object_dict = deprecated_object_instance.to_dict() +deprecated_object_dict = deprecated_object_instance.model_dump(by_alias=True) # create an instance of DeprecatedObject from a dict -deprecated_object_from_dict = DeprecatedObject.from_dict(deprecated_object_dict) +deprecated_object_from_dict = DeprecatedObject.model_validate(deprecated_object_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/DiscriminatorAllOfSub.md b/samples/openapi3/client/petstore/python-httpx/docs/DiscriminatorAllOfSub.md index f72b6e8e68ca..9453c541c53a 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/DiscriminatorAllOfSub.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/DiscriminatorAllOfSub.md @@ -14,14 +14,14 @@ from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub # TODO update the JSON string below json = "{}" # create an instance of DiscriminatorAllOfSub from a JSON string -discriminator_all_of_sub_instance = DiscriminatorAllOfSub.from_json(json) +discriminator_all_of_sub_instance = DiscriminatorAllOfSub.model_validate_json(json) # print the JSON string representation of the object -print(DiscriminatorAllOfSub.to_json()) +print(DiscriminatorAllOfSub.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -discriminator_all_of_sub_dict = discriminator_all_of_sub_instance.to_dict() +discriminator_all_of_sub_dict = discriminator_all_of_sub_instance.model_dump(by_alias=True) # create an instance of DiscriminatorAllOfSub from a dict -discriminator_all_of_sub_from_dict = DiscriminatorAllOfSub.from_dict(discriminator_all_of_sub_dict) +discriminator_all_of_sub_from_dict = DiscriminatorAllOfSub.model_validate(discriminator_all_of_sub_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/DiscriminatorAllOfSuper.md b/samples/openapi3/client/petstore/python-httpx/docs/DiscriminatorAllOfSuper.md index 477c05bfc446..c83f6792acab 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/DiscriminatorAllOfSuper.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/DiscriminatorAllOfSuper.md @@ -15,14 +15,14 @@ from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSup # TODO update the JSON string below json = "{}" # create an instance of DiscriminatorAllOfSuper from a JSON string -discriminator_all_of_super_instance = DiscriminatorAllOfSuper.from_json(json) +discriminator_all_of_super_instance = DiscriminatorAllOfSuper.model_validate_json(json) # print the JSON string representation of the object -print(DiscriminatorAllOfSuper.to_json()) +print(DiscriminatorAllOfSuper.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -discriminator_all_of_super_dict = discriminator_all_of_super_instance.to_dict() +discriminator_all_of_super_dict = discriminator_all_of_super_instance.model_dump(by_alias=True) # create an instance of DiscriminatorAllOfSuper from a dict -discriminator_all_of_super_from_dict = DiscriminatorAllOfSuper.from_dict(discriminator_all_of_super_dict) +discriminator_all_of_super_from_dict = DiscriminatorAllOfSuper.model_validate(discriminator_all_of_super_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Dog.md b/samples/openapi3/client/petstore/python-httpx/docs/Dog.md index ed23f613d01d..099b3f781b4b 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Dog.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Dog.md @@ -15,14 +15,14 @@ from petstore_api.models.dog import Dog # TODO update the JSON string below json = "{}" # create an instance of Dog from a JSON string -dog_instance = Dog.from_json(json) +dog_instance = Dog.model_validate_json(json) # print the JSON string representation of the object -print(Dog.to_json()) +print(Dog.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -dog_dict = dog_instance.to_dict() +dog_dict = dog_instance.model_dump(by_alias=True) # create an instance of Dog from a dict -dog_from_dict = Dog.from_dict(dog_dict) +dog_from_dict = Dog.model_validate(dog_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/DummyModel.md b/samples/openapi3/client/petstore/python-httpx/docs/DummyModel.md index 01b675977f58..bf4ef8ec2b03 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/DummyModel.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/DummyModel.md @@ -16,14 +16,14 @@ from petstore_api.models.dummy_model import DummyModel # TODO update the JSON string below json = "{}" # create an instance of DummyModel from a JSON string -dummy_model_instance = DummyModel.from_json(json) +dummy_model_instance = DummyModel.model_validate_json(json) # print the JSON string representation of the object -print(DummyModel.to_json()) +print(DummyModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -dummy_model_dict = dummy_model_instance.to_dict() +dummy_model_dict = dummy_model_instance.model_dump(by_alias=True) # create an instance of DummyModel from a dict -dummy_model_from_dict = DummyModel.from_dict(dummy_model_dict) +dummy_model_from_dict = DummyModel.model_validate(dummy_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/EnumArrays.md b/samples/openapi3/client/petstore/python-httpx/docs/EnumArrays.md index f44617497bce..fa9dc0d523a9 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/EnumArrays.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/EnumArrays.md @@ -16,14 +16,14 @@ from petstore_api.models.enum_arrays import EnumArrays # TODO update the JSON string below json = "{}" # create an instance of EnumArrays from a JSON string -enum_arrays_instance = EnumArrays.from_json(json) +enum_arrays_instance = EnumArrays.model_validate_json(json) # print the JSON string representation of the object -print(EnumArrays.to_json()) +print(EnumArrays.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -enum_arrays_dict = enum_arrays_instance.to_dict() +enum_arrays_dict = enum_arrays_instance.model_dump(by_alias=True) # create an instance of EnumArrays from a dict -enum_arrays_from_dict = EnumArrays.from_dict(enum_arrays_dict) +enum_arrays_from_dict = EnumArrays.model_validate(enum_arrays_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/EnumRefWithDefaultValue.md b/samples/openapi3/client/petstore/python-httpx/docs/EnumRefWithDefaultValue.md index eeb0dc66969f..89bfb7c31366 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/EnumRefWithDefaultValue.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/EnumRefWithDefaultValue.md @@ -15,14 +15,14 @@ from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultVa # TODO update the JSON string below json = "{}" # create an instance of EnumRefWithDefaultValue from a JSON string -enum_ref_with_default_value_instance = EnumRefWithDefaultValue.from_json(json) +enum_ref_with_default_value_instance = EnumRefWithDefaultValue.model_validate_json(json) # print the JSON string representation of the object -print(EnumRefWithDefaultValue.to_json()) +print(EnumRefWithDefaultValue.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -enum_ref_with_default_value_dict = enum_ref_with_default_value_instance.to_dict() +enum_ref_with_default_value_dict = enum_ref_with_default_value_instance.model_dump(by_alias=True) # create an instance of EnumRefWithDefaultValue from a dict -enum_ref_with_default_value_from_dict = EnumRefWithDefaultValue.from_dict(enum_ref_with_default_value_dict) +enum_ref_with_default_value_from_dict = EnumRefWithDefaultValue.model_validate(enum_ref_with_default_value_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/EnumTest.md b/samples/openapi3/client/petstore/python-httpx/docs/EnumTest.md index 9f96c605d888..c6127df54638 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/EnumTest.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/EnumTest.md @@ -27,14 +27,14 @@ from petstore_api.models.enum_test import EnumTest # TODO update the JSON string below json = "{}" # create an instance of EnumTest from a JSON string -enum_test_instance = EnumTest.from_json(json) +enum_test_instance = EnumTest.model_validate_json(json) # print the JSON string representation of the object -print(EnumTest.to_json()) +print(EnumTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -enum_test_dict = enum_test_instance.to_dict() +enum_test_dict = enum_test_instance.model_dump(by_alias=True) # create an instance of EnumTest from a dict -enum_test_from_dict = EnumTest.from_dict(enum_test_dict) +enum_test_from_dict = EnumTest.model_validate(enum_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Feeding.md b/samples/openapi3/client/petstore/python-httpx/docs/Feeding.md index 9f92b5d964d3..177cae170e77 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Feeding.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Feeding.md @@ -17,14 +17,14 @@ from petstore_api.models.feeding import Feeding # TODO update the JSON string below json = "{}" # create an instance of Feeding from a JSON string -feeding_instance = Feeding.from_json(json) +feeding_instance = Feeding.model_validate_json(json) # print the JSON string representation of the object -print(Feeding.to_json()) +print(Feeding.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -feeding_dict = feeding_instance.to_dict() +feeding_dict = feeding_instance.model_dump(by_alias=True) # create an instance of Feeding from a dict -feeding_from_dict = Feeding.from_dict(feeding_dict) +feeding_from_dict = Feeding.model_validate(feeding_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/File.md b/samples/openapi3/client/petstore/python-httpx/docs/File.md index 23f0567411ce..0b5942557efe 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/File.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/File.md @@ -16,14 +16,14 @@ from petstore_api.models.file import File # TODO update the JSON string below json = "{}" # create an instance of File from a JSON string -file_instance = File.from_json(json) +file_instance = File.model_validate_json(json) # print the JSON string representation of the object -print(File.to_json()) +print(File.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -file_dict = file_instance.to_dict() +file_dict = file_instance.model_dump(by_alias=True) # create an instance of File from a dict -file_from_dict = File.from_dict(file_dict) +file_from_dict = File.model_validate(file_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/FileSchemaTestClass.md b/samples/openapi3/client/petstore/python-httpx/docs/FileSchemaTestClass.md index e1118042a8ec..917f4ce73382 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/FileSchemaTestClass.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/FileSchemaTestClass.md @@ -16,14 +16,14 @@ from petstore_api.models.file_schema_test_class import FileSchemaTestClass # TODO update the JSON string below json = "{}" # create an instance of FileSchemaTestClass from a JSON string -file_schema_test_class_instance = FileSchemaTestClass.from_json(json) +file_schema_test_class_instance = FileSchemaTestClass.model_validate_json(json) # print the JSON string representation of the object -print(FileSchemaTestClass.to_json()) +print(FileSchemaTestClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -file_schema_test_class_dict = file_schema_test_class_instance.to_dict() +file_schema_test_class_dict = file_schema_test_class_instance.model_dump(by_alias=True) # create an instance of FileSchemaTestClass from a dict -file_schema_test_class_from_dict = FileSchemaTestClass.from_dict(file_schema_test_class_dict) +file_schema_test_class_from_dict = FileSchemaTestClass.model_validate(file_schema_test_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/FirstRef.md b/samples/openapi3/client/petstore/python-httpx/docs/FirstRef.md index 94b8ddc5ac22..51617b213a4f 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/FirstRef.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/FirstRef.md @@ -16,14 +16,14 @@ from petstore_api.models.first_ref import FirstRef # TODO update the JSON string below json = "{}" # create an instance of FirstRef from a JSON string -first_ref_instance = FirstRef.from_json(json) +first_ref_instance = FirstRef.model_validate_json(json) # print the JSON string representation of the object -print(FirstRef.to_json()) +print(FirstRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -first_ref_dict = first_ref_instance.to_dict() +first_ref_dict = first_ref_instance.model_dump(by_alias=True) # create an instance of FirstRef from a dict -first_ref_from_dict = FirstRef.from_dict(first_ref_dict) +first_ref_from_dict = FirstRef.model_validate(first_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Foo.md b/samples/openapi3/client/petstore/python-httpx/docs/Foo.md index f635b0daa6db..e25a5a16bac5 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Foo.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Foo.md @@ -15,14 +15,14 @@ from petstore_api.models.foo import Foo # TODO update the JSON string below json = "{}" # create an instance of Foo from a JSON string -foo_instance = Foo.from_json(json) +foo_instance = Foo.model_validate_json(json) # print the JSON string representation of the object -print(Foo.to_json()) +print(Foo.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -foo_dict = foo_instance.to_dict() +foo_dict = foo_instance.model_dump(by_alias=True) # create an instance of Foo from a dict -foo_from_dict = Foo.from_dict(foo_dict) +foo_from_dict = Foo.model_validate(foo_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/FooGetDefaultResponse.md b/samples/openapi3/client/petstore/python-httpx/docs/FooGetDefaultResponse.md index 8d84f795b00a..dab8d870b496 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/FooGetDefaultResponse.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/FooGetDefaultResponse.md @@ -15,14 +15,14 @@ from petstore_api.models.foo_get_default_response import FooGetDefaultResponse # TODO update the JSON string below json = "{}" # create an instance of FooGetDefaultResponse from a JSON string -foo_get_default_response_instance = FooGetDefaultResponse.from_json(json) +foo_get_default_response_instance = FooGetDefaultResponse.model_validate_json(json) # print the JSON string representation of the object -print(FooGetDefaultResponse.to_json()) +print(FooGetDefaultResponse.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -foo_get_default_response_dict = foo_get_default_response_instance.to_dict() +foo_get_default_response_dict = foo_get_default_response_instance.model_dump(by_alias=True) # create an instance of FooGetDefaultResponse from a dict -foo_get_default_response_from_dict = FooGetDefaultResponse.from_dict(foo_get_default_response_dict) +foo_get_default_response_from_dict = FooGetDefaultResponse.model_validate(foo_get_default_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/FormatTest.md b/samples/openapi3/client/petstore/python-httpx/docs/FormatTest.md index 714d2401bbae..7b4bcb6513f8 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/FormatTest.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/FormatTest.md @@ -31,14 +31,14 @@ from petstore_api.models.format_test import FormatTest # TODO update the JSON string below json = "{}" # create an instance of FormatTest from a JSON string -format_test_instance = FormatTest.from_json(json) +format_test_instance = FormatTest.model_validate_json(json) # print the JSON string representation of the object -print(FormatTest.to_json()) +print(FormatTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -format_test_dict = format_test_instance.to_dict() +format_test_dict = format_test_instance.model_dump(by_alias=True) # create an instance of FormatTest from a dict -format_test_from_dict = FormatTest.from_dict(format_test_dict) +format_test_from_dict = FormatTest.model_validate(format_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/HasOnlyReadOnly.md b/samples/openapi3/client/petstore/python-httpx/docs/HasOnlyReadOnly.md index fdc48781b15a..a2d020b6a2cb 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/HasOnlyReadOnly.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/HasOnlyReadOnly.md @@ -16,14 +16,14 @@ from petstore_api.models.has_only_read_only import HasOnlyReadOnly # TODO update the JSON string below json = "{}" # create an instance of HasOnlyReadOnly from a JSON string -has_only_read_only_instance = HasOnlyReadOnly.from_json(json) +has_only_read_only_instance = HasOnlyReadOnly.model_validate_json(json) # print the JSON string representation of the object -print(HasOnlyReadOnly.to_json()) +print(HasOnlyReadOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -has_only_read_only_dict = has_only_read_only_instance.to_dict() +has_only_read_only_dict = has_only_read_only_instance.model_dump(by_alias=True) # create an instance of HasOnlyReadOnly from a dict -has_only_read_only_from_dict = HasOnlyReadOnly.from_dict(has_only_read_only_dict) +has_only_read_only_from_dict = HasOnlyReadOnly.model_validate(has_only_read_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/HealthCheckResult.md b/samples/openapi3/client/petstore/python-httpx/docs/HealthCheckResult.md index d4a2b187167f..49c69cf1d84b 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/HealthCheckResult.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/HealthCheckResult.md @@ -16,14 +16,14 @@ from petstore_api.models.health_check_result import HealthCheckResult # TODO update the JSON string below json = "{}" # create an instance of HealthCheckResult from a JSON string -health_check_result_instance = HealthCheckResult.from_json(json) +health_check_result_instance = HealthCheckResult.model_validate_json(json) # print the JSON string representation of the object -print(HealthCheckResult.to_json()) +print(HealthCheckResult.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -health_check_result_dict = health_check_result_instance.to_dict() +health_check_result_dict = health_check_result_instance.model_dump(by_alias=True) # create an instance of HealthCheckResult from a dict -health_check_result_from_dict = HealthCheckResult.from_dict(health_check_result_dict) +health_check_result_from_dict = HealthCheckResult.model_validate(health_check_result_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/HuntingDog.md b/samples/openapi3/client/petstore/python-httpx/docs/HuntingDog.md index 6db6745dd022..a3a905d84550 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/HuntingDog.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/HuntingDog.md @@ -15,14 +15,14 @@ from petstore_api.models.hunting_dog import HuntingDog # TODO update the JSON string below json = "{}" # create an instance of HuntingDog from a JSON string -hunting_dog_instance = HuntingDog.from_json(json) +hunting_dog_instance = HuntingDog.model_validate_json(json) # print the JSON string representation of the object -print(HuntingDog.to_json()) +print(HuntingDog.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -hunting_dog_dict = hunting_dog_instance.to_dict() +hunting_dog_dict = hunting_dog_instance.model_dump(by_alias=True) # create an instance of HuntingDog from a dict -hunting_dog_from_dict = HuntingDog.from_dict(hunting_dog_dict) +hunting_dog_from_dict = HuntingDog.model_validate(hunting_dog_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Info.md b/samples/openapi3/client/petstore/python-httpx/docs/Info.md index db88778a9143..753e1d770730 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Info.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Info.md @@ -15,14 +15,14 @@ from petstore_api.models.info import Info # TODO update the JSON string below json = "{}" # create an instance of Info from a JSON string -info_instance = Info.from_json(json) +info_instance = Info.model_validate_json(json) # print the JSON string representation of the object -print(Info.to_json()) +print(Info.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -info_dict = info_instance.to_dict() +info_dict = info_instance.model_dump(by_alias=True) # create an instance of Info from a dict -info_from_dict = Info.from_dict(info_dict) +info_from_dict = Info.model_validate(info_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/InnerDictWithProperty.md b/samples/openapi3/client/petstore/python-httpx/docs/InnerDictWithProperty.md index 7b82ebb770b8..2a922855b34f 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/InnerDictWithProperty.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/InnerDictWithProperty.md @@ -15,14 +15,14 @@ from petstore_api.models.inner_dict_with_property import InnerDictWithProperty # TODO update the JSON string below json = "{}" # create an instance of InnerDictWithProperty from a JSON string -inner_dict_with_property_instance = InnerDictWithProperty.from_json(json) +inner_dict_with_property_instance = InnerDictWithProperty.model_validate_json(json) # print the JSON string representation of the object -print(InnerDictWithProperty.to_json()) +print(InnerDictWithProperty.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -inner_dict_with_property_dict = inner_dict_with_property_instance.to_dict() +inner_dict_with_property_dict = inner_dict_with_property_instance.model_dump(by_alias=True) # create an instance of InnerDictWithProperty from a dict -inner_dict_with_property_from_dict = InnerDictWithProperty.from_dict(inner_dict_with_property_dict) +inner_dict_with_property_from_dict = InnerDictWithProperty.model_validate(inner_dict_with_property_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/InputAllOf.md b/samples/openapi3/client/petstore/python-httpx/docs/InputAllOf.md index 45298f5308fc..ee77a141784a 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/InputAllOf.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/InputAllOf.md @@ -15,14 +15,14 @@ from petstore_api.models.input_all_of import InputAllOf # TODO update the JSON string below json = "{}" # create an instance of InputAllOf from a JSON string -input_all_of_instance = InputAllOf.from_json(json) +input_all_of_instance = InputAllOf.model_validate_json(json) # print the JSON string representation of the object -print(InputAllOf.to_json()) +print(InputAllOf.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -input_all_of_dict = input_all_of_instance.to_dict() +input_all_of_dict = input_all_of_instance.model_dump(by_alias=True) # create an instance of InputAllOf from a dict -input_all_of_from_dict = InputAllOf.from_dict(input_all_of_dict) +input_all_of_from_dict = InputAllOf.model_validate(input_all_of_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/IntOrString.md b/samples/openapi3/client/petstore/python-httpx/docs/IntOrString.md index b4070b9a8c79..6274e6fbc696 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/IntOrString.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/IntOrString.md @@ -14,14 +14,14 @@ from petstore_api.models.int_or_string import IntOrString # TODO update the JSON string below json = "{}" # create an instance of IntOrString from a JSON string -int_or_string_instance = IntOrString.from_json(json) +int_or_string_instance = IntOrString.model_validate_json(json) # print the JSON string representation of the object -print(IntOrString.to_json()) +print(IntOrString.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -int_or_string_dict = int_or_string_instance.to_dict() +int_or_string_dict = int_or_string_instance.model_dump(by_alias=True) # create an instance of IntOrString from a dict -int_or_string_from_dict = IntOrString.from_dict(int_or_string_dict) +int_or_string_from_dict = IntOrString.model_validate(int_or_string_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/ListClass.md b/samples/openapi3/client/petstore/python-httpx/docs/ListClass.md index 01068b7d22c3..00e12b663833 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/ListClass.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/ListClass.md @@ -15,14 +15,14 @@ from petstore_api.models.list_class import ListClass # TODO update the JSON string below json = "{}" # create an instance of ListClass from a JSON string -list_class_instance = ListClass.from_json(json) +list_class_instance = ListClass.model_validate_json(json) # print the JSON string representation of the object -print(ListClass.to_json()) +print(ListClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -list_class_dict = list_class_instance.to_dict() +list_class_dict = list_class_instance.model_dump(by_alias=True) # create an instance of ListClass from a dict -list_class_from_dict = ListClass.from_dict(list_class_dict) +list_class_from_dict = ListClass.model_validate(list_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/MapOfArrayOfModel.md b/samples/openapi3/client/petstore/python-httpx/docs/MapOfArrayOfModel.md index 71a4ef66b682..dbfba20ac23b 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/MapOfArrayOfModel.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/MapOfArrayOfModel.md @@ -15,14 +15,14 @@ from petstore_api.models.map_of_array_of_model import MapOfArrayOfModel # TODO update the JSON string below json = "{}" # create an instance of MapOfArrayOfModel from a JSON string -map_of_array_of_model_instance = MapOfArrayOfModel.from_json(json) +map_of_array_of_model_instance = MapOfArrayOfModel.model_validate_json(json) # print the JSON string representation of the object -print(MapOfArrayOfModel.to_json()) +print(MapOfArrayOfModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -map_of_array_of_model_dict = map_of_array_of_model_instance.to_dict() +map_of_array_of_model_dict = map_of_array_of_model_instance.model_dump(by_alias=True) # create an instance of MapOfArrayOfModel from a dict -map_of_array_of_model_from_dict = MapOfArrayOfModel.from_dict(map_of_array_of_model_dict) +map_of_array_of_model_from_dict = MapOfArrayOfModel.model_validate(map_of_array_of_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/MapTest.md b/samples/openapi3/client/petstore/python-httpx/docs/MapTest.md index d04b82e9378c..61382a4e3cd8 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/MapTest.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/MapTest.md @@ -18,14 +18,14 @@ from petstore_api.models.map_test import MapTest # TODO update the JSON string below json = "{}" # create an instance of MapTest from a JSON string -map_test_instance = MapTest.from_json(json) +map_test_instance = MapTest.model_validate_json(json) # print the JSON string representation of the object -print(MapTest.to_json()) +print(MapTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -map_test_dict = map_test_instance.to_dict() +map_test_dict = map_test_instance.model_dump(by_alias=True) # create an instance of MapTest from a dict -map_test_from_dict = MapTest.from_dict(map_test_dict) +map_test_from_dict = MapTest.model_validate(map_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/openapi3/client/petstore/python-httpx/docs/MixedPropertiesAndAdditionalPropertiesClass.md index 84134317aefc..41ef9465d498 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -17,14 +17,14 @@ from petstore_api.models.mixed_properties_and_additional_properties_class import # TODO update the JSON string below json = "{}" # create an instance of MixedPropertiesAndAdditionalPropertiesClass from a JSON string -mixed_properties_and_additional_properties_class_instance = MixedPropertiesAndAdditionalPropertiesClass.from_json(json) +mixed_properties_and_additional_properties_class_instance = MixedPropertiesAndAdditionalPropertiesClass.model_validate_json(json) # print the JSON string representation of the object -print(MixedPropertiesAndAdditionalPropertiesClass.to_json()) +print(MixedPropertiesAndAdditionalPropertiesClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -mixed_properties_and_additional_properties_class_dict = mixed_properties_and_additional_properties_class_instance.to_dict() +mixed_properties_and_additional_properties_class_dict = mixed_properties_and_additional_properties_class_instance.model_dump(by_alias=True) # create an instance of MixedPropertiesAndAdditionalPropertiesClass from a dict -mixed_properties_and_additional_properties_class_from_dict = MixedPropertiesAndAdditionalPropertiesClass.from_dict(mixed_properties_and_additional_properties_class_dict) +mixed_properties_and_additional_properties_class_from_dict = MixedPropertiesAndAdditionalPropertiesClass.model_validate(mixed_properties_and_additional_properties_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Model200Response.md b/samples/openapi3/client/petstore/python-httpx/docs/Model200Response.md index 7fdbdefc6cec..56b765c788de 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Model200Response.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Model200Response.md @@ -17,14 +17,14 @@ from petstore_api.models.model200_response import Model200Response # TODO update the JSON string below json = "{}" # create an instance of Model200Response from a JSON string -model200_response_instance = Model200Response.from_json(json) +model200_response_instance = Model200Response.model_validate_json(json) # print the JSON string representation of the object -print(Model200Response.to_json()) +print(Model200Response.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model200_response_dict = model200_response_instance.to_dict() +model200_response_dict = model200_response_instance.model_dump(by_alias=True) # create an instance of Model200Response from a dict -model200_response_from_dict = Model200Response.from_dict(model200_response_dict) +model200_response_from_dict = Model200Response.model_validate(model200_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/ModelApiResponse.md b/samples/openapi3/client/petstore/python-httpx/docs/ModelApiResponse.md index 5ddc0db2a0f3..1fe361910ecb 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/ModelApiResponse.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/ModelApiResponse.md @@ -17,14 +17,14 @@ from petstore_api.models.model_api_response import ModelApiResponse # TODO update the JSON string below json = "{}" # create an instance of ModelApiResponse from a JSON string -model_api_response_instance = ModelApiResponse.from_json(json) +model_api_response_instance = ModelApiResponse.model_validate_json(json) # print the JSON string representation of the object -print(ModelApiResponse.to_json()) +print(ModelApiResponse.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model_api_response_dict = model_api_response_instance.to_dict() +model_api_response_dict = model_api_response_instance.model_dump(by_alias=True) # create an instance of ModelApiResponse from a dict -model_api_response_from_dict = ModelApiResponse.from_dict(model_api_response_dict) +model_api_response_from_dict = ModelApiResponse.model_validate(model_api_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/ModelField.md b/samples/openapi3/client/petstore/python-httpx/docs/ModelField.md index 9073b5dbdb00..8fa1be583ae3 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/ModelField.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/ModelField.md @@ -15,14 +15,14 @@ from petstore_api.models.model_field import ModelField # TODO update the JSON string below json = "{}" # create an instance of ModelField from a JSON string -model_field_instance = ModelField.from_json(json) +model_field_instance = ModelField.model_validate_json(json) # print the JSON string representation of the object -print(ModelField.to_json()) +print(ModelField.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model_field_dict = model_field_instance.to_dict() +model_field_dict = model_field_instance.model_dump(by_alias=True) # create an instance of ModelField from a dict -model_field_from_dict = ModelField.from_dict(model_field_dict) +model_field_from_dict = ModelField.model_validate(model_field_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/ModelReturn.md b/samples/openapi3/client/petstore/python-httpx/docs/ModelReturn.md index 7d327053b0c3..fbda0142410b 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/ModelReturn.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/ModelReturn.md @@ -16,14 +16,14 @@ from petstore_api.models.model_return import ModelReturn # TODO update the JSON string below json = "{}" # create an instance of ModelReturn from a JSON string -model_return_instance = ModelReturn.from_json(json) +model_return_instance = ModelReturn.model_validate_json(json) # print the JSON string representation of the object -print(ModelReturn.to_json()) +print(ModelReturn.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model_return_dict = model_return_instance.to_dict() +model_return_dict = model_return_instance.model_dump(by_alias=True) # create an instance of ModelReturn from a dict -model_return_from_dict = ModelReturn.from_dict(model_return_dict) +model_return_from_dict = ModelReturn.model_validate(model_return_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/MultiArrays.md b/samples/openapi3/client/petstore/python-httpx/docs/MultiArrays.md index fea5139e7e73..5feb5eb83587 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/MultiArrays.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/MultiArrays.md @@ -16,14 +16,14 @@ from petstore_api.models.multi_arrays import MultiArrays # TODO update the JSON string below json = "{}" # create an instance of MultiArrays from a JSON string -multi_arrays_instance = MultiArrays.from_json(json) +multi_arrays_instance = MultiArrays.model_validate_json(json) # print the JSON string representation of the object -print(MultiArrays.to_json()) +print(MultiArrays.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -multi_arrays_dict = multi_arrays_instance.to_dict() +multi_arrays_dict = multi_arrays_instance.model_dump(by_alias=True) # create an instance of MultiArrays from a dict -multi_arrays_from_dict = MultiArrays.from_dict(multi_arrays_dict) +multi_arrays_from_dict = MultiArrays.model_validate(multi_arrays_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Name.md b/samples/openapi3/client/petstore/python-httpx/docs/Name.md index 5a04ec1ada06..fe30c2a76d97 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Name.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Name.md @@ -19,14 +19,14 @@ from petstore_api.models.name import Name # TODO update the JSON string below json = "{}" # create an instance of Name from a JSON string -name_instance = Name.from_json(json) +name_instance = Name.model_validate_json(json) # print the JSON string representation of the object -print(Name.to_json()) +print(Name.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -name_dict = name_instance.to_dict() +name_dict = name_instance.model_dump(by_alias=True) # create an instance of Name from a dict -name_from_dict = Name.from_dict(name_dict) +name_from_dict = Name.model_validate(name_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/NullableClass.md b/samples/openapi3/client/petstore/python-httpx/docs/NullableClass.md index 0387dcc2c67a..fafc21b70778 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/NullableClass.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/NullableClass.md @@ -27,14 +27,14 @@ from petstore_api.models.nullable_class import NullableClass # TODO update the JSON string below json = "{}" # create an instance of NullableClass from a JSON string -nullable_class_instance = NullableClass.from_json(json) +nullable_class_instance = NullableClass.model_validate_json(json) # print the JSON string representation of the object -print(NullableClass.to_json()) +print(NullableClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -nullable_class_dict = nullable_class_instance.to_dict() +nullable_class_dict = nullable_class_instance.model_dump(by_alias=True) # create an instance of NullableClass from a dict -nullable_class_from_dict = NullableClass.from_dict(nullable_class_dict) +nullable_class_from_dict = NullableClass.model_validate(nullable_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/NullableProperty.md b/samples/openapi3/client/petstore/python-httpx/docs/NullableProperty.md index 30edaf4844b2..1738420f6e1c 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/NullableProperty.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/NullableProperty.md @@ -16,14 +16,14 @@ from petstore_api.models.nullable_property import NullableProperty # TODO update the JSON string below json = "{}" # create an instance of NullableProperty from a JSON string -nullable_property_instance = NullableProperty.from_json(json) +nullable_property_instance = NullableProperty.model_validate_json(json) # print the JSON string representation of the object -print(NullableProperty.to_json()) +print(NullableProperty.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -nullable_property_dict = nullable_property_instance.to_dict() +nullable_property_dict = nullable_property_instance.model_dump(by_alias=True) # create an instance of NullableProperty from a dict -nullable_property_from_dict = NullableProperty.from_dict(nullable_property_dict) +nullable_property_from_dict = NullableProperty.model_validate(nullable_property_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/NumberOnly.md b/samples/openapi3/client/petstore/python-httpx/docs/NumberOnly.md index 415dd25585d4..739426b7c295 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/NumberOnly.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/NumberOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.number_only import NumberOnly # TODO update the JSON string below json = "{}" # create an instance of NumberOnly from a JSON string -number_only_instance = NumberOnly.from_json(json) +number_only_instance = NumberOnly.model_validate_json(json) # print the JSON string representation of the object -print(NumberOnly.to_json()) +print(NumberOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -number_only_dict = number_only_instance.to_dict() +number_only_dict = number_only_instance.model_dump(by_alias=True) # create an instance of NumberOnly from a dict -number_only_from_dict = NumberOnly.from_dict(number_only_dict) +number_only_from_dict = NumberOnly.model_validate(number_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/ObjectToTestAdditionalProperties.md b/samples/openapi3/client/petstore/python-httpx/docs/ObjectToTestAdditionalProperties.md index f6bc34c98e65..eec52f82c2ca 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/ObjectToTestAdditionalProperties.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/ObjectToTestAdditionalProperties.md @@ -16,14 +16,14 @@ from petstore_api.models.object_to_test_additional_properties import ObjectToTes # TODO update the JSON string below json = "{}" # create an instance of ObjectToTestAdditionalProperties from a JSON string -object_to_test_additional_properties_instance = ObjectToTestAdditionalProperties.from_json(json) +object_to_test_additional_properties_instance = ObjectToTestAdditionalProperties.model_validate_json(json) # print the JSON string representation of the object -print(ObjectToTestAdditionalProperties.to_json()) +print(ObjectToTestAdditionalProperties.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -object_to_test_additional_properties_dict = object_to_test_additional_properties_instance.to_dict() +object_to_test_additional_properties_dict = object_to_test_additional_properties_instance.model_dump(by_alias=True) # create an instance of ObjectToTestAdditionalProperties from a dict -object_to_test_additional_properties_from_dict = ObjectToTestAdditionalProperties.from_dict(object_to_test_additional_properties_dict) +object_to_test_additional_properties_from_dict = ObjectToTestAdditionalProperties.model_validate(object_to_test_additional_properties_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/ObjectWithDeprecatedFields.md b/samples/openapi3/client/petstore/python-httpx/docs/ObjectWithDeprecatedFields.md index 6dbd2ace04f1..6329b1899970 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/ObjectWithDeprecatedFields.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/ObjectWithDeprecatedFields.md @@ -18,14 +18,14 @@ from petstore_api.models.object_with_deprecated_fields import ObjectWithDeprecat # TODO update the JSON string below json = "{}" # create an instance of ObjectWithDeprecatedFields from a JSON string -object_with_deprecated_fields_instance = ObjectWithDeprecatedFields.from_json(json) +object_with_deprecated_fields_instance = ObjectWithDeprecatedFields.model_validate_json(json) # print the JSON string representation of the object -print(ObjectWithDeprecatedFields.to_json()) +print(ObjectWithDeprecatedFields.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -object_with_deprecated_fields_dict = object_with_deprecated_fields_instance.to_dict() +object_with_deprecated_fields_dict = object_with_deprecated_fields_instance.model_dump(by_alias=True) # create an instance of ObjectWithDeprecatedFields from a dict -object_with_deprecated_fields_from_dict = ObjectWithDeprecatedFields.from_dict(object_with_deprecated_fields_dict) +object_with_deprecated_fields_from_dict = ObjectWithDeprecatedFields.model_validate(object_with_deprecated_fields_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Order.md b/samples/openapi3/client/petstore/python-httpx/docs/Order.md index 00526b8d04b9..8d4b8ac2983f 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Order.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Order.md @@ -20,14 +20,14 @@ from petstore_api.models.order import Order # TODO update the JSON string below json = "{}" # create an instance of Order from a JSON string -order_instance = Order.from_json(json) +order_instance = Order.model_validate_json(json) # print the JSON string representation of the object -print(Order.to_json()) +print(Order.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -order_dict = order_instance.to_dict() +order_dict = order_instance.model_dump(by_alias=True) # create an instance of Order from a dict -order_from_dict = Order.from_dict(order_dict) +order_from_dict = Order.model_validate(order_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/OuterComposite.md b/samples/openapi3/client/petstore/python-httpx/docs/OuterComposite.md index c8242c2d2653..bff67df11388 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/OuterComposite.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/OuterComposite.md @@ -17,14 +17,14 @@ from petstore_api.models.outer_composite import OuterComposite # TODO update the JSON string below json = "{}" # create an instance of OuterComposite from a JSON string -outer_composite_instance = OuterComposite.from_json(json) +outer_composite_instance = OuterComposite.model_validate_json(json) # print the JSON string representation of the object -print(OuterComposite.to_json()) +print(OuterComposite.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -outer_composite_dict = outer_composite_instance.to_dict() +outer_composite_dict = outer_composite_instance.model_dump(by_alias=True) # create an instance of OuterComposite from a dict -outer_composite_from_dict = OuterComposite.from_dict(outer_composite_dict) +outer_composite_from_dict = OuterComposite.model_validate(outer_composite_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/OuterObjectWithEnumProperty.md b/samples/openapi3/client/petstore/python-httpx/docs/OuterObjectWithEnumProperty.md index 6137dbd98da6..39611a8868a7 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/OuterObjectWithEnumProperty.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/OuterObjectWithEnumProperty.md @@ -16,14 +16,14 @@ from petstore_api.models.outer_object_with_enum_property import OuterObjectWithE # TODO update the JSON string below json = "{}" # create an instance of OuterObjectWithEnumProperty from a JSON string -outer_object_with_enum_property_instance = OuterObjectWithEnumProperty.from_json(json) +outer_object_with_enum_property_instance = OuterObjectWithEnumProperty.model_validate_json(json) # print the JSON string representation of the object -print(OuterObjectWithEnumProperty.to_json()) +print(OuterObjectWithEnumProperty.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -outer_object_with_enum_property_dict = outer_object_with_enum_property_instance.to_dict() +outer_object_with_enum_property_dict = outer_object_with_enum_property_instance.model_dump(by_alias=True) # create an instance of OuterObjectWithEnumProperty from a dict -outer_object_with_enum_property_from_dict = OuterObjectWithEnumProperty.from_dict(outer_object_with_enum_property_dict) +outer_object_with_enum_property_from_dict = OuterObjectWithEnumProperty.model_validate(outer_object_with_enum_property_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Parent.md b/samples/openapi3/client/petstore/python-httpx/docs/Parent.md index 7387f9250aad..700d8446226c 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Parent.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Parent.md @@ -15,14 +15,14 @@ from petstore_api.models.parent import Parent # TODO update the JSON string below json = "{}" # create an instance of Parent from a JSON string -parent_instance = Parent.from_json(json) +parent_instance = Parent.model_validate_json(json) # print the JSON string representation of the object -print(Parent.to_json()) +print(Parent.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -parent_dict = parent_instance.to_dict() +parent_dict = parent_instance.model_dump(by_alias=True) # create an instance of Parent from a dict -parent_from_dict = Parent.from_dict(parent_dict) +parent_from_dict = Parent.model_validate(parent_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/ParentWithOptionalDict.md b/samples/openapi3/client/petstore/python-httpx/docs/ParentWithOptionalDict.md index bfc8688ea26f..7af4744a1016 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/ParentWithOptionalDict.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/ParentWithOptionalDict.md @@ -15,14 +15,14 @@ from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict # TODO update the JSON string below json = "{}" # create an instance of ParentWithOptionalDict from a JSON string -parent_with_optional_dict_instance = ParentWithOptionalDict.from_json(json) +parent_with_optional_dict_instance = ParentWithOptionalDict.model_validate_json(json) # print the JSON string representation of the object -print(ParentWithOptionalDict.to_json()) +print(ParentWithOptionalDict.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -parent_with_optional_dict_dict = parent_with_optional_dict_instance.to_dict() +parent_with_optional_dict_dict = parent_with_optional_dict_instance.model_dump(by_alias=True) # create an instance of ParentWithOptionalDict from a dict -parent_with_optional_dict_from_dict = ParentWithOptionalDict.from_dict(parent_with_optional_dict_dict) +parent_with_optional_dict_from_dict = ParentWithOptionalDict.model_validate(parent_with_optional_dict_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Pet.md b/samples/openapi3/client/petstore/python-httpx/docs/Pet.md index 5329cf2fb925..e09f1b8b22ff 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Pet.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Pet.md @@ -20,14 +20,14 @@ from petstore_api.models.pet import Pet # TODO update the JSON string below json = "{}" # create an instance of Pet from a JSON string -pet_instance = Pet.from_json(json) +pet_instance = Pet.model_validate_json(json) # print the JSON string representation of the object -print(Pet.to_json()) +print(Pet.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -pet_dict = pet_instance.to_dict() +pet_dict = pet_instance.model_dump(by_alias=True) # create an instance of Pet from a dict -pet_from_dict = Pet.from_dict(pet_dict) +pet_from_dict = Pet.model_validate(pet_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Pig.md b/samples/openapi3/client/petstore/python-httpx/docs/Pig.md index 625930676083..8c9de7a86c8a 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Pig.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Pig.md @@ -17,14 +17,14 @@ from petstore_api.models.pig import Pig # TODO update the JSON string below json = "{}" # create an instance of Pig from a JSON string -pig_instance = Pig.from_json(json) +pig_instance = Pig.model_validate_json(json) # print the JSON string representation of the object -print(Pig.to_json()) +print(Pig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -pig_dict = pig_instance.to_dict() +pig_dict = pig_instance.model_dump(by_alias=True) # create an instance of Pig from a dict -pig_from_dict = Pig.from_dict(pig_dict) +pig_from_dict = Pig.model_validate(pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/PonySizes.md b/samples/openapi3/client/petstore/python-httpx/docs/PonySizes.md index ced44c872060..03af5df5ed23 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/PonySizes.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/PonySizes.md @@ -15,14 +15,14 @@ from petstore_api.models.pony_sizes import PonySizes # TODO update the JSON string below json = "{}" # create an instance of PonySizes from a JSON string -pony_sizes_instance = PonySizes.from_json(json) +pony_sizes_instance = PonySizes.model_validate_json(json) # print the JSON string representation of the object -print(PonySizes.to_json()) +print(PonySizes.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -pony_sizes_dict = pony_sizes_instance.to_dict() +pony_sizes_dict = pony_sizes_instance.model_dump(by_alias=True) # create an instance of PonySizes from a dict -pony_sizes_from_dict = PonySizes.from_dict(pony_sizes_dict) +pony_sizes_from_dict = PonySizes.model_validate(pony_sizes_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/PoopCleaning.md b/samples/openapi3/client/petstore/python-httpx/docs/PoopCleaning.md index 8f9c25e08316..b58624f40112 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/PoopCleaning.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/PoopCleaning.md @@ -17,14 +17,14 @@ from petstore_api.models.poop_cleaning import PoopCleaning # TODO update the JSON string below json = "{}" # create an instance of PoopCleaning from a JSON string -poop_cleaning_instance = PoopCleaning.from_json(json) +poop_cleaning_instance = PoopCleaning.model_validate_json(json) # print the JSON string representation of the object -print(PoopCleaning.to_json()) +print(PoopCleaning.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -poop_cleaning_dict = poop_cleaning_instance.to_dict() +poop_cleaning_dict = poop_cleaning_instance.model_dump(by_alias=True) # create an instance of PoopCleaning from a dict -poop_cleaning_from_dict = PoopCleaning.from_dict(poop_cleaning_dict) +poop_cleaning_from_dict = PoopCleaning.model_validate(poop_cleaning_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/PrimitiveString.md b/samples/openapi3/client/petstore/python-httpx/docs/PrimitiveString.md index 85ceb632e167..c2296ead4a1a 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/PrimitiveString.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/PrimitiveString.md @@ -15,14 +15,14 @@ from petstore_api.models.primitive_string import PrimitiveString # TODO update the JSON string below json = "{}" # create an instance of PrimitiveString from a JSON string -primitive_string_instance = PrimitiveString.from_json(json) +primitive_string_instance = PrimitiveString.model_validate_json(json) # print the JSON string representation of the object -print(PrimitiveString.to_json()) +print(PrimitiveString.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -primitive_string_dict = primitive_string_instance.to_dict() +primitive_string_dict = primitive_string_instance.model_dump(by_alias=True) # create an instance of PrimitiveString from a dict -primitive_string_from_dict = PrimitiveString.from_dict(primitive_string_dict) +primitive_string_from_dict = PrimitiveString.model_validate(primitive_string_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/PropertyMap.md b/samples/openapi3/client/petstore/python-httpx/docs/PropertyMap.md index a55a0e5c6f01..3982b35d5724 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/PropertyMap.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/PropertyMap.md @@ -15,14 +15,14 @@ from petstore_api.models.property_map import PropertyMap # TODO update the JSON string below json = "{}" # create an instance of PropertyMap from a JSON string -property_map_instance = PropertyMap.from_json(json) +property_map_instance = PropertyMap.model_validate_json(json) # print the JSON string representation of the object -print(PropertyMap.to_json()) +print(PropertyMap.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -property_map_dict = property_map_instance.to_dict() +property_map_dict = property_map_instance.model_dump(by_alias=True) # create an instance of PropertyMap from a dict -property_map_from_dict = PropertyMap.from_dict(property_map_dict) +property_map_from_dict = PropertyMap.model_validate(property_map_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/PropertyNameCollision.md b/samples/openapi3/client/petstore/python-httpx/docs/PropertyNameCollision.md index 40c233670dd0..e98d6ad2aa59 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/PropertyNameCollision.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/PropertyNameCollision.md @@ -17,14 +17,14 @@ from petstore_api.models.property_name_collision import PropertyNameCollision # TODO update the JSON string below json = "{}" # create an instance of PropertyNameCollision from a JSON string -property_name_collision_instance = PropertyNameCollision.from_json(json) +property_name_collision_instance = PropertyNameCollision.model_validate_json(json) # print the JSON string representation of the object -print(PropertyNameCollision.to_json()) +print(PropertyNameCollision.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -property_name_collision_dict = property_name_collision_instance.to_dict() +property_name_collision_dict = property_name_collision_instance.model_dump(by_alias=True) # create an instance of PropertyNameCollision from a dict -property_name_collision_from_dict = PropertyNameCollision.from_dict(property_name_collision_dict) +property_name_collision_from_dict = PropertyNameCollision.model_validate(property_name_collision_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/ReadOnlyFirst.md b/samples/openapi3/client/petstore/python-httpx/docs/ReadOnlyFirst.md index 686ec5da41c9..51831854b601 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/ReadOnlyFirst.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/ReadOnlyFirst.md @@ -16,14 +16,14 @@ from petstore_api.models.read_only_first import ReadOnlyFirst # TODO update the JSON string below json = "{}" # create an instance of ReadOnlyFirst from a JSON string -read_only_first_instance = ReadOnlyFirst.from_json(json) +read_only_first_instance = ReadOnlyFirst.model_validate_json(json) # print the JSON string representation of the object -print(ReadOnlyFirst.to_json()) +print(ReadOnlyFirst.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -read_only_first_dict = read_only_first_instance.to_dict() +read_only_first_dict = read_only_first_instance.model_dump(by_alias=True) # create an instance of ReadOnlyFirst from a dict -read_only_first_from_dict = ReadOnlyFirst.from_dict(read_only_first_dict) +read_only_first_from_dict = ReadOnlyFirst.model_validate(read_only_first_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/SecondCircularAllOfRef.md b/samples/openapi3/client/petstore/python-httpx/docs/SecondCircularAllOfRef.md index 65ebdd4c7e1d..173a4eb5fd68 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/SecondCircularAllOfRef.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/SecondCircularAllOfRef.md @@ -16,14 +16,14 @@ from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRe # TODO update the JSON string below json = "{}" # create an instance of SecondCircularAllOfRef from a JSON string -second_circular_all_of_ref_instance = SecondCircularAllOfRef.from_json(json) +second_circular_all_of_ref_instance = SecondCircularAllOfRef.model_validate_json(json) # print the JSON string representation of the object -print(SecondCircularAllOfRef.to_json()) +print(SecondCircularAllOfRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -second_circular_all_of_ref_dict = second_circular_all_of_ref_instance.to_dict() +second_circular_all_of_ref_dict = second_circular_all_of_ref_instance.model_dump(by_alias=True) # create an instance of SecondCircularAllOfRef from a dict -second_circular_all_of_ref_from_dict = SecondCircularAllOfRef.from_dict(second_circular_all_of_ref_dict) +second_circular_all_of_ref_from_dict = SecondCircularAllOfRef.model_validate(second_circular_all_of_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/SecondRef.md b/samples/openapi3/client/petstore/python-httpx/docs/SecondRef.md index dfb1a0ac6db5..87c1e1d4bb3a 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/SecondRef.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/SecondRef.md @@ -16,14 +16,14 @@ from petstore_api.models.second_ref import SecondRef # TODO update the JSON string below json = "{}" # create an instance of SecondRef from a JSON string -second_ref_instance = SecondRef.from_json(json) +second_ref_instance = SecondRef.model_validate_json(json) # print the JSON string representation of the object -print(SecondRef.to_json()) +print(SecondRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -second_ref_dict = second_ref_instance.to_dict() +second_ref_dict = second_ref_instance.model_dump(by_alias=True) # create an instance of SecondRef from a dict -second_ref_from_dict = SecondRef.from_dict(second_ref_dict) +second_ref_from_dict = SecondRef.model_validate(second_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/SelfReferenceModel.md b/samples/openapi3/client/petstore/python-httpx/docs/SelfReferenceModel.md index 208cdac04b6f..68c6e661ac94 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/SelfReferenceModel.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/SelfReferenceModel.md @@ -16,14 +16,14 @@ from petstore_api.models.self_reference_model import SelfReferenceModel # TODO update the JSON string below json = "{}" # create an instance of SelfReferenceModel from a JSON string -self_reference_model_instance = SelfReferenceModel.from_json(json) +self_reference_model_instance = SelfReferenceModel.model_validate_json(json) # print the JSON string representation of the object -print(SelfReferenceModel.to_json()) +print(SelfReferenceModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -self_reference_model_dict = self_reference_model_instance.to_dict() +self_reference_model_dict = self_reference_model_instance.model_dump(by_alias=True) # create an instance of SelfReferenceModel from a dict -self_reference_model_from_dict = SelfReferenceModel.from_dict(self_reference_model_dict) +self_reference_model_from_dict = SelfReferenceModel.model_validate(self_reference_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/SpecialModelName.md b/samples/openapi3/client/petstore/python-httpx/docs/SpecialModelName.md index 35303f34efd2..0e99036d92f4 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/SpecialModelName.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/SpecialModelName.md @@ -15,14 +15,14 @@ from petstore_api.models.special_model_name import SpecialModelName # TODO update the JSON string below json = "{}" # create an instance of SpecialModelName from a JSON string -special_model_name_instance = SpecialModelName.from_json(json) +special_model_name_instance = SpecialModelName.model_validate_json(json) # print the JSON string representation of the object -print(SpecialModelName.to_json()) +print(SpecialModelName.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -special_model_name_dict = special_model_name_instance.to_dict() +special_model_name_dict = special_model_name_instance.model_dump(by_alias=True) # create an instance of SpecialModelName from a dict -special_model_name_from_dict = SpecialModelName.from_dict(special_model_name_dict) +special_model_name_from_dict = SpecialModelName.model_validate(special_model_name_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/SpecialName.md b/samples/openapi3/client/petstore/python-httpx/docs/SpecialName.md index ccc550b16e33..5d00c8517aaa 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/SpecialName.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/SpecialName.md @@ -17,14 +17,14 @@ from petstore_api.models.special_name import SpecialName # TODO update the JSON string below json = "{}" # create an instance of SpecialName from a JSON string -special_name_instance = SpecialName.from_json(json) +special_name_instance = SpecialName.model_validate_json(json) # print the JSON string representation of the object -print(SpecialName.to_json()) +print(SpecialName.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -special_name_dict = special_name_instance.to_dict() +special_name_dict = special_name_instance.model_dump(by_alias=True) # create an instance of SpecialName from a dict -special_name_from_dict = SpecialName.from_dict(special_name_dict) +special_name_from_dict = SpecialName.model_validate(special_name_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Tag.md b/samples/openapi3/client/petstore/python-httpx/docs/Tag.md index 4106d9cfe5db..98068caba254 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Tag.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Tag.md @@ -16,14 +16,14 @@ from petstore_api.models.tag import Tag # TODO update the JSON string below json = "{}" # create an instance of Tag from a JSON string -tag_instance = Tag.from_json(json) +tag_instance = Tag.model_validate_json(json) # print the JSON string representation of the object -print(Tag.to_json()) +print(Tag.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -tag_dict = tag_instance.to_dict() +tag_dict = tag_instance.model_dump(by_alias=True) # create an instance of Tag from a dict -tag_from_dict = Tag.from_dict(tag_dict) +tag_from_dict = Tag.model_validate(tag_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Task.md b/samples/openapi3/client/petstore/python-httpx/docs/Task.md index 85fa2776a059..92aed88f998b 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Task.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Task.md @@ -17,14 +17,14 @@ from petstore_api.models.task import Task # TODO update the JSON string below json = "{}" # create an instance of Task from a JSON string -task_instance = Task.from_json(json) +task_instance = Task.model_validate_json(json) # print the JSON string representation of the object -print(Task.to_json()) +print(Task.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -task_dict = task_instance.to_dict() +task_dict = task_instance.model_dump(by_alias=True) # create an instance of Task from a dict -task_from_dict = Task.from_dict(task_dict) +task_from_dict = Task.model_validate(task_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/TaskActivity.md b/samples/openapi3/client/petstore/python-httpx/docs/TaskActivity.md index e905a477292d..3f8e10cf7ae5 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/TaskActivity.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/TaskActivity.md @@ -17,14 +17,14 @@ from petstore_api.models.task_activity import TaskActivity # TODO update the JSON string below json = "{}" # create an instance of TaskActivity from a JSON string -task_activity_instance = TaskActivity.from_json(json) +task_activity_instance = TaskActivity.model_validate_json(json) # print the JSON string representation of the object -print(TaskActivity.to_json()) +print(TaskActivity.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -task_activity_dict = task_activity_instance.to_dict() +task_activity_dict = task_activity_instance.model_dump(by_alias=True) # create an instance of TaskActivity from a dict -task_activity_from_dict = TaskActivity.from_dict(task_activity_dict) +task_activity_from_dict = TaskActivity.model_validate(task_activity_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/TestErrorResponsesWithModel400Response.md b/samples/openapi3/client/petstore/python-httpx/docs/TestErrorResponsesWithModel400Response.md index be416bbad0f7..ba20c0666f90 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/TestErrorResponsesWithModel400Response.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/TestErrorResponsesWithModel400Response.md @@ -15,14 +15,14 @@ from petstore_api.models.test_error_responses_with_model400_response import Test # TODO update the JSON string below json = "{}" # create an instance of TestErrorResponsesWithModel400Response from a JSON string -test_error_responses_with_model400_response_instance = TestErrorResponsesWithModel400Response.from_json(json) +test_error_responses_with_model400_response_instance = TestErrorResponsesWithModel400Response.model_validate_json(json) # print the JSON string representation of the object -print(TestErrorResponsesWithModel400Response.to_json()) +print(TestErrorResponsesWithModel400Response.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_error_responses_with_model400_response_dict = test_error_responses_with_model400_response_instance.to_dict() +test_error_responses_with_model400_response_dict = test_error_responses_with_model400_response_instance.model_dump(by_alias=True) # create an instance of TestErrorResponsesWithModel400Response from a dict -test_error_responses_with_model400_response_from_dict = TestErrorResponsesWithModel400Response.from_dict(test_error_responses_with_model400_response_dict) +test_error_responses_with_model400_response_from_dict = TestErrorResponsesWithModel400Response.model_validate(test_error_responses_with_model400_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/TestErrorResponsesWithModel404Response.md b/samples/openapi3/client/petstore/python-httpx/docs/TestErrorResponsesWithModel404Response.md index 1c984f847bf1..d229d30e7b39 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/TestErrorResponsesWithModel404Response.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/TestErrorResponsesWithModel404Response.md @@ -15,14 +15,14 @@ from petstore_api.models.test_error_responses_with_model404_response import Test # TODO update the JSON string below json = "{}" # create an instance of TestErrorResponsesWithModel404Response from a JSON string -test_error_responses_with_model404_response_instance = TestErrorResponsesWithModel404Response.from_json(json) +test_error_responses_with_model404_response_instance = TestErrorResponsesWithModel404Response.model_validate_json(json) # print the JSON string representation of the object -print(TestErrorResponsesWithModel404Response.to_json()) +print(TestErrorResponsesWithModel404Response.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_error_responses_with_model404_response_dict = test_error_responses_with_model404_response_instance.to_dict() +test_error_responses_with_model404_response_dict = test_error_responses_with_model404_response_instance.model_dump(by_alias=True) # create an instance of TestErrorResponsesWithModel404Response from a dict -test_error_responses_with_model404_response_from_dict = TestErrorResponsesWithModel404Response.from_dict(test_error_responses_with_model404_response_dict) +test_error_responses_with_model404_response_from_dict = TestErrorResponsesWithModel404Response.model_validate(test_error_responses_with_model404_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/TestInlineFreeformAdditionalPropertiesRequest.md b/samples/openapi3/client/petstore/python-httpx/docs/TestInlineFreeformAdditionalPropertiesRequest.md index 511132d689be..6fd235e60800 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/TestInlineFreeformAdditionalPropertiesRequest.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/TestInlineFreeformAdditionalPropertiesRequest.md @@ -15,14 +15,14 @@ from petstore_api.models.test_inline_freeform_additional_properties_request impo # TODO update the JSON string below json = "{}" # create an instance of TestInlineFreeformAdditionalPropertiesRequest from a JSON string -test_inline_freeform_additional_properties_request_instance = TestInlineFreeformAdditionalPropertiesRequest.from_json(json) +test_inline_freeform_additional_properties_request_instance = TestInlineFreeformAdditionalPropertiesRequest.model_validate_json(json) # print the JSON string representation of the object -print(TestInlineFreeformAdditionalPropertiesRequest.to_json()) +print(TestInlineFreeformAdditionalPropertiesRequest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_inline_freeform_additional_properties_request_dict = test_inline_freeform_additional_properties_request_instance.to_dict() +test_inline_freeform_additional_properties_request_dict = test_inline_freeform_additional_properties_request_instance.model_dump(by_alias=True) # create an instance of TestInlineFreeformAdditionalPropertiesRequest from a dict -test_inline_freeform_additional_properties_request_from_dict = TestInlineFreeformAdditionalPropertiesRequest.from_dict(test_inline_freeform_additional_properties_request_dict) +test_inline_freeform_additional_properties_request_from_dict = TestInlineFreeformAdditionalPropertiesRequest.model_validate(test_inline_freeform_additional_properties_request_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/TestModelWithEnumDefault.md b/samples/openapi3/client/petstore/python-httpx/docs/TestModelWithEnumDefault.md index 7d46e86deba4..d98d6ad35cb3 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/TestModelWithEnumDefault.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/TestModelWithEnumDefault.md @@ -19,14 +19,14 @@ from petstore_api.models.test_model_with_enum_default import TestModelWithEnumDe # TODO update the JSON string below json = "{}" # create an instance of TestModelWithEnumDefault from a JSON string -test_model_with_enum_default_instance = TestModelWithEnumDefault.from_json(json) +test_model_with_enum_default_instance = TestModelWithEnumDefault.model_validate_json(json) # print the JSON string representation of the object -print(TestModelWithEnumDefault.to_json()) +print(TestModelWithEnumDefault.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_model_with_enum_default_dict = test_model_with_enum_default_instance.to_dict() +test_model_with_enum_default_dict = test_model_with_enum_default_instance.model_dump(by_alias=True) # create an instance of TestModelWithEnumDefault from a dict -test_model_with_enum_default_from_dict = TestModelWithEnumDefault.from_dict(test_model_with_enum_default_dict) +test_model_with_enum_default_from_dict = TestModelWithEnumDefault.model_validate(test_model_with_enum_default_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/TestObjectForMultipartRequestsRequestMarker.md b/samples/openapi3/client/petstore/python-httpx/docs/TestObjectForMultipartRequestsRequestMarker.md index ff0ca9ee00ac..4ef346d455be 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/TestObjectForMultipartRequestsRequestMarker.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/TestObjectForMultipartRequestsRequestMarker.md @@ -15,14 +15,14 @@ from petstore_api.models.test_object_for_multipart_requests_request_marker impor # TODO update the JSON string below json = "{}" # create an instance of TestObjectForMultipartRequestsRequestMarker from a JSON string -test_object_for_multipart_requests_request_marker_instance = TestObjectForMultipartRequestsRequestMarker.from_json(json) +test_object_for_multipart_requests_request_marker_instance = TestObjectForMultipartRequestsRequestMarker.model_validate_json(json) # print the JSON string representation of the object -print(TestObjectForMultipartRequestsRequestMarker.to_json()) +print(TestObjectForMultipartRequestsRequestMarker.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_object_for_multipart_requests_request_marker_dict = test_object_for_multipart_requests_request_marker_instance.to_dict() +test_object_for_multipart_requests_request_marker_dict = test_object_for_multipart_requests_request_marker_instance.model_dump(by_alias=True) # create an instance of TestObjectForMultipartRequestsRequestMarker from a dict -test_object_for_multipart_requests_request_marker_from_dict = TestObjectForMultipartRequestsRequestMarker.from_dict(test_object_for_multipart_requests_request_marker_dict) +test_object_for_multipart_requests_request_marker_from_dict = TestObjectForMultipartRequestsRequestMarker.model_validate(test_object_for_multipart_requests_request_marker_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/Tiger.md b/samples/openapi3/client/petstore/python-httpx/docs/Tiger.md index f1cf2133f0f7..bf096ee0be68 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/Tiger.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/Tiger.md @@ -15,14 +15,14 @@ from petstore_api.models.tiger import Tiger # TODO update the JSON string below json = "{}" # create an instance of Tiger from a JSON string -tiger_instance = Tiger.from_json(json) +tiger_instance = Tiger.model_validate_json(json) # print the JSON string representation of the object -print(Tiger.to_json()) +print(Tiger.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -tiger_dict = tiger_instance.to_dict() +tiger_dict = tiger_instance.model_dump(by_alias=True) # create an instance of Tiger from a dict -tiger_from_dict = Tiger.from_dict(tiger_dict) +tiger_from_dict = Tiger.model_validate(tiger_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/UnnamedDictWithAdditionalModelListProperties.md b/samples/openapi3/client/petstore/python-httpx/docs/UnnamedDictWithAdditionalModelListProperties.md index 68cd00ab0a7a..a8d992c4e033 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/UnnamedDictWithAdditionalModelListProperties.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/UnnamedDictWithAdditionalModelListProperties.md @@ -15,14 +15,14 @@ from petstore_api.models.unnamed_dict_with_additional_model_list_properties impo # TODO update the JSON string below json = "{}" # create an instance of UnnamedDictWithAdditionalModelListProperties from a JSON string -unnamed_dict_with_additional_model_list_properties_instance = UnnamedDictWithAdditionalModelListProperties.from_json(json) +unnamed_dict_with_additional_model_list_properties_instance = UnnamedDictWithAdditionalModelListProperties.model_validate_json(json) # print the JSON string representation of the object -print(UnnamedDictWithAdditionalModelListProperties.to_json()) +print(UnnamedDictWithAdditionalModelListProperties.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -unnamed_dict_with_additional_model_list_properties_dict = unnamed_dict_with_additional_model_list_properties_instance.to_dict() +unnamed_dict_with_additional_model_list_properties_dict = unnamed_dict_with_additional_model_list_properties_instance.model_dump(by_alias=True) # create an instance of UnnamedDictWithAdditionalModelListProperties from a dict -unnamed_dict_with_additional_model_list_properties_from_dict = UnnamedDictWithAdditionalModelListProperties.from_dict(unnamed_dict_with_additional_model_list_properties_dict) +unnamed_dict_with_additional_model_list_properties_from_dict = UnnamedDictWithAdditionalModelListProperties.model_validate(unnamed_dict_with_additional_model_list_properties_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/UnnamedDictWithAdditionalStringListProperties.md b/samples/openapi3/client/petstore/python-httpx/docs/UnnamedDictWithAdditionalStringListProperties.md index 045b0e22ad09..44aa893d69a7 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/UnnamedDictWithAdditionalStringListProperties.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/UnnamedDictWithAdditionalStringListProperties.md @@ -15,14 +15,14 @@ from petstore_api.models.unnamed_dict_with_additional_string_list_properties imp # TODO update the JSON string below json = "{}" # create an instance of UnnamedDictWithAdditionalStringListProperties from a JSON string -unnamed_dict_with_additional_string_list_properties_instance = UnnamedDictWithAdditionalStringListProperties.from_json(json) +unnamed_dict_with_additional_string_list_properties_instance = UnnamedDictWithAdditionalStringListProperties.model_validate_json(json) # print the JSON string representation of the object -print(UnnamedDictWithAdditionalStringListProperties.to_json()) +print(UnnamedDictWithAdditionalStringListProperties.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -unnamed_dict_with_additional_string_list_properties_dict = unnamed_dict_with_additional_string_list_properties_instance.to_dict() +unnamed_dict_with_additional_string_list_properties_dict = unnamed_dict_with_additional_string_list_properties_instance.model_dump(by_alias=True) # create an instance of UnnamedDictWithAdditionalStringListProperties from a dict -unnamed_dict_with_additional_string_list_properties_from_dict = UnnamedDictWithAdditionalStringListProperties.from_dict(unnamed_dict_with_additional_string_list_properties_dict) +unnamed_dict_with_additional_string_list_properties_from_dict = UnnamedDictWithAdditionalStringListProperties.model_validate(unnamed_dict_with_additional_string_list_properties_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/UploadFileWithAdditionalPropertiesRequestObject.md b/samples/openapi3/client/petstore/python-httpx/docs/UploadFileWithAdditionalPropertiesRequestObject.md index 141027780371..096740ca96c2 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/UploadFileWithAdditionalPropertiesRequestObject.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/UploadFileWithAdditionalPropertiesRequestObject.md @@ -16,14 +16,14 @@ from petstore_api.models.upload_file_with_additional_properties_request_object i # TODO update the JSON string below json = "{}" # create an instance of UploadFileWithAdditionalPropertiesRequestObject from a JSON string -upload_file_with_additional_properties_request_object_instance = UploadFileWithAdditionalPropertiesRequestObject.from_json(json) +upload_file_with_additional_properties_request_object_instance = UploadFileWithAdditionalPropertiesRequestObject.model_validate_json(json) # print the JSON string representation of the object -print(UploadFileWithAdditionalPropertiesRequestObject.to_json()) +print(UploadFileWithAdditionalPropertiesRequestObject.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -upload_file_with_additional_properties_request_object_dict = upload_file_with_additional_properties_request_object_instance.to_dict() +upload_file_with_additional_properties_request_object_dict = upload_file_with_additional_properties_request_object_instance.model_dump(by_alias=True) # create an instance of UploadFileWithAdditionalPropertiesRequestObject from a dict -upload_file_with_additional_properties_request_object_from_dict = UploadFileWithAdditionalPropertiesRequestObject.from_dict(upload_file_with_additional_properties_request_object_dict) +upload_file_with_additional_properties_request_object_from_dict = UploadFileWithAdditionalPropertiesRequestObject.model_validate(upload_file_with_additional_properties_request_object_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/User.md b/samples/openapi3/client/petstore/python-httpx/docs/User.md index c45d26d27043..1986137ecc70 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/User.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/User.md @@ -22,14 +22,14 @@ from petstore_api.models.user import User # TODO update the JSON string below json = "{}" # create an instance of User from a JSON string -user_instance = User.from_json(json) +user_instance = User.model_validate_json(json) # print the JSON string representation of the object -print(User.to_json()) +print(User.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -user_dict = user_instance.to_dict() +user_dict = user_instance.model_dump(by_alias=True) # create an instance of User from a dict -user_from_dict = User.from_dict(user_dict) +user_from_dict = User.model_validate(user_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/docs/WithNestedOneOf.md b/samples/openapi3/client/petstore/python-httpx/docs/WithNestedOneOf.md index e7bbbc28fc2d..63b0f83540d1 100644 --- a/samples/openapi3/client/petstore/python-httpx/docs/WithNestedOneOf.md +++ b/samples/openapi3/client/petstore/python-httpx/docs/WithNestedOneOf.md @@ -17,14 +17,14 @@ from petstore_api.models.with_nested_one_of import WithNestedOneOf # TODO update the JSON string below json = "{}" # create an instance of WithNestedOneOf from a JSON string -with_nested_one_of_instance = WithNestedOneOf.from_json(json) +with_nested_one_of_instance = WithNestedOneOf.model_validate_json(json) # print the JSON string representation of the object -print(WithNestedOneOf.to_json()) +print(WithNestedOneOf.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -with_nested_one_of_dict = with_nested_one_of_instance.to_dict() +with_nested_one_of_dict = with_nested_one_of_instance.model_dump(by_alias=True) # create an instance of WithNestedOneOf from a dict -with_nested_one_of_from_dict = WithNestedOneOf.from_dict(with_nested_one_of_dict) +with_nested_one_of_from_dict = WithNestedOneOf.model_validate(with_nested_one_of_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/another_fake_api.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/another_fake_api.py index b1d830a31eef..0d456a35c3a4 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/another_fake_api.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/another_fake_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field from typing_extensions import Annotated diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/default_api.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/default_api.py index bf2c62a53aed..4bca18df4343 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/default_api.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/default_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from petstore_api.models.foo_get_default_response import FooGetDefaultResponse diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/fake_api.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/fake_api.py index 3bb7f0218ef8..04b92f2c140d 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/fake_api.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/fake_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from datetime import date, datetime from pydantic import Field, StrictBool, StrictBytes, StrictInt, StrictStr, field_validator diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/fake_classname_tags123_api.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/fake_classname_tags123_api.py index 58c76f1daaf3..53fb3b184e87 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/fake_classname_tags123_api.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/fake_classname_tags123_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field from typing_extensions import Annotated diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/import_test_datetime_api.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/import_test_datetime_api.py index bb82beefad78..bf38df779595 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/import_test_datetime_api.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/import_test_datetime_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from datetime import datetime diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/pet_api.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/pet_api.py index 6f4f8092ea56..f4058216394b 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/pet_api.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/pet_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field, StrictBytes, StrictInt, StrictStr, field_validator from typing import List, Optional, Tuple, Union diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/store_api.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/store_api.py index dc8d8de5c645..48eedc258b3d 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/store_api.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/store_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field, StrictInt, StrictStr from typing import Dict diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/user_api.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/user_api.py index 4e6d222045bf..683dfadd5e3b 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/api/user_api.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/api/user_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field, StrictStr from typing import List diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py index de233385434d..a0054a46fbdf 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py @@ -315,7 +315,7 @@ def response_deserialize( return_data = self.__deserialize_file(response_data) elif response_type is not None: match = None - content_type = response_data.headers.get('content-type') + content_type = response_data.getheader('content-type') if content_type is not None: match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type) encoding = match.group(1) if match else "utf-8" @@ -332,7 +332,7 @@ def response_deserialize( return ApiResponse( status_code = response_data.status, data = return_data, - headers = response_data.headers, + headers = response_data.getheaders(), raw_data = response_data.data ) @@ -383,13 +383,10 @@ def sanitize_for_serialization(self, obj): # and attributes which value is not None. # Convert attribute name to json key in # model definition for request. - if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')): - obj_dict = obj.to_dict() - else: - obj_dict = obj.__dict__ + obj_dict = obj.model_dump(by_alias=True, exclude_none=True) if isinstance(obj_dict, list): - # here we handle instances that can either be a list or something else, and only became a real list by calling to_dict() + # here we handle instances that can either be a list or something else, and only became a real list by calling model_dump(by_alias=True) return self.sanitize_for_serialization(obj_dict) return { @@ -711,7 +708,7 @@ def __deserialize_file(self, response): os.close(fd) os.remove(path) - content_disposition = response.headers.get("Content-Disposition") + content_disposition = response.getheader("Content-Disposition") if content_disposition: m = re.search( r'filename=[\'"]?([^\'"\s]+)[\'"]?', @@ -811,4 +808,4 @@ def __deserialize_model(self, data, klass): :return: model object. """ - return klass.from_dict(data) + return klass.model_validate(data) diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py index 8a5ebdc1143f..b136a2a6d1a7 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/configuration.py @@ -18,8 +18,7 @@ import logging from logging import FileHandler import sys -from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union -from typing_extensions import NotRequired, Self +from typing import Any, ClassVar, Dict, List, Literal, NotRequired, Optional, TypedDict, Union, Self from petstore_api.signing import HttpSigningConfiguration diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/exceptions.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/exceptions.py index cb0ecfbf7018..a5d2c10c55be 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/exceptions.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/exceptions.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """ OpenAPI Petstore @@ -11,8 +9,8 @@ Do not edit the class manually. """ # noqa: E501 -from typing import Any, Optional -from typing_extensions import Self + +from typing import Any, Optional, Self class OpenApiException(Exception): """The base exception class for all OpenAPIExceptions""" @@ -104,9 +102,9 @@ def __init__(self, msg, path_to_item=None) -> None: class ApiException(OpenApiException): def __init__( - self, - status=None, - reason=None, + self, + status=None, + reason=None, http_resp=None, *, body: Optional[str] = None, @@ -128,14 +126,14 @@ def __init__( self.body = http_resp.data.decode('utf-8') except Exception: pass - self.headers = http_resp.headers + self.headers = http_resp.getheaders() @classmethod def from_response( - cls, - *, - http_resp, - body: Optional[str], + cls, + *, + http_resp, + body: Optional[str], data: Optional[Any], ) -> Self: if http_resp.status == 400: @@ -169,11 +167,8 @@ def __str__(self): error_message += "HTTP response headers: {0}\n".format( self.headers) - if self.body: - error_message += "HTTP response body: {0}\n".format(self.body) - - if self.data: - error_message += "HTTP response data: {0}\n".format(self.data) + if self.data or self.body: + error_message += "HTTP response body: {0}\n".format(self.data or self.body) return error_message diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_any_type.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_any_type.py index 291b5e55e353..9986695fc1ec 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_any_type.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_any_type.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesAnyType(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesAnyType from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesAnyType from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_class.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_class.py index 4b2cc457e499..8b59d27c9ff6 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_class.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesClass(BaseModel): """ @@ -41,49 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "map_property": obj.get("map_property"), - "map_of_map_property": obj.get("map_of_map_property") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_object.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_object.py index 00707c3c4818..a514124192f5 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_object.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_object.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesObject(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesObject from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesObject from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_with_description_only.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_with_description_only.py index d8049b519ed0..a01f7169f6a4 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_with_description_only.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_with_description_only.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesWithDescriptionOnly(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesWithDescriptionOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesWithDescriptionOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/all_of_super_model.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/all_of_super_model.py index 03f554592935..e14106518d97 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/all_of_super_model.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/all_of_super_model.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AllOfSuperModel(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AllOfSuperModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AllOfSuperModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_name": obj.get("_name") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/all_of_with_single_ref.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/all_of_with_single_ref.py index 44c7da9114a8..223e5c6a765d 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/all_of_with_single_ref.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/all_of_with_single_ref.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.single_ref_type import SingleRefType -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AllOfWithSingleRef(BaseModel): """ @@ -42,49 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AllOfWithSingleRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AllOfWithSingleRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "username": obj.get("username"), - "SingleRefType": obj.get("SingleRefType") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/animal.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/animal.py index 56bec73a9ccd..9646242f3df6 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/animal.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/animal.py @@ -20,8 +20,8 @@ from importlib import import_module from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional, Union -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -64,48 +64,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[Cat, Dog]]: - """Create an instance of Animal from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[Cat, Dog]]: - """Create an instance of Animal from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'Cat': - return import_module("petstore_api.models.cat").Cat.from_dict(obj) - if object_type == 'Dog': - return import_module("petstore_api.models.dog").Dog.from_dict(obj) - - raise ValueError("Animal failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_color.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_color.py index f6d277e79498..8e0c6051da74 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_color.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_color.py @@ -20,137 +20,30 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import List, Optional from typing_extensions import Annotated -from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict -from typing_extensions import Literal, Self -from pydantic import Field +from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict, Literal, Self +from pydantic import Field, RootModel ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"] -class AnyOfColor(BaseModel): + +class AnyOfColor(RootModel[Union[List[int], str]]): """ Any of RGB array, RGBA array, or hex string. """ - # data type: List[int] - 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_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: - actual_instance: Optional[Union[List[int], str]] = None - else: - actual_instance: Any = None - any_of_schemas: Set[str] = { "List[int]", "str" } - - model_config = { - "validate_assignment": True, - "protected_namespaces": (), - } - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_anyof(cls, v): - instance = AnyOfColor.model_construct() - error_messages = [] - # validate data type: List[int] - try: - instance.anyof_schema_1_validator = v - return v - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: List[int] - try: - instance.anyof_schema_2_validator = v - return v - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: str - try: - instance.anyof_schema_3_validator = v - return v - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - if error_messages: - # no match - raise ValueError("No match found when setting the actual_instance in AnyOfColor with anyOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - # deserialize data into List[int] - try: - # validation - instance.anyof_schema_1_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.anyof_schema_1_validator - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into List[int] - try: - # validation - instance.anyof_schema_2_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.anyof_schema_2_validator - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into str - try: - # validation - instance.anyof_schema_3_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.anyof_schema_3_validator - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if error_messages: - # no match - raise ValueError("No match found when deserializing the JSON string into AnyOfColor with anyOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + root: Union[List[int], str] = Field( + ... + ) + + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_pig.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_pig.py index c949e136f415..df3bae10d3a6 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_pig.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_pig.py @@ -21,114 +21,30 @@ from typing import Optional from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig -from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict -from typing_extensions import Literal, Self -from pydantic import Field +from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict, Literal, Self +from pydantic import Field, RootModel ANYOFPIG_ANY_OF_SCHEMAS = ["BasquePig", "DanishPig"] -class AnyOfPig(BaseModel): + +class AnyOfPig(RootModel[Union[BasquePig, DanishPig]]): """ AnyOfPig """ - # data type: BasquePig - anyof_schema_1_validator: Optional[BasquePig] = None - # data type: DanishPig - anyof_schema_2_validator: Optional[DanishPig] = None - if TYPE_CHECKING: - actual_instance: Optional[Union[BasquePig, DanishPig]] = None - else: - actual_instance: Any = None - any_of_schemas: Set[str] = { "BasquePig", "DanishPig" } - - model_config = { - "validate_assignment": True, - "protected_namespaces": (), - } - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_anyof(cls, v): - instance = AnyOfPig.model_construct() - error_messages = [] - # validate data type: BasquePig - if not isinstance(v, BasquePig): - error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`") - else: - return v - - # validate data type: DanishPig - if not isinstance(v, DanishPig): - error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`") - else: - return v - - if error_messages: - # no match - raise ValueError("No match found when setting the actual_instance in AnyOfPig with anyOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - # anyof_schema_1_validator: Optional[BasquePig] = None - try: - instance.actual_instance = BasquePig.from_json(json_str) - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # anyof_schema_2_validator: Optional[DanishPig] = None - try: - instance.actual_instance = DanishPig.from_json(json_str) - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if error_messages: - # no match - raise ValueError("No match found when deserializing the JSON string into AnyOfPig with anyOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], BasquePig, DanishPig]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + root: Union[BasquePig, DanishPig] = Field( + ... + ) + + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_of_array_of_model.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_of_array_of_model.py index 4f8eeda66c30..c5204e2fb306 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_of_array_of_model.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayOfArrayOfModel(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in another_property (list of list) - _items = [] - if self.another_property: - for _item_another_property in self.another_property: - if _item_another_property: - _items.append( - [_inner_item.to_dict() for _inner_item in _item_another_property if _inner_item is not None] - ) - _dict['another_property'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "another_property": [ - [Tag.from_dict(_inner_item) for _inner_item in _item] - for _item in obj["another_property"] - ] if obj.get("another_property") is not None else None - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_of_array_of_number_only.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_of_array_of_number_only.py index 02b0f6d657f4..2374c09d8bf0 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_of_array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_of_array_of_number_only.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayOfArrayOfNumberOnly(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfNumberOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfNumberOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "ArrayArrayNumber": obj.get("ArrayArrayNumber") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_of_number_only.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_of_number_only.py index b22632b0ce4d..16545c13d9f2 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_of_number_only.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayOfNumberOnly(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayOfNumberOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayOfNumberOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "ArrayNumber": obj.get("ArrayNumber") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_test.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_test.py index e8f8acf67cc0..61b4fb891399 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_test.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/array_test.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from typing_extensions import Annotated from petstore_api.models.read_only_first import ReadOnlyFirst -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayTest(BaseModel): """ @@ -45,63 +45,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in array_array_of_model (list of list) - _items = [] - if self.array_array_of_model: - for _item_array_array_of_model in self.array_array_of_model: - if _item_array_array_of_model: - _items.append( - [_inner_item.to_dict() for _inner_item in _item_array_array_of_model if _inner_item is not None] - ) - _dict['array_array_of_model'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "array_of_string": obj.get("array_of_string"), - "array_of_nullable_float": obj.get("array_of_nullable_float"), - "array_array_of_integer": obj.get("array_array_of_integer"), - "array_array_of_model": [ - [ReadOnlyFirst.from_dict(_inner_item) for _inner_item in _item] - for _item in obj["array_array_of_model"] - ] if obj.get("array_array_of_model") is not None else None - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/base_discriminator.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/base_discriminator.py index f13c270b56b5..b0a9914bb2bf 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/base_discriminator.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/base_discriminator.py @@ -20,8 +20,8 @@ from importlib import import_module from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional, Union -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -63,48 +63,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[PrimitiveString, Info]]: - """Create an instance of BaseDiscriminator from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[PrimitiveString, Info]]: - """Create an instance of BaseDiscriminator from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'PrimitiveString': - return import_module("petstore_api.models.primitive_string").PrimitiveString.from_dict(obj) - if object_type == 'Info': - return import_module("petstore_api.models.info").Info.from_dict(obj) - - raise ValueError("BaseDiscriminator failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/basque_pig.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/basque_pig.py index a1f32a6edcfc..78b6e31c6313 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/basque_pig.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/basque_pig.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class BasquePig(BaseModel): """ @@ -41,49 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of BasquePig from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of BasquePig from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "color": obj.get("color") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/bathing.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/bathing.py index 088e6ad3b873..f6336229e61a 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/bathing.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/bathing.py @@ -19,15 +19,21 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Bathing(BaseModel): """ Bathing """ # noqa: E501 - task_name: StrictStr - function_name: StrictStr + task_name: Literal['cleaning_deep'] = Field( + ..., + description="task_name of the Bathing" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Bathing" + ) content: StrictStr __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -56,50 +62,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Bathing from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Bathing from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "task_name": obj.get("task_name"), - "function_name": obj.get("function_name"), - "content": obj.get("content") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/capitalization.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/capitalization.py index b3c20af54440..0145e1b19bea 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/capitalization.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/capitalization.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Capitalization(BaseModel): """ @@ -45,53 +45,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Capitalization from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Capitalization from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "smallCamel": obj.get("smallCamel"), - "CapitalCamel": obj.get("CapitalCamel"), - "small_Snake": obj.get("small_Snake"), - "Capital_Snake": obj.get("Capital_Snake"), - "SCA_ETH_Flow_Points": obj.get("SCA_ETH_Flow_Points"), - "ATT_NAME": obj.get("ATT_NAME") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/cat.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/cat.py index 0c2c9788dca3..77ec7bf1e9a7 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/cat.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/cat.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict, StrictBool from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.animal import Animal -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Cat(Animal): """ @@ -41,50 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Cat from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Cat from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "color": obj.get("color") if obj.get("color") is not None else 'red', - "declawed": obj.get("declawed") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/category.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/category.py index dcc6247b5ac7..9e05503386fc 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/category.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/category.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Category(BaseModel): """ @@ -41,49 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Category from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Category from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") if obj.get("name") is not None else 'default-name' - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/circular_all_of_ref.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/circular_all_of_ref.py index f98247ae0fb5..b3805c6c0a72 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/circular_all_of_ref.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/circular_all_of_ref.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class CircularAllOfRef(BaseModel): """ @@ -41,57 +41,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of CircularAllOfRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in second_circular_all_of_ref (list) - _items = [] - if self.second_circular_all_of_ref: - for _item_second_circular_all_of_ref in self.second_circular_all_of_ref: - if _item_second_circular_all_of_ref: - _items.append(_item_second_circular_all_of_ref.to_dict()) - _dict['secondCircularAllOfRef'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of CircularAllOfRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_name": obj.get("_name"), - "secondCircularAllOfRef": [SecondCircularAllOfRef.from_dict(_item) for _item in obj["secondCircularAllOfRef"]] if obj.get("secondCircularAllOfRef") is not None else None - }) - return _obj from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/circular_reference_model.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/circular_reference_model.py index 3b2854caaac2..ef203d8a9bb9 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/circular_reference_model.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/circular_reference_model.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class CircularReferenceModel(BaseModel): """ @@ -41,53 +41,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of CircularReferenceModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of nested - if self.nested: - _dict['nested'] = self.nested.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of CircularReferenceModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "nested": FirstRef.from_dict(obj["nested"]) if obj.get("nested") is not None else None - }) - return _obj from petstore_api.models.first_ref import FirstRef # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/class_model.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/class_model.py index 6def0e52d146..b6e82dcd7a53 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/class_model.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/class_model.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ClassModel(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ClassModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ClassModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_class": obj.get("_class") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/client.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/client.py index 1c12c9a145c8..2bd0f1eb7995 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/client.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/client.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Client(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Client from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Client from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "client": obj.get("client") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/color.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/color.py index bb740fb597d4..7fe333c7a3b9 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/color.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/color.py @@ -18,150 +18,27 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Any, List, Optional from typing_extensions import Annotated -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self COLOR_ONE_OF_SCHEMAS = ["List[int]", "str"] -class Color(BaseModel): +class Color(RootModel[Union[List[int], str]]): """ 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_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_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: Set[str] = { "List[int]", "str" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[List[int], str] = Field( + ... ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - if v is None: - return v - - instance = Color.model_construct() - error_messages = [] - match = 0 - # validate data type: List[int] - try: - instance.oneof_schema_1_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: List[int] - try: - instance.oneof_schema_2_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: str - try: - instance.oneof_schema_3_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: Optional[str]) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - if json_str is None: - return instance - - error_messages = [] - match = 0 - - # deserialize data into List[int] - try: - # validation - instance.oneof_schema_1_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_1_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into List[int] - try: - # validation - instance.oneof_schema_2_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_2_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into str - try: - # validation - instance.oneof_schema_3_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_3_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/creature.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/creature.py index 2ed3aa42bf99..304672d67040 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/creature.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/creature.py @@ -21,8 +21,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Union from petstore_api.models.creature_info import CreatureInfo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -64,49 +64,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[HuntingDog]]: - """Create an instance of Creature from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of info - if self.info: - _dict['info'] = self.info.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[HuntingDog]]: - """Create an instance of Creature from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'HuntingDog': - return import_module("petstore_api.models.hunting_dog").HuntingDog.from_dict(obj) - - raise ValueError("Creature failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/creature_info.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/creature_info.py index e7927446c238..2d81c0654e7b 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/creature_info.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/creature_info.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class CreatureInfo(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of CreatureInfo from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of CreatureInfo from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/danish_pig.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/danish_pig.py index 061e16a486a5..1f1abc8848a4 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/danish_pig.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/danish_pig.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DanishPig(BaseModel): """ @@ -41,49 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DanishPig from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DanishPig from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "size": obj.get("size") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/data_output_format.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/data_output_format.py index ee3df76c5169..e32ebe9a5ee4 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/data_output_format.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/data_output_format.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class DataOutputFormat(StrEnum): -class DataOutputFormat(str, Enum): """ DataOutputFormat """ - """ - allowed enum values - """ + # Allowed enum values JSON = 'JSON' CSV = 'CSV' XML = 'XML' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of DataOutputFormat from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/deprecated_object.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/deprecated_object.py index bb4747a1e18c..f76e4520350b 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/deprecated_object.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/deprecated_object.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DeprecatedObject(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DeprecatedObject from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DeprecatedObject from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/discriminator_all_of_sub.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/discriminator_all_of_sub.py index 2e8d4a6d7633..a7c1d0abd705 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/discriminator_all_of_sub.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/discriminator_all_of_sub.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict from typing import Any, ClassVar, Dict, List from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DiscriminatorAllOfSub(DiscriminatorAllOfSuper): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DiscriminatorAllOfSub from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DiscriminatorAllOfSub from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "elementType": obj.get("elementType") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/discriminator_all_of_super.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/discriminator_all_of_super.py index ee910f90ea69..44b5ac27198f 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/discriminator_all_of_super.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/discriminator_all_of_super.py @@ -20,8 +20,8 @@ from importlib import import_module from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Union -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -62,46 +62,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[DiscriminatorAllOfSub]]: - """Create an instance of DiscriminatorAllOfSuper from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[DiscriminatorAllOfSub]]: - """Create an instance of DiscriminatorAllOfSuper from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'DiscriminatorAllOfSub': - return import_module("petstore_api.models.discriminator_all_of_sub").DiscriminatorAllOfSub.from_dict(obj) - - raise ValueError("DiscriminatorAllOfSuper failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/dog.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/dog.py index a0f4ed786b4e..036575e157f3 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/dog.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/dog.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.animal import Animal -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Dog(Animal): """ @@ -41,50 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Dog from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Dog from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "color": obj.get("color") if obj.get("color") is not None else 'red', - "breed": obj.get("breed") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/dummy_model.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/dummy_model.py index 3050cbf66dc4..82fd4e04c987 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/dummy_model.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/dummy_model.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DummyModel(BaseModel): """ @@ -41,53 +41,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DummyModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of self_ref - if self.self_ref: - _dict['self_ref'] = self.self_ref.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DummyModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "category": obj.get("category"), - "self_ref": SelfReferenceModel.from_dict(obj["self_ref"]) if obj.get("self_ref") is not None else None - }) - return _obj from petstore_api.models.self_reference_model import SelfReferenceModel # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_arrays.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_arrays.py index 68ceb962b03e..9df2ad1d4957 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_arrays.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_arrays.py @@ -19,15 +19,17 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class EnumArrays(BaseModel): """ EnumArrays """ # noqa: E501 - just_symbol: Optional[StrictStr] = None - array_enum: Optional[List[StrictStr]] = None + just_symbol: Optional[Just_symbolEnum] = Field( + None, + description="just_symbol of the EnumArrays" + ) __properties: ClassVar[List[str]] = ["just_symbol", "array_enum"] @field_validator('just_symbol') @@ -62,49 +64,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of EnumArrays from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of EnumArrays from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "just_symbol": obj.get("just_symbol"), - "array_enum": obj.get("array_enum") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_class.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_class.py index 1ba5af8036df..b4e61d237db8 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_class.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_class.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumClass(StrEnum): -class EnumClass(str, Enum): """ EnumClass """ - """ - allowed enum values - """ + # Allowed enum values ABC = '_abc' MINUS_EFG = '-efg' LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS = '(xyz)' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumClass from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_number_vendor_ext.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_number_vendor_ext.py index 5588de5c7043..91d2161cbc6d 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_number_vendor_ext.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_number_vendor_ext.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumNumberVendorExt(IntEnum): -class EnumNumberVendorExt(int, Enum): """ EnumNumberVendorExt """ - """ - allowed enum values - """ + # Allowed enum values FortyTwo = 42 Eigtheen = 18 FiftySix = 56 @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumNumberVendorExt from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_ref_with_default_value.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_ref_with_default_value.py index 9d97e3fd16d4..84065f0b77dd 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_ref_with_default_value.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_ref_with_default_value.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.data_output_format import DataOutputFormat -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class EnumRefWithDefaultValue(BaseModel): """ @@ -41,48 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of EnumRefWithDefaultValue from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of EnumRefWithDefaultValue from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "report_format": obj.get("report_format") if obj.get("report_format") is not None else DataOutputFormat.JSON - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_string1.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_string1.py index 678b4e12661f..d6970ff8346f 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_string1.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_string1.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumString1(StrEnum): -class EnumString1(str, Enum): """ EnumString1 """ - """ - allowed enum values - """ + # Allowed enum values A = 'a' B = 'b' @@ -34,4 +32,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumString1 from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_string2.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_string2.py index a959f554e0af..c4fc722f826a 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_string2.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_string2.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumString2(StrEnum): -class EnumString2(str, Enum): """ EnumString2 """ - """ - allowed enum values - """ + # Allowed enum values C = 'c' D = 'd' @@ -34,4 +32,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumString2 from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_string_vendor_ext.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_string_vendor_ext.py index 821812e9b088..175ace79326f 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_string_vendor_ext.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_string_vendor_ext.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumStringVendorExt(StrEnum): -class EnumStringVendorExt(str, Enum): """ EnumStringVendorExt """ - """ - allowed enum values - """ + # Allowed enum values FOO_XEnumVarname = 'FOO' BarVar_XEnumVarname = 'Bar' bazVar_XEnumVarname = 'baz' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumStringVendorExt from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_test.py index b7e6ec36230f..b37d73101dc6 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_test.py @@ -25,20 +25,41 @@ from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue from petstore_api.models.outer_enum_integer import OuterEnumInteger from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntegerDefaultValue -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class EnumTest(BaseModel): """ EnumTest """ # noqa: E501 - enum_string: Optional[StrictStr] = None - enum_string_required: StrictStr - enum_integer_default: Optional[StrictInt] = 5 - enum_integer: Optional[StrictInt] = None - enum_number: Optional[float] = None - enum_string_single_member: Optional[StrictStr] = None - enum_integer_single_member: Optional[StrictInt] = None + enum_string: Optional[Enum_stringEnum] = Field( + None, + description="enum_string of the EnumTest" + ) + enum_string_required: Enum_string_requiredEnum = Field( + ..., + description="enum_string_required of the EnumTest" + ) + enum_integer_default: Optional[Enum_integer_defaultEnum] = Field( + None, + description="enum_integer_default of the EnumTest" + ) + enum_integer: Optional[Enum_integerEnum] = Field( + None, + description="enum_integer of the EnumTest" + ) + enum_number: Optional[Enum_numberEnum] = Field( + None, + description="enum_number of the EnumTest" + ) + enum_string_single_member: Literal['abc'] = Field( + None, + description="enum_string_single_member of the EnumTest" + ) + enum_integer_single_member: Literal['100'] = Field( + None, + description="enum_integer_single_member of the EnumTest" + ) outer_enum: Optional[OuterEnum] = Field(default=None, alias="outerEnum") outer_enum_integer: Optional[OuterEnumInteger] = Field(default=None, alias="outerEnumInteger") outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=OuterEnumDefaultValue.PLACED, alias="outerEnumDefaultValue") @@ -125,65 +146,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of EnumTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # set to None if outer_enum (nullable) is None - # 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of EnumTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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, - "enum_integer": obj.get("enum_integer"), - "enum_number": obj.get("enum_number"), - "enum_string_single_member": obj.get("enum_string_single_member"), - "enum_integer_single_member": obj.get("enum_integer_single_member"), - "outerEnum": obj.get("outerEnum"), - "outerEnumInteger": obj.get("outerEnumInteger"), - "outerEnumDefaultValue": obj.get("outerEnumDefaultValue") if obj.get("outerEnumDefaultValue") is not None else OuterEnumDefaultValue.PLACED, - "outerEnumIntegerDefaultValue": obj.get("outerEnumIntegerDefaultValue") if obj.get("outerEnumIntegerDefaultValue") is not None else OuterEnumIntegerDefaultValue.NUMBER_0, - "enumNumberVendorExt": obj.get("enumNumberVendorExt"), - "enumStringVendorExt": obj.get("enumStringVendorExt") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/feeding.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/feeding.py index 1183b314fdd0..6064c0ac4b80 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/feeding.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/feeding.py @@ -19,15 +19,21 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Feeding(BaseModel): """ Feeding """ # noqa: E501 - task_name: StrictStr - function_name: StrictStr + task_name: Literal['cleaning'] = Field( + ..., + description="task_name of the Feeding" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Feeding" + ) content: StrictStr __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -56,50 +62,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Feeding from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Feeding from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "task_name": obj.get("task_name"), - "function_name": obj.get("function_name"), - "content": obj.get("content") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/file.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/file.py index 0ecacf44bb8e..f433bf9d4fe0 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/file.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/file.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class File(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of File from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of File from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "sourceURI": obj.get("sourceURI") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/file_schema_test_class.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/file_schema_test_class.py index c533c0777b24..98039554d624 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/file_schema_test_class.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/file_schema_test_class.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.file import File -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FileSchemaTestClass(BaseModel): """ @@ -42,59 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FileSchemaTestClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of file - if self.file: - _dict['file'] = self.file.to_dict() - # override the default output from pydantic by calling `to_dict()` of each item in files (list) - _items = [] - if self.files: - for _item_files in self.files: - if _item_files: - _items.append(_item_files.to_dict()) - _dict['files'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FileSchemaTestClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "file": File.from_dict(obj["file"]) if obj.get("file") is not None else None, - "files": [File.from_dict(_item) for _item in obj["files"]] if obj.get("files") is not None else None - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/first_ref.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/first_ref.py index 6aa0f722d874..07dd1a27b6b6 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/first_ref.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/first_ref.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FirstRef(BaseModel): """ @@ -41,53 +41,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FirstRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of self_ref - if self.self_ref: - _dict['self_ref'] = self.self_ref.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FirstRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "category": obj.get("category"), - "self_ref": SecondRef.from_dict(obj["self_ref"]) if obj.get("self_ref") is not None else None - }) - return _obj from petstore_api.models.second_ref import SecondRef # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/foo.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/foo.py index 67b29f1ab87c..2e09049eba3a 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/foo.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/foo.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Foo(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Foo from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Foo from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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-httpx/petstore_api/models/foo_get_default_response.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/foo_get_default_response.py index ae191aad80a8..8303a4f631a5 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/foo_get_default_response.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/foo_get_default_response.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.foo import Foo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FooGetDefaultResponse(BaseModel): """ @@ -41,51 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FooGetDefaultResponse from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of string - if self.string: - _dict['string'] = self.string.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FooGetDefaultResponse from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "string": Foo.from_dict(obj["string"]) if obj.get("string") is not None else None - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/format_test.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/format_test.py index 8d70a96f3a7c..421e8b67b534 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/format_test.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/format_test.py @@ -23,8 +23,8 @@ from typing import Any, ClassVar, Dict, List, Optional, Tuple, Union from typing_extensions import Annotated from uuid import UUID -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FormatTest(BaseModel): """ @@ -100,64 +100,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FormatTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FormatTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "integer": obj.get("integer"), - "int32": obj.get("int32"), - "int64": obj.get("int64"), - "number": obj.get("number"), - "float": obj.get("float"), - "double": obj.get("double"), - "decimal": obj.get("decimal"), - "string": obj.get("string"), - "string_with_double_quote_pattern": obj.get("string_with_double_quote_pattern"), - "byte": obj.get("byte"), - "binary": obj.get("binary"), - "date": obj.get("date"), - "dateTime": obj.get("dateTime"), - "uuid": obj.get("uuid"), - "password": obj.get("password"), - "pattern_with_digits": obj.get("pattern_with_digits"), - "pattern_with_digits_and_delimiter": obj.get("pattern_with_digits_and_delimiter") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/has_only_read_only.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/has_only_read_only.py index 2137bc880484..957a9bd0d924 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/has_only_read_only.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/has_only_read_only.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class HasOnlyReadOnly(BaseModel): """ @@ -41,53 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of HasOnlyReadOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * OpenAPI `readOnly` fields are excluded. - * OpenAPI `readOnly` fields are excluded. - """ - excluded_fields: Set[str] = set([ - "bar", - "foo", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of HasOnlyReadOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "bar": obj.get("bar"), - "foo": obj.get("foo") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/health_check_result.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/health_check_result.py index 4dbdd852097f..914aea7237e6 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/health_check_result.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/health_check_result.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class HealthCheckResult(BaseModel): """ @@ -40,53 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of HealthCheckResult from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # set to None if nullable_message (nullable) is None - # 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of HealthCheckResult from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "NullableMessage": obj.get("NullableMessage") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/hunting_dog.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/hunting_dog.py index cd678616f62f..f699b1197d7d 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/hunting_dog.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/hunting_dog.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.creature import Creature from petstore_api.models.creature_info import CreatureInfo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class HuntingDog(Creature): """ @@ -42,53 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of HuntingDog from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of info - if self.info: - _dict['info'] = self.info.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of HuntingDog from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "info": CreatureInfo.from_dict(obj["info"]) if obj.get("info") is not None else None, - "type": obj.get("type"), - "isTrained": obj.get("isTrained") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/info.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/info.py index 5a15b5f9f52f..342c71caf992 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/info.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/info.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.base_discriminator import BaseDiscriminator -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Info(BaseDiscriminator): """ @@ -41,52 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Info from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of val - if self.val: - _dict['val'] = self.val.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Info from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_typeName": obj.get("_typeName"), - "val": BaseDiscriminator.from_dict(obj["val"]) if obj.get("val") is not None else None - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/inner_dict_with_property.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/inner_dict_with_property.py index 27816b995f53..67a9824abe1d 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/inner_dict_with_property.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/inner_dict_with_property.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class InnerDictWithProperty(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of InnerDictWithProperty from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of InnerDictWithProperty from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "aProperty": obj.get("aProperty") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/input_all_of.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/input_all_of.py index 63870cca83ed..1e2a992990c2 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/input_all_of.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/input_all_of.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class InputAllOf(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of InputAllOf from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in some_data (dict) - _field_dict = {} - if self.some_data: - for _key_some_data in self.some_data: - if self.some_data[_key_some_data]: - _field_dict[_key_some_data] = self.some_data[_key_some_data].to_dict() - _dict['some_data'] = _field_dict - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of InputAllOf from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "some_data": dict( - (_k, Tag.from_dict(_v)) - for _k, _v in obj["some_data"].items() - ) - if obj.get("some_data") is not None - else None - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/int_or_string.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/int_or_string.py index f2a5a0a2d4a3..63f94b788677 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/int_or_string.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/int_or_string.py @@ -18,127 +18,27 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Any, List, Optional from typing_extensions import Annotated -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self INTORSTRING_ONE_OF_SCHEMAS = ["int", "str"] -class IntOrString(BaseModel): +class IntOrString(RootModel[Union[int, str]]): """ IntOrString """ - # data type: int - oneof_schema_1_validator: Optional[Annotated[int, Field(strict=True, ge=10)]] = None - # data type: str - oneof_schema_2_validator: Optional[StrictStr] = None - actual_instance: Optional[Union[int, str]] = None - one_of_schemas: Set[str] = { "int", "str" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[int, str] = Field( + ... ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - instance = IntOrString.model_construct() - error_messages = [] - match = 0 - # validate data type: int - try: - instance.oneof_schema_1_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: str - try: - instance.oneof_schema_2_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # deserialize data into int - try: - # validation - instance.oneof_schema_1_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_1_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into str - try: - # validation - instance.oneof_schema_2_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_2_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], int, str]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/list_class.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/list_class.py index ab12a7fac521..74d6399aeb7f 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/list_class.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/list_class.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ListClass(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ListClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ListClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "123-list": obj.get("123-list") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/map_of_array_of_model.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/map_of_array_of_model.py index a9bd000ad9ba..0f339a87cf07 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/map_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/map_of_array_of_model.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MapOfArrayOfModel(BaseModel): """ @@ -41,64 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MapOfArrayOfModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in shop_id_to_org_online_lip_map (dict of array) - _field_dict_of_array = {} - if self.shop_id_to_org_online_lip_map: - for _key_shop_id_to_org_online_lip_map in self.shop_id_to_org_online_lip_map: - if self.shop_id_to_org_online_lip_map[_key_shop_id_to_org_online_lip_map] is not None: - _field_dict_of_array[_key_shop_id_to_org_online_lip_map] = [ - _item.to_dict() for _item in self.shop_id_to_org_online_lip_map[_key_shop_id_to_org_online_lip_map] - ] - _dict['shopIdToOrgOnlineLipMap'] = _field_dict_of_array - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MapOfArrayOfModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "shopIdToOrgOnlineLipMap": dict( - (_k, - [Tag.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("shopIdToOrgOnlineLipMap", {}).items() - ) - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/map_test.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/map_test.py index 2a056ab5532a..516c89c56ee6 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/map_test.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/map_test.py @@ -19,15 +19,18 @@ from pydantic import BaseModel, ConfigDict, StrictBool, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MapTest(BaseModel): """ MapTest """ # noqa: E501 map_map_of_string: Optional[Dict[str, Dict[str, StrictStr]]] = None - map_of_enum_string: Optional[Dict[str, StrictStr]] = None + map_of_enum_string: Optional[Dict[str, str]] = Field( + None, + description="map_of_enum_string of the MapTest" + ) direct_map: Optional[Dict[str, StrictBool]] = None indirect_map: Optional[Dict[str, StrictBool]] = None __properties: ClassVar[List[str]] = ["map_map_of_string", "map_of_enum_string", "direct_map", "indirect_map"] @@ -54,51 +57,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MapTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MapTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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"), - "indirect_map": obj.get("indirect_map") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/mixed_properties_and_additional_properties_class.py index 46998dfb5c68..42de85aa28f7 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -22,8 +22,8 @@ from typing import Any, ClassVar, Dict, List, Optional from uuid import UUID from petstore_api.models.animal import Animal -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): """ @@ -45,62 +45,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MixedPropertiesAndAdditionalPropertiesClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in map (dict) - _field_dict = {} - if self.map: - for _key_map in self.map: - if self.map[_key_map]: - _field_dict[_key_map] = self.map[_key_map].to_dict() - _dict['map'] = _field_dict - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MixedPropertiesAndAdditionalPropertiesClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "uuid": obj.get("uuid"), - "dateTime": obj.get("dateTime"), - "map": dict( - (_k, Animal.from_dict(_v)) - for _k, _v in obj["map"].items() - ) - if obj.get("map") is not None - else None - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model200_response.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model200_response.py index d6012c57fbd7..b65f251b4ac2 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model200_response.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model200_response.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Model200Response(BaseModel): """ @@ -41,49 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Model200Response from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Model200Response from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name"), - "class": obj.get("class") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model_api_response.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model_api_response.py index 005c77823bef..5e061c8596eb 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model_api_response.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model_api_response.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ModelApiResponse(BaseModel): """ @@ -42,50 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ModelApiResponse from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ModelApiResponse from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "code": obj.get("code"), - "type": obj.get("type"), - "message": obj.get("message") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model_field.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model_field.py index 9e36a6ac7e48..9f7ec1d8e8f6 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model_field.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model_field.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ModelField(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ModelField from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ModelField from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "field": obj.get("field") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model_return.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model_return.py index a8c0f53f6c19..fcb4326a6d21 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model_return.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/model_return.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ModelReturn(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ModelReturn from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ModelReturn from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "return": obj.get("return") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/multi_arrays.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/multi_arrays.py index 177a8359468f..4bc0deaa6875 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/multi_arrays.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/multi_arrays.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.file import File from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MultiArrays(BaseModel): """ @@ -43,63 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MultiArrays from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in tags (list) - _items = [] - if self.tags: - for _item_tags in self.tags: - if _item_tags: - _items.append(_item_tags.to_dict()) - _dict['tags'] = _items - # override the default output from pydantic by calling `to_dict()` of each item in files (list) - _items = [] - if self.files: - for _item_files in self.files: - if _item_files: - _items.append(_item_files.to_dict()) - _dict['files'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MultiArrays from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "tags": [Tag.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None, - "files": [File.from_dict(_item) for _item in obj["files"]] if obj.get("files") is not None else None - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/name.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/name.py index f33b2ecb18be..3c663054f54e 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/name.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/name.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Name(BaseModel): """ @@ -43,55 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Name from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * OpenAPI `readOnly` fields are excluded. - * OpenAPI `readOnly` fields are excluded. - """ - excluded_fields: Set[str] = set([ - "snake_case", - "var_123_number", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Name from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name"), - "snake_case": obj.get("snake_case"), - "property": obj.get("property"), - "123Number": obj.get("123Number") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/nullable_class.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/nullable_class.py index 9d1414954830..3d3d9df95b29 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/nullable_class.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/nullable_class.py @@ -20,8 +20,8 @@ from datetime import date, datetime from pydantic import BaseModel, ConfigDict, StrictBool, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class NullableClass(BaseModel): """ @@ -54,127 +54,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of NullableClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - # set to None if required_integer_prop (nullable) is None - # 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 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 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 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 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 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 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 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 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 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 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of NullableClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "required_integer_prop": obj.get("required_integer_prop"), - "integer_prop": obj.get("integer_prop"), - "number_prop": obj.get("number_prop"), - "boolean_prop": obj.get("boolean_prop"), - "string_prop": obj.get("string_prop"), - "date_prop": obj.get("date_prop"), - "datetime_prop": obj.get("datetime_prop"), - "array_nullable_prop": obj.get("array_nullable_prop"), - "array_and_items_nullable_prop": obj.get("array_and_items_nullable_prop"), - "array_items_nullable": obj.get("array_items_nullable"), - "object_nullable_prop": obj.get("object_nullable_prop"), - "object_and_items_nullable_prop": obj.get("object_and_items_nullable_prop"), - "object_items_nullable": obj.get("object_items_nullable") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/nullable_property.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/nullable_property.py index 2324745d7dd1..6ec823c425f3 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/nullable_property.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/nullable_property.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, field_validator from typing import Any, ClassVar, Dict, List, Optional from typing_extensions import Annotated -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class NullableProperty(BaseModel): """ @@ -52,54 +52,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of NullableProperty from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # set to None if name (nullable) is None - # and model_fields_set contains the field - if self.name is None and "name" in self.model_fields_set: - _dict['name'] = None - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of NullableProperty from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/number_only.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/number_only.py index 18c3ec953080..567c5c62453b 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/number_only.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/number_only.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class NumberOnly(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of NumberOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of NumberOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "JustNumber": obj.get("JustNumber") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/object_to_test_additional_properties.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/object_to_test_additional_properties.py index 22b8bd401a1c..2335de5cc99f 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/object_to_test_additional_properties.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/object_to_test_additional_properties.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictBool from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ObjectToTestAdditionalProperties(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ObjectToTestAdditionalProperties from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ObjectToTestAdditionalProperties from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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-httpx/petstore_api/models/object_with_deprecated_fields.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/object_with_deprecated_fields.py index 4d76d9f5fc72..7f7bc9cfd6ce 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/object_with_deprecated_fields.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/object_with_deprecated_fields.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.deprecated_object import DeprecatedObject -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ObjectWithDeprecatedFields(BaseModel): """ @@ -44,54 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ObjectWithDeprecatedFields from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of deprecated_ref - if self.deprecated_ref: - _dict['deprecatedRef'] = self.deprecated_ref.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ObjectWithDeprecatedFields from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "uuid": obj.get("uuid"), - "id": obj.get("id"), - "deprecatedRef": DeprecatedObject.from_dict(obj["deprecatedRef"]) if obj.get("deprecatedRef") is not None else None, - "bars": obj.get("bars") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/one_of_enum_string.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/one_of_enum_string.py index 53101c37cc8b..eff2055e8a61 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/one_of_enum_string.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/one_of_enum_string.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OneOfEnumString(StrEnum): -class OneOfEnumString(str, Enum): """ oneOf enum strings """ - """ - allowed enum values - """ + # Allowed enum values A = 'a' B = 'b' C = 'c' @@ -36,4 +34,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OneOfEnumString from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/order.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/order.py index f742027e088a..95127b5d93d2 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/order.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/order.py @@ -20,8 +20,8 @@ from datetime import datetime from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Order(BaseModel): """ @@ -31,7 +31,10 @@ class Order(BaseModel): pet_id: Optional[StrictInt] = Field(default=None, alias="petId") quantity: Optional[StrictInt] = None ship_date: Optional[datetime] = Field(default=None, alias="shipDate") - status: Optional[StrictStr] = Field(default=None, description="Order Status") + status: Optional[StatusEnum] = Field( + None, + description="Order Status" + ) complete: Optional[StrictBool] = False __properties: ClassVar[List[str]] = ["id", "petId", "quantity", "shipDate", "status", "complete"] @@ -56,53 +59,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Order from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Order from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "petId": obj.get("petId"), - "quantity": obj.get("quantity"), - "shipDate": obj.get("shipDate"), - "status": obj.get("status"), - "complete": obj.get("complete") if obj.get("complete") is not None else False - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_composite.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_composite.py index 6a82d49970cb..92ad3b493d46 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_composite.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_composite.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictBool, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class OuterComposite(BaseModel): """ @@ -42,50 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of OuterComposite from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of OuterComposite from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "my_number": obj.get("my_number"), - "my_string": obj.get("my_string"), - "my_boolean": obj.get("my_boolean") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum.py index ac48cc0dc4d8..ee5753ebef43 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnum(StrEnum): -class OuterEnum(str, Enum): """ OuterEnum """ - """ - allowed enum values - """ + # Allowed enum values PLACED = 'placed' APPROVED = 'approved' DELIVERED = 'delivered' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnum from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum_default_value.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum_default_value.py index 99d6fd5fc042..7b013c460e2b 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum_default_value.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum_default_value.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnumDefaultValue(StrEnum): -class OuterEnumDefaultValue(str, Enum): """ OuterEnumDefaultValue """ - """ - allowed enum values - """ + # Allowed enum values PLACED = 'placed' APPROVED = 'approved' DELIVERED = 'delivered' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnumDefaultValue from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum_integer.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum_integer.py index b771b7a61f55..03ee644405ed 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum_integer.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum_integer.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnumInteger(IntEnum): -class OuterEnumInteger(int, Enum): """ OuterEnumInteger """ - """ - allowed enum values - """ + # Allowed enum values NUMBER_0 = 0 NUMBER_1 = 1 NUMBER_2 = 2 @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnumInteger from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum_integer_default_value.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum_integer_default_value.py index 8df41b2bd320..55735ba9b13f 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum_integer_default_value.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_enum_integer_default_value.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnumIntegerDefaultValue(IntEnum): -class OuterEnumIntegerDefaultValue(int, Enum): """ OuterEnumIntegerDefaultValue """ - """ - allowed enum values - """ + # Allowed enum values NUMBER_MINUS_1 = -1 NUMBER_0 = 0 NUMBER_1 = 1 @@ -36,4 +34,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnumIntegerDefaultValue from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_object_with_enum_property.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_object_with_enum_property.py index 4f453c2a8d0c..b46c7db60925 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_object_with_enum_property.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_object_with_enum_property.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.outer_enum import OuterEnum from petstore_api.models.outer_enum_integer import OuterEnumInteger -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class OuterObjectWithEnumProperty(BaseModel): """ @@ -43,54 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of OuterObjectWithEnumProperty from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # set to None if str_value (nullable) is None - # 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of OuterObjectWithEnumProperty from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "str_value": obj.get("str_value"), - "value": obj.get("value") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/parent.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/parent.py index 5986da45ab04..6dfd21dee63f 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/parent.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/parent.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.inner_dict_with_property import InnerDictWithProperty -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Parent(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Parent from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in optional_dict (dict) - _field_dict = {} - if self.optional_dict: - for _key_optional_dict in self.optional_dict: - if self.optional_dict[_key_optional_dict]: - _field_dict[_key_optional_dict] = self.optional_dict[_key_optional_dict].to_dict() - _dict['optionalDict'] = _field_dict - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Parent from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "optionalDict": dict( - (_k, InnerDictWithProperty.from_dict(_v)) - for _k, _v in obj["optionalDict"].items() - ) - if obj.get("optionalDict") is not None - else None - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/parent_with_optional_dict.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/parent_with_optional_dict.py index 84445b64043a..2e81abb75704 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/parent_with_optional_dict.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/parent_with_optional_dict.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.inner_dict_with_property import InnerDictWithProperty -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ParentWithOptionalDict(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ParentWithOptionalDict from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in optional_dict (dict) - _field_dict = {} - if self.optional_dict: - for _key_optional_dict in self.optional_dict: - if self.optional_dict[_key_optional_dict]: - _field_dict[_key_optional_dict] = self.optional_dict[_key_optional_dict].to_dict() - _dict['optionalDict'] = _field_dict - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ParentWithOptionalDict from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "optionalDict": dict( - (_k, InnerDictWithProperty.from_dict(_v)) - for _k, _v in obj["optionalDict"].items() - ) - if obj.get("optionalDict") is not None - else None - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/pet.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/pet.py index be47c3b1a894..4988087c1e98 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/pet.py @@ -22,8 +22,8 @@ from typing_extensions import Annotated from petstore_api.models.category import Category from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Pet(BaseModel): """ @@ -34,7 +34,10 @@ class Pet(BaseModel): name: StrictStr 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") + status: Optional[StatusEnum] = Field( + None, + description="pet status in the store" + ) __properties: ClassVar[List[str]] = ["id", "category", "name", "photoUrls", "tags", "status"] @field_validator('status') @@ -58,63 +61,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Pet from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of category - if self.category: - _dict['category'] = self.category.to_dict() - # override the default output from pydantic by calling `to_dict()` of each item in tags (list) - _items = [] - if self.tags: - for _item_tags in self.tags: - if _item_tags: - _items.append(_item_tags.to_dict()) - _dict['tags'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Pet from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "category": Category.from_dict(obj["category"]) if obj.get("category") is not None else None, - "name": obj.get("name"), - "photoUrls": obj.get("photoUrls"), - "tags": [Tag.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None, - "status": obj.get("status") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/pig.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/pig.py index b3a759e89b7b..5daca5745f89 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/pig.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/pig.py @@ -19,122 +19,27 @@ from typing import Any, List, Optional from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self PIG_ONE_OF_SCHEMAS = ["BasquePig", "DanishPig"] -class Pig(BaseModel): +class Pig(RootModel[Union[BasquePig, DanishPig]]): """ Pig """ - # data type: BasquePig - oneof_schema_1_validator: Optional[BasquePig] = None - # data type: DanishPig - oneof_schema_2_validator: Optional[DanishPig] = None - actual_instance: Optional[Union[BasquePig, DanishPig]] = None - one_of_schemas: Set[str] = { "BasquePig", "DanishPig" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[BasquePig, DanishPig] = Field( + ..., discriminator="class_name" ) - - discriminator_value_class_map: Dict[str, str] = { - } - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - instance = Pig.model_construct() - error_messages = [] - match = 0 - # validate data type: BasquePig - if not isinstance(v, BasquePig): - error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`") - else: - match += 1 - # validate data type: DanishPig - if not isinstance(v, DanishPig): - error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`") - else: - match += 1 - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # deserialize data into BasquePig - try: - instance.actual_instance = BasquePig.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into DanishPig - try: - instance.actual_instance = DanishPig.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], BasquePig, DanishPig]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/pony_sizes.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/pony_sizes.py index 00bd38659577..07fad564629c 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/pony_sizes.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/pony_sizes.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.type import Type -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PonySizes(BaseModel): """ @@ -41,48 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PonySizes from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PonySizes from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "type": obj.get("type") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/poop_cleaning.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/poop_cleaning.py index 047cf0d481a9..c651907e168f 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/poop_cleaning.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/poop_cleaning.py @@ -19,15 +19,21 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PoopCleaning(BaseModel): """ PoopCleaning """ # noqa: E501 - task_name: StrictStr - function_name: StrictStr + task_name: Literal['cleaning'] = Field( + ..., + description="task_name of the PoopCleaning" + ) + function_name: Literal['care'] = Field( + ..., + description="function_name of the PoopCleaning" + ) content: StrictStr __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -56,50 +62,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PoopCleaning from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PoopCleaning from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "task_name": obj.get("task_name"), - "function_name": obj.get("function_name"), - "content": obj.get("content") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/primitive_string.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/primitive_string.py index 5a7065597861..47f666784246 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/primitive_string.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/primitive_string.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.base_discriminator import BaseDiscriminator -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PrimitiveString(BaseDiscriminator): """ @@ -41,49 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PrimitiveString from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PrimitiveString from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_typeName": obj.get("_typeName"), - "_value": obj.get("_value") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/property_map.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/property_map.py index 940016a86a72..60fe171e2156 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/property_map.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/property_map.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PropertyMap(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PropertyMap from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in some_data (dict) - _field_dict = {} - if self.some_data: - for _key_some_data in self.some_data: - if self.some_data[_key_some_data]: - _field_dict[_key_some_data] = self.some_data[_key_some_data].to_dict() - _dict['some_data'] = _field_dict - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PropertyMap from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "some_data": dict( - (_k, Tag.from_dict(_v)) - for _k, _v in obj["some_data"].items() - ) - if obj.get("some_data") is not None - else None - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/property_name_collision.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/property_name_collision.py index 0eb56422b648..5ed85fc37ac0 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/property_name_collision.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/property_name_collision.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PropertyNameCollision(BaseModel): """ @@ -42,50 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PropertyNameCollision from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PropertyNameCollision from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_type": obj.get("_type"), - "type": obj.get("type"), - "type_": obj.get("type_") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/read_only_first.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/read_only_first.py index c9f4fc6c0df9..d6dd229d91cf 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/read_only_first.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/read_only_first.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ReadOnlyFirst(BaseModel): """ @@ -41,51 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ReadOnlyFirst from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * OpenAPI `readOnly` fields are excluded. - """ - excluded_fields: Set[str] = set([ - "bar", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ReadOnlyFirst from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "bar": obj.get("bar"), - "baz": obj.get("baz") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/second_circular_all_of_ref.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/second_circular_all_of_ref.py index 854749b4fb13..b4959634120d 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/second_circular_all_of_ref.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/second_circular_all_of_ref.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SecondCircularAllOfRef(BaseModel): """ @@ -41,57 +41,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SecondCircularAllOfRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in circular_all_of_ref (list) - _items = [] - if self.circular_all_of_ref: - for _item_circular_all_of_ref in self.circular_all_of_ref: - if _item_circular_all_of_ref: - _items.append(_item_circular_all_of_ref.to_dict()) - _dict['circularAllOfRef'] = _items - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SecondCircularAllOfRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_name": obj.get("_name"), - "circularAllOfRef": [CircularAllOfRef.from_dict(_item) for _item in obj["circularAllOfRef"]] if obj.get("circularAllOfRef") is not None else None - }) - return _obj from petstore_api.models.circular_all_of_ref import CircularAllOfRef # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/second_ref.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/second_ref.py index c6627cf0ba63..01a112e0d179 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/second_ref.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/second_ref.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SecondRef(BaseModel): """ @@ -41,53 +41,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SecondRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of circular_ref - if self.circular_ref: - _dict['circular_ref'] = self.circular_ref.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SecondRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "category": obj.get("category"), - "circular_ref": CircularReferenceModel.from_dict(obj["circular_ref"]) if obj.get("circular_ref") is not None else None - }) - return _obj from petstore_api.models.circular_reference_model import CircularReferenceModel # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/self_reference_model.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/self_reference_model.py index 7c145db0d3ae..9810032e9801 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/self_reference_model.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/self_reference_model.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SelfReferenceModel(BaseModel): """ @@ -41,53 +41,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SelfReferenceModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of nested - if self.nested: - _dict['nested'] = self.nested.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SelfReferenceModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "nested": DummyModel.from_dict(obj["nested"]) if obj.get("nested") is not None else None - }) - return _obj from petstore_api.models.dummy_model import DummyModel # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/single_ref_type.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/single_ref_type.py index 91ab07e2535c..32b33b2271fe 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/single_ref_type.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/single_ref_type.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class SingleRefType(StrEnum): -class SingleRefType(str, Enum): """ SingleRefType """ - """ - allowed enum values - """ + # Allowed enum values ADMIN = 'admin' USER = 'user' @@ -34,4 +32,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of SingleRefType from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/special_character_enum.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/special_character_enum.py index 1d85fd148d4b..bf8d0a25df90 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/special_character_enum.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/special_character_enum.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class SpecialCharacterEnum(StrEnum): -class SpecialCharacterEnum(str, Enum): """ SpecialCharacterEnum """ - """ - allowed enum values - """ + # Allowed enum values ENUM_456 = '456' ENUM_123ABC = '123abc' UNDERSCORE = '_' @@ -42,4 +40,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of SpecialCharacterEnum from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/special_model_name.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/special_model_name.py index 0336e24d17da..945d996f5c15 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/special_model_name.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/special_model_name.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SpecialModelName(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SpecialModelName from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SpecialModelName from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "$special[property.name]": obj.get("$special[property.name]") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/special_name.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/special_name.py index d3c8f6185683..b9022dde3cbf 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/special_name.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/special_name.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.category import Category -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SpecialName(BaseModel): """ @@ -29,7 +29,10 @@ class SpecialName(BaseModel): """ # noqa: E501 var_property: Optional[StrictInt] = Field(default=None, alias="property") var_async: Optional[Category] = Field(default=None, alias="async") - var_schema: Optional[StrictStr] = Field(default=None, description="pet status in the store", alias="schema") + var_schema: Optional[Var_schemaEnum] = Field( + None, + description="pet status in the store" + ) __properties: ClassVar[List[str]] = ["property", "async", "schema"] @field_validator('var_schema') @@ -53,53 +56,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SpecialName from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of var_async - if self.var_async: - _dict['async'] = self.var_async.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SpecialName from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "property": obj.get("property"), - "async": Category.from_dict(obj["async"]) if obj.get("async") is not None else None, - "schema": obj.get("schema") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/tag.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/tag.py index e5ddcbcd4a74..0c7f9d698ace 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/tag.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/tag.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Tag(BaseModel): """ @@ -41,49 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Tag from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Tag from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/task.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/task.py index 312b2c8ee473..c8864c78e282 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/task.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/task.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List from uuid import UUID from petstore_api.models.task_activity import TaskActivity -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Task(BaseModel): """ @@ -43,52 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Task from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of activity - if self.activity: - _dict['activity'] = self.activity.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Task from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "activity": TaskActivity.from_dict(obj["activity"]) if obj.get("activity") is not None else None - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/task_activity.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/task_activity.py index cc1e1fc5a60f..d7b8b1e71af3 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/task_activity.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/task_activity.py @@ -20,132 +20,27 @@ from petstore_api.models.bathing import Bathing from petstore_api.models.feeding import Feeding from petstore_api.models.poop_cleaning import PoopCleaning -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self TASKACTIVITY_ONE_OF_SCHEMAS = ["Bathing", "Feeding", "PoopCleaning"] -class TaskActivity(BaseModel): +class TaskActivity(RootModel[Union[Bathing, Feeding, PoopCleaning]]): """ TaskActivity """ - # data type: PoopCleaning - oneof_schema_1_validator: Optional[PoopCleaning] = None - # data type: Feeding - oneof_schema_2_validator: Optional[Feeding] = None - # data type: Bathing - oneof_schema_3_validator: Optional[Bathing] = None - actual_instance: Optional[Union[Bathing, Feeding, PoopCleaning]] = None - one_of_schemas: Set[str] = { "Bathing", "Feeding", "PoopCleaning" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[Bathing, Feeding, PoopCleaning] = Field( + ... ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - instance = TaskActivity.model_construct() - error_messages = [] - match = 0 - # validate data type: PoopCleaning - if not isinstance(v, PoopCleaning): - error_messages.append(f"Error! Input type `{type(v)}` is not `PoopCleaning`") - else: - match += 1 - # validate data type: Feeding - if not isinstance(v, Feeding): - error_messages.append(f"Error! Input type `{type(v)}` is not `Feeding`") - else: - match += 1 - # validate data type: Bathing - if not isinstance(v, Bathing): - error_messages.append(f"Error! Input type `{type(v)}` is not `Bathing`") - else: - match += 1 - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # deserialize data into PoopCleaning - try: - instance.actual_instance = PoopCleaning.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into Feeding - try: - instance.actual_instance = Feeding.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into Bathing - try: - instance.actual_instance = Bathing.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], Bathing, Feeding, PoopCleaning]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_enum.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_enum.py index 8eae227a84e9..331f0fd597bd 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_enum.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_enum.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class TestEnum(StrEnum): -class TestEnum(str, Enum): """ TestEnum """ - """ - allowed enum values - """ + # Allowed enum values ONE = 'ONE' TWO = 'TWO' THREE = 'THREE' @@ -36,4 +34,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of TestEnum from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_enum_with_default.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_enum_with_default.py index 9304d3ab8497..0f3d74610b96 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_enum_with_default.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_enum_with_default.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class TestEnumWithDefault(StrEnum): -class TestEnumWithDefault(str, Enum): """ TestEnumWithDefault """ - """ - allowed enum values - """ + # Allowed enum values EIN = 'EIN' ZWEI = 'ZWEI' DREI = 'DREI' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of TestEnumWithDefault from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_error_responses_with_model400_response.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_error_responses_with_model400_response.py index cba4ab845e5e..15bb872e0575 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_error_responses_with_model400_response.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_error_responses_with_model400_response.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestErrorResponsesWithModel400Response(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel400Response from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel400Response from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "reason400": obj.get("reason400") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_error_responses_with_model404_response.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_error_responses_with_model404_response.py index 787ca11942ab..a124d7230c5d 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_error_responses_with_model404_response.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_error_responses_with_model404_response.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestErrorResponsesWithModel404Response(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel404Response from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel404Response from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "reason404": obj.get("reason404") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_inline_freeform_additional_properties_request.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_inline_freeform_additional_properties_request.py index 7b93d84864f2..ef3e742d900f 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_inline_freeform_additional_properties_request.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_inline_freeform_additional_properties_request.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestInlineFreeformAdditionalPropertiesRequest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestInlineFreeformAdditionalPropertiesRequest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "someProperty": obj.get("someProperty") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_model_with_enum_default.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_model_with_enum_default.py index 218fa8f16d22..ac8b4f6c0cdd 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_model_with_enum_default.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_model_with_enum_default.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.test_enum import TestEnum from petstore_api.models.test_enum_with_default import TestEnumWithDefault -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestModelWithEnumDefault(BaseModel): """ @@ -32,7 +32,10 @@ class TestModelWithEnumDefault(BaseModel): test_string: Optional[StrictStr] = None test_enum_with_default: Optional[TestEnumWithDefault] = TestEnumWithDefault.ZWEI test_string_with_default: Optional[StrictStr] = 'ahoy matey' - test_inline_defined_enum_with_default: Optional[StrictStr] = 'B' + test_inline_defined_enum_with_default: Optional[Test_inline_defined_enum_with_defaultEnum] = Field( + None, + description="test_inline_defined_enum_with_default of the TestModelWithEnumDefault" + ) __properties: ClassVar[List[str]] = ["test_enum", "test_string", "test_enum_with_default", "test_string_with_default", "test_inline_defined_enum_with_default"] @field_validator('test_inline_defined_enum_with_default') @@ -56,52 +59,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestModelWithEnumDefault from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestModelWithEnumDefault from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "test_enum": obj.get("test_enum"), - "test_string": obj.get("test_string"), - "test_enum_with_default": obj.get("test_enum_with_default") if obj.get("test_enum_with_default") is not None else TestEnumWithDefault.ZWEI, - "test_string_with_default": obj.get("test_string_with_default") if obj.get("test_string_with_default") is not None else 'ahoy matey', - "test_inline_defined_enum_with_default": obj.get("test_inline_defined_enum_with_default") if obj.get("test_inline_defined_enum_with_default") is not None else 'B' - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_object_for_multipart_requests_request_marker.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_object_for_multipart_requests_request_marker.py index a5c3bfdbb1b5..4d2abed68fea 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_object_for_multipart_requests_request_marker.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/test_object_for_multipart_requests_request_marker.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestObjectForMultipartRequestsRequestMarker(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestObjectForMultipartRequestsRequestMarker from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestObjectForMultipartRequestsRequestMarker from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/tiger.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/tiger.py index bf8cbf0596ae..60baf0a7da5e 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/tiger.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/tiger.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Tiger(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Tiger from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Tiger from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "skill": obj.get("skill") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/type.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/type.py index 35a847de894f..3ab767b6125b 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/type.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/type.py @@ -14,18 +14,17 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self -class Type(int, Enum): +class Type(Enum): + """ Type """ - """ - allowed enum values - """ + # Allowed enum values NUMBER_2_DOT_0 = 2.0 NUMBER_1_DOT_0 = 1.0 NUMBER_0_DOT_5 = 0.5 @@ -36,4 +35,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of Type from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py index e50edf2efa85..65dd088726a3 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.creature_info import CreatureInfo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class UnnamedDictWithAdditionalModelListProperties(BaseModel): """ @@ -41,64 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalModelListProperties from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in dict_property (dict of array) - _field_dict_of_array = {} - if self.dict_property: - for _key_dict_property in self.dict_property: - if self.dict_property[_key_dict_property] is not None: - _field_dict_of_array[_key_dict_property] = [ - _item.to_dict() for _item in self.dict_property[_key_dict_property] - ] - _dict['dictProperty'] = _field_dict_of_array - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalModelListProperties from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "dictProperty": dict( - (_k, - [CreatureInfo.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("dictProperty", {}).items() - ) - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py index 477dcae27c7c..8cb9fb502b34 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class UnnamedDictWithAdditionalStringListProperties(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalStringListProperties from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalStringListProperties from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "dictProperty": obj.get("dictProperty") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/upload_file_with_additional_properties_request_object.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/upload_file_with_additional_properties_request_object.py index 9040618ac0d7..935ac02add3a 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/upload_file_with_additional_properties_request_object.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/upload_file_with_additional_properties_request_object.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class UploadFileWithAdditionalPropertiesRequestObject(BaseModel): """ @@ -40,48 +40,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of UploadFileWithAdditionalPropertiesRequestObject from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of UploadFileWithAdditionalPropertiesRequestObject from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/user.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/user.py index 45e0a66f89dd..833099b0f43b 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/user.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/user.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class User(BaseModel): """ @@ -47,55 +47,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of User from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of User from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "username": obj.get("username"), - "firstName": obj.get("firstName"), - "lastName": obj.get("lastName"), - "email": obj.get("email"), - "password": obj.get("password"), - "phone": obj.get("phone"), - "userStatus": obj.get("userStatus") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/with_nested_one_of.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/with_nested_one_of.py index f2cd8b7a3a30..37e9ab665d40 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/with_nested_one_of.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/with_nested_one_of.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.one_of_enum_string import OneOfEnumString from petstore_api.models.pig import Pig -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class WithNestedOneOf(BaseModel): """ @@ -44,53 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of WithNestedOneOf from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - """ - excluded_fields: Set[str] = set([ - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of nested_pig - if self.nested_pig: - _dict['nested_pig'] = self.nested_pig.to_dict() - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of WithNestedOneOf from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "nested_pig": Pig.from_dict(obj["nested_pig"]) if obj.get("nested_pig") is not None else None, - "nested_oneof_enum_string": obj.get("nested_oneof_enum_string") - }) - return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/pyproject.toml b/samples/openapi3/client/petstore/python-httpx/pyproject.toml index 17720c14e8c2..f424fbed3c0a 100644 --- a/samples/openapi3/client/petstore/python-httpx/pyproject.toml +++ b/samples/openapi3/client/petstore/python-httpx/pyproject.toml @@ -8,11 +8,13 @@ authors = [ license = { text = "Apache-2.0" } readme = "README.md" keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"] -requires-python = ">=3.9" +requires-python = ">=3.11" dependencies = [ + "urllib3 (>=2.1.0,<3.0.0)", "python-dateutil (>=2.8.2)", - "httpx (>=0.28.1)", + "aiohttp (>=3.8.4)", + "aiohttp-retry (>=2.8.3)", "pem (>=19.3.0)", "pycryptodome (>=3.9.0)", "pydantic (>=2)", diff --git a/samples/openapi3/client/petstore/python-httpx/setup.py b/samples/openapi3/client/petstore/python-httpx/setup.py index e9883ecf3ccc..6fcb284b3ad3 100644 --- a/samples/openapi3/client/petstore/python-httpx/setup.py +++ b/samples/openapi3/client/petstore/python-httpx/setup.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """ OpenAPI Petstore @@ -12,6 +10,7 @@ """ # noqa: E501 + from setuptools import setup, find_packages # noqa: H301 # To install the library, run the following @@ -22,8 +21,9 @@ # http://pypi.python.org/pypi/setuptools NAME = "petstore-api" VERSION = "1.0.0" -PYTHON_REQUIRES = ">= 3.9" +PYTHON_REQUIRES = ">= 3.11" REQUIRES = [ + "urllib3 >= 2.1.0, < 3.0.0", "python-dateutil >= 2.8.2", "httpx >= 0.28.1", "pem >= 19.3.0", diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesAnyType.md b/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesAnyType.md index 314cba3a614c..6491c95beba5 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesAnyType.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesAnyType.md @@ -15,14 +15,14 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesAnyType from a JSON string -additional_properties_any_type_instance = AdditionalPropertiesAnyType.from_json(json) +additional_properties_any_type_instance = AdditionalPropertiesAnyType.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesAnyType.to_json()) +print(AdditionalPropertiesAnyType.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_any_type_dict = additional_properties_any_type_instance.to_dict() +additional_properties_any_type_dict = additional_properties_any_type_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesAnyType from a dict -additional_properties_any_type_from_dict = AdditionalPropertiesAnyType.from_dict(additional_properties_any_type_dict) +additional_properties_any_type_from_dict = AdditionalPropertiesAnyType.model_validate(additional_properties_any_type_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesClass.md b/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesClass.md index 8d4c08707f55..2a618964bc5c 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesClass.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesClass.md @@ -16,14 +16,14 @@ from petstore_api.models.additional_properties_class import AdditionalProperties # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesClass from a JSON string -additional_properties_class_instance = AdditionalPropertiesClass.from_json(json) +additional_properties_class_instance = AdditionalPropertiesClass.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesClass.to_json()) +print(AdditionalPropertiesClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_class_dict = additional_properties_class_instance.to_dict() +additional_properties_class_dict = additional_properties_class_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesClass from a dict -additional_properties_class_from_dict = AdditionalPropertiesClass.from_dict(additional_properties_class_dict) +additional_properties_class_from_dict = AdditionalPropertiesClass.model_validate(additional_properties_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesObject.md b/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesObject.md index d647ec64896f..1c66f8e5d29a 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesObject.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesObject.md @@ -15,14 +15,14 @@ from petstore_api.models.additional_properties_object import AdditionalPropertie # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesObject from a JSON string -additional_properties_object_instance = AdditionalPropertiesObject.from_json(json) +additional_properties_object_instance = AdditionalPropertiesObject.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesObject.to_json()) +print(AdditionalPropertiesObject.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_object_dict = additional_properties_object_instance.to_dict() +additional_properties_object_dict = additional_properties_object_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesObject from a dict -additional_properties_object_from_dict = AdditionalPropertiesObject.from_dict(additional_properties_object_dict) +additional_properties_object_from_dict = AdditionalPropertiesObject.model_validate(additional_properties_object_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesWithDescriptionOnly.md b/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesWithDescriptionOnly.md index 061f5524872b..88d66f028a2b 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesWithDescriptionOnly.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesWithDescriptionOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.additional_properties_with_description_only import Addi # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesWithDescriptionOnly from a JSON string -additional_properties_with_description_only_instance = AdditionalPropertiesWithDescriptionOnly.from_json(json) +additional_properties_with_description_only_instance = AdditionalPropertiesWithDescriptionOnly.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesWithDescriptionOnly.to_json()) +print(AdditionalPropertiesWithDescriptionOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_with_description_only_dict = additional_properties_with_description_only_instance.to_dict() +additional_properties_with_description_only_dict = additional_properties_with_description_only_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesWithDescriptionOnly from a dict -additional_properties_with_description_only_from_dict = AdditionalPropertiesWithDescriptionOnly.from_dict(additional_properties_with_description_only_dict) +additional_properties_with_description_only_from_dict = AdditionalPropertiesWithDescriptionOnly.model_validate(additional_properties_with_description_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/AllOfSuperModel.md b/samples/openapi3/client/petstore/python-lazyImports/docs/AllOfSuperModel.md index 421a1527f1ef..bec62554ebf0 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/AllOfSuperModel.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/AllOfSuperModel.md @@ -15,14 +15,14 @@ from petstore_api.models.all_of_super_model import AllOfSuperModel # TODO update the JSON string below json = "{}" # create an instance of AllOfSuperModel from a JSON string -all_of_super_model_instance = AllOfSuperModel.from_json(json) +all_of_super_model_instance = AllOfSuperModel.model_validate_json(json) # print the JSON string representation of the object -print(AllOfSuperModel.to_json()) +print(AllOfSuperModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -all_of_super_model_dict = all_of_super_model_instance.to_dict() +all_of_super_model_dict = all_of_super_model_instance.model_dump(by_alias=True) # create an instance of AllOfSuperModel from a dict -all_of_super_model_from_dict = AllOfSuperModel.from_dict(all_of_super_model_dict) +all_of_super_model_from_dict = AllOfSuperModel.model_validate(all_of_super_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/AllOfWithSingleRef.md b/samples/openapi3/client/petstore/python-lazyImports/docs/AllOfWithSingleRef.md index 203a4b5da3d5..05ae8a658ab3 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/AllOfWithSingleRef.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/AllOfWithSingleRef.md @@ -16,14 +16,14 @@ from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef # TODO update the JSON string below json = "{}" # create an instance of AllOfWithSingleRef from a JSON string -all_of_with_single_ref_instance = AllOfWithSingleRef.from_json(json) +all_of_with_single_ref_instance = AllOfWithSingleRef.model_validate_json(json) # print the JSON string representation of the object -print(AllOfWithSingleRef.to_json()) +print(AllOfWithSingleRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -all_of_with_single_ref_dict = all_of_with_single_ref_instance.to_dict() +all_of_with_single_ref_dict = all_of_with_single_ref_instance.model_dump(by_alias=True) # create an instance of AllOfWithSingleRef from a dict -all_of_with_single_ref_from_dict = AllOfWithSingleRef.from_dict(all_of_with_single_ref_dict) +all_of_with_single_ref_from_dict = AllOfWithSingleRef.model_validate(all_of_with_single_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Animal.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Animal.md index 381d27b66e44..eb20439f3782 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Animal.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Animal.md @@ -16,14 +16,14 @@ from petstore_api.models.animal import Animal # TODO update the JSON string below json = "{}" # create an instance of Animal from a JSON string -animal_instance = Animal.from_json(json) +animal_instance = Animal.model_validate_json(json) # print the JSON string representation of the object -print(Animal.to_json()) +print(Animal.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -animal_dict = animal_instance.to_dict() +animal_dict = animal_instance.model_dump(by_alias=True) # create an instance of Animal from a dict -animal_from_dict = Animal.from_dict(animal_dict) +animal_from_dict = Animal.model_validate(animal_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/AnyOfColor.md b/samples/openapi3/client/petstore/python-lazyImports/docs/AnyOfColor.md index 6ed75dd7b48a..c656fdbbae05 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/AnyOfColor.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/AnyOfColor.md @@ -15,14 +15,14 @@ from petstore_api.models.any_of_color import AnyOfColor # TODO update the JSON string below json = "{}" # create an instance of AnyOfColor from a JSON string -any_of_color_instance = AnyOfColor.from_json(json) +any_of_color_instance = AnyOfColor.model_validate_json(json) # print the JSON string representation of the object -print(AnyOfColor.to_json()) +print(AnyOfColor.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -any_of_color_dict = any_of_color_instance.to_dict() +any_of_color_dict = any_of_color_instance.model_dump(by_alias=True) # create an instance of AnyOfColor from a dict -any_of_color_from_dict = AnyOfColor.from_dict(any_of_color_dict) +any_of_color_from_dict = AnyOfColor.model_validate(any_of_color_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/AnyOfPig.md b/samples/openapi3/client/petstore/python-lazyImports/docs/AnyOfPig.md index 9367e2261898..0c273f175319 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/AnyOfPig.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/AnyOfPig.md @@ -17,14 +17,14 @@ from petstore_api.models.any_of_pig import AnyOfPig # TODO update the JSON string below json = "{}" # create an instance of AnyOfPig from a JSON string -any_of_pig_instance = AnyOfPig.from_json(json) +any_of_pig_instance = AnyOfPig.model_validate_json(json) # print the JSON string representation of the object -print(AnyOfPig.to_json()) +print(AnyOfPig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -any_of_pig_dict = any_of_pig_instance.to_dict() +any_of_pig_dict = any_of_pig_instance.model_dump(by_alias=True) # create an instance of AnyOfPig from a dict -any_of_pig_from_dict = AnyOfPig.from_dict(any_of_pig_dict) +any_of_pig_from_dict = AnyOfPig.model_validate(any_of_pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayOfArrayOfModel.md b/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayOfArrayOfModel.md index f866863d53f9..83505f6eb05b 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayOfArrayOfModel.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayOfArrayOfModel.md @@ -15,14 +15,14 @@ from petstore_api.models.array_of_array_of_model import ArrayOfArrayOfModel # TODO update the JSON string below json = "{}" # create an instance of ArrayOfArrayOfModel from a JSON string -array_of_array_of_model_instance = ArrayOfArrayOfModel.from_json(json) +array_of_array_of_model_instance = ArrayOfArrayOfModel.model_validate_json(json) # print the JSON string representation of the object -print(ArrayOfArrayOfModel.to_json()) +print(ArrayOfArrayOfModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_of_array_of_model_dict = array_of_array_of_model_instance.to_dict() +array_of_array_of_model_dict = array_of_array_of_model_instance.model_dump(by_alias=True) # create an instance of ArrayOfArrayOfModel from a dict -array_of_array_of_model_from_dict = ArrayOfArrayOfModel.from_dict(array_of_array_of_model_dict) +array_of_array_of_model_from_dict = ArrayOfArrayOfModel.model_validate(array_of_array_of_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayOfArrayOfNumberOnly.md b/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayOfArrayOfNumberOnly.md index 32bd2dfbf1e2..0027448edc27 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayOfArrayOfNumberOnly.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayOfArrayOfNumberOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumb # TODO update the JSON string below json = "{}" # create an instance of ArrayOfArrayOfNumberOnly from a JSON string -array_of_array_of_number_only_instance = ArrayOfArrayOfNumberOnly.from_json(json) +array_of_array_of_number_only_instance = ArrayOfArrayOfNumberOnly.model_validate_json(json) # print the JSON string representation of the object -print(ArrayOfArrayOfNumberOnly.to_json()) +print(ArrayOfArrayOfNumberOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_of_array_of_number_only_dict = array_of_array_of_number_only_instance.to_dict() +array_of_array_of_number_only_dict = array_of_array_of_number_only_instance.model_dump(by_alias=True) # create an instance of ArrayOfArrayOfNumberOnly from a dict -array_of_array_of_number_only_from_dict = ArrayOfArrayOfNumberOnly.from_dict(array_of_array_of_number_only_dict) +array_of_array_of_number_only_from_dict = ArrayOfArrayOfNumberOnly.model_validate(array_of_array_of_number_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayOfNumberOnly.md b/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayOfNumberOnly.md index b814d7594942..81aeee6c1add 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayOfNumberOnly.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayOfNumberOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.array_of_number_only import ArrayOfNumberOnly # TODO update the JSON string below json = "{}" # create an instance of ArrayOfNumberOnly from a JSON string -array_of_number_only_instance = ArrayOfNumberOnly.from_json(json) +array_of_number_only_instance = ArrayOfNumberOnly.model_validate_json(json) # print the JSON string representation of the object -print(ArrayOfNumberOnly.to_json()) +print(ArrayOfNumberOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_of_number_only_dict = array_of_number_only_instance.to_dict() +array_of_number_only_dict = array_of_number_only_instance.model_dump(by_alias=True) # create an instance of ArrayOfNumberOnly from a dict -array_of_number_only_from_dict = ArrayOfNumberOnly.from_dict(array_of_number_only_dict) +array_of_number_only_from_dict = ArrayOfNumberOnly.model_validate(array_of_number_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayTest.md b/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayTest.md index ed871fae662d..62b868a02c64 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayTest.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/ArrayTest.md @@ -18,14 +18,14 @@ from petstore_api.models.array_test import ArrayTest # TODO update the JSON string below json = "{}" # create an instance of ArrayTest from a JSON string -array_test_instance = ArrayTest.from_json(json) +array_test_instance = ArrayTest.model_validate_json(json) # print the JSON string representation of the object -print(ArrayTest.to_json()) +print(ArrayTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_test_dict = array_test_instance.to_dict() +array_test_dict = array_test_instance.model_dump(by_alias=True) # create an instance of ArrayTest from a dict -array_test_from_dict = ArrayTest.from_dict(array_test_dict) +array_test_from_dict = ArrayTest.model_validate(array_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/BaseDiscriminator.md b/samples/openapi3/client/petstore/python-lazyImports/docs/BaseDiscriminator.md index fcdbeb032e68..a317fc0421fe 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/BaseDiscriminator.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/BaseDiscriminator.md @@ -15,14 +15,14 @@ from petstore_api.models.base_discriminator import BaseDiscriminator # TODO update the JSON string below json = "{}" # create an instance of BaseDiscriminator from a JSON string -base_discriminator_instance = BaseDiscriminator.from_json(json) +base_discriminator_instance = BaseDiscriminator.model_validate_json(json) # print the JSON string representation of the object -print(BaseDiscriminator.to_json()) +print(BaseDiscriminator.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -base_discriminator_dict = base_discriminator_instance.to_dict() +base_discriminator_dict = base_discriminator_instance.model_dump(by_alias=True) # create an instance of BaseDiscriminator from a dict -base_discriminator_from_dict = BaseDiscriminator.from_dict(base_discriminator_dict) +base_discriminator_from_dict = BaseDiscriminator.model_validate(base_discriminator_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/BasquePig.md b/samples/openapi3/client/petstore/python-lazyImports/docs/BasquePig.md index ee28d628722f..8af258aa7901 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/BasquePig.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/BasquePig.md @@ -16,14 +16,14 @@ from petstore_api.models.basque_pig import BasquePig # TODO update the JSON string below json = "{}" # create an instance of BasquePig from a JSON string -basque_pig_instance = BasquePig.from_json(json) +basque_pig_instance = BasquePig.model_validate_json(json) # print the JSON string representation of the object -print(BasquePig.to_json()) +print(BasquePig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -basque_pig_dict = basque_pig_instance.to_dict() +basque_pig_dict = basque_pig_instance.model_dump(by_alias=True) # create an instance of BasquePig from a dict -basque_pig_from_dict = BasquePig.from_dict(basque_pig_dict) +basque_pig_from_dict = BasquePig.model_validate(basque_pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Bathing.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Bathing.md index 6ad70e2f67cc..5365c9614d17 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Bathing.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Bathing.md @@ -17,14 +17,14 @@ from petstore_api.models.bathing import Bathing # TODO update the JSON string below json = "{}" # create an instance of Bathing from a JSON string -bathing_instance = Bathing.from_json(json) +bathing_instance = Bathing.model_validate_json(json) # print the JSON string representation of the object -print(Bathing.to_json()) +print(Bathing.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -bathing_dict = bathing_instance.to_dict() +bathing_dict = bathing_instance.model_dump(by_alias=True) # create an instance of Bathing from a dict -bathing_from_dict = Bathing.from_dict(bathing_dict) +bathing_from_dict = Bathing.model_validate(bathing_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Capitalization.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Capitalization.md index 6f564a8ed8c9..efbf7520b692 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Capitalization.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Capitalization.md @@ -20,14 +20,14 @@ from petstore_api.models.capitalization import Capitalization # TODO update the JSON string below json = "{}" # create an instance of Capitalization from a JSON string -capitalization_instance = Capitalization.from_json(json) +capitalization_instance = Capitalization.model_validate_json(json) # print the JSON string representation of the object -print(Capitalization.to_json()) +print(Capitalization.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -capitalization_dict = capitalization_instance.to_dict() +capitalization_dict = capitalization_instance.model_dump(by_alias=True) # create an instance of Capitalization from a dict -capitalization_from_dict = Capitalization.from_dict(capitalization_dict) +capitalization_from_dict = Capitalization.model_validate(capitalization_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Cat.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Cat.md index d0e39efdb33e..2940176bb9b8 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Cat.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Cat.md @@ -15,14 +15,14 @@ from petstore_api.models.cat import Cat # TODO update the JSON string below json = "{}" # create an instance of Cat from a JSON string -cat_instance = Cat.from_json(json) +cat_instance = Cat.model_validate_json(json) # print the JSON string representation of the object -print(Cat.to_json()) +print(Cat.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -cat_dict = cat_instance.to_dict() +cat_dict = cat_instance.model_dump(by_alias=True) # create an instance of Cat from a dict -cat_from_dict = Cat.from_dict(cat_dict) +cat_from_dict = Cat.model_validate(cat_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Category.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Category.md index dbde14b7344c..a1509b71308f 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Category.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Category.md @@ -16,14 +16,14 @@ from petstore_api.models.category import Category # TODO update the JSON string below json = "{}" # create an instance of Category from a JSON string -category_instance = Category.from_json(json) +category_instance = Category.model_validate_json(json) # print the JSON string representation of the object -print(Category.to_json()) +print(Category.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -category_dict = category_instance.to_dict() +category_dict = category_instance.model_dump(by_alias=True) # create an instance of Category from a dict -category_from_dict = Category.from_dict(category_dict) +category_from_dict = Category.model_validate(category_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/CircularAllOfRef.md b/samples/openapi3/client/petstore/python-lazyImports/docs/CircularAllOfRef.md index 65b171177e58..aaab0079b3f4 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/CircularAllOfRef.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/CircularAllOfRef.md @@ -16,14 +16,14 @@ from petstore_api.models.circular_all_of_ref import CircularAllOfRef # TODO update the JSON string below json = "{}" # create an instance of CircularAllOfRef from a JSON string -circular_all_of_ref_instance = CircularAllOfRef.from_json(json) +circular_all_of_ref_instance = CircularAllOfRef.model_validate_json(json) # print the JSON string representation of the object -print(CircularAllOfRef.to_json()) +print(CircularAllOfRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -circular_all_of_ref_dict = circular_all_of_ref_instance.to_dict() +circular_all_of_ref_dict = circular_all_of_ref_instance.model_dump(by_alias=True) # create an instance of CircularAllOfRef from a dict -circular_all_of_ref_from_dict = CircularAllOfRef.from_dict(circular_all_of_ref_dict) +circular_all_of_ref_from_dict = CircularAllOfRef.model_validate(circular_all_of_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/CircularReferenceModel.md b/samples/openapi3/client/petstore/python-lazyImports/docs/CircularReferenceModel.md index 87216f7273ab..33ec5e9b09bf 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/CircularReferenceModel.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/CircularReferenceModel.md @@ -16,14 +16,14 @@ from petstore_api.models.circular_reference_model import CircularReferenceModel # TODO update the JSON string below json = "{}" # create an instance of CircularReferenceModel from a JSON string -circular_reference_model_instance = CircularReferenceModel.from_json(json) +circular_reference_model_instance = CircularReferenceModel.model_validate_json(json) # print the JSON string representation of the object -print(CircularReferenceModel.to_json()) +print(CircularReferenceModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -circular_reference_model_dict = circular_reference_model_instance.to_dict() +circular_reference_model_dict = circular_reference_model_instance.model_dump(by_alias=True) # create an instance of CircularReferenceModel from a dict -circular_reference_model_from_dict = CircularReferenceModel.from_dict(circular_reference_model_dict) +circular_reference_model_from_dict = CircularReferenceModel.model_validate(circular_reference_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/ClassModel.md b/samples/openapi3/client/petstore/python-lazyImports/docs/ClassModel.md index ea76a5c157bf..9e69a69b5c27 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/ClassModel.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/ClassModel.md @@ -16,14 +16,14 @@ from petstore_api.models.class_model import ClassModel # TODO update the JSON string below json = "{}" # create an instance of ClassModel from a JSON string -class_model_instance = ClassModel.from_json(json) +class_model_instance = ClassModel.model_validate_json(json) # print the JSON string representation of the object -print(ClassModel.to_json()) +print(ClassModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -class_model_dict = class_model_instance.to_dict() +class_model_dict = class_model_instance.model_dump(by_alias=True) # create an instance of ClassModel from a dict -class_model_from_dict = ClassModel.from_dict(class_model_dict) +class_model_from_dict = ClassModel.model_validate(class_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Client.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Client.md index 22321c189150..6a9b3d800434 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Client.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Client.md @@ -15,14 +15,14 @@ from petstore_api.models.client import Client # TODO update the JSON string below json = "{}" # create an instance of Client from a JSON string -client_instance = Client.from_json(json) +client_instance = Client.model_validate_json(json) # print the JSON string representation of the object -print(Client.to_json()) +print(Client.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -client_dict = client_instance.to_dict() +client_dict = client_instance.model_dump(by_alias=True) # create an instance of Client from a dict -client_from_dict = Client.from_dict(client_dict) +client_from_dict = Client.model_validate(client_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Color.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Color.md index 9ac3ab2e91f4..088998e89af9 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Color.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Color.md @@ -15,14 +15,14 @@ from petstore_api.models.color import Color # TODO update the JSON string below json = "{}" # create an instance of Color from a JSON string -color_instance = Color.from_json(json) +color_instance = Color.model_validate_json(json) # print the JSON string representation of the object -print(Color.to_json()) +print(Color.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -color_dict = color_instance.to_dict() +color_dict = color_instance.model_dump(by_alias=True) # create an instance of Color from a dict -color_from_dict = Color.from_dict(color_dict) +color_from_dict = Color.model_validate(color_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Creature.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Creature.md index a4710214c198..bc746b2856e9 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Creature.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Creature.md @@ -16,14 +16,14 @@ from petstore_api.models.creature import Creature # TODO update the JSON string below json = "{}" # create an instance of Creature from a JSON string -creature_instance = Creature.from_json(json) +creature_instance = Creature.model_validate_json(json) # print the JSON string representation of the object -print(Creature.to_json()) +print(Creature.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -creature_dict = creature_instance.to_dict() +creature_dict = creature_instance.model_dump(by_alias=True) # create an instance of Creature from a dict -creature_from_dict = Creature.from_dict(creature_dict) +creature_from_dict = Creature.model_validate(creature_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/CreatureInfo.md b/samples/openapi3/client/petstore/python-lazyImports/docs/CreatureInfo.md index db3b82bb9ff5..a355b9e52802 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/CreatureInfo.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/CreatureInfo.md @@ -15,14 +15,14 @@ from petstore_api.models.creature_info import CreatureInfo # TODO update the JSON string below json = "{}" # create an instance of CreatureInfo from a JSON string -creature_info_instance = CreatureInfo.from_json(json) +creature_info_instance = CreatureInfo.model_validate_json(json) # print the JSON string representation of the object -print(CreatureInfo.to_json()) +print(CreatureInfo.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -creature_info_dict = creature_info_instance.to_dict() +creature_info_dict = creature_info_instance.model_dump(by_alias=True) # create an instance of CreatureInfo from a dict -creature_info_from_dict = CreatureInfo.from_dict(creature_info_dict) +creature_info_from_dict = CreatureInfo.model_validate(creature_info_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/DanishPig.md b/samples/openapi3/client/petstore/python-lazyImports/docs/DanishPig.md index 16941388832a..58902d70f7bd 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/DanishPig.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/DanishPig.md @@ -16,14 +16,14 @@ from petstore_api.models.danish_pig import DanishPig # TODO update the JSON string below json = "{}" # create an instance of DanishPig from a JSON string -danish_pig_instance = DanishPig.from_json(json) +danish_pig_instance = DanishPig.model_validate_json(json) # print the JSON string representation of the object -print(DanishPig.to_json()) +print(DanishPig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -danish_pig_dict = danish_pig_instance.to_dict() +danish_pig_dict = danish_pig_instance.model_dump(by_alias=True) # create an instance of DanishPig from a dict -danish_pig_from_dict = DanishPig.from_dict(danish_pig_dict) +danish_pig_from_dict = DanishPig.model_validate(danish_pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/DeprecatedObject.md b/samples/openapi3/client/petstore/python-lazyImports/docs/DeprecatedObject.md index 6b362f379ba4..55abc18b24d6 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/DeprecatedObject.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/DeprecatedObject.md @@ -15,14 +15,14 @@ from petstore_api.models.deprecated_object import DeprecatedObject # TODO update the JSON string below json = "{}" # create an instance of DeprecatedObject from a JSON string -deprecated_object_instance = DeprecatedObject.from_json(json) +deprecated_object_instance = DeprecatedObject.model_validate_json(json) # print the JSON string representation of the object -print(DeprecatedObject.to_json()) +print(DeprecatedObject.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -deprecated_object_dict = deprecated_object_instance.to_dict() +deprecated_object_dict = deprecated_object_instance.model_dump(by_alias=True) # create an instance of DeprecatedObject from a dict -deprecated_object_from_dict = DeprecatedObject.from_dict(deprecated_object_dict) +deprecated_object_from_dict = DeprecatedObject.model_validate(deprecated_object_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/DiscriminatorAllOfSub.md b/samples/openapi3/client/petstore/python-lazyImports/docs/DiscriminatorAllOfSub.md index f72b6e8e68ca..9453c541c53a 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/DiscriminatorAllOfSub.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/DiscriminatorAllOfSub.md @@ -14,14 +14,14 @@ from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub # TODO update the JSON string below json = "{}" # create an instance of DiscriminatorAllOfSub from a JSON string -discriminator_all_of_sub_instance = DiscriminatorAllOfSub.from_json(json) +discriminator_all_of_sub_instance = DiscriminatorAllOfSub.model_validate_json(json) # print the JSON string representation of the object -print(DiscriminatorAllOfSub.to_json()) +print(DiscriminatorAllOfSub.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -discriminator_all_of_sub_dict = discriminator_all_of_sub_instance.to_dict() +discriminator_all_of_sub_dict = discriminator_all_of_sub_instance.model_dump(by_alias=True) # create an instance of DiscriminatorAllOfSub from a dict -discriminator_all_of_sub_from_dict = DiscriminatorAllOfSub.from_dict(discriminator_all_of_sub_dict) +discriminator_all_of_sub_from_dict = DiscriminatorAllOfSub.model_validate(discriminator_all_of_sub_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/DiscriminatorAllOfSuper.md b/samples/openapi3/client/petstore/python-lazyImports/docs/DiscriminatorAllOfSuper.md index 477c05bfc446..c83f6792acab 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/DiscriminatorAllOfSuper.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/DiscriminatorAllOfSuper.md @@ -15,14 +15,14 @@ from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSup # TODO update the JSON string below json = "{}" # create an instance of DiscriminatorAllOfSuper from a JSON string -discriminator_all_of_super_instance = DiscriminatorAllOfSuper.from_json(json) +discriminator_all_of_super_instance = DiscriminatorAllOfSuper.model_validate_json(json) # print the JSON string representation of the object -print(DiscriminatorAllOfSuper.to_json()) +print(DiscriminatorAllOfSuper.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -discriminator_all_of_super_dict = discriminator_all_of_super_instance.to_dict() +discriminator_all_of_super_dict = discriminator_all_of_super_instance.model_dump(by_alias=True) # create an instance of DiscriminatorAllOfSuper from a dict -discriminator_all_of_super_from_dict = DiscriminatorAllOfSuper.from_dict(discriminator_all_of_super_dict) +discriminator_all_of_super_from_dict = DiscriminatorAllOfSuper.model_validate(discriminator_all_of_super_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Dog.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Dog.md index ed23f613d01d..099b3f781b4b 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Dog.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Dog.md @@ -15,14 +15,14 @@ from petstore_api.models.dog import Dog # TODO update the JSON string below json = "{}" # create an instance of Dog from a JSON string -dog_instance = Dog.from_json(json) +dog_instance = Dog.model_validate_json(json) # print the JSON string representation of the object -print(Dog.to_json()) +print(Dog.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -dog_dict = dog_instance.to_dict() +dog_dict = dog_instance.model_dump(by_alias=True) # create an instance of Dog from a dict -dog_from_dict = Dog.from_dict(dog_dict) +dog_from_dict = Dog.model_validate(dog_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/DummyModel.md b/samples/openapi3/client/petstore/python-lazyImports/docs/DummyModel.md index 01b675977f58..bf4ef8ec2b03 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/DummyModel.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/DummyModel.md @@ -16,14 +16,14 @@ from petstore_api.models.dummy_model import DummyModel # TODO update the JSON string below json = "{}" # create an instance of DummyModel from a JSON string -dummy_model_instance = DummyModel.from_json(json) +dummy_model_instance = DummyModel.model_validate_json(json) # print the JSON string representation of the object -print(DummyModel.to_json()) +print(DummyModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -dummy_model_dict = dummy_model_instance.to_dict() +dummy_model_dict = dummy_model_instance.model_dump(by_alias=True) # create an instance of DummyModel from a dict -dummy_model_from_dict = DummyModel.from_dict(dummy_model_dict) +dummy_model_from_dict = DummyModel.model_validate(dummy_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/EnumArrays.md b/samples/openapi3/client/petstore/python-lazyImports/docs/EnumArrays.md index f44617497bce..fa9dc0d523a9 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/EnumArrays.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/EnumArrays.md @@ -16,14 +16,14 @@ from petstore_api.models.enum_arrays import EnumArrays # TODO update the JSON string below json = "{}" # create an instance of EnumArrays from a JSON string -enum_arrays_instance = EnumArrays.from_json(json) +enum_arrays_instance = EnumArrays.model_validate_json(json) # print the JSON string representation of the object -print(EnumArrays.to_json()) +print(EnumArrays.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -enum_arrays_dict = enum_arrays_instance.to_dict() +enum_arrays_dict = enum_arrays_instance.model_dump(by_alias=True) # create an instance of EnumArrays from a dict -enum_arrays_from_dict = EnumArrays.from_dict(enum_arrays_dict) +enum_arrays_from_dict = EnumArrays.model_validate(enum_arrays_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/EnumRefWithDefaultValue.md b/samples/openapi3/client/petstore/python-lazyImports/docs/EnumRefWithDefaultValue.md index eeb0dc66969f..89bfb7c31366 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/EnumRefWithDefaultValue.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/EnumRefWithDefaultValue.md @@ -15,14 +15,14 @@ from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultVa # TODO update the JSON string below json = "{}" # create an instance of EnumRefWithDefaultValue from a JSON string -enum_ref_with_default_value_instance = EnumRefWithDefaultValue.from_json(json) +enum_ref_with_default_value_instance = EnumRefWithDefaultValue.model_validate_json(json) # print the JSON string representation of the object -print(EnumRefWithDefaultValue.to_json()) +print(EnumRefWithDefaultValue.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -enum_ref_with_default_value_dict = enum_ref_with_default_value_instance.to_dict() +enum_ref_with_default_value_dict = enum_ref_with_default_value_instance.model_dump(by_alias=True) # create an instance of EnumRefWithDefaultValue from a dict -enum_ref_with_default_value_from_dict = EnumRefWithDefaultValue.from_dict(enum_ref_with_default_value_dict) +enum_ref_with_default_value_from_dict = EnumRefWithDefaultValue.model_validate(enum_ref_with_default_value_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/EnumTest.md b/samples/openapi3/client/petstore/python-lazyImports/docs/EnumTest.md index 9f96c605d888..c6127df54638 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/EnumTest.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/EnumTest.md @@ -27,14 +27,14 @@ from petstore_api.models.enum_test import EnumTest # TODO update the JSON string below json = "{}" # create an instance of EnumTest from a JSON string -enum_test_instance = EnumTest.from_json(json) +enum_test_instance = EnumTest.model_validate_json(json) # print the JSON string representation of the object -print(EnumTest.to_json()) +print(EnumTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -enum_test_dict = enum_test_instance.to_dict() +enum_test_dict = enum_test_instance.model_dump(by_alias=True) # create an instance of EnumTest from a dict -enum_test_from_dict = EnumTest.from_dict(enum_test_dict) +enum_test_from_dict = EnumTest.model_validate(enum_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Feeding.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Feeding.md index 9f92b5d964d3..177cae170e77 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Feeding.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Feeding.md @@ -17,14 +17,14 @@ from petstore_api.models.feeding import Feeding # TODO update the JSON string below json = "{}" # create an instance of Feeding from a JSON string -feeding_instance = Feeding.from_json(json) +feeding_instance = Feeding.model_validate_json(json) # print the JSON string representation of the object -print(Feeding.to_json()) +print(Feeding.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -feeding_dict = feeding_instance.to_dict() +feeding_dict = feeding_instance.model_dump(by_alias=True) # create an instance of Feeding from a dict -feeding_from_dict = Feeding.from_dict(feeding_dict) +feeding_from_dict = Feeding.model_validate(feeding_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/File.md b/samples/openapi3/client/petstore/python-lazyImports/docs/File.md index 23f0567411ce..0b5942557efe 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/File.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/File.md @@ -16,14 +16,14 @@ from petstore_api.models.file import File # TODO update the JSON string below json = "{}" # create an instance of File from a JSON string -file_instance = File.from_json(json) +file_instance = File.model_validate_json(json) # print the JSON string representation of the object -print(File.to_json()) +print(File.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -file_dict = file_instance.to_dict() +file_dict = file_instance.model_dump(by_alias=True) # create an instance of File from a dict -file_from_dict = File.from_dict(file_dict) +file_from_dict = File.model_validate(file_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/FileSchemaTestClass.md b/samples/openapi3/client/petstore/python-lazyImports/docs/FileSchemaTestClass.md index e1118042a8ec..917f4ce73382 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/FileSchemaTestClass.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/FileSchemaTestClass.md @@ -16,14 +16,14 @@ from petstore_api.models.file_schema_test_class import FileSchemaTestClass # TODO update the JSON string below json = "{}" # create an instance of FileSchemaTestClass from a JSON string -file_schema_test_class_instance = FileSchemaTestClass.from_json(json) +file_schema_test_class_instance = FileSchemaTestClass.model_validate_json(json) # print the JSON string representation of the object -print(FileSchemaTestClass.to_json()) +print(FileSchemaTestClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -file_schema_test_class_dict = file_schema_test_class_instance.to_dict() +file_schema_test_class_dict = file_schema_test_class_instance.model_dump(by_alias=True) # create an instance of FileSchemaTestClass from a dict -file_schema_test_class_from_dict = FileSchemaTestClass.from_dict(file_schema_test_class_dict) +file_schema_test_class_from_dict = FileSchemaTestClass.model_validate(file_schema_test_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/FirstRef.md b/samples/openapi3/client/petstore/python-lazyImports/docs/FirstRef.md index 94b8ddc5ac22..51617b213a4f 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/FirstRef.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/FirstRef.md @@ -16,14 +16,14 @@ from petstore_api.models.first_ref import FirstRef # TODO update the JSON string below json = "{}" # create an instance of FirstRef from a JSON string -first_ref_instance = FirstRef.from_json(json) +first_ref_instance = FirstRef.model_validate_json(json) # print the JSON string representation of the object -print(FirstRef.to_json()) +print(FirstRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -first_ref_dict = first_ref_instance.to_dict() +first_ref_dict = first_ref_instance.model_dump(by_alias=True) # create an instance of FirstRef from a dict -first_ref_from_dict = FirstRef.from_dict(first_ref_dict) +first_ref_from_dict = FirstRef.model_validate(first_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Foo.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Foo.md index f635b0daa6db..e25a5a16bac5 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Foo.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Foo.md @@ -15,14 +15,14 @@ from petstore_api.models.foo import Foo # TODO update the JSON string below json = "{}" # create an instance of Foo from a JSON string -foo_instance = Foo.from_json(json) +foo_instance = Foo.model_validate_json(json) # print the JSON string representation of the object -print(Foo.to_json()) +print(Foo.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -foo_dict = foo_instance.to_dict() +foo_dict = foo_instance.model_dump(by_alias=True) # create an instance of Foo from a dict -foo_from_dict = Foo.from_dict(foo_dict) +foo_from_dict = Foo.model_validate(foo_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/FooGetDefaultResponse.md b/samples/openapi3/client/petstore/python-lazyImports/docs/FooGetDefaultResponse.md index 8d84f795b00a..dab8d870b496 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/FooGetDefaultResponse.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/FooGetDefaultResponse.md @@ -15,14 +15,14 @@ from petstore_api.models.foo_get_default_response import FooGetDefaultResponse # TODO update the JSON string below json = "{}" # create an instance of FooGetDefaultResponse from a JSON string -foo_get_default_response_instance = FooGetDefaultResponse.from_json(json) +foo_get_default_response_instance = FooGetDefaultResponse.model_validate_json(json) # print the JSON string representation of the object -print(FooGetDefaultResponse.to_json()) +print(FooGetDefaultResponse.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -foo_get_default_response_dict = foo_get_default_response_instance.to_dict() +foo_get_default_response_dict = foo_get_default_response_instance.model_dump(by_alias=True) # create an instance of FooGetDefaultResponse from a dict -foo_get_default_response_from_dict = FooGetDefaultResponse.from_dict(foo_get_default_response_dict) +foo_get_default_response_from_dict = FooGetDefaultResponse.model_validate(foo_get_default_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/FormatTest.md b/samples/openapi3/client/petstore/python-lazyImports/docs/FormatTest.md index 714d2401bbae..7b4bcb6513f8 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/FormatTest.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/FormatTest.md @@ -31,14 +31,14 @@ from petstore_api.models.format_test import FormatTest # TODO update the JSON string below json = "{}" # create an instance of FormatTest from a JSON string -format_test_instance = FormatTest.from_json(json) +format_test_instance = FormatTest.model_validate_json(json) # print the JSON string representation of the object -print(FormatTest.to_json()) +print(FormatTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -format_test_dict = format_test_instance.to_dict() +format_test_dict = format_test_instance.model_dump(by_alias=True) # create an instance of FormatTest from a dict -format_test_from_dict = FormatTest.from_dict(format_test_dict) +format_test_from_dict = FormatTest.model_validate(format_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/HasOnlyReadOnly.md b/samples/openapi3/client/petstore/python-lazyImports/docs/HasOnlyReadOnly.md index fdc48781b15a..a2d020b6a2cb 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/HasOnlyReadOnly.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/HasOnlyReadOnly.md @@ -16,14 +16,14 @@ from petstore_api.models.has_only_read_only import HasOnlyReadOnly # TODO update the JSON string below json = "{}" # create an instance of HasOnlyReadOnly from a JSON string -has_only_read_only_instance = HasOnlyReadOnly.from_json(json) +has_only_read_only_instance = HasOnlyReadOnly.model_validate_json(json) # print the JSON string representation of the object -print(HasOnlyReadOnly.to_json()) +print(HasOnlyReadOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -has_only_read_only_dict = has_only_read_only_instance.to_dict() +has_only_read_only_dict = has_only_read_only_instance.model_dump(by_alias=True) # create an instance of HasOnlyReadOnly from a dict -has_only_read_only_from_dict = HasOnlyReadOnly.from_dict(has_only_read_only_dict) +has_only_read_only_from_dict = HasOnlyReadOnly.model_validate(has_only_read_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/HealthCheckResult.md b/samples/openapi3/client/petstore/python-lazyImports/docs/HealthCheckResult.md index d4a2b187167f..49c69cf1d84b 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/HealthCheckResult.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/HealthCheckResult.md @@ -16,14 +16,14 @@ from petstore_api.models.health_check_result import HealthCheckResult # TODO update the JSON string below json = "{}" # create an instance of HealthCheckResult from a JSON string -health_check_result_instance = HealthCheckResult.from_json(json) +health_check_result_instance = HealthCheckResult.model_validate_json(json) # print the JSON string representation of the object -print(HealthCheckResult.to_json()) +print(HealthCheckResult.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -health_check_result_dict = health_check_result_instance.to_dict() +health_check_result_dict = health_check_result_instance.model_dump(by_alias=True) # create an instance of HealthCheckResult from a dict -health_check_result_from_dict = HealthCheckResult.from_dict(health_check_result_dict) +health_check_result_from_dict = HealthCheckResult.model_validate(health_check_result_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/HuntingDog.md b/samples/openapi3/client/petstore/python-lazyImports/docs/HuntingDog.md index 6db6745dd022..a3a905d84550 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/HuntingDog.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/HuntingDog.md @@ -15,14 +15,14 @@ from petstore_api.models.hunting_dog import HuntingDog # TODO update the JSON string below json = "{}" # create an instance of HuntingDog from a JSON string -hunting_dog_instance = HuntingDog.from_json(json) +hunting_dog_instance = HuntingDog.model_validate_json(json) # print the JSON string representation of the object -print(HuntingDog.to_json()) +print(HuntingDog.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -hunting_dog_dict = hunting_dog_instance.to_dict() +hunting_dog_dict = hunting_dog_instance.model_dump(by_alias=True) # create an instance of HuntingDog from a dict -hunting_dog_from_dict = HuntingDog.from_dict(hunting_dog_dict) +hunting_dog_from_dict = HuntingDog.model_validate(hunting_dog_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Info.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Info.md index db88778a9143..753e1d770730 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Info.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Info.md @@ -15,14 +15,14 @@ from petstore_api.models.info import Info # TODO update the JSON string below json = "{}" # create an instance of Info from a JSON string -info_instance = Info.from_json(json) +info_instance = Info.model_validate_json(json) # print the JSON string representation of the object -print(Info.to_json()) +print(Info.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -info_dict = info_instance.to_dict() +info_dict = info_instance.model_dump(by_alias=True) # create an instance of Info from a dict -info_from_dict = Info.from_dict(info_dict) +info_from_dict = Info.model_validate(info_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/InnerDictWithProperty.md b/samples/openapi3/client/petstore/python-lazyImports/docs/InnerDictWithProperty.md index 7b82ebb770b8..2a922855b34f 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/InnerDictWithProperty.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/InnerDictWithProperty.md @@ -15,14 +15,14 @@ from petstore_api.models.inner_dict_with_property import InnerDictWithProperty # TODO update the JSON string below json = "{}" # create an instance of InnerDictWithProperty from a JSON string -inner_dict_with_property_instance = InnerDictWithProperty.from_json(json) +inner_dict_with_property_instance = InnerDictWithProperty.model_validate_json(json) # print the JSON string representation of the object -print(InnerDictWithProperty.to_json()) +print(InnerDictWithProperty.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -inner_dict_with_property_dict = inner_dict_with_property_instance.to_dict() +inner_dict_with_property_dict = inner_dict_with_property_instance.model_dump(by_alias=True) # create an instance of InnerDictWithProperty from a dict -inner_dict_with_property_from_dict = InnerDictWithProperty.from_dict(inner_dict_with_property_dict) +inner_dict_with_property_from_dict = InnerDictWithProperty.model_validate(inner_dict_with_property_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/InputAllOf.md b/samples/openapi3/client/petstore/python-lazyImports/docs/InputAllOf.md index 45298f5308fc..ee77a141784a 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/InputAllOf.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/InputAllOf.md @@ -15,14 +15,14 @@ from petstore_api.models.input_all_of import InputAllOf # TODO update the JSON string below json = "{}" # create an instance of InputAllOf from a JSON string -input_all_of_instance = InputAllOf.from_json(json) +input_all_of_instance = InputAllOf.model_validate_json(json) # print the JSON string representation of the object -print(InputAllOf.to_json()) +print(InputAllOf.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -input_all_of_dict = input_all_of_instance.to_dict() +input_all_of_dict = input_all_of_instance.model_dump(by_alias=True) # create an instance of InputAllOf from a dict -input_all_of_from_dict = InputAllOf.from_dict(input_all_of_dict) +input_all_of_from_dict = InputAllOf.model_validate(input_all_of_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/IntOrString.md b/samples/openapi3/client/petstore/python-lazyImports/docs/IntOrString.md index b4070b9a8c79..6274e6fbc696 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/IntOrString.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/IntOrString.md @@ -14,14 +14,14 @@ from petstore_api.models.int_or_string import IntOrString # TODO update the JSON string below json = "{}" # create an instance of IntOrString from a JSON string -int_or_string_instance = IntOrString.from_json(json) +int_or_string_instance = IntOrString.model_validate_json(json) # print the JSON string representation of the object -print(IntOrString.to_json()) +print(IntOrString.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -int_or_string_dict = int_or_string_instance.to_dict() +int_or_string_dict = int_or_string_instance.model_dump(by_alias=True) # create an instance of IntOrString from a dict -int_or_string_from_dict = IntOrString.from_dict(int_or_string_dict) +int_or_string_from_dict = IntOrString.model_validate(int_or_string_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/ListClass.md b/samples/openapi3/client/petstore/python-lazyImports/docs/ListClass.md index 01068b7d22c3..00e12b663833 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/ListClass.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/ListClass.md @@ -15,14 +15,14 @@ from petstore_api.models.list_class import ListClass # TODO update the JSON string below json = "{}" # create an instance of ListClass from a JSON string -list_class_instance = ListClass.from_json(json) +list_class_instance = ListClass.model_validate_json(json) # print the JSON string representation of the object -print(ListClass.to_json()) +print(ListClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -list_class_dict = list_class_instance.to_dict() +list_class_dict = list_class_instance.model_dump(by_alias=True) # create an instance of ListClass from a dict -list_class_from_dict = ListClass.from_dict(list_class_dict) +list_class_from_dict = ListClass.model_validate(list_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/MapOfArrayOfModel.md b/samples/openapi3/client/petstore/python-lazyImports/docs/MapOfArrayOfModel.md index 71a4ef66b682..dbfba20ac23b 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/MapOfArrayOfModel.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/MapOfArrayOfModel.md @@ -15,14 +15,14 @@ from petstore_api.models.map_of_array_of_model import MapOfArrayOfModel # TODO update the JSON string below json = "{}" # create an instance of MapOfArrayOfModel from a JSON string -map_of_array_of_model_instance = MapOfArrayOfModel.from_json(json) +map_of_array_of_model_instance = MapOfArrayOfModel.model_validate_json(json) # print the JSON string representation of the object -print(MapOfArrayOfModel.to_json()) +print(MapOfArrayOfModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -map_of_array_of_model_dict = map_of_array_of_model_instance.to_dict() +map_of_array_of_model_dict = map_of_array_of_model_instance.model_dump(by_alias=True) # create an instance of MapOfArrayOfModel from a dict -map_of_array_of_model_from_dict = MapOfArrayOfModel.from_dict(map_of_array_of_model_dict) +map_of_array_of_model_from_dict = MapOfArrayOfModel.model_validate(map_of_array_of_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/MapTest.md b/samples/openapi3/client/petstore/python-lazyImports/docs/MapTest.md index d04b82e9378c..61382a4e3cd8 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/MapTest.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/MapTest.md @@ -18,14 +18,14 @@ from petstore_api.models.map_test import MapTest # TODO update the JSON string below json = "{}" # create an instance of MapTest from a JSON string -map_test_instance = MapTest.from_json(json) +map_test_instance = MapTest.model_validate_json(json) # print the JSON string representation of the object -print(MapTest.to_json()) +print(MapTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -map_test_dict = map_test_instance.to_dict() +map_test_dict = map_test_instance.model_dump(by_alias=True) # create an instance of MapTest from a dict -map_test_from_dict = MapTest.from_dict(map_test_dict) +map_test_from_dict = MapTest.model_validate(map_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/openapi3/client/petstore/python-lazyImports/docs/MixedPropertiesAndAdditionalPropertiesClass.md index 84134317aefc..41ef9465d498 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -17,14 +17,14 @@ from petstore_api.models.mixed_properties_and_additional_properties_class import # TODO update the JSON string below json = "{}" # create an instance of MixedPropertiesAndAdditionalPropertiesClass from a JSON string -mixed_properties_and_additional_properties_class_instance = MixedPropertiesAndAdditionalPropertiesClass.from_json(json) +mixed_properties_and_additional_properties_class_instance = MixedPropertiesAndAdditionalPropertiesClass.model_validate_json(json) # print the JSON string representation of the object -print(MixedPropertiesAndAdditionalPropertiesClass.to_json()) +print(MixedPropertiesAndAdditionalPropertiesClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -mixed_properties_and_additional_properties_class_dict = mixed_properties_and_additional_properties_class_instance.to_dict() +mixed_properties_and_additional_properties_class_dict = mixed_properties_and_additional_properties_class_instance.model_dump(by_alias=True) # create an instance of MixedPropertiesAndAdditionalPropertiesClass from a dict -mixed_properties_and_additional_properties_class_from_dict = MixedPropertiesAndAdditionalPropertiesClass.from_dict(mixed_properties_and_additional_properties_class_dict) +mixed_properties_and_additional_properties_class_from_dict = MixedPropertiesAndAdditionalPropertiesClass.model_validate(mixed_properties_and_additional_properties_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Model200Response.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Model200Response.md index 7fdbdefc6cec..56b765c788de 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Model200Response.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Model200Response.md @@ -17,14 +17,14 @@ from petstore_api.models.model200_response import Model200Response # TODO update the JSON string below json = "{}" # create an instance of Model200Response from a JSON string -model200_response_instance = Model200Response.from_json(json) +model200_response_instance = Model200Response.model_validate_json(json) # print the JSON string representation of the object -print(Model200Response.to_json()) +print(Model200Response.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model200_response_dict = model200_response_instance.to_dict() +model200_response_dict = model200_response_instance.model_dump(by_alias=True) # create an instance of Model200Response from a dict -model200_response_from_dict = Model200Response.from_dict(model200_response_dict) +model200_response_from_dict = Model200Response.model_validate(model200_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/ModelApiResponse.md b/samples/openapi3/client/petstore/python-lazyImports/docs/ModelApiResponse.md index 5ddc0db2a0f3..1fe361910ecb 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/ModelApiResponse.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/ModelApiResponse.md @@ -17,14 +17,14 @@ from petstore_api.models.model_api_response import ModelApiResponse # TODO update the JSON string below json = "{}" # create an instance of ModelApiResponse from a JSON string -model_api_response_instance = ModelApiResponse.from_json(json) +model_api_response_instance = ModelApiResponse.model_validate_json(json) # print the JSON string representation of the object -print(ModelApiResponse.to_json()) +print(ModelApiResponse.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model_api_response_dict = model_api_response_instance.to_dict() +model_api_response_dict = model_api_response_instance.model_dump(by_alias=True) # create an instance of ModelApiResponse from a dict -model_api_response_from_dict = ModelApiResponse.from_dict(model_api_response_dict) +model_api_response_from_dict = ModelApiResponse.model_validate(model_api_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/ModelField.md b/samples/openapi3/client/petstore/python-lazyImports/docs/ModelField.md index 9073b5dbdb00..8fa1be583ae3 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/ModelField.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/ModelField.md @@ -15,14 +15,14 @@ from petstore_api.models.model_field import ModelField # TODO update the JSON string below json = "{}" # create an instance of ModelField from a JSON string -model_field_instance = ModelField.from_json(json) +model_field_instance = ModelField.model_validate_json(json) # print the JSON string representation of the object -print(ModelField.to_json()) +print(ModelField.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model_field_dict = model_field_instance.to_dict() +model_field_dict = model_field_instance.model_dump(by_alias=True) # create an instance of ModelField from a dict -model_field_from_dict = ModelField.from_dict(model_field_dict) +model_field_from_dict = ModelField.model_validate(model_field_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/ModelReturn.md b/samples/openapi3/client/petstore/python-lazyImports/docs/ModelReturn.md index 7d327053b0c3..fbda0142410b 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/ModelReturn.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/ModelReturn.md @@ -16,14 +16,14 @@ from petstore_api.models.model_return import ModelReturn # TODO update the JSON string below json = "{}" # create an instance of ModelReturn from a JSON string -model_return_instance = ModelReturn.from_json(json) +model_return_instance = ModelReturn.model_validate_json(json) # print the JSON string representation of the object -print(ModelReturn.to_json()) +print(ModelReturn.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model_return_dict = model_return_instance.to_dict() +model_return_dict = model_return_instance.model_dump(by_alias=True) # create an instance of ModelReturn from a dict -model_return_from_dict = ModelReturn.from_dict(model_return_dict) +model_return_from_dict = ModelReturn.model_validate(model_return_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/MultiArrays.md b/samples/openapi3/client/petstore/python-lazyImports/docs/MultiArrays.md index fea5139e7e73..5feb5eb83587 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/MultiArrays.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/MultiArrays.md @@ -16,14 +16,14 @@ from petstore_api.models.multi_arrays import MultiArrays # TODO update the JSON string below json = "{}" # create an instance of MultiArrays from a JSON string -multi_arrays_instance = MultiArrays.from_json(json) +multi_arrays_instance = MultiArrays.model_validate_json(json) # print the JSON string representation of the object -print(MultiArrays.to_json()) +print(MultiArrays.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -multi_arrays_dict = multi_arrays_instance.to_dict() +multi_arrays_dict = multi_arrays_instance.model_dump(by_alias=True) # create an instance of MultiArrays from a dict -multi_arrays_from_dict = MultiArrays.from_dict(multi_arrays_dict) +multi_arrays_from_dict = MultiArrays.model_validate(multi_arrays_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Name.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Name.md index 5a04ec1ada06..fe30c2a76d97 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Name.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Name.md @@ -19,14 +19,14 @@ from petstore_api.models.name import Name # TODO update the JSON string below json = "{}" # create an instance of Name from a JSON string -name_instance = Name.from_json(json) +name_instance = Name.model_validate_json(json) # print the JSON string representation of the object -print(Name.to_json()) +print(Name.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -name_dict = name_instance.to_dict() +name_dict = name_instance.model_dump(by_alias=True) # create an instance of Name from a dict -name_from_dict = Name.from_dict(name_dict) +name_from_dict = Name.model_validate(name_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/NullableClass.md b/samples/openapi3/client/petstore/python-lazyImports/docs/NullableClass.md index 0387dcc2c67a..fafc21b70778 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/NullableClass.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/NullableClass.md @@ -27,14 +27,14 @@ from petstore_api.models.nullable_class import NullableClass # TODO update the JSON string below json = "{}" # create an instance of NullableClass from a JSON string -nullable_class_instance = NullableClass.from_json(json) +nullable_class_instance = NullableClass.model_validate_json(json) # print the JSON string representation of the object -print(NullableClass.to_json()) +print(NullableClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -nullable_class_dict = nullable_class_instance.to_dict() +nullable_class_dict = nullable_class_instance.model_dump(by_alias=True) # create an instance of NullableClass from a dict -nullable_class_from_dict = NullableClass.from_dict(nullable_class_dict) +nullable_class_from_dict = NullableClass.model_validate(nullable_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/NullableProperty.md b/samples/openapi3/client/petstore/python-lazyImports/docs/NullableProperty.md index 30edaf4844b2..1738420f6e1c 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/NullableProperty.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/NullableProperty.md @@ -16,14 +16,14 @@ from petstore_api.models.nullable_property import NullableProperty # TODO update the JSON string below json = "{}" # create an instance of NullableProperty from a JSON string -nullable_property_instance = NullableProperty.from_json(json) +nullable_property_instance = NullableProperty.model_validate_json(json) # print the JSON string representation of the object -print(NullableProperty.to_json()) +print(NullableProperty.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -nullable_property_dict = nullable_property_instance.to_dict() +nullable_property_dict = nullable_property_instance.model_dump(by_alias=True) # create an instance of NullableProperty from a dict -nullable_property_from_dict = NullableProperty.from_dict(nullable_property_dict) +nullable_property_from_dict = NullableProperty.model_validate(nullable_property_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/NumberOnly.md b/samples/openapi3/client/petstore/python-lazyImports/docs/NumberOnly.md index 415dd25585d4..739426b7c295 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/NumberOnly.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/NumberOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.number_only import NumberOnly # TODO update the JSON string below json = "{}" # create an instance of NumberOnly from a JSON string -number_only_instance = NumberOnly.from_json(json) +number_only_instance = NumberOnly.model_validate_json(json) # print the JSON string representation of the object -print(NumberOnly.to_json()) +print(NumberOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -number_only_dict = number_only_instance.to_dict() +number_only_dict = number_only_instance.model_dump(by_alias=True) # create an instance of NumberOnly from a dict -number_only_from_dict = NumberOnly.from_dict(number_only_dict) +number_only_from_dict = NumberOnly.model_validate(number_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/ObjectToTestAdditionalProperties.md b/samples/openapi3/client/petstore/python-lazyImports/docs/ObjectToTestAdditionalProperties.md index f6bc34c98e65..eec52f82c2ca 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/ObjectToTestAdditionalProperties.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/ObjectToTestAdditionalProperties.md @@ -16,14 +16,14 @@ from petstore_api.models.object_to_test_additional_properties import ObjectToTes # TODO update the JSON string below json = "{}" # create an instance of ObjectToTestAdditionalProperties from a JSON string -object_to_test_additional_properties_instance = ObjectToTestAdditionalProperties.from_json(json) +object_to_test_additional_properties_instance = ObjectToTestAdditionalProperties.model_validate_json(json) # print the JSON string representation of the object -print(ObjectToTestAdditionalProperties.to_json()) +print(ObjectToTestAdditionalProperties.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -object_to_test_additional_properties_dict = object_to_test_additional_properties_instance.to_dict() +object_to_test_additional_properties_dict = object_to_test_additional_properties_instance.model_dump(by_alias=True) # create an instance of ObjectToTestAdditionalProperties from a dict -object_to_test_additional_properties_from_dict = ObjectToTestAdditionalProperties.from_dict(object_to_test_additional_properties_dict) +object_to_test_additional_properties_from_dict = ObjectToTestAdditionalProperties.model_validate(object_to_test_additional_properties_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/ObjectWithDeprecatedFields.md b/samples/openapi3/client/petstore/python-lazyImports/docs/ObjectWithDeprecatedFields.md index 6dbd2ace04f1..6329b1899970 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/ObjectWithDeprecatedFields.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/ObjectWithDeprecatedFields.md @@ -18,14 +18,14 @@ from petstore_api.models.object_with_deprecated_fields import ObjectWithDeprecat # TODO update the JSON string below json = "{}" # create an instance of ObjectWithDeprecatedFields from a JSON string -object_with_deprecated_fields_instance = ObjectWithDeprecatedFields.from_json(json) +object_with_deprecated_fields_instance = ObjectWithDeprecatedFields.model_validate_json(json) # print the JSON string representation of the object -print(ObjectWithDeprecatedFields.to_json()) +print(ObjectWithDeprecatedFields.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -object_with_deprecated_fields_dict = object_with_deprecated_fields_instance.to_dict() +object_with_deprecated_fields_dict = object_with_deprecated_fields_instance.model_dump(by_alias=True) # create an instance of ObjectWithDeprecatedFields from a dict -object_with_deprecated_fields_from_dict = ObjectWithDeprecatedFields.from_dict(object_with_deprecated_fields_dict) +object_with_deprecated_fields_from_dict = ObjectWithDeprecatedFields.model_validate(object_with_deprecated_fields_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/OneOfEnumString.md b/samples/openapi3/client/petstore/python-lazyImports/docs/OneOfEnumString.md index 1d385c092934..e435ccb90c73 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/OneOfEnumString.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/OneOfEnumString.md @@ -15,14 +15,14 @@ from petstore_api.models.one_of_enum_string import OneOfEnumString # TODO update the JSON string below json = "{}" # create an instance of OneOfEnumString from a JSON string -one_of_enum_string_instance = OneOfEnumString.from_json(json) +one_of_enum_string_instance = OneOfEnumString.model_validate_json(json) # print the JSON string representation of the object -print(OneOfEnumString.to_json()) +print(OneOfEnumString.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -one_of_enum_string_dict = one_of_enum_string_instance.to_dict() +one_of_enum_string_dict = one_of_enum_string_instance.model_dump(by_alias=True) # create an instance of OneOfEnumString from a dict -one_of_enum_string_from_dict = OneOfEnumString.from_dict(one_of_enum_string_dict) +one_of_enum_string_from_dict = OneOfEnumString.model_validate(one_of_enum_string_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Order.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Order.md index 00526b8d04b9..8d4b8ac2983f 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Order.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Order.md @@ -20,14 +20,14 @@ from petstore_api.models.order import Order # TODO update the JSON string below json = "{}" # create an instance of Order from a JSON string -order_instance = Order.from_json(json) +order_instance = Order.model_validate_json(json) # print the JSON string representation of the object -print(Order.to_json()) +print(Order.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -order_dict = order_instance.to_dict() +order_dict = order_instance.model_dump(by_alias=True) # create an instance of Order from a dict -order_from_dict = Order.from_dict(order_dict) +order_from_dict = Order.model_validate(order_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/OuterComposite.md b/samples/openapi3/client/petstore/python-lazyImports/docs/OuterComposite.md index c8242c2d2653..bff67df11388 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/OuterComposite.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/OuterComposite.md @@ -17,14 +17,14 @@ from petstore_api.models.outer_composite import OuterComposite # TODO update the JSON string below json = "{}" # create an instance of OuterComposite from a JSON string -outer_composite_instance = OuterComposite.from_json(json) +outer_composite_instance = OuterComposite.model_validate_json(json) # print the JSON string representation of the object -print(OuterComposite.to_json()) +print(OuterComposite.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -outer_composite_dict = outer_composite_instance.to_dict() +outer_composite_dict = outer_composite_instance.model_dump(by_alias=True) # create an instance of OuterComposite from a dict -outer_composite_from_dict = OuterComposite.from_dict(outer_composite_dict) +outer_composite_from_dict = OuterComposite.model_validate(outer_composite_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/OuterObjectWithEnumProperty.md b/samples/openapi3/client/petstore/python-lazyImports/docs/OuterObjectWithEnumProperty.md index 6137dbd98da6..39611a8868a7 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/OuterObjectWithEnumProperty.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/OuterObjectWithEnumProperty.md @@ -16,14 +16,14 @@ from petstore_api.models.outer_object_with_enum_property import OuterObjectWithE # TODO update the JSON string below json = "{}" # create an instance of OuterObjectWithEnumProperty from a JSON string -outer_object_with_enum_property_instance = OuterObjectWithEnumProperty.from_json(json) +outer_object_with_enum_property_instance = OuterObjectWithEnumProperty.model_validate_json(json) # print the JSON string representation of the object -print(OuterObjectWithEnumProperty.to_json()) +print(OuterObjectWithEnumProperty.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -outer_object_with_enum_property_dict = outer_object_with_enum_property_instance.to_dict() +outer_object_with_enum_property_dict = outer_object_with_enum_property_instance.model_dump(by_alias=True) # create an instance of OuterObjectWithEnumProperty from a dict -outer_object_with_enum_property_from_dict = OuterObjectWithEnumProperty.from_dict(outer_object_with_enum_property_dict) +outer_object_with_enum_property_from_dict = OuterObjectWithEnumProperty.model_validate(outer_object_with_enum_property_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Parent.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Parent.md index 7387f9250aad..700d8446226c 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Parent.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Parent.md @@ -15,14 +15,14 @@ from petstore_api.models.parent import Parent # TODO update the JSON string below json = "{}" # create an instance of Parent from a JSON string -parent_instance = Parent.from_json(json) +parent_instance = Parent.model_validate_json(json) # print the JSON string representation of the object -print(Parent.to_json()) +print(Parent.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -parent_dict = parent_instance.to_dict() +parent_dict = parent_instance.model_dump(by_alias=True) # create an instance of Parent from a dict -parent_from_dict = Parent.from_dict(parent_dict) +parent_from_dict = Parent.model_validate(parent_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/ParentWithOptionalDict.md b/samples/openapi3/client/petstore/python-lazyImports/docs/ParentWithOptionalDict.md index bfc8688ea26f..7af4744a1016 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/ParentWithOptionalDict.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/ParentWithOptionalDict.md @@ -15,14 +15,14 @@ from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict # TODO update the JSON string below json = "{}" # create an instance of ParentWithOptionalDict from a JSON string -parent_with_optional_dict_instance = ParentWithOptionalDict.from_json(json) +parent_with_optional_dict_instance = ParentWithOptionalDict.model_validate_json(json) # print the JSON string representation of the object -print(ParentWithOptionalDict.to_json()) +print(ParentWithOptionalDict.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -parent_with_optional_dict_dict = parent_with_optional_dict_instance.to_dict() +parent_with_optional_dict_dict = parent_with_optional_dict_instance.model_dump(by_alias=True) # create an instance of ParentWithOptionalDict from a dict -parent_with_optional_dict_from_dict = ParentWithOptionalDict.from_dict(parent_with_optional_dict_dict) +parent_with_optional_dict_from_dict = ParentWithOptionalDict.model_validate(parent_with_optional_dict_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Pet.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Pet.md index 5329cf2fb925..e09f1b8b22ff 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Pet.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Pet.md @@ -20,14 +20,14 @@ from petstore_api.models.pet import Pet # TODO update the JSON string below json = "{}" # create an instance of Pet from a JSON string -pet_instance = Pet.from_json(json) +pet_instance = Pet.model_validate_json(json) # print the JSON string representation of the object -print(Pet.to_json()) +print(Pet.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -pet_dict = pet_instance.to_dict() +pet_dict = pet_instance.model_dump(by_alias=True) # create an instance of Pet from a dict -pet_from_dict = Pet.from_dict(pet_dict) +pet_from_dict = Pet.model_validate(pet_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Pig.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Pig.md index 625930676083..8c9de7a86c8a 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Pig.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Pig.md @@ -17,14 +17,14 @@ from petstore_api.models.pig import Pig # TODO update the JSON string below json = "{}" # create an instance of Pig from a JSON string -pig_instance = Pig.from_json(json) +pig_instance = Pig.model_validate_json(json) # print the JSON string representation of the object -print(Pig.to_json()) +print(Pig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -pig_dict = pig_instance.to_dict() +pig_dict = pig_instance.model_dump(by_alias=True) # create an instance of Pig from a dict -pig_from_dict = Pig.from_dict(pig_dict) +pig_from_dict = Pig.model_validate(pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/PonySizes.md b/samples/openapi3/client/petstore/python-lazyImports/docs/PonySizes.md index ced44c872060..03af5df5ed23 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/PonySizes.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/PonySizes.md @@ -15,14 +15,14 @@ from petstore_api.models.pony_sizes import PonySizes # TODO update the JSON string below json = "{}" # create an instance of PonySizes from a JSON string -pony_sizes_instance = PonySizes.from_json(json) +pony_sizes_instance = PonySizes.model_validate_json(json) # print the JSON string representation of the object -print(PonySizes.to_json()) +print(PonySizes.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -pony_sizes_dict = pony_sizes_instance.to_dict() +pony_sizes_dict = pony_sizes_instance.model_dump(by_alias=True) # create an instance of PonySizes from a dict -pony_sizes_from_dict = PonySizes.from_dict(pony_sizes_dict) +pony_sizes_from_dict = PonySizes.model_validate(pony_sizes_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/PoopCleaning.md b/samples/openapi3/client/petstore/python-lazyImports/docs/PoopCleaning.md index 8f9c25e08316..b58624f40112 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/PoopCleaning.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/PoopCleaning.md @@ -17,14 +17,14 @@ from petstore_api.models.poop_cleaning import PoopCleaning # TODO update the JSON string below json = "{}" # create an instance of PoopCleaning from a JSON string -poop_cleaning_instance = PoopCleaning.from_json(json) +poop_cleaning_instance = PoopCleaning.model_validate_json(json) # print the JSON string representation of the object -print(PoopCleaning.to_json()) +print(PoopCleaning.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -poop_cleaning_dict = poop_cleaning_instance.to_dict() +poop_cleaning_dict = poop_cleaning_instance.model_dump(by_alias=True) # create an instance of PoopCleaning from a dict -poop_cleaning_from_dict = PoopCleaning.from_dict(poop_cleaning_dict) +poop_cleaning_from_dict = PoopCleaning.model_validate(poop_cleaning_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/PrimitiveString.md b/samples/openapi3/client/petstore/python-lazyImports/docs/PrimitiveString.md index 85ceb632e167..c2296ead4a1a 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/PrimitiveString.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/PrimitiveString.md @@ -15,14 +15,14 @@ from petstore_api.models.primitive_string import PrimitiveString # TODO update the JSON string below json = "{}" # create an instance of PrimitiveString from a JSON string -primitive_string_instance = PrimitiveString.from_json(json) +primitive_string_instance = PrimitiveString.model_validate_json(json) # print the JSON string representation of the object -print(PrimitiveString.to_json()) +print(PrimitiveString.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -primitive_string_dict = primitive_string_instance.to_dict() +primitive_string_dict = primitive_string_instance.model_dump(by_alias=True) # create an instance of PrimitiveString from a dict -primitive_string_from_dict = PrimitiveString.from_dict(primitive_string_dict) +primitive_string_from_dict = PrimitiveString.model_validate(primitive_string_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/PropertyMap.md b/samples/openapi3/client/petstore/python-lazyImports/docs/PropertyMap.md index a55a0e5c6f01..3982b35d5724 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/PropertyMap.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/PropertyMap.md @@ -15,14 +15,14 @@ from petstore_api.models.property_map import PropertyMap # TODO update the JSON string below json = "{}" # create an instance of PropertyMap from a JSON string -property_map_instance = PropertyMap.from_json(json) +property_map_instance = PropertyMap.model_validate_json(json) # print the JSON string representation of the object -print(PropertyMap.to_json()) +print(PropertyMap.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -property_map_dict = property_map_instance.to_dict() +property_map_dict = property_map_instance.model_dump(by_alias=True) # create an instance of PropertyMap from a dict -property_map_from_dict = PropertyMap.from_dict(property_map_dict) +property_map_from_dict = PropertyMap.model_validate(property_map_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/PropertyNameCollision.md b/samples/openapi3/client/petstore/python-lazyImports/docs/PropertyNameCollision.md index 40c233670dd0..e98d6ad2aa59 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/PropertyNameCollision.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/PropertyNameCollision.md @@ -17,14 +17,14 @@ from petstore_api.models.property_name_collision import PropertyNameCollision # TODO update the JSON string below json = "{}" # create an instance of PropertyNameCollision from a JSON string -property_name_collision_instance = PropertyNameCollision.from_json(json) +property_name_collision_instance = PropertyNameCollision.model_validate_json(json) # print the JSON string representation of the object -print(PropertyNameCollision.to_json()) +print(PropertyNameCollision.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -property_name_collision_dict = property_name_collision_instance.to_dict() +property_name_collision_dict = property_name_collision_instance.model_dump(by_alias=True) # create an instance of PropertyNameCollision from a dict -property_name_collision_from_dict = PropertyNameCollision.from_dict(property_name_collision_dict) +property_name_collision_from_dict = PropertyNameCollision.model_validate(property_name_collision_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/ReadOnlyFirst.md b/samples/openapi3/client/petstore/python-lazyImports/docs/ReadOnlyFirst.md index 686ec5da41c9..51831854b601 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/ReadOnlyFirst.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/ReadOnlyFirst.md @@ -16,14 +16,14 @@ from petstore_api.models.read_only_first import ReadOnlyFirst # TODO update the JSON string below json = "{}" # create an instance of ReadOnlyFirst from a JSON string -read_only_first_instance = ReadOnlyFirst.from_json(json) +read_only_first_instance = ReadOnlyFirst.model_validate_json(json) # print the JSON string representation of the object -print(ReadOnlyFirst.to_json()) +print(ReadOnlyFirst.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -read_only_first_dict = read_only_first_instance.to_dict() +read_only_first_dict = read_only_first_instance.model_dump(by_alias=True) # create an instance of ReadOnlyFirst from a dict -read_only_first_from_dict = ReadOnlyFirst.from_dict(read_only_first_dict) +read_only_first_from_dict = ReadOnlyFirst.model_validate(read_only_first_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/SecondCircularAllOfRef.md b/samples/openapi3/client/petstore/python-lazyImports/docs/SecondCircularAllOfRef.md index 65ebdd4c7e1d..173a4eb5fd68 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/SecondCircularAllOfRef.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/SecondCircularAllOfRef.md @@ -16,14 +16,14 @@ from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRe # TODO update the JSON string below json = "{}" # create an instance of SecondCircularAllOfRef from a JSON string -second_circular_all_of_ref_instance = SecondCircularAllOfRef.from_json(json) +second_circular_all_of_ref_instance = SecondCircularAllOfRef.model_validate_json(json) # print the JSON string representation of the object -print(SecondCircularAllOfRef.to_json()) +print(SecondCircularAllOfRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -second_circular_all_of_ref_dict = second_circular_all_of_ref_instance.to_dict() +second_circular_all_of_ref_dict = second_circular_all_of_ref_instance.model_dump(by_alias=True) # create an instance of SecondCircularAllOfRef from a dict -second_circular_all_of_ref_from_dict = SecondCircularAllOfRef.from_dict(second_circular_all_of_ref_dict) +second_circular_all_of_ref_from_dict = SecondCircularAllOfRef.model_validate(second_circular_all_of_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/SecondRef.md b/samples/openapi3/client/petstore/python-lazyImports/docs/SecondRef.md index dfb1a0ac6db5..87c1e1d4bb3a 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/SecondRef.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/SecondRef.md @@ -16,14 +16,14 @@ from petstore_api.models.second_ref import SecondRef # TODO update the JSON string below json = "{}" # create an instance of SecondRef from a JSON string -second_ref_instance = SecondRef.from_json(json) +second_ref_instance = SecondRef.model_validate_json(json) # print the JSON string representation of the object -print(SecondRef.to_json()) +print(SecondRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -second_ref_dict = second_ref_instance.to_dict() +second_ref_dict = second_ref_instance.model_dump(by_alias=True) # create an instance of SecondRef from a dict -second_ref_from_dict = SecondRef.from_dict(second_ref_dict) +second_ref_from_dict = SecondRef.model_validate(second_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/SelfReferenceModel.md b/samples/openapi3/client/petstore/python-lazyImports/docs/SelfReferenceModel.md index 208cdac04b6f..68c6e661ac94 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/SelfReferenceModel.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/SelfReferenceModel.md @@ -16,14 +16,14 @@ from petstore_api.models.self_reference_model import SelfReferenceModel # TODO update the JSON string below json = "{}" # create an instance of SelfReferenceModel from a JSON string -self_reference_model_instance = SelfReferenceModel.from_json(json) +self_reference_model_instance = SelfReferenceModel.model_validate_json(json) # print the JSON string representation of the object -print(SelfReferenceModel.to_json()) +print(SelfReferenceModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -self_reference_model_dict = self_reference_model_instance.to_dict() +self_reference_model_dict = self_reference_model_instance.model_dump(by_alias=True) # create an instance of SelfReferenceModel from a dict -self_reference_model_from_dict = SelfReferenceModel.from_dict(self_reference_model_dict) +self_reference_model_from_dict = SelfReferenceModel.model_validate(self_reference_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/SpecialModelName.md b/samples/openapi3/client/petstore/python-lazyImports/docs/SpecialModelName.md index 35303f34efd2..0e99036d92f4 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/SpecialModelName.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/SpecialModelName.md @@ -15,14 +15,14 @@ from petstore_api.models.special_model_name import SpecialModelName # TODO update the JSON string below json = "{}" # create an instance of SpecialModelName from a JSON string -special_model_name_instance = SpecialModelName.from_json(json) +special_model_name_instance = SpecialModelName.model_validate_json(json) # print the JSON string representation of the object -print(SpecialModelName.to_json()) +print(SpecialModelName.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -special_model_name_dict = special_model_name_instance.to_dict() +special_model_name_dict = special_model_name_instance.model_dump(by_alias=True) # create an instance of SpecialModelName from a dict -special_model_name_from_dict = SpecialModelName.from_dict(special_model_name_dict) +special_model_name_from_dict = SpecialModelName.model_validate(special_model_name_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/SpecialName.md b/samples/openapi3/client/petstore/python-lazyImports/docs/SpecialName.md index ccc550b16e33..5d00c8517aaa 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/SpecialName.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/SpecialName.md @@ -17,14 +17,14 @@ from petstore_api.models.special_name import SpecialName # TODO update the JSON string below json = "{}" # create an instance of SpecialName from a JSON string -special_name_instance = SpecialName.from_json(json) +special_name_instance = SpecialName.model_validate_json(json) # print the JSON string representation of the object -print(SpecialName.to_json()) +print(SpecialName.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -special_name_dict = special_name_instance.to_dict() +special_name_dict = special_name_instance.model_dump(by_alias=True) # create an instance of SpecialName from a dict -special_name_from_dict = SpecialName.from_dict(special_name_dict) +special_name_from_dict = SpecialName.model_validate(special_name_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Tag.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Tag.md index 4106d9cfe5db..98068caba254 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Tag.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Tag.md @@ -16,14 +16,14 @@ from petstore_api.models.tag import Tag # TODO update the JSON string below json = "{}" # create an instance of Tag from a JSON string -tag_instance = Tag.from_json(json) +tag_instance = Tag.model_validate_json(json) # print the JSON string representation of the object -print(Tag.to_json()) +print(Tag.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -tag_dict = tag_instance.to_dict() +tag_dict = tag_instance.model_dump(by_alias=True) # create an instance of Tag from a dict -tag_from_dict = Tag.from_dict(tag_dict) +tag_from_dict = Tag.model_validate(tag_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Task.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Task.md index 85fa2776a059..92aed88f998b 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Task.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Task.md @@ -17,14 +17,14 @@ from petstore_api.models.task import Task # TODO update the JSON string below json = "{}" # create an instance of Task from a JSON string -task_instance = Task.from_json(json) +task_instance = Task.model_validate_json(json) # print the JSON string representation of the object -print(Task.to_json()) +print(Task.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -task_dict = task_instance.to_dict() +task_dict = task_instance.model_dump(by_alias=True) # create an instance of Task from a dict -task_from_dict = Task.from_dict(task_dict) +task_from_dict = Task.model_validate(task_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/TaskActivity.md b/samples/openapi3/client/petstore/python-lazyImports/docs/TaskActivity.md index e905a477292d..3f8e10cf7ae5 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/TaskActivity.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/TaskActivity.md @@ -17,14 +17,14 @@ from petstore_api.models.task_activity import TaskActivity # TODO update the JSON string below json = "{}" # create an instance of TaskActivity from a JSON string -task_activity_instance = TaskActivity.from_json(json) +task_activity_instance = TaskActivity.model_validate_json(json) # print the JSON string representation of the object -print(TaskActivity.to_json()) +print(TaskActivity.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -task_activity_dict = task_activity_instance.to_dict() +task_activity_dict = task_activity_instance.model_dump(by_alias=True) # create an instance of TaskActivity from a dict -task_activity_from_dict = TaskActivity.from_dict(task_activity_dict) +task_activity_from_dict = TaskActivity.model_validate(task_activity_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/TestErrorResponsesWithModel400Response.md b/samples/openapi3/client/petstore/python-lazyImports/docs/TestErrorResponsesWithModel400Response.md index be416bbad0f7..ba20c0666f90 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/TestErrorResponsesWithModel400Response.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/TestErrorResponsesWithModel400Response.md @@ -15,14 +15,14 @@ from petstore_api.models.test_error_responses_with_model400_response import Test # TODO update the JSON string below json = "{}" # create an instance of TestErrorResponsesWithModel400Response from a JSON string -test_error_responses_with_model400_response_instance = TestErrorResponsesWithModel400Response.from_json(json) +test_error_responses_with_model400_response_instance = TestErrorResponsesWithModel400Response.model_validate_json(json) # print the JSON string representation of the object -print(TestErrorResponsesWithModel400Response.to_json()) +print(TestErrorResponsesWithModel400Response.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_error_responses_with_model400_response_dict = test_error_responses_with_model400_response_instance.to_dict() +test_error_responses_with_model400_response_dict = test_error_responses_with_model400_response_instance.model_dump(by_alias=True) # create an instance of TestErrorResponsesWithModel400Response from a dict -test_error_responses_with_model400_response_from_dict = TestErrorResponsesWithModel400Response.from_dict(test_error_responses_with_model400_response_dict) +test_error_responses_with_model400_response_from_dict = TestErrorResponsesWithModel400Response.model_validate(test_error_responses_with_model400_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/TestErrorResponsesWithModel404Response.md b/samples/openapi3/client/petstore/python-lazyImports/docs/TestErrorResponsesWithModel404Response.md index 1c984f847bf1..d229d30e7b39 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/TestErrorResponsesWithModel404Response.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/TestErrorResponsesWithModel404Response.md @@ -15,14 +15,14 @@ from petstore_api.models.test_error_responses_with_model404_response import Test # TODO update the JSON string below json = "{}" # create an instance of TestErrorResponsesWithModel404Response from a JSON string -test_error_responses_with_model404_response_instance = TestErrorResponsesWithModel404Response.from_json(json) +test_error_responses_with_model404_response_instance = TestErrorResponsesWithModel404Response.model_validate_json(json) # print the JSON string representation of the object -print(TestErrorResponsesWithModel404Response.to_json()) +print(TestErrorResponsesWithModel404Response.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_error_responses_with_model404_response_dict = test_error_responses_with_model404_response_instance.to_dict() +test_error_responses_with_model404_response_dict = test_error_responses_with_model404_response_instance.model_dump(by_alias=True) # create an instance of TestErrorResponsesWithModel404Response from a dict -test_error_responses_with_model404_response_from_dict = TestErrorResponsesWithModel404Response.from_dict(test_error_responses_with_model404_response_dict) +test_error_responses_with_model404_response_from_dict = TestErrorResponsesWithModel404Response.model_validate(test_error_responses_with_model404_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/TestInlineFreeformAdditionalPropertiesRequest.md b/samples/openapi3/client/petstore/python-lazyImports/docs/TestInlineFreeformAdditionalPropertiesRequest.md index 511132d689be..6fd235e60800 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/TestInlineFreeformAdditionalPropertiesRequest.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/TestInlineFreeformAdditionalPropertiesRequest.md @@ -15,14 +15,14 @@ from petstore_api.models.test_inline_freeform_additional_properties_request impo # TODO update the JSON string below json = "{}" # create an instance of TestInlineFreeformAdditionalPropertiesRequest from a JSON string -test_inline_freeform_additional_properties_request_instance = TestInlineFreeformAdditionalPropertiesRequest.from_json(json) +test_inline_freeform_additional_properties_request_instance = TestInlineFreeformAdditionalPropertiesRequest.model_validate_json(json) # print the JSON string representation of the object -print(TestInlineFreeformAdditionalPropertiesRequest.to_json()) +print(TestInlineFreeformAdditionalPropertiesRequest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_inline_freeform_additional_properties_request_dict = test_inline_freeform_additional_properties_request_instance.to_dict() +test_inline_freeform_additional_properties_request_dict = test_inline_freeform_additional_properties_request_instance.model_dump(by_alias=True) # create an instance of TestInlineFreeformAdditionalPropertiesRequest from a dict -test_inline_freeform_additional_properties_request_from_dict = TestInlineFreeformAdditionalPropertiesRequest.from_dict(test_inline_freeform_additional_properties_request_dict) +test_inline_freeform_additional_properties_request_from_dict = TestInlineFreeformAdditionalPropertiesRequest.model_validate(test_inline_freeform_additional_properties_request_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/TestModelWithEnumDefault.md b/samples/openapi3/client/petstore/python-lazyImports/docs/TestModelWithEnumDefault.md index 7d46e86deba4..d98d6ad35cb3 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/TestModelWithEnumDefault.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/TestModelWithEnumDefault.md @@ -19,14 +19,14 @@ from petstore_api.models.test_model_with_enum_default import TestModelWithEnumDe # TODO update the JSON string below json = "{}" # create an instance of TestModelWithEnumDefault from a JSON string -test_model_with_enum_default_instance = TestModelWithEnumDefault.from_json(json) +test_model_with_enum_default_instance = TestModelWithEnumDefault.model_validate_json(json) # print the JSON string representation of the object -print(TestModelWithEnumDefault.to_json()) +print(TestModelWithEnumDefault.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_model_with_enum_default_dict = test_model_with_enum_default_instance.to_dict() +test_model_with_enum_default_dict = test_model_with_enum_default_instance.model_dump(by_alias=True) # create an instance of TestModelWithEnumDefault from a dict -test_model_with_enum_default_from_dict = TestModelWithEnumDefault.from_dict(test_model_with_enum_default_dict) +test_model_with_enum_default_from_dict = TestModelWithEnumDefault.model_validate(test_model_with_enum_default_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/TestObjectForMultipartRequestsRequestMarker.md b/samples/openapi3/client/petstore/python-lazyImports/docs/TestObjectForMultipartRequestsRequestMarker.md index ff0ca9ee00ac..4ef346d455be 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/TestObjectForMultipartRequestsRequestMarker.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/TestObjectForMultipartRequestsRequestMarker.md @@ -15,14 +15,14 @@ from petstore_api.models.test_object_for_multipart_requests_request_marker impor # TODO update the JSON string below json = "{}" # create an instance of TestObjectForMultipartRequestsRequestMarker from a JSON string -test_object_for_multipart_requests_request_marker_instance = TestObjectForMultipartRequestsRequestMarker.from_json(json) +test_object_for_multipart_requests_request_marker_instance = TestObjectForMultipartRequestsRequestMarker.model_validate_json(json) # print the JSON string representation of the object -print(TestObjectForMultipartRequestsRequestMarker.to_json()) +print(TestObjectForMultipartRequestsRequestMarker.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_object_for_multipart_requests_request_marker_dict = test_object_for_multipart_requests_request_marker_instance.to_dict() +test_object_for_multipart_requests_request_marker_dict = test_object_for_multipart_requests_request_marker_instance.model_dump(by_alias=True) # create an instance of TestObjectForMultipartRequestsRequestMarker from a dict -test_object_for_multipart_requests_request_marker_from_dict = TestObjectForMultipartRequestsRequestMarker.from_dict(test_object_for_multipart_requests_request_marker_dict) +test_object_for_multipart_requests_request_marker_from_dict = TestObjectForMultipartRequestsRequestMarker.model_validate(test_object_for_multipart_requests_request_marker_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/Tiger.md b/samples/openapi3/client/petstore/python-lazyImports/docs/Tiger.md index f1cf2133f0f7..bf096ee0be68 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/Tiger.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/Tiger.md @@ -15,14 +15,14 @@ from petstore_api.models.tiger import Tiger # TODO update the JSON string below json = "{}" # create an instance of Tiger from a JSON string -tiger_instance = Tiger.from_json(json) +tiger_instance = Tiger.model_validate_json(json) # print the JSON string representation of the object -print(Tiger.to_json()) +print(Tiger.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -tiger_dict = tiger_instance.to_dict() +tiger_dict = tiger_instance.model_dump(by_alias=True) # create an instance of Tiger from a dict -tiger_from_dict = Tiger.from_dict(tiger_dict) +tiger_from_dict = Tiger.model_validate(tiger_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/UnnamedDictWithAdditionalModelListProperties.md b/samples/openapi3/client/petstore/python-lazyImports/docs/UnnamedDictWithAdditionalModelListProperties.md index 68cd00ab0a7a..a8d992c4e033 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/UnnamedDictWithAdditionalModelListProperties.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/UnnamedDictWithAdditionalModelListProperties.md @@ -15,14 +15,14 @@ from petstore_api.models.unnamed_dict_with_additional_model_list_properties impo # TODO update the JSON string below json = "{}" # create an instance of UnnamedDictWithAdditionalModelListProperties from a JSON string -unnamed_dict_with_additional_model_list_properties_instance = UnnamedDictWithAdditionalModelListProperties.from_json(json) +unnamed_dict_with_additional_model_list_properties_instance = UnnamedDictWithAdditionalModelListProperties.model_validate_json(json) # print the JSON string representation of the object -print(UnnamedDictWithAdditionalModelListProperties.to_json()) +print(UnnamedDictWithAdditionalModelListProperties.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -unnamed_dict_with_additional_model_list_properties_dict = unnamed_dict_with_additional_model_list_properties_instance.to_dict() +unnamed_dict_with_additional_model_list_properties_dict = unnamed_dict_with_additional_model_list_properties_instance.model_dump(by_alias=True) # create an instance of UnnamedDictWithAdditionalModelListProperties from a dict -unnamed_dict_with_additional_model_list_properties_from_dict = UnnamedDictWithAdditionalModelListProperties.from_dict(unnamed_dict_with_additional_model_list_properties_dict) +unnamed_dict_with_additional_model_list_properties_from_dict = UnnamedDictWithAdditionalModelListProperties.model_validate(unnamed_dict_with_additional_model_list_properties_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/UnnamedDictWithAdditionalStringListProperties.md b/samples/openapi3/client/petstore/python-lazyImports/docs/UnnamedDictWithAdditionalStringListProperties.md index 045b0e22ad09..44aa893d69a7 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/UnnamedDictWithAdditionalStringListProperties.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/UnnamedDictWithAdditionalStringListProperties.md @@ -15,14 +15,14 @@ from petstore_api.models.unnamed_dict_with_additional_string_list_properties imp # TODO update the JSON string below json = "{}" # create an instance of UnnamedDictWithAdditionalStringListProperties from a JSON string -unnamed_dict_with_additional_string_list_properties_instance = UnnamedDictWithAdditionalStringListProperties.from_json(json) +unnamed_dict_with_additional_string_list_properties_instance = UnnamedDictWithAdditionalStringListProperties.model_validate_json(json) # print the JSON string representation of the object -print(UnnamedDictWithAdditionalStringListProperties.to_json()) +print(UnnamedDictWithAdditionalStringListProperties.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -unnamed_dict_with_additional_string_list_properties_dict = unnamed_dict_with_additional_string_list_properties_instance.to_dict() +unnamed_dict_with_additional_string_list_properties_dict = unnamed_dict_with_additional_string_list_properties_instance.model_dump(by_alias=True) # create an instance of UnnamedDictWithAdditionalStringListProperties from a dict -unnamed_dict_with_additional_string_list_properties_from_dict = UnnamedDictWithAdditionalStringListProperties.from_dict(unnamed_dict_with_additional_string_list_properties_dict) +unnamed_dict_with_additional_string_list_properties_from_dict = UnnamedDictWithAdditionalStringListProperties.model_validate(unnamed_dict_with_additional_string_list_properties_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/UploadFileWithAdditionalPropertiesRequestObject.md b/samples/openapi3/client/petstore/python-lazyImports/docs/UploadFileWithAdditionalPropertiesRequestObject.md index 141027780371..096740ca96c2 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/UploadFileWithAdditionalPropertiesRequestObject.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/UploadFileWithAdditionalPropertiesRequestObject.md @@ -16,14 +16,14 @@ from petstore_api.models.upload_file_with_additional_properties_request_object i # TODO update the JSON string below json = "{}" # create an instance of UploadFileWithAdditionalPropertiesRequestObject from a JSON string -upload_file_with_additional_properties_request_object_instance = UploadFileWithAdditionalPropertiesRequestObject.from_json(json) +upload_file_with_additional_properties_request_object_instance = UploadFileWithAdditionalPropertiesRequestObject.model_validate_json(json) # print the JSON string representation of the object -print(UploadFileWithAdditionalPropertiesRequestObject.to_json()) +print(UploadFileWithAdditionalPropertiesRequestObject.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -upload_file_with_additional_properties_request_object_dict = upload_file_with_additional_properties_request_object_instance.to_dict() +upload_file_with_additional_properties_request_object_dict = upload_file_with_additional_properties_request_object_instance.model_dump(by_alias=True) # create an instance of UploadFileWithAdditionalPropertiesRequestObject from a dict -upload_file_with_additional_properties_request_object_from_dict = UploadFileWithAdditionalPropertiesRequestObject.from_dict(upload_file_with_additional_properties_request_object_dict) +upload_file_with_additional_properties_request_object_from_dict = UploadFileWithAdditionalPropertiesRequestObject.model_validate(upload_file_with_additional_properties_request_object_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/User.md b/samples/openapi3/client/petstore/python-lazyImports/docs/User.md index c45d26d27043..1986137ecc70 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/User.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/User.md @@ -22,14 +22,14 @@ from petstore_api.models.user import User # TODO update the JSON string below json = "{}" # create an instance of User from a JSON string -user_instance = User.from_json(json) +user_instance = User.model_validate_json(json) # print the JSON string representation of the object -print(User.to_json()) +print(User.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -user_dict = user_instance.to_dict() +user_dict = user_instance.model_dump(by_alias=True) # create an instance of User from a dict -user_from_dict = User.from_dict(user_dict) +user_from_dict = User.model_validate(user_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/docs/WithNestedOneOf.md b/samples/openapi3/client/petstore/python-lazyImports/docs/WithNestedOneOf.md index e7bbbc28fc2d..63b0f83540d1 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/docs/WithNestedOneOf.md +++ b/samples/openapi3/client/petstore/python-lazyImports/docs/WithNestedOneOf.md @@ -17,14 +17,14 @@ from petstore_api.models.with_nested_one_of import WithNestedOneOf # TODO update the JSON string below json = "{}" # create an instance of WithNestedOneOf from a JSON string -with_nested_one_of_instance = WithNestedOneOf.from_json(json) +with_nested_one_of_instance = WithNestedOneOf.model_validate_json(json) # print the JSON string representation of the object -print(WithNestedOneOf.to_json()) +print(WithNestedOneOf.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -with_nested_one_of_dict = with_nested_one_of_instance.to_dict() +with_nested_one_of_dict = with_nested_one_of_instance.model_dump(by_alias=True) # create an instance of WithNestedOneOf from a dict -with_nested_one_of_from_dict = WithNestedOneOf.from_dict(with_nested_one_of_dict) +with_nested_one_of_from_dict = WithNestedOneOf.model_validate(with_nested_one_of_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/another_fake_api.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/another_fake_api.py index 07328c8975e3..1e19c6d880d1 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/another_fake_api.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/another_fake_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field from typing_extensions import Annotated diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/default_api.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/default_api.py index 3be576102f96..5f05c540a238 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/default_api.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/default_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from petstore_api.models.foo_get_default_response import FooGetDefaultResponse diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/fake_api.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/fake_api.py index 17761ab9bd0e..6d99595e3059 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/fake_api.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/fake_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from datetime import date, datetime from pydantic import Field, StrictBool, StrictBytes, StrictFloat, StrictInt, StrictStr, field_validator diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/fake_classname_tags123_api.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/fake_classname_tags123_api.py index 558590bab2de..c5596bef9393 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/fake_classname_tags123_api.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/fake_classname_tags123_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field from typing_extensions import Annotated diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/import_test_datetime_api.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/import_test_datetime_api.py index 6d9829ac664e..a59a3c99cbc4 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/import_test_datetime_api.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/import_test_datetime_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from datetime import datetime diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/pet_api.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/pet_api.py index 5925ad96e7e0..21539d3dde23 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/pet_api.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/pet_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field, StrictBytes, StrictInt, StrictStr, field_validator from typing import List, Optional, Tuple, Union diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/store_api.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/store_api.py index 942f7bc25a33..edb9dce2f565 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/store_api.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/store_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field, StrictInt, StrictStr from typing import Dict diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/user_api.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/user_api.py index b2a4ced88095..b19c4fb54a4f 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/user_api.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api/user_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field, StrictStr from typing import List diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api_client.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api_client.py index 9f1cbc811db7..28d7bf8e8cd8 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/api_client.py @@ -312,7 +312,7 @@ def response_deserialize( return_data = self.__deserialize_file(response_data) elif response_type is not None: match = None - content_type = response_data.headers.get('content-type') + content_type = response_data.getheader('content-type') if content_type is not None: match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type) encoding = match.group(1) if match else "utf-8" @@ -329,7 +329,7 @@ def response_deserialize( return ApiResponse( status_code = response_data.status, data = return_data, - headers = response_data.headers, + headers = response_data.getheaders(), raw_data = response_data.data ) @@ -380,13 +380,10 @@ def sanitize_for_serialization(self, obj): # and attributes which value is not None. # Convert attribute name to json key in # model definition for request. - if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')): - obj_dict = obj.to_dict() - else: - obj_dict = obj.__dict__ + obj_dict = obj.model_dump(by_alias=True, exclude_none=True) if isinstance(obj_dict, list): - # here we handle instances that can either be a list or something else, and only became a real list by calling to_dict() + # here we handle instances that can either be a list or something else, and only became a real list by calling model_dump(by_alias=True) return self.sanitize_for_serialization(obj_dict) return { @@ -708,7 +705,7 @@ def __deserialize_file(self, response): os.close(fd) os.remove(path) - content_disposition = response.headers.get("Content-Disposition") + content_disposition = response.getheader("Content-Disposition") if content_disposition: m = re.search( r'filename=[\'"]?([^\'"\s]+)[\'"]?', @@ -808,4 +805,4 @@ def __deserialize_model(self, data, klass): :return: model object. """ - return klass.from_dict(data) + return klass.model_validate(data) diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py index 0bd1cbdcadd2..5a5242c4ea31 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/configuration.py @@ -18,8 +18,7 @@ from logging import FileHandler import multiprocessing import sys -from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union -from typing_extensions import NotRequired, Self +from typing import Any, ClassVar, Dict, List, Literal, NotRequired, Optional, TypedDict, Union, Self import urllib3 diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/exceptions.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/exceptions.py index cb0ecfbf7018..a5d2c10c55be 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/exceptions.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/exceptions.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """ OpenAPI Petstore @@ -11,8 +9,8 @@ Do not edit the class manually. """ # noqa: E501 -from typing import Any, Optional -from typing_extensions import Self + +from typing import Any, Optional, Self class OpenApiException(Exception): """The base exception class for all OpenAPIExceptions""" @@ -104,9 +102,9 @@ def __init__(self, msg, path_to_item=None) -> None: class ApiException(OpenApiException): def __init__( - self, - status=None, - reason=None, + self, + status=None, + reason=None, http_resp=None, *, body: Optional[str] = None, @@ -128,14 +126,14 @@ def __init__( self.body = http_resp.data.decode('utf-8') except Exception: pass - self.headers = http_resp.headers + self.headers = http_resp.getheaders() @classmethod def from_response( - cls, - *, - http_resp, - body: Optional[str], + cls, + *, + http_resp, + body: Optional[str], data: Optional[Any], ) -> Self: if http_resp.status == 400: @@ -169,11 +167,8 @@ def __str__(self): error_message += "HTTP response headers: {0}\n".format( self.headers) - if self.body: - error_message += "HTTP response body: {0}\n".format(self.body) - - if self.data: - error_message += "HTTP response data: {0}\n".format(self.data) + if self.data or self.body: + error_message += "HTTP response body: {0}\n".format(self.data or self.body) return error_message diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_any_type.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_any_type.py index 291b5e55e353..9986695fc1ec 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_any_type.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_any_type.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesAnyType(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesAnyType from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesAnyType from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_class.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_class.py index 220f23a423b4..de26ad42fa5a 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_class.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesClass(BaseModel): """ @@ -42,61 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "map_property": obj.get("map_property"), - "map_of_map_property": obj.get("map_of_map_property") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_object.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_object.py index 00707c3c4818..a514124192f5 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_object.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_object.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesObject(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesObject from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesObject from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_with_description_only.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_with_description_only.py index d8049b519ed0..a01f7169f6a4 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_with_description_only.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_with_description_only.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesWithDescriptionOnly(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesWithDescriptionOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesWithDescriptionOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/all_of_super_model.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/all_of_super_model.py index b63bba1206a2..f3ef47ec2415 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/all_of_super_model.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/all_of_super_model.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AllOfSuperModel(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AllOfSuperModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AllOfSuperModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_name": obj.get("_name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/all_of_with_single_ref.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/all_of_with_single_ref.py index e3fa084b0709..7f23c83d6dbf 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/all_of_with_single_ref.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/all_of_with_single_ref.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.single_ref_type import SingleRefType -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AllOfWithSingleRef(BaseModel): """ @@ -43,61 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AllOfWithSingleRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AllOfWithSingleRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "username": obj.get("username"), - "SingleRefType": obj.get("SingleRefType") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/animal.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/animal.py index 131ad8d0ed60..3b28901459f4 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/animal.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/animal.py @@ -20,8 +20,8 @@ from importlib import import_module from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional, Union -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -65,55 +65,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[Cat, Dog]]: - """Create an instance of Animal from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[Cat, Dog]]: - """Create an instance of Animal from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'Cat': - return import_module("petstore_api.models.cat").Cat.from_dict(obj) - if object_type == 'Dog': - return import_module("petstore_api.models.dog").Dog.from_dict(obj) - - raise ValueError("Animal failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/any_of_color.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/any_of_color.py index f6d277e79498..8e0c6051da74 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/any_of_color.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/any_of_color.py @@ -20,137 +20,30 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import List, Optional from typing_extensions import Annotated -from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict -from typing_extensions import Literal, Self -from pydantic import Field +from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict, Literal, Self +from pydantic import Field, RootModel ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"] -class AnyOfColor(BaseModel): + +class AnyOfColor(RootModel[Union[List[int], str]]): """ Any of RGB array, RGBA array, or hex string. """ - # data type: List[int] - 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_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: - actual_instance: Optional[Union[List[int], str]] = None - else: - actual_instance: Any = None - any_of_schemas: Set[str] = { "List[int]", "str" } - - model_config = { - "validate_assignment": True, - "protected_namespaces": (), - } - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_anyof(cls, v): - instance = AnyOfColor.model_construct() - error_messages = [] - # validate data type: List[int] - try: - instance.anyof_schema_1_validator = v - return v - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: List[int] - try: - instance.anyof_schema_2_validator = v - return v - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: str - try: - instance.anyof_schema_3_validator = v - return v - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - if error_messages: - # no match - raise ValueError("No match found when setting the actual_instance in AnyOfColor with anyOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - # deserialize data into List[int] - try: - # validation - instance.anyof_schema_1_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.anyof_schema_1_validator - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into List[int] - try: - # validation - instance.anyof_schema_2_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.anyof_schema_2_validator - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into str - try: - # validation - instance.anyof_schema_3_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.anyof_schema_3_validator - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if error_messages: - # no match - raise ValueError("No match found when deserializing the JSON string into AnyOfColor with anyOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + root: Union[List[int], str] = Field( + ... + ) + + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/any_of_pig.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/any_of_pig.py index c949e136f415..df3bae10d3a6 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/any_of_pig.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/any_of_pig.py @@ -21,114 +21,30 @@ from typing import Optional from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig -from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict -from typing_extensions import Literal, Self -from pydantic import Field +from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict, Literal, Self +from pydantic import Field, RootModel ANYOFPIG_ANY_OF_SCHEMAS = ["BasquePig", "DanishPig"] -class AnyOfPig(BaseModel): + +class AnyOfPig(RootModel[Union[BasquePig, DanishPig]]): """ AnyOfPig """ - # data type: BasquePig - anyof_schema_1_validator: Optional[BasquePig] = None - # data type: DanishPig - anyof_schema_2_validator: Optional[DanishPig] = None - if TYPE_CHECKING: - actual_instance: Optional[Union[BasquePig, DanishPig]] = None - else: - actual_instance: Any = None - any_of_schemas: Set[str] = { "BasquePig", "DanishPig" } - - model_config = { - "validate_assignment": True, - "protected_namespaces": (), - } - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_anyof(cls, v): - instance = AnyOfPig.model_construct() - error_messages = [] - # validate data type: BasquePig - if not isinstance(v, BasquePig): - error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`") - else: - return v - - # validate data type: DanishPig - if not isinstance(v, DanishPig): - error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`") - else: - return v - - if error_messages: - # no match - raise ValueError("No match found when setting the actual_instance in AnyOfPig with anyOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - # anyof_schema_1_validator: Optional[BasquePig] = None - try: - instance.actual_instance = BasquePig.from_json(json_str) - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # anyof_schema_2_validator: Optional[DanishPig] = None - try: - instance.actual_instance = DanishPig.from_json(json_str) - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if error_messages: - # no match - raise ValueError("No match found when deserializing the JSON string into AnyOfPig with anyOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], BasquePig, DanishPig]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + root: Union[BasquePig, DanishPig] = Field( + ... + ) + + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_of_array_of_model.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_of_array_of_model.py index 80d4aa689164..4db366070a84 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_of_array_of_model.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayOfArrayOfModel(BaseModel): """ @@ -42,72 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in another_property (list of list) - _items = [] - if self.another_property: - for _item_another_property in self.another_property: - if _item_another_property: - _items.append( - [_inner_item.to_dict() for _inner_item in _item_another_property if _inner_item is not None] - ) - _dict['another_property'] = _items - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "another_property": [ - [Tag.from_dict(_inner_item) for _inner_item in _item] - for _item in obj["another_property"] - ] if obj.get("another_property") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_of_array_of_number_only.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_of_array_of_number_only.py index 847ae88c4ffa..f9178dcf1dc8 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_of_array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_of_array_of_number_only.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictFloat from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayOfArrayOfNumberOnly(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfNumberOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfNumberOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "ArrayArrayNumber": obj.get("ArrayArrayNumber") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_of_number_only.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_of_number_only.py index 4634914c33eb..54c3b8a8e843 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_of_number_only.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictFloat from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayOfNumberOnly(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayOfNumberOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayOfNumberOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "ArrayNumber": obj.get("ArrayNumber") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_test.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_test.py index 9cadd4e7beb7..d44a7bc9d98f 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_test.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/array_test.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from typing_extensions import Annotated from petstore_api.models.read_only_first import ReadOnlyFirst -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayTest(BaseModel): """ @@ -46,75 +46,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in array_array_of_model (list of list) - _items = [] - if self.array_array_of_model: - for _item_array_array_of_model in self.array_array_of_model: - if _item_array_array_of_model: - _items.append( - [_inner_item.to_dict() for _inner_item in _item_array_array_of_model if _inner_item is not None] - ) - _dict['array_array_of_model'] = _items - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "array_of_string": obj.get("array_of_string"), - "array_of_nullable_float": obj.get("array_of_nullable_float"), - "array_array_of_integer": obj.get("array_array_of_integer"), - "array_array_of_model": [ - [ReadOnlyFirst.from_dict(_inner_item) for _inner_item in _item] - for _item in obj["array_array_of_model"] - ] if obj.get("array_array_of_model") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/base_discriminator.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/base_discriminator.py index 40b49a2fca7f..f4255f6ed26c 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/base_discriminator.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/base_discriminator.py @@ -20,8 +20,8 @@ from importlib import import_module from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional, Union -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -64,55 +64,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[PrimitiveString, Info]]: - """Create an instance of BaseDiscriminator from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[PrimitiveString, Info]]: - """Create an instance of BaseDiscriminator from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'PrimitiveString': - return import_module("petstore_api.models.primitive_string").PrimitiveString.from_dict(obj) - if object_type == 'Info': - return import_module("petstore_api.models.info").Info.from_dict(obj) - - raise ValueError("BaseDiscriminator failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/basque_pig.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/basque_pig.py index 4a5b9e3bcb9d..557bef94ca91 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/basque_pig.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/basque_pig.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class BasquePig(BaseModel): """ @@ -42,61 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of BasquePig from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of BasquePig from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "color": obj.get("color") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/bathing.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/bathing.py index 289d9d4670ab..56d8a286ef7d 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/bathing.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/bathing.py @@ -19,15 +19,21 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Bathing(BaseModel): """ Bathing """ # noqa: E501 - task_name: StrictStr - function_name: StrictStr + task_name: Literal['cleaning_deep'] = Field( + ..., + description="task_name of the Bathing" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Bathing" + ) content: StrictStr additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -57,62 +63,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Bathing from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Bathing from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "task_name": obj.get("task_name"), - "function_name": obj.get("function_name"), - "content": obj.get("content") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/capitalization.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/capitalization.py index d98aa21e532d..51b26b53289a 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/capitalization.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/capitalization.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Capitalization(BaseModel): """ @@ -46,65 +46,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Capitalization from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Capitalization from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "smallCamel": obj.get("smallCamel"), - "CapitalCamel": obj.get("CapitalCamel"), - "small_Snake": obj.get("small_Snake"), - "Capital_Snake": obj.get("Capital_Snake"), - "SCA_ETH_Flow_Points": obj.get("SCA_ETH_Flow_Points"), - "ATT_NAME": obj.get("ATT_NAME") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/cat.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/cat.py index 86002178c904..6a81ff03f877 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/cat.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/cat.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict, StrictBool from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.animal import Animal -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Cat(Animal): """ @@ -42,62 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Cat from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Cat from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "color": obj.get("color") if obj.get("color") is not None else 'red', - "declawed": obj.get("declawed") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/category.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/category.py index c659f1845726..9e6ea156d85a 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/category.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/category.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Category(BaseModel): """ @@ -42,61 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Category from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Category from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") if obj.get("name") is not None else 'default-name' - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/circular_all_of_ref.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/circular_all_of_ref.py index d3b6cbe57ea1..cab8f24cdaa9 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/circular_all_of_ref.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/circular_all_of_ref.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class CircularAllOfRef(BaseModel): """ @@ -42,69 +42,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of CircularAllOfRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in second_circular_all_of_ref (list) - _items = [] - if self.second_circular_all_of_ref: - for _item_second_circular_all_of_ref in self.second_circular_all_of_ref: - if _item_second_circular_all_of_ref: - _items.append(_item_second_circular_all_of_ref.to_dict()) - _dict['secondCircularAllOfRef'] = _items - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of CircularAllOfRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_name": obj.get("_name"), - "secondCircularAllOfRef": [SecondCircularAllOfRef.from_dict(_item) for _item in obj["secondCircularAllOfRef"]] if obj.get("secondCircularAllOfRef") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/circular_reference_model.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/circular_reference_model.py index 8c118f3c09b2..d9b322b55545 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/circular_reference_model.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/circular_reference_model.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class CircularReferenceModel(BaseModel): """ @@ -42,65 +42,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of CircularReferenceModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of nested - if self.nested: - _dict['nested'] = self.nested.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of CircularReferenceModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "nested": FirstRef.from_dict(obj["nested"]) if obj.get("nested") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj from petstore_api.models.first_ref import FirstRef # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/class_model.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/class_model.py index 06f8f91b83cb..b9ab6eb6a718 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/class_model.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/class_model.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ClassModel(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ClassModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ClassModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_class": obj.get("_class") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/client.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/client.py index d3376d62357b..58f46fa71338 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/client.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/client.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Client(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Client from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Client from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "client": obj.get("client") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/color.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/color.py index bb740fb597d4..7fe333c7a3b9 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/color.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/color.py @@ -18,150 +18,27 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Any, List, Optional from typing_extensions import Annotated -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self COLOR_ONE_OF_SCHEMAS = ["List[int]", "str"] -class Color(BaseModel): +class Color(RootModel[Union[List[int], str]]): """ 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_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_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: Set[str] = { "List[int]", "str" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[List[int], str] = Field( + ... ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - if v is None: - return v - - instance = Color.model_construct() - error_messages = [] - match = 0 - # validate data type: List[int] - try: - instance.oneof_schema_1_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: List[int] - try: - instance.oneof_schema_2_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: str - try: - instance.oneof_schema_3_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: Optional[str]) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - if json_str is None: - return instance - - error_messages = [] - match = 0 - - # deserialize data into List[int] - try: - # validation - instance.oneof_schema_1_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_1_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into List[int] - try: - # validation - instance.oneof_schema_2_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_2_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into str - try: - # validation - instance.oneof_schema_3_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_3_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/creature.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/creature.py index ce6a70327b1a..a087df77dbde 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/creature.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/creature.py @@ -21,8 +21,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Union from petstore_api.models.creature_info import CreatureInfo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -65,56 +65,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[HuntingDog]]: - """Create an instance of Creature from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of info - if self.info: - _dict['info'] = self.info.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[HuntingDog]]: - """Create an instance of Creature from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'HuntingDog': - return import_module("petstore_api.models.hunting_dog").HuntingDog.from_dict(obj) - - raise ValueError("Creature failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/creature_info.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/creature_info.py index e7fef158a580..ab35ccf566ed 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/creature_info.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/creature_info.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class CreatureInfo(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of CreatureInfo from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of CreatureInfo from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/danish_pig.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/danish_pig.py index df4a80d33908..ebe9dd758e04 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/danish_pig.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/danish_pig.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DanishPig(BaseModel): """ @@ -42,61 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DanishPig from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DanishPig from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "size": obj.get("size") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/data_output_format.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/data_output_format.py index ee3df76c5169..e32ebe9a5ee4 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/data_output_format.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/data_output_format.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class DataOutputFormat(StrEnum): -class DataOutputFormat(str, Enum): """ DataOutputFormat """ - """ - allowed enum values - """ + # Allowed enum values JSON = 'JSON' CSV = 'CSV' XML = 'XML' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of DataOutputFormat from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/deprecated_object.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/deprecated_object.py index ad0ec89a5b7a..bed31b70ad2c 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/deprecated_object.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/deprecated_object.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DeprecatedObject(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DeprecatedObject from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DeprecatedObject from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/discriminator_all_of_sub.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/discriminator_all_of_sub.py index 9723d2e28c74..fc3cc32bba36 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/discriminator_all_of_sub.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/discriminator_all_of_sub.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict from typing import Any, ClassVar, Dict, List from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DiscriminatorAllOfSub(DiscriminatorAllOfSuper): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DiscriminatorAllOfSub from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DiscriminatorAllOfSub from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "elementType": obj.get("elementType") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/discriminator_all_of_super.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/discriminator_all_of_super.py index e3d62831065a..44d0e9c5a4a8 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/discriminator_all_of_super.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/discriminator_all_of_super.py @@ -20,8 +20,8 @@ from importlib import import_module from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Union -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -63,53 +63,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[DiscriminatorAllOfSub]]: - """Create an instance of DiscriminatorAllOfSuper from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[DiscriminatorAllOfSub]]: - """Create an instance of DiscriminatorAllOfSuper from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'DiscriminatorAllOfSub': - return import_module("petstore_api.models.discriminator_all_of_sub").DiscriminatorAllOfSub.from_dict(obj) - - raise ValueError("DiscriminatorAllOfSuper failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/dog.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/dog.py index cde0f5d27e0c..c4ea2a0f0ddf 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/dog.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/dog.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.animal import Animal -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Dog(Animal): """ @@ -42,62 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Dog from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Dog from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "color": obj.get("color") if obj.get("color") is not None else 'red', - "breed": obj.get("breed") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/dummy_model.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/dummy_model.py index 47fdb81a397a..b1ae29288bd6 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/dummy_model.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/dummy_model.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DummyModel(BaseModel): """ @@ -42,65 +42,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DummyModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of self_ref - if self.self_ref: - _dict['self_ref'] = self.self_ref.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DummyModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "category": obj.get("category"), - "self_ref": SelfReferenceModel.from_dict(obj["self_ref"]) if obj.get("self_ref") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj from petstore_api.models.self_reference_model import SelfReferenceModel # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_arrays.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_arrays.py index 17d3e0afd2df..0d50b57b3b07 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_arrays.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_arrays.py @@ -19,15 +19,17 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class EnumArrays(BaseModel): """ EnumArrays """ # noqa: E501 - just_symbol: Optional[StrictStr] = None - array_enum: Optional[List[StrictStr]] = None + just_symbol: Optional[Just_symbolEnum] = Field( + None, + description="just_symbol of the EnumArrays" + ) additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["just_symbol", "array_enum"] @@ -63,61 +65,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of EnumArrays from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of EnumArrays from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "just_symbol": obj.get("just_symbol"), - "array_enum": obj.get("array_enum") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_class.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_class.py index 1ba5af8036df..b4e61d237db8 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_class.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_class.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumClass(StrEnum): -class EnumClass(str, Enum): """ EnumClass """ - """ - allowed enum values - """ + # Allowed enum values ABC = '_abc' MINUS_EFG = '-efg' LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS = '(xyz)' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumClass from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_number_vendor_ext.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_number_vendor_ext.py index 5588de5c7043..91d2161cbc6d 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_number_vendor_ext.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_number_vendor_ext.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumNumberVendorExt(IntEnum): -class EnumNumberVendorExt(int, Enum): """ EnumNumberVendorExt """ - """ - allowed enum values - """ + # Allowed enum values FortyTwo = 42 Eigtheen = 18 FiftySix = 56 @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumNumberVendorExt from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_ref_with_default_value.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_ref_with_default_value.py index d864e80d0a73..3d04280d92cc 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_ref_with_default_value.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_ref_with_default_value.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.data_output_format import DataOutputFormat -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class EnumRefWithDefaultValue(BaseModel): """ @@ -42,60 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of EnumRefWithDefaultValue from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of EnumRefWithDefaultValue from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "report_format": obj.get("report_format") if obj.get("report_format") is not None else DataOutputFormat.JSON - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_string1.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_string1.py index 678b4e12661f..d6970ff8346f 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_string1.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_string1.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumString1(StrEnum): -class EnumString1(str, Enum): """ EnumString1 """ - """ - allowed enum values - """ + # Allowed enum values A = 'a' B = 'b' @@ -34,4 +32,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumString1 from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_string2.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_string2.py index a959f554e0af..c4fc722f826a 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_string2.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_string2.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumString2(StrEnum): -class EnumString2(str, Enum): """ EnumString2 """ - """ - allowed enum values - """ + # Allowed enum values C = 'c' D = 'd' @@ -34,4 +32,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumString2 from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_string_vendor_ext.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_string_vendor_ext.py index 821812e9b088..175ace79326f 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_string_vendor_ext.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_string_vendor_ext.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumStringVendorExt(StrEnum): -class EnumStringVendorExt(str, Enum): """ EnumStringVendorExt """ - """ - allowed enum values - """ + # Allowed enum values FOO_XEnumVarname = 'FOO' BarVar_XEnumVarname = 'Bar' bazVar_XEnumVarname = 'baz' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumStringVendorExt from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_test.py index d39c2c95775e..81e6523384b2 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_test.py @@ -25,20 +25,41 @@ from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue from petstore_api.models.outer_enum_integer import OuterEnumInteger from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntegerDefaultValue -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class EnumTest(BaseModel): """ EnumTest """ # noqa: E501 - enum_string: Optional[StrictStr] = None - enum_string_required: StrictStr - enum_integer_default: Optional[StrictInt] = 5 - enum_integer: Optional[StrictInt] = None - enum_number: Optional[StrictFloat] = None - enum_string_single_member: Optional[StrictStr] = None - enum_integer_single_member: Optional[StrictInt] = None + enum_string: Optional[Enum_stringEnum] = Field( + None, + description="enum_string of the EnumTest" + ) + enum_string_required: Enum_string_requiredEnum = Field( + ..., + description="enum_string_required of the EnumTest" + ) + enum_integer_default: Optional[Enum_integer_defaultEnum] = Field( + None, + description="enum_integer_default of the EnumTest" + ) + enum_integer: Optional[Enum_integerEnum] = Field( + None, + description="enum_integer of the EnumTest" + ) + enum_number: Optional[Enum_numberEnum] = Field( + None, + description="enum_number of the EnumTest" + ) + enum_string_single_member: Literal['abc'] = Field( + None, + description="enum_string_single_member of the EnumTest" + ) + enum_integer_single_member: Literal['100'] = Field( + None, + description="enum_integer_single_member of the EnumTest" + ) outer_enum: Optional[OuterEnum] = Field(default=None, alias="outerEnum") outer_enum_integer: Optional[OuterEnumInteger] = Field(default=None, alias="outerEnumInteger") outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=OuterEnumDefaultValue.PLACED, alias="outerEnumDefaultValue") @@ -126,77 +147,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of EnumTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - # set to None if outer_enum (nullable) is None - # 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of EnumTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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, - "enum_integer": obj.get("enum_integer"), - "enum_number": obj.get("enum_number"), - "enum_string_single_member": obj.get("enum_string_single_member"), - "enum_integer_single_member": obj.get("enum_integer_single_member"), - "outerEnum": obj.get("outerEnum"), - "outerEnumInteger": obj.get("outerEnumInteger"), - "outerEnumDefaultValue": obj.get("outerEnumDefaultValue") if obj.get("outerEnumDefaultValue") is not None else OuterEnumDefaultValue.PLACED, - "outerEnumIntegerDefaultValue": obj.get("outerEnumIntegerDefaultValue") if obj.get("outerEnumIntegerDefaultValue") is not None else OuterEnumIntegerDefaultValue.NUMBER_0, - "enumNumberVendorExt": obj.get("enumNumberVendorExt"), - "enumStringVendorExt": obj.get("enumStringVendorExt") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/feeding.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/feeding.py index 5c406bc9e65e..4105e2913921 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/feeding.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/feeding.py @@ -19,15 +19,21 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Feeding(BaseModel): """ Feeding """ # noqa: E501 - task_name: StrictStr - function_name: StrictStr + task_name: Literal['cleaning'] = Field( + ..., + description="task_name of the Feeding" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Feeding" + ) content: StrictStr additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -57,62 +63,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Feeding from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Feeding from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "task_name": obj.get("task_name"), - "function_name": obj.get("function_name"), - "content": obj.get("content") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/file.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/file.py index 4c661cadabc4..5b0f97a3d1f0 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/file.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/file.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class File(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of File from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of File from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "sourceURI": obj.get("sourceURI") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/file_schema_test_class.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/file_schema_test_class.py index 09a543010f4d..8a6e72a5a457 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/file_schema_test_class.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/file_schema_test_class.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.file import File -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FileSchemaTestClass(BaseModel): """ @@ -43,71 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FileSchemaTestClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of file - if self.file: - _dict['file'] = self.file.to_dict() - # override the default output from pydantic by calling `to_dict()` of each item in files (list) - _items = [] - if self.files: - for _item_files in self.files: - if _item_files: - _items.append(_item_files.to_dict()) - _dict['files'] = _items - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FileSchemaTestClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "file": File.from_dict(obj["file"]) if obj.get("file") is not None else None, - "files": [File.from_dict(_item) for _item in obj["files"]] if obj.get("files") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/first_ref.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/first_ref.py index 7680dfdf418c..86df2c1c6205 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/first_ref.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/first_ref.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FirstRef(BaseModel): """ @@ -42,65 +42,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FirstRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of self_ref - if self.self_ref: - _dict['self_ref'] = self.self_ref.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FirstRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "category": obj.get("category"), - "self_ref": SecondRef.from_dict(obj["self_ref"]) if obj.get("self_ref") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj from petstore_api.models.second_ref import SecondRef # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/foo.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/foo.py index 81e3839ea17c..73b9f4512aaf 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/foo.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/foo.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Foo(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Foo from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Foo from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "bar": obj.get("bar") if obj.get("bar") is not None else 'bar' - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/foo_get_default_response.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/foo_get_default_response.py index 4cd23db39125..15a78079f4fa 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/foo_get_default_response.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/foo_get_default_response.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.foo import Foo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FooGetDefaultResponse(BaseModel): """ @@ -42,63 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FooGetDefaultResponse from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of string - if self.string: - _dict['string'] = self.string.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FooGetDefaultResponse from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "string": Foo.from_dict(obj["string"]) if obj.get("string") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/format_test.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/format_test.py index 4aca97f91c48..20b38c1af87b 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/format_test.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/format_test.py @@ -23,8 +23,8 @@ from typing import Any, ClassVar, Dict, List, Optional, Tuple, Union from typing_extensions import Annotated from uuid import UUID -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FormatTest(BaseModel): """ @@ -101,76 +101,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FormatTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FormatTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "integer": obj.get("integer"), - "int32": obj.get("int32"), - "int64": obj.get("int64"), - "number": obj.get("number"), - "float": obj.get("float"), - "double": obj.get("double"), - "decimal": obj.get("decimal"), - "string": obj.get("string"), - "string_with_double_quote_pattern": obj.get("string_with_double_quote_pattern"), - "byte": obj.get("byte"), - "binary": obj.get("binary"), - "date": obj.get("date"), - "dateTime": obj.get("dateTime"), - "uuid": obj.get("uuid"), - "password": obj.get("password"), - "pattern_with_digits": obj.get("pattern_with_digits"), - "pattern_with_digits_and_delimiter": obj.get("pattern_with_digits_and_delimiter") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/has_only_read_only.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/has_only_read_only.py index 77360fedbae5..df61369961f9 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/has_only_read_only.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/has_only_read_only.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class HasOnlyReadOnly(BaseModel): """ @@ -42,65 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of HasOnlyReadOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * OpenAPI `readOnly` fields are excluded. - * OpenAPI `readOnly` fields are excluded. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "bar", - "foo", - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of HasOnlyReadOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "bar": obj.get("bar"), - "foo": obj.get("foo") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/health_check_result.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/health_check_result.py index 59f444aedaa3..8e5a35a68b5e 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/health_check_result.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/health_check_result.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class HealthCheckResult(BaseModel): """ @@ -41,65 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of HealthCheckResult from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - # set to None if nullable_message (nullable) is None - # 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of HealthCheckResult from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "NullableMessage": obj.get("NullableMessage") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/hunting_dog.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/hunting_dog.py index f7d03f4044ea..1f111dd5f9fc 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/hunting_dog.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/hunting_dog.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.creature import Creature from petstore_api.models.creature_info import CreatureInfo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class HuntingDog(Creature): """ @@ -43,65 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of HuntingDog from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of info - if self.info: - _dict['info'] = self.info.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of HuntingDog from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "info": CreatureInfo.from_dict(obj["info"]) if obj.get("info") is not None else None, - "type": obj.get("type"), - "isTrained": obj.get("isTrained") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/info.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/info.py index 94e663b3aaab..eefe81adf411 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/info.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/info.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.base_discriminator import BaseDiscriminator -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Info(BaseDiscriminator): """ @@ -42,64 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Info from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of val - if self.val: - _dict['val'] = self.val.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Info from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_typeName": obj.get("_typeName"), - "val": BaseDiscriminator.from_dict(obj["val"]) if obj.get("val") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/inner_dict_with_property.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/inner_dict_with_property.py index b43fa8b19fef..565a461bea8e 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/inner_dict_with_property.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/inner_dict_with_property.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class InnerDictWithProperty(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of InnerDictWithProperty from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of InnerDictWithProperty from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "aProperty": obj.get("aProperty") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/input_all_of.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/input_all_of.py index e4a81ff70006..36c28f74d15a 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/input_all_of.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/input_all_of.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class InputAllOf(BaseModel): """ @@ -42,72 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of InputAllOf from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in some_data (dict) - _field_dict = {} - if self.some_data: - for _key_some_data in self.some_data: - if self.some_data[_key_some_data]: - _field_dict[_key_some_data] = self.some_data[_key_some_data].to_dict() - _dict['some_data'] = _field_dict - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of InputAllOf from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "some_data": dict( - (_k, Tag.from_dict(_v)) - for _k, _v in obj["some_data"].items() - ) - if obj.get("some_data") is not None - else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/int_or_string.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/int_or_string.py index f2a5a0a2d4a3..63f94b788677 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/int_or_string.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/int_or_string.py @@ -18,127 +18,27 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Any, List, Optional from typing_extensions import Annotated -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self INTORSTRING_ONE_OF_SCHEMAS = ["int", "str"] -class IntOrString(BaseModel): +class IntOrString(RootModel[Union[int, str]]): """ IntOrString """ - # data type: int - oneof_schema_1_validator: Optional[Annotated[int, Field(strict=True, ge=10)]] = None - # data type: str - oneof_schema_2_validator: Optional[StrictStr] = None - actual_instance: Optional[Union[int, str]] = None - one_of_schemas: Set[str] = { "int", "str" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[int, str] = Field( + ... ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - instance = IntOrString.model_construct() - error_messages = [] - match = 0 - # validate data type: int - try: - instance.oneof_schema_1_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: str - try: - instance.oneof_schema_2_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # deserialize data into int - try: - # validation - instance.oneof_schema_1_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_1_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into str - try: - # validation - instance.oneof_schema_2_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_2_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], int, str]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/list_class.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/list_class.py index e00f3d820b88..c3219f03314c 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/list_class.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/list_class.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ListClass(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ListClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ListClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "123-list": obj.get("123-list") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/map_of_array_of_model.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/map_of_array_of_model.py index 68816ab29531..97c5b812f6bb 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/map_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/map_of_array_of_model.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MapOfArrayOfModel(BaseModel): """ @@ -42,76 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MapOfArrayOfModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in shop_id_to_org_online_lip_map (dict of array) - _field_dict_of_array = {} - if self.shop_id_to_org_online_lip_map: - for _key_shop_id_to_org_online_lip_map in self.shop_id_to_org_online_lip_map: - if self.shop_id_to_org_online_lip_map[_key_shop_id_to_org_online_lip_map] is not None: - _field_dict_of_array[_key_shop_id_to_org_online_lip_map] = [ - _item.to_dict() for _item in self.shop_id_to_org_online_lip_map[_key_shop_id_to_org_online_lip_map] - ] - _dict['shopIdToOrgOnlineLipMap'] = _field_dict_of_array - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MapOfArrayOfModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "shopIdToOrgOnlineLipMap": dict( - (_k, - [Tag.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("shopIdToOrgOnlineLipMap", {}).items() - ) - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/map_test.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/map_test.py index 4cefd36427f9..51deeba849bf 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/map_test.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/map_test.py @@ -19,15 +19,18 @@ from pydantic import BaseModel, ConfigDict, StrictBool, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MapTest(BaseModel): """ MapTest """ # noqa: E501 map_map_of_string: Optional[Dict[str, Dict[str, StrictStr]]] = None - map_of_enum_string: Optional[Dict[str, StrictStr]] = None + map_of_enum_string: Optional[Dict[str, str]] = Field( + None, + description="map_of_enum_string of the MapTest" + ) direct_map: Optional[Dict[str, StrictBool]] = None indirect_map: Optional[Dict[str, StrictBool]] = None additional_properties: Dict[str, Any] = {} @@ -55,63 +58,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MapTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MapTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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"), - "indirect_map": obj.get("indirect_map") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/mixed_properties_and_additional_properties_class.py index c21f442bb798..7275fe85f367 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -22,8 +22,8 @@ from typing import Any, ClassVar, Dict, List, Optional from uuid import UUID from petstore_api.models.animal import Animal -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): """ @@ -46,74 +46,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MixedPropertiesAndAdditionalPropertiesClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in map (dict) - _field_dict = {} - if self.map: - for _key_map in self.map: - if self.map[_key_map]: - _field_dict[_key_map] = self.map[_key_map].to_dict() - _dict['map'] = _field_dict - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MixedPropertiesAndAdditionalPropertiesClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "uuid": obj.get("uuid"), - "dateTime": obj.get("dateTime"), - "map": dict( - (_k, Animal.from_dict(_v)) - for _k, _v in obj["map"].items() - ) - if obj.get("map") is not None - else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model200_response.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model200_response.py index 60e43a0e28e6..318bdc6f7854 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model200_response.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model200_response.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Model200Response(BaseModel): """ @@ -42,61 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Model200Response from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Model200Response from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name"), - "class": obj.get("class") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model_api_response.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model_api_response.py index 7141160c57d9..9a6114ad8c63 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model_api_response.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model_api_response.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ModelApiResponse(BaseModel): """ @@ -43,62 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ModelApiResponse from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ModelApiResponse from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "code": obj.get("code"), - "type": obj.get("type"), - "message": obj.get("message") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model_field.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model_field.py index d7b03848fe16..e0625b2fb00b 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model_field.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model_field.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ModelField(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ModelField from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ModelField from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "field": obj.get("field") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model_return.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model_return.py index 3f2558bc6e7d..6802ace821de 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model_return.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/model_return.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ModelReturn(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ModelReturn from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ModelReturn from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "return": obj.get("return") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/multi_arrays.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/multi_arrays.py index 80fa67f8a11c..afbf2b94be61 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/multi_arrays.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/multi_arrays.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.file import File from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MultiArrays(BaseModel): """ @@ -44,75 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MultiArrays from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in tags (list) - _items = [] - if self.tags: - for _item_tags in self.tags: - if _item_tags: - _items.append(_item_tags.to_dict()) - _dict['tags'] = _items - # override the default output from pydantic by calling `to_dict()` of each item in files (list) - _items = [] - if self.files: - for _item_files in self.files: - if _item_files: - _items.append(_item_files.to_dict()) - _dict['files'] = _items - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MultiArrays from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "tags": [Tag.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None, - "files": [File.from_dict(_item) for _item in obj["files"]] if obj.get("files") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/name.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/name.py index 01b02f834137..7c81c2a4afb4 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/name.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/name.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Name(BaseModel): """ @@ -44,67 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Name from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * OpenAPI `readOnly` fields are excluded. - * OpenAPI `readOnly` fields are excluded. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "snake_case", - "var_123_number", - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Name from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name"), - "snake_case": obj.get("snake_case"), - "property": obj.get("property"), - "123Number": obj.get("123Number") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/nullable_class.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/nullable_class.py index cb27fbf691c2..8ecb7bfd27b8 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/nullable_class.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/nullable_class.py @@ -20,8 +20,8 @@ from datetime import date, datetime from pydantic import BaseModel, ConfigDict, StrictBool, StrictFloat, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class NullableClass(BaseModel): """ @@ -54,127 +54,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of NullableClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - # set to None if required_integer_prop (nullable) is None - # 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 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 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 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 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 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 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 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 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 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 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of NullableClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "required_integer_prop": obj.get("required_integer_prop"), - "integer_prop": obj.get("integer_prop"), - "number_prop": obj.get("number_prop"), - "boolean_prop": obj.get("boolean_prop"), - "string_prop": obj.get("string_prop"), - "date_prop": obj.get("date_prop"), - "datetime_prop": obj.get("datetime_prop"), - "array_nullable_prop": obj.get("array_nullable_prop"), - "array_and_items_nullable_prop": obj.get("array_and_items_nullable_prop"), - "array_items_nullable": obj.get("array_items_nullable"), - "object_nullable_prop": obj.get("object_nullable_prop"), - "object_and_items_nullable_prop": obj.get("object_and_items_nullable_prop"), - "object_items_nullable": obj.get("object_items_nullable") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/nullable_property.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/nullable_property.py index e73cd1509c90..a48bc3dd705e 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/nullable_property.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/nullable_property.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, field_validator from typing import Any, ClassVar, Dict, List, Optional from typing_extensions import Annotated -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class NullableProperty(BaseModel): """ @@ -53,66 +53,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of NullableProperty from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - # set to None if name (nullable) is None - # and model_fields_set contains the field - if self.name is None and "name" in self.model_fields_set: - _dict['name'] = None - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of NullableProperty from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/number_only.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/number_only.py index f74010e908bb..3753e92311f8 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/number_only.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/number_only.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictFloat from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class NumberOnly(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of NumberOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of NumberOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "JustNumber": obj.get("JustNumber") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/object_to_test_additional_properties.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/object_to_test_additional_properties.py index 097bdd34e2be..874115c4d65a 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/object_to_test_additional_properties.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/object_to_test_additional_properties.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictBool from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ObjectToTestAdditionalProperties(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ObjectToTestAdditionalProperties from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ObjectToTestAdditionalProperties from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "property": obj.get("property") if obj.get("property") is not None else False - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/object_with_deprecated_fields.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/object_with_deprecated_fields.py index 0c0cc840680b..6d5be11528f1 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/object_with_deprecated_fields.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/object_with_deprecated_fields.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.deprecated_object import DeprecatedObject -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ObjectWithDeprecatedFields(BaseModel): """ @@ -45,66 +45,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ObjectWithDeprecatedFields from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of deprecated_ref - if self.deprecated_ref: - _dict['deprecatedRef'] = self.deprecated_ref.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ObjectWithDeprecatedFields from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "uuid": obj.get("uuid"), - "id": obj.get("id"), - "deprecatedRef": DeprecatedObject.from_dict(obj["deprecatedRef"]) if obj.get("deprecatedRef") is not None else None, - "bars": obj.get("bars") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/one_of_enum_string.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/one_of_enum_string.py index f180178737db..71f902b5e94a 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/one_of_enum_string.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/one_of_enum_string.py @@ -19,119 +19,27 @@ from typing import Any, List, Optional from petstore_api.models.enum_string1 import EnumString1 from petstore_api.models.enum_string2 import EnumString2 -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self ONEOFENUMSTRING_ONE_OF_SCHEMAS = ["EnumString1", "EnumString2"] -class OneOfEnumString(BaseModel): +class OneOfEnumString(RootModel[Union[EnumString1, EnumString2]]): """ oneOf enum strings """ - # data type: EnumString1 - oneof_schema_1_validator: Optional[EnumString1] = None - # data type: EnumString2 - oneof_schema_2_validator: Optional[EnumString2] = None - actual_instance: Optional[Union[EnumString1, EnumString2]] = None - one_of_schemas: Set[str] = { "EnumString1", "EnumString2" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[EnumString1, EnumString2] = Field( + ... ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - instance = OneOfEnumString.model_construct() - error_messages = [] - match = 0 - # validate data type: EnumString1 - if not isinstance(v, EnumString1): - error_messages.append(f"Error! Input type `{type(v)}` is not `EnumString1`") - else: - match += 1 - # validate data type: EnumString2 - if not isinstance(v, EnumString2): - error_messages.append(f"Error! Input type `{type(v)}` is not `EnumString2`") - else: - match += 1 - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in OneOfEnumString with oneOf schemas: EnumString1, EnumString2. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in OneOfEnumString with oneOf schemas: EnumString1, EnumString2. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # deserialize data into EnumString1 - try: - instance.actual_instance = EnumString1.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into EnumString2 - try: - instance.actual_instance = EnumString2.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into OneOfEnumString with oneOf schemas: EnumString1, EnumString2. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into OneOfEnumString with oneOf schemas: EnumString1, EnumString2. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], EnumString1, EnumString2]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/order.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/order.py index 12dd1ef117d2..33ab402180fc 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/order.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/order.py @@ -20,8 +20,8 @@ from datetime import datetime from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Order(BaseModel): """ @@ -31,7 +31,10 @@ class Order(BaseModel): pet_id: Optional[StrictInt] = Field(default=None, alias="petId") quantity: Optional[StrictInt] = None ship_date: Optional[datetime] = Field(default=None, alias="shipDate") - status: Optional[StrictStr] = Field(default=None, description="Order Status") + status: Optional[StatusEnum] = Field( + None, + description="Order Status" + ) complete: Optional[StrictBool] = False additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["id", "petId", "quantity", "shipDate", "status", "complete"] @@ -57,65 +60,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Order from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Order from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "petId": obj.get("petId"), - "quantity": obj.get("quantity"), - "shipDate": obj.get("shipDate"), - "status": obj.get("status"), - "complete": obj.get("complete") if obj.get("complete") is not None else False - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_composite.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_composite.py index 5242660b636b..35cd37ef677d 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_composite.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_composite.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictBool, StrictFloat, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class OuterComposite(BaseModel): """ @@ -43,62 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of OuterComposite from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of OuterComposite from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "my_number": obj.get("my_number"), - "my_string": obj.get("my_string"), - "my_boolean": obj.get("my_boolean") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum.py index ac48cc0dc4d8..ee5753ebef43 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnum(StrEnum): -class OuterEnum(str, Enum): """ OuterEnum """ - """ - allowed enum values - """ + # Allowed enum values PLACED = 'placed' APPROVED = 'approved' DELIVERED = 'delivered' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnum from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum_default_value.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum_default_value.py index 99d6fd5fc042..7b013c460e2b 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum_default_value.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum_default_value.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnumDefaultValue(StrEnum): -class OuterEnumDefaultValue(str, Enum): """ OuterEnumDefaultValue """ - """ - allowed enum values - """ + # Allowed enum values PLACED = 'placed' APPROVED = 'approved' DELIVERED = 'delivered' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnumDefaultValue from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum_integer.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum_integer.py index b771b7a61f55..03ee644405ed 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum_integer.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum_integer.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnumInteger(IntEnum): -class OuterEnumInteger(int, Enum): """ OuterEnumInteger """ - """ - allowed enum values - """ + # Allowed enum values NUMBER_0 = 0 NUMBER_1 = 1 NUMBER_2 = 2 @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnumInteger from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum_integer_default_value.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum_integer_default_value.py index 8df41b2bd320..55735ba9b13f 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum_integer_default_value.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_enum_integer_default_value.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnumIntegerDefaultValue(IntEnum): -class OuterEnumIntegerDefaultValue(int, Enum): """ OuterEnumIntegerDefaultValue """ - """ - allowed enum values - """ + # Allowed enum values NUMBER_MINUS_1 = -1 NUMBER_0 = 0 NUMBER_1 = 1 @@ -36,4 +34,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnumIntegerDefaultValue from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_object_with_enum_property.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_object_with_enum_property.py index f8d215a21c94..a795684bf7c9 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_object_with_enum_property.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_object_with_enum_property.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.outer_enum import OuterEnum from petstore_api.models.outer_enum_integer import OuterEnumInteger -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class OuterObjectWithEnumProperty(BaseModel): """ @@ -44,66 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of OuterObjectWithEnumProperty from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - # set to None if str_value (nullable) is None - # 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of OuterObjectWithEnumProperty from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "str_value": obj.get("str_value"), - "value": obj.get("value") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/parent.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/parent.py index 8a30758ab8fd..a9a75ad1c0ad 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/parent.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/parent.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.inner_dict_with_property import InnerDictWithProperty -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Parent(BaseModel): """ @@ -42,72 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Parent from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in optional_dict (dict) - _field_dict = {} - if self.optional_dict: - for _key_optional_dict in self.optional_dict: - if self.optional_dict[_key_optional_dict]: - _field_dict[_key_optional_dict] = self.optional_dict[_key_optional_dict].to_dict() - _dict['optionalDict'] = _field_dict - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Parent from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "optionalDict": dict( - (_k, InnerDictWithProperty.from_dict(_v)) - for _k, _v in obj["optionalDict"].items() - ) - if obj.get("optionalDict") is not None - else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/parent_with_optional_dict.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/parent_with_optional_dict.py index 509693dd1441..a264218563b6 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/parent_with_optional_dict.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/parent_with_optional_dict.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.inner_dict_with_property import InnerDictWithProperty -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ParentWithOptionalDict(BaseModel): """ @@ -42,72 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ParentWithOptionalDict from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in optional_dict (dict) - _field_dict = {} - if self.optional_dict: - for _key_optional_dict in self.optional_dict: - if self.optional_dict[_key_optional_dict]: - _field_dict[_key_optional_dict] = self.optional_dict[_key_optional_dict].to_dict() - _dict['optionalDict'] = _field_dict - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ParentWithOptionalDict from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "optionalDict": dict( - (_k, InnerDictWithProperty.from_dict(_v)) - for _k, _v in obj["optionalDict"].items() - ) - if obj.get("optionalDict") is not None - else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/pet.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/pet.py index 48f0c2fceeb7..91af8ee6ba46 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/pet.py @@ -22,8 +22,8 @@ from typing_extensions import Annotated from petstore_api.models.category import Category from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Pet(BaseModel): """ @@ -34,7 +34,10 @@ class Pet(BaseModel): name: StrictStr 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") + status: Optional[StatusEnum] = Field( + None, + description="pet status in the store" + ) additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["id", "category", "name", "photoUrls", "tags", "status"] @@ -59,75 +62,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Pet from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of category - if self.category: - _dict['category'] = self.category.to_dict() - # override the default output from pydantic by calling `to_dict()` of each item in tags (list) - _items = [] - if self.tags: - for _item_tags in self.tags: - if _item_tags: - _items.append(_item_tags.to_dict()) - _dict['tags'] = _items - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Pet from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "category": Category.from_dict(obj["category"]) if obj.get("category") is not None else None, - "name": obj.get("name"), - "photoUrls": obj.get("photoUrls"), - "tags": [Tag.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None, - "status": obj.get("status") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/pig.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/pig.py index 06798245b8fe..5daca5745f89 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/pig.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/pig.py @@ -19,137 +19,27 @@ from typing import Any, List, Optional from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self PIG_ONE_OF_SCHEMAS = ["BasquePig", "DanishPig"] -class Pig(BaseModel): +class Pig(RootModel[Union[BasquePig, DanishPig]]): """ Pig """ - # data type: BasquePig - oneof_schema_1_validator: Optional[BasquePig] = None - # data type: DanishPig - oneof_schema_2_validator: Optional[DanishPig] = None - actual_instance: Optional[Union[BasquePig, DanishPig]] = None - one_of_schemas: Set[str] = { "BasquePig", "DanishPig" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[BasquePig, DanishPig] = Field( + ..., discriminator="class_name" ) - - discriminator_value_class_map: Dict[str, str] = { - } - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - instance = Pig.model_construct() - error_messages = [] - match = 0 - # validate data type: BasquePig - if not isinstance(v, BasquePig): - error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`") - else: - match += 1 - # validate data type: DanishPig - if not isinstance(v, DanishPig): - error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`") - else: - match += 1 - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # use oneOf discriminator to lookup the data type - _data_type = json.loads(json_str).get("className") - if not _data_type: - raise ValueError("Failed to lookup data type from the field `className` in the input.") - - # check if data type is `BasquePig` - if _data_type == "BasquePig": - instance.actual_instance = BasquePig.from_json(json_str) - return instance - - # check if data type is `DanishPig` - if _data_type == "DanishPig": - instance.actual_instance = DanishPig.from_json(json_str) - return instance - - # deserialize data into BasquePig - try: - instance.actual_instance = BasquePig.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into DanishPig - try: - instance.actual_instance = DanishPig.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], BasquePig, DanishPig]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/pony_sizes.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/pony_sizes.py index 74efce9a4d06..83152c982e7b 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/pony_sizes.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/pony_sizes.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.type import Type -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PonySizes(BaseModel): """ @@ -42,60 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PonySizes from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PonySizes from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "type": obj.get("type") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/poop_cleaning.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/poop_cleaning.py index 76eb72a941bf..37e10750fad4 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/poop_cleaning.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/poop_cleaning.py @@ -19,15 +19,21 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PoopCleaning(BaseModel): """ PoopCleaning """ # noqa: E501 - task_name: StrictStr - function_name: StrictStr + task_name: Literal['cleaning'] = Field( + ..., + description="task_name of the PoopCleaning" + ) + function_name: Literal['care'] = Field( + ..., + description="function_name of the PoopCleaning" + ) content: StrictStr additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -57,62 +63,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PoopCleaning from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PoopCleaning from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "task_name": obj.get("task_name"), - "function_name": obj.get("function_name"), - "content": obj.get("content") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/primitive_string.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/primitive_string.py index f7a971519f2f..ee3c056b5623 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/primitive_string.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/primitive_string.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.base_discriminator import BaseDiscriminator -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PrimitiveString(BaseDiscriminator): """ @@ -42,61 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PrimitiveString from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PrimitiveString from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_typeName": obj.get("_typeName"), - "_value": obj.get("_value") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/property_map.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/property_map.py index 0da2a14293de..4a43d9e24edc 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/property_map.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/property_map.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PropertyMap(BaseModel): """ @@ -42,72 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PropertyMap from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in some_data (dict) - _field_dict = {} - if self.some_data: - for _key_some_data in self.some_data: - if self.some_data[_key_some_data]: - _field_dict[_key_some_data] = self.some_data[_key_some_data].to_dict() - _dict['some_data'] = _field_dict - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PropertyMap from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "some_data": dict( - (_k, Tag.from_dict(_v)) - for _k, _v in obj["some_data"].items() - ) - if obj.get("some_data") is not None - else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/property_name_collision.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/property_name_collision.py index d07aef22cd82..b6d487528a02 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/property_name_collision.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/property_name_collision.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PropertyNameCollision(BaseModel): """ @@ -43,62 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PropertyNameCollision from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PropertyNameCollision from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_type": obj.get("_type"), - "type": obj.get("type"), - "type_": obj.get("type_") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/read_only_first.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/read_only_first.py index 5a4155fcfa13..603220f24d18 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/read_only_first.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/read_only_first.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ReadOnlyFirst(BaseModel): """ @@ -42,63 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ReadOnlyFirst from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * OpenAPI `readOnly` fields are excluded. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "bar", - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ReadOnlyFirst from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "bar": obj.get("bar"), - "baz": obj.get("baz") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/second_circular_all_of_ref.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/second_circular_all_of_ref.py index 13d6327314c3..990b82832e77 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/second_circular_all_of_ref.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/second_circular_all_of_ref.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SecondCircularAllOfRef(BaseModel): """ @@ -42,69 +42,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SecondCircularAllOfRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in circular_all_of_ref (list) - _items = [] - if self.circular_all_of_ref: - for _item_circular_all_of_ref in self.circular_all_of_ref: - if _item_circular_all_of_ref: - _items.append(_item_circular_all_of_ref.to_dict()) - _dict['circularAllOfRef'] = _items - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SecondCircularAllOfRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_name": obj.get("_name"), - "circularAllOfRef": [CircularAllOfRef.from_dict(_item) for _item in obj["circularAllOfRef"]] if obj.get("circularAllOfRef") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj from petstore_api.models.circular_all_of_ref import CircularAllOfRef # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/second_ref.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/second_ref.py index 701e0dccaacf..a63609d87b58 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/second_ref.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/second_ref.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SecondRef(BaseModel): """ @@ -42,65 +42,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SecondRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of circular_ref - if self.circular_ref: - _dict['circular_ref'] = self.circular_ref.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SecondRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "category": obj.get("category"), - "circular_ref": CircularReferenceModel.from_dict(obj["circular_ref"]) if obj.get("circular_ref") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj from petstore_api.models.circular_reference_model import CircularReferenceModel # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/self_reference_model.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/self_reference_model.py index 0273b10dada6..52b57d85f2f0 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/self_reference_model.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/self_reference_model.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SelfReferenceModel(BaseModel): """ @@ -42,65 +42,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SelfReferenceModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of nested - if self.nested: - _dict['nested'] = self.nested.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SelfReferenceModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "nested": DummyModel.from_dict(obj["nested"]) if obj.get("nested") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj from petstore_api.models.dummy_model import DummyModel # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/single_ref_type.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/single_ref_type.py index 91ab07e2535c..32b33b2271fe 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/single_ref_type.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/single_ref_type.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class SingleRefType(StrEnum): -class SingleRefType(str, Enum): """ SingleRefType """ - """ - allowed enum values - """ + # Allowed enum values ADMIN = 'admin' USER = 'user' @@ -34,4 +32,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of SingleRefType from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/special_character_enum.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/special_character_enum.py index 1d85fd148d4b..bf8d0a25df90 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/special_character_enum.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/special_character_enum.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class SpecialCharacterEnum(StrEnum): -class SpecialCharacterEnum(str, Enum): """ SpecialCharacterEnum """ - """ - allowed enum values - """ + # Allowed enum values ENUM_456 = '456' ENUM_123ABC = '123abc' UNDERSCORE = '_' @@ -42,4 +40,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of SpecialCharacterEnum from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/special_model_name.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/special_model_name.py index 84686054875a..2b034d4781fc 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/special_model_name.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/special_model_name.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SpecialModelName(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SpecialModelName from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SpecialModelName from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "$special[property.name]": obj.get("$special[property.name]") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/special_name.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/special_name.py index e43761d33dfc..009e9faef3e5 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/special_name.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/special_name.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.category import Category -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SpecialName(BaseModel): """ @@ -29,7 +29,10 @@ class SpecialName(BaseModel): """ # noqa: E501 var_property: Optional[StrictInt] = Field(default=None, alias="property") var_async: Optional[Category] = Field(default=None, alias="async") - var_schema: Optional[StrictStr] = Field(default=None, description="pet status in the store", alias="schema") + var_schema: Optional[Var_schemaEnum] = Field( + None, + description="pet status in the store" + ) additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["property", "async", "schema"] @@ -54,65 +57,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SpecialName from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of var_async - if self.var_async: - _dict['async'] = self.var_async.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SpecialName from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "property": obj.get("property"), - "async": Category.from_dict(obj["async"]) if obj.get("async") is not None else None, - "schema": obj.get("schema") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/tag.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/tag.py index b3893aecb683..83d45ff62847 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/tag.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/tag.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Tag(BaseModel): """ @@ -42,61 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Tag from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Tag from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/task.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/task.py index a8e0fa11ff84..ce18bee68e6c 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/task.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/task.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List from uuid import UUID from petstore_api.models.task_activity import TaskActivity -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Task(BaseModel): """ @@ -44,64 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Task from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of activity - if self.activity: - _dict['activity'] = self.activity.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Task from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "activity": TaskActivity.from_dict(obj["activity"]) if obj.get("activity") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/task_activity.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/task_activity.py index cc1e1fc5a60f..d7b8b1e71af3 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/task_activity.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/task_activity.py @@ -20,132 +20,27 @@ from petstore_api.models.bathing import Bathing from petstore_api.models.feeding import Feeding from petstore_api.models.poop_cleaning import PoopCleaning -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self TASKACTIVITY_ONE_OF_SCHEMAS = ["Bathing", "Feeding", "PoopCleaning"] -class TaskActivity(BaseModel): +class TaskActivity(RootModel[Union[Bathing, Feeding, PoopCleaning]]): """ TaskActivity """ - # data type: PoopCleaning - oneof_schema_1_validator: Optional[PoopCleaning] = None - # data type: Feeding - oneof_schema_2_validator: Optional[Feeding] = None - # data type: Bathing - oneof_schema_3_validator: Optional[Bathing] = None - actual_instance: Optional[Union[Bathing, Feeding, PoopCleaning]] = None - one_of_schemas: Set[str] = { "Bathing", "Feeding", "PoopCleaning" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[Bathing, Feeding, PoopCleaning] = Field( + ... ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - instance = TaskActivity.model_construct() - error_messages = [] - match = 0 - # validate data type: PoopCleaning - if not isinstance(v, PoopCleaning): - error_messages.append(f"Error! Input type `{type(v)}` is not `PoopCleaning`") - else: - match += 1 - # validate data type: Feeding - if not isinstance(v, Feeding): - error_messages.append(f"Error! Input type `{type(v)}` is not `Feeding`") - else: - match += 1 - # validate data type: Bathing - if not isinstance(v, Bathing): - error_messages.append(f"Error! Input type `{type(v)}` is not `Bathing`") - else: - match += 1 - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # deserialize data into PoopCleaning - try: - instance.actual_instance = PoopCleaning.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into Feeding - try: - instance.actual_instance = Feeding.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into Bathing - try: - instance.actual_instance = Bathing.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], Bathing, Feeding, PoopCleaning]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_enum.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_enum.py index 8eae227a84e9..331f0fd597bd 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_enum.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_enum.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class TestEnum(StrEnum): -class TestEnum(str, Enum): """ TestEnum """ - """ - allowed enum values - """ + # Allowed enum values ONE = 'ONE' TWO = 'TWO' THREE = 'THREE' @@ -36,4 +34,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of TestEnum from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_enum_with_default.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_enum_with_default.py index 9304d3ab8497..0f3d74610b96 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_enum_with_default.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_enum_with_default.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class TestEnumWithDefault(StrEnum): -class TestEnumWithDefault(str, Enum): """ TestEnumWithDefault """ - """ - allowed enum values - """ + # Allowed enum values EIN = 'EIN' ZWEI = 'ZWEI' DREI = 'DREI' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of TestEnumWithDefault from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_error_responses_with_model400_response.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_error_responses_with_model400_response.py index f5fe068c9111..b9aba57407ee 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_error_responses_with_model400_response.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_error_responses_with_model400_response.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestErrorResponsesWithModel400Response(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel400Response from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel400Response from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "reason400": obj.get("reason400") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_error_responses_with_model404_response.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_error_responses_with_model404_response.py index 39e6c512ed3e..c71e043f9977 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_error_responses_with_model404_response.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_error_responses_with_model404_response.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestErrorResponsesWithModel404Response(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel404Response from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel404Response from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "reason404": obj.get("reason404") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_inline_freeform_additional_properties_request.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_inline_freeform_additional_properties_request.py index 7b93d84864f2..ef3e742d900f 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_inline_freeform_additional_properties_request.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_inline_freeform_additional_properties_request.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestInlineFreeformAdditionalPropertiesRequest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestInlineFreeformAdditionalPropertiesRequest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "someProperty": obj.get("someProperty") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_model_with_enum_default.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_model_with_enum_default.py index 4bff5e699a37..a0144b2722d6 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_model_with_enum_default.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_model_with_enum_default.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.test_enum import TestEnum from petstore_api.models.test_enum_with_default import TestEnumWithDefault -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestModelWithEnumDefault(BaseModel): """ @@ -32,7 +32,10 @@ class TestModelWithEnumDefault(BaseModel): test_string: Optional[StrictStr] = None test_enum_with_default: Optional[TestEnumWithDefault] = TestEnumWithDefault.ZWEI test_string_with_default: Optional[StrictStr] = 'ahoy matey' - test_inline_defined_enum_with_default: Optional[StrictStr] = 'B' + test_inline_defined_enum_with_default: Optional[Test_inline_defined_enum_with_defaultEnum] = Field( + None, + description="test_inline_defined_enum_with_default of the TestModelWithEnumDefault" + ) additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["test_enum", "test_string", "test_enum_with_default", "test_string_with_default", "test_inline_defined_enum_with_default"] @@ -57,64 +60,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestModelWithEnumDefault from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestModelWithEnumDefault from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "test_enum": obj.get("test_enum"), - "test_string": obj.get("test_string"), - "test_enum_with_default": obj.get("test_enum_with_default") if obj.get("test_enum_with_default") is not None else TestEnumWithDefault.ZWEI, - "test_string_with_default": obj.get("test_string_with_default") if obj.get("test_string_with_default") is not None else 'ahoy matey', - "test_inline_defined_enum_with_default": obj.get("test_inline_defined_enum_with_default") if obj.get("test_inline_defined_enum_with_default") is not None else 'B' - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_object_for_multipart_requests_request_marker.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_object_for_multipart_requests_request_marker.py index c31d72482d59..add356ef35d9 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_object_for_multipart_requests_request_marker.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/test_object_for_multipart_requests_request_marker.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestObjectForMultipartRequestsRequestMarker(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestObjectForMultipartRequestsRequestMarker from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestObjectForMultipartRequestsRequestMarker from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/tiger.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/tiger.py index c2dab004fe1a..4ea2db55add2 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/tiger.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/tiger.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Tiger(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Tiger from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Tiger from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "skill": obj.get("skill") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/type.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/type.py index 35a847de894f..3ab767b6125b 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/type.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/type.py @@ -14,18 +14,17 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self -class Type(int, Enum): +class Type(Enum): + """ Type """ - """ - allowed enum values - """ + # Allowed enum values NUMBER_2_DOT_0 = 2.0 NUMBER_1_DOT_0 = 1.0 NUMBER_0_DOT_5 = 0.5 @@ -36,4 +35,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of Type from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py index e5b5cb4ddeda..715c752174a9 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.creature_info import CreatureInfo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class UnnamedDictWithAdditionalModelListProperties(BaseModel): """ @@ -42,76 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalModelListProperties from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in dict_property (dict of array) - _field_dict_of_array = {} - if self.dict_property: - for _key_dict_property in self.dict_property: - if self.dict_property[_key_dict_property] is not None: - _field_dict_of_array[_key_dict_property] = [ - _item.to_dict() for _item in self.dict_property[_key_dict_property] - ] - _dict['dictProperty'] = _field_dict_of_array - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalModelListProperties from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "dictProperty": dict( - (_k, - [CreatureInfo.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("dictProperty", {}).items() - ) - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py index f4c7625325c8..e870fc2c8c5a 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class UnnamedDictWithAdditionalStringListProperties(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalStringListProperties from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalStringListProperties from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "dictProperty": obj.get("dictProperty") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/upload_file_with_additional_properties_request_object.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/upload_file_with_additional_properties_request_object.py index 6d79131bfe79..ce2388786f9e 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/upload_file_with_additional_properties_request_object.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/upload_file_with_additional_properties_request_object.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class UploadFileWithAdditionalPropertiesRequestObject(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of UploadFileWithAdditionalPropertiesRequestObject from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of UploadFileWithAdditionalPropertiesRequestObject from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/user.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/user.py index ceeb6d4ae54c..c39fb5355ec7 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/user.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/user.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class User(BaseModel): """ @@ -48,67 +48,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of User from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of User from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "username": obj.get("username"), - "firstName": obj.get("firstName"), - "lastName": obj.get("lastName"), - "email": obj.get("email"), - "password": obj.get("password"), - "phone": obj.get("phone"), - "userStatus": obj.get("userStatus") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/with_nested_one_of.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/with_nested_one_of.py index eb7e90879e90..48bd6d586129 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/with_nested_one_of.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/with_nested_one_of.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.one_of_enum_string import OneOfEnumString from petstore_api.models.pig import Pig -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class WithNestedOneOf(BaseModel): """ @@ -45,68 +45,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of WithNestedOneOf from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of nested_pig - if self.nested_pig: - _dict['nested_pig'] = self.nested_pig.to_dict() - # override the default output from pydantic by calling `to_dict()` of nested_oneof_enum_string - if self.nested_oneof_enum_string: - _dict['nested_oneof_enum_string'] = self.nested_oneof_enum_string.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of WithNestedOneOf from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "nested_pig": Pig.from_dict(obj["nested_pig"]) if obj.get("nested_pig") is not None else None, - "nested_oneof_enum_string": OneOfEnumString.from_dict(obj["nested_oneof_enum_string"]) if obj.get("nested_oneof_enum_string") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/pyproject.toml b/samples/openapi3/client/petstore/python-lazyImports/pyproject.toml index a466656e8b6e..238f4e671ac6 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/pyproject.toml +++ b/samples/openapi3/client/petstore/python-lazyImports/pyproject.toml @@ -8,7 +8,7 @@ authors = [ license = { text = "Apache-2.0" } readme = "README.md" keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"] -requires-python = ">=3.9" +requires-python = ">=3.11" dependencies = [ "urllib3 (>=2.1.0,<3.0.0)", diff --git a/samples/openapi3/client/petstore/python-lazyImports/setup.py b/samples/openapi3/client/petstore/python-lazyImports/setup.py index 5edb21a69e69..0a454926a270 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/setup.py +++ b/samples/openapi3/client/petstore/python-lazyImports/setup.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """ OpenAPI Petstore @@ -12,6 +10,7 @@ """ # noqa: E501 + from setuptools import setup, find_packages # noqa: H301 # To install the library, run the following @@ -22,7 +21,7 @@ # http://pypi.python.org/pypi/setuptools NAME = "petstore-api" VERSION = "1.0.0" -PYTHON_REQUIRES = ">= 3.9" +PYTHON_REQUIRES = ">= 3.11" REQUIRES = [ "urllib3 >= 2.1.0, < 3.0.0", "python-dateutil >= 2.8.2", diff --git a/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesAnyType.md b/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesAnyType.md index 314cba3a614c..6491c95beba5 100644 --- a/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesAnyType.md +++ b/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesAnyType.md @@ -15,14 +15,14 @@ from petstore_api.models.additional_properties_any_type import AdditionalPropert # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesAnyType from a JSON string -additional_properties_any_type_instance = AdditionalPropertiesAnyType.from_json(json) +additional_properties_any_type_instance = AdditionalPropertiesAnyType.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesAnyType.to_json()) +print(AdditionalPropertiesAnyType.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_any_type_dict = additional_properties_any_type_instance.to_dict() +additional_properties_any_type_dict = additional_properties_any_type_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesAnyType from a dict -additional_properties_any_type_from_dict = AdditionalPropertiesAnyType.from_dict(additional_properties_any_type_dict) +additional_properties_any_type_from_dict = AdditionalPropertiesAnyType.model_validate(additional_properties_any_type_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesClass.md b/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesClass.md index 8d4c08707f55..2a618964bc5c 100644 --- a/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesClass.md +++ b/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesClass.md @@ -16,14 +16,14 @@ from petstore_api.models.additional_properties_class import AdditionalProperties # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesClass from a JSON string -additional_properties_class_instance = AdditionalPropertiesClass.from_json(json) +additional_properties_class_instance = AdditionalPropertiesClass.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesClass.to_json()) +print(AdditionalPropertiesClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_class_dict = additional_properties_class_instance.to_dict() +additional_properties_class_dict = additional_properties_class_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesClass from a dict -additional_properties_class_from_dict = AdditionalPropertiesClass.from_dict(additional_properties_class_dict) +additional_properties_class_from_dict = AdditionalPropertiesClass.model_validate(additional_properties_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesObject.md b/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesObject.md index d647ec64896f..1c66f8e5d29a 100644 --- a/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesObject.md +++ b/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesObject.md @@ -15,14 +15,14 @@ from petstore_api.models.additional_properties_object import AdditionalPropertie # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesObject from a JSON string -additional_properties_object_instance = AdditionalPropertiesObject.from_json(json) +additional_properties_object_instance = AdditionalPropertiesObject.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesObject.to_json()) +print(AdditionalPropertiesObject.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_object_dict = additional_properties_object_instance.to_dict() +additional_properties_object_dict = additional_properties_object_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesObject from a dict -additional_properties_object_from_dict = AdditionalPropertiesObject.from_dict(additional_properties_object_dict) +additional_properties_object_from_dict = AdditionalPropertiesObject.model_validate(additional_properties_object_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesWithDescriptionOnly.md b/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesWithDescriptionOnly.md index 061f5524872b..88d66f028a2b 100644 --- a/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesWithDescriptionOnly.md +++ b/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesWithDescriptionOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.additional_properties_with_description_only import Addi # TODO update the JSON string below json = "{}" # create an instance of AdditionalPropertiesWithDescriptionOnly from a JSON string -additional_properties_with_description_only_instance = AdditionalPropertiesWithDescriptionOnly.from_json(json) +additional_properties_with_description_only_instance = AdditionalPropertiesWithDescriptionOnly.model_validate_json(json) # print the JSON string representation of the object -print(AdditionalPropertiesWithDescriptionOnly.to_json()) +print(AdditionalPropertiesWithDescriptionOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -additional_properties_with_description_only_dict = additional_properties_with_description_only_instance.to_dict() +additional_properties_with_description_only_dict = additional_properties_with_description_only_instance.model_dump(by_alias=True) # create an instance of AdditionalPropertiesWithDescriptionOnly from a dict -additional_properties_with_description_only_from_dict = AdditionalPropertiesWithDescriptionOnly.from_dict(additional_properties_with_description_only_dict) +additional_properties_with_description_only_from_dict = AdditionalPropertiesWithDescriptionOnly.model_validate(additional_properties_with_description_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/AllOfSuperModel.md b/samples/openapi3/client/petstore/python/docs/AllOfSuperModel.md index 421a1527f1ef..bec62554ebf0 100644 --- a/samples/openapi3/client/petstore/python/docs/AllOfSuperModel.md +++ b/samples/openapi3/client/petstore/python/docs/AllOfSuperModel.md @@ -15,14 +15,14 @@ from petstore_api.models.all_of_super_model import AllOfSuperModel # TODO update the JSON string below json = "{}" # create an instance of AllOfSuperModel from a JSON string -all_of_super_model_instance = AllOfSuperModel.from_json(json) +all_of_super_model_instance = AllOfSuperModel.model_validate_json(json) # print the JSON string representation of the object -print(AllOfSuperModel.to_json()) +print(AllOfSuperModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -all_of_super_model_dict = all_of_super_model_instance.to_dict() +all_of_super_model_dict = all_of_super_model_instance.model_dump(by_alias=True) # create an instance of AllOfSuperModel from a dict -all_of_super_model_from_dict = AllOfSuperModel.from_dict(all_of_super_model_dict) +all_of_super_model_from_dict = AllOfSuperModel.model_validate(all_of_super_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/AllOfWithSingleRef.md b/samples/openapi3/client/petstore/python/docs/AllOfWithSingleRef.md index 203a4b5da3d5..05ae8a658ab3 100644 --- a/samples/openapi3/client/petstore/python/docs/AllOfWithSingleRef.md +++ b/samples/openapi3/client/petstore/python/docs/AllOfWithSingleRef.md @@ -16,14 +16,14 @@ from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef # TODO update the JSON string below json = "{}" # create an instance of AllOfWithSingleRef from a JSON string -all_of_with_single_ref_instance = AllOfWithSingleRef.from_json(json) +all_of_with_single_ref_instance = AllOfWithSingleRef.model_validate_json(json) # print the JSON string representation of the object -print(AllOfWithSingleRef.to_json()) +print(AllOfWithSingleRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -all_of_with_single_ref_dict = all_of_with_single_ref_instance.to_dict() +all_of_with_single_ref_dict = all_of_with_single_ref_instance.model_dump(by_alias=True) # create an instance of AllOfWithSingleRef from a dict -all_of_with_single_ref_from_dict = AllOfWithSingleRef.from_dict(all_of_with_single_ref_dict) +all_of_with_single_ref_from_dict = AllOfWithSingleRef.model_validate(all_of_with_single_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Animal.md b/samples/openapi3/client/petstore/python/docs/Animal.md index 381d27b66e44..eb20439f3782 100644 --- a/samples/openapi3/client/petstore/python/docs/Animal.md +++ b/samples/openapi3/client/petstore/python/docs/Animal.md @@ -16,14 +16,14 @@ from petstore_api.models.animal import Animal # TODO update the JSON string below json = "{}" # create an instance of Animal from a JSON string -animal_instance = Animal.from_json(json) +animal_instance = Animal.model_validate_json(json) # print the JSON string representation of the object -print(Animal.to_json()) +print(Animal.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -animal_dict = animal_instance.to_dict() +animal_dict = animal_instance.model_dump(by_alias=True) # create an instance of Animal from a dict -animal_from_dict = Animal.from_dict(animal_dict) +animal_from_dict = Animal.model_validate(animal_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/AnyOfColor.md b/samples/openapi3/client/petstore/python/docs/AnyOfColor.md index 6ed75dd7b48a..c656fdbbae05 100644 --- a/samples/openapi3/client/petstore/python/docs/AnyOfColor.md +++ b/samples/openapi3/client/petstore/python/docs/AnyOfColor.md @@ -15,14 +15,14 @@ from petstore_api.models.any_of_color import AnyOfColor # TODO update the JSON string below json = "{}" # create an instance of AnyOfColor from a JSON string -any_of_color_instance = AnyOfColor.from_json(json) +any_of_color_instance = AnyOfColor.model_validate_json(json) # print the JSON string representation of the object -print(AnyOfColor.to_json()) +print(AnyOfColor.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -any_of_color_dict = any_of_color_instance.to_dict() +any_of_color_dict = any_of_color_instance.model_dump(by_alias=True) # create an instance of AnyOfColor from a dict -any_of_color_from_dict = AnyOfColor.from_dict(any_of_color_dict) +any_of_color_from_dict = AnyOfColor.model_validate(any_of_color_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/AnyOfPig.md b/samples/openapi3/client/petstore/python/docs/AnyOfPig.md index 9367e2261898..0c273f175319 100644 --- a/samples/openapi3/client/petstore/python/docs/AnyOfPig.md +++ b/samples/openapi3/client/petstore/python/docs/AnyOfPig.md @@ -17,14 +17,14 @@ from petstore_api.models.any_of_pig import AnyOfPig # TODO update the JSON string below json = "{}" # create an instance of AnyOfPig from a JSON string -any_of_pig_instance = AnyOfPig.from_json(json) +any_of_pig_instance = AnyOfPig.model_validate_json(json) # print the JSON string representation of the object -print(AnyOfPig.to_json()) +print(AnyOfPig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -any_of_pig_dict = any_of_pig_instance.to_dict() +any_of_pig_dict = any_of_pig_instance.model_dump(by_alias=True) # create an instance of AnyOfPig from a dict -any_of_pig_from_dict = AnyOfPig.from_dict(any_of_pig_dict) +any_of_pig_from_dict = AnyOfPig.model_validate(any_of_pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/ArrayOfArrayOfModel.md b/samples/openapi3/client/petstore/python/docs/ArrayOfArrayOfModel.md index f866863d53f9..83505f6eb05b 100644 --- a/samples/openapi3/client/petstore/python/docs/ArrayOfArrayOfModel.md +++ b/samples/openapi3/client/petstore/python/docs/ArrayOfArrayOfModel.md @@ -15,14 +15,14 @@ from petstore_api.models.array_of_array_of_model import ArrayOfArrayOfModel # TODO update the JSON string below json = "{}" # create an instance of ArrayOfArrayOfModel from a JSON string -array_of_array_of_model_instance = ArrayOfArrayOfModel.from_json(json) +array_of_array_of_model_instance = ArrayOfArrayOfModel.model_validate_json(json) # print the JSON string representation of the object -print(ArrayOfArrayOfModel.to_json()) +print(ArrayOfArrayOfModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_of_array_of_model_dict = array_of_array_of_model_instance.to_dict() +array_of_array_of_model_dict = array_of_array_of_model_instance.model_dump(by_alias=True) # create an instance of ArrayOfArrayOfModel from a dict -array_of_array_of_model_from_dict = ArrayOfArrayOfModel.from_dict(array_of_array_of_model_dict) +array_of_array_of_model_from_dict = ArrayOfArrayOfModel.model_validate(array_of_array_of_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/ArrayOfArrayOfNumberOnly.md b/samples/openapi3/client/petstore/python/docs/ArrayOfArrayOfNumberOnly.md index 32bd2dfbf1e2..0027448edc27 100644 --- a/samples/openapi3/client/petstore/python/docs/ArrayOfArrayOfNumberOnly.md +++ b/samples/openapi3/client/petstore/python/docs/ArrayOfArrayOfNumberOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumb # TODO update the JSON string below json = "{}" # create an instance of ArrayOfArrayOfNumberOnly from a JSON string -array_of_array_of_number_only_instance = ArrayOfArrayOfNumberOnly.from_json(json) +array_of_array_of_number_only_instance = ArrayOfArrayOfNumberOnly.model_validate_json(json) # print the JSON string representation of the object -print(ArrayOfArrayOfNumberOnly.to_json()) +print(ArrayOfArrayOfNumberOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_of_array_of_number_only_dict = array_of_array_of_number_only_instance.to_dict() +array_of_array_of_number_only_dict = array_of_array_of_number_only_instance.model_dump(by_alias=True) # create an instance of ArrayOfArrayOfNumberOnly from a dict -array_of_array_of_number_only_from_dict = ArrayOfArrayOfNumberOnly.from_dict(array_of_array_of_number_only_dict) +array_of_array_of_number_only_from_dict = ArrayOfArrayOfNumberOnly.model_validate(array_of_array_of_number_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/ArrayOfNumberOnly.md b/samples/openapi3/client/petstore/python/docs/ArrayOfNumberOnly.md index b814d7594942..81aeee6c1add 100644 --- a/samples/openapi3/client/petstore/python/docs/ArrayOfNumberOnly.md +++ b/samples/openapi3/client/petstore/python/docs/ArrayOfNumberOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.array_of_number_only import ArrayOfNumberOnly # TODO update the JSON string below json = "{}" # create an instance of ArrayOfNumberOnly from a JSON string -array_of_number_only_instance = ArrayOfNumberOnly.from_json(json) +array_of_number_only_instance = ArrayOfNumberOnly.model_validate_json(json) # print the JSON string representation of the object -print(ArrayOfNumberOnly.to_json()) +print(ArrayOfNumberOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_of_number_only_dict = array_of_number_only_instance.to_dict() +array_of_number_only_dict = array_of_number_only_instance.model_dump(by_alias=True) # create an instance of ArrayOfNumberOnly from a dict -array_of_number_only_from_dict = ArrayOfNumberOnly.from_dict(array_of_number_only_dict) +array_of_number_only_from_dict = ArrayOfNumberOnly.model_validate(array_of_number_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/ArrayTest.md b/samples/openapi3/client/petstore/python/docs/ArrayTest.md index ed871fae662d..62b868a02c64 100644 --- a/samples/openapi3/client/petstore/python/docs/ArrayTest.md +++ b/samples/openapi3/client/petstore/python/docs/ArrayTest.md @@ -18,14 +18,14 @@ from petstore_api.models.array_test import ArrayTest # TODO update the JSON string below json = "{}" # create an instance of ArrayTest from a JSON string -array_test_instance = ArrayTest.from_json(json) +array_test_instance = ArrayTest.model_validate_json(json) # print the JSON string representation of the object -print(ArrayTest.to_json()) +print(ArrayTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -array_test_dict = array_test_instance.to_dict() +array_test_dict = array_test_instance.model_dump(by_alias=True) # create an instance of ArrayTest from a dict -array_test_from_dict = ArrayTest.from_dict(array_test_dict) +array_test_from_dict = ArrayTest.model_validate(array_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/BaseDiscriminator.md b/samples/openapi3/client/petstore/python/docs/BaseDiscriminator.md index fcdbeb032e68..a317fc0421fe 100644 --- a/samples/openapi3/client/petstore/python/docs/BaseDiscriminator.md +++ b/samples/openapi3/client/petstore/python/docs/BaseDiscriminator.md @@ -15,14 +15,14 @@ from petstore_api.models.base_discriminator import BaseDiscriminator # TODO update the JSON string below json = "{}" # create an instance of BaseDiscriminator from a JSON string -base_discriminator_instance = BaseDiscriminator.from_json(json) +base_discriminator_instance = BaseDiscriminator.model_validate_json(json) # print the JSON string representation of the object -print(BaseDiscriminator.to_json()) +print(BaseDiscriminator.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -base_discriminator_dict = base_discriminator_instance.to_dict() +base_discriminator_dict = base_discriminator_instance.model_dump(by_alias=True) # create an instance of BaseDiscriminator from a dict -base_discriminator_from_dict = BaseDiscriminator.from_dict(base_discriminator_dict) +base_discriminator_from_dict = BaseDiscriminator.model_validate(base_discriminator_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/BasquePig.md b/samples/openapi3/client/petstore/python/docs/BasquePig.md index ee28d628722f..8af258aa7901 100644 --- a/samples/openapi3/client/petstore/python/docs/BasquePig.md +++ b/samples/openapi3/client/petstore/python/docs/BasquePig.md @@ -16,14 +16,14 @@ from petstore_api.models.basque_pig import BasquePig # TODO update the JSON string below json = "{}" # create an instance of BasquePig from a JSON string -basque_pig_instance = BasquePig.from_json(json) +basque_pig_instance = BasquePig.model_validate_json(json) # print the JSON string representation of the object -print(BasquePig.to_json()) +print(BasquePig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -basque_pig_dict = basque_pig_instance.to_dict() +basque_pig_dict = basque_pig_instance.model_dump(by_alias=True) # create an instance of BasquePig from a dict -basque_pig_from_dict = BasquePig.from_dict(basque_pig_dict) +basque_pig_from_dict = BasquePig.model_validate(basque_pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Bathing.md b/samples/openapi3/client/petstore/python/docs/Bathing.md index 6ad70e2f67cc..5365c9614d17 100644 --- a/samples/openapi3/client/petstore/python/docs/Bathing.md +++ b/samples/openapi3/client/petstore/python/docs/Bathing.md @@ -17,14 +17,14 @@ from petstore_api.models.bathing import Bathing # TODO update the JSON string below json = "{}" # create an instance of Bathing from a JSON string -bathing_instance = Bathing.from_json(json) +bathing_instance = Bathing.model_validate_json(json) # print the JSON string representation of the object -print(Bathing.to_json()) +print(Bathing.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -bathing_dict = bathing_instance.to_dict() +bathing_dict = bathing_instance.model_dump(by_alias=True) # create an instance of Bathing from a dict -bathing_from_dict = Bathing.from_dict(bathing_dict) +bathing_from_dict = Bathing.model_validate(bathing_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Capitalization.md b/samples/openapi3/client/petstore/python/docs/Capitalization.md index 6f564a8ed8c9..efbf7520b692 100644 --- a/samples/openapi3/client/petstore/python/docs/Capitalization.md +++ b/samples/openapi3/client/petstore/python/docs/Capitalization.md @@ -20,14 +20,14 @@ from petstore_api.models.capitalization import Capitalization # TODO update the JSON string below json = "{}" # create an instance of Capitalization from a JSON string -capitalization_instance = Capitalization.from_json(json) +capitalization_instance = Capitalization.model_validate_json(json) # print the JSON string representation of the object -print(Capitalization.to_json()) +print(Capitalization.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -capitalization_dict = capitalization_instance.to_dict() +capitalization_dict = capitalization_instance.model_dump(by_alias=True) # create an instance of Capitalization from a dict -capitalization_from_dict = Capitalization.from_dict(capitalization_dict) +capitalization_from_dict = Capitalization.model_validate(capitalization_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Cat.md b/samples/openapi3/client/petstore/python/docs/Cat.md index d0e39efdb33e..2940176bb9b8 100644 --- a/samples/openapi3/client/petstore/python/docs/Cat.md +++ b/samples/openapi3/client/petstore/python/docs/Cat.md @@ -15,14 +15,14 @@ from petstore_api.models.cat import Cat # TODO update the JSON string below json = "{}" # create an instance of Cat from a JSON string -cat_instance = Cat.from_json(json) +cat_instance = Cat.model_validate_json(json) # print the JSON string representation of the object -print(Cat.to_json()) +print(Cat.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -cat_dict = cat_instance.to_dict() +cat_dict = cat_instance.model_dump(by_alias=True) # create an instance of Cat from a dict -cat_from_dict = Cat.from_dict(cat_dict) +cat_from_dict = Cat.model_validate(cat_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Category.md b/samples/openapi3/client/petstore/python/docs/Category.md index dbde14b7344c..a1509b71308f 100644 --- a/samples/openapi3/client/petstore/python/docs/Category.md +++ b/samples/openapi3/client/petstore/python/docs/Category.md @@ -16,14 +16,14 @@ from petstore_api.models.category import Category # TODO update the JSON string below json = "{}" # create an instance of Category from a JSON string -category_instance = Category.from_json(json) +category_instance = Category.model_validate_json(json) # print the JSON string representation of the object -print(Category.to_json()) +print(Category.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -category_dict = category_instance.to_dict() +category_dict = category_instance.model_dump(by_alias=True) # create an instance of Category from a dict -category_from_dict = Category.from_dict(category_dict) +category_from_dict = Category.model_validate(category_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/CircularAllOfRef.md b/samples/openapi3/client/petstore/python/docs/CircularAllOfRef.md index 65b171177e58..aaab0079b3f4 100644 --- a/samples/openapi3/client/petstore/python/docs/CircularAllOfRef.md +++ b/samples/openapi3/client/petstore/python/docs/CircularAllOfRef.md @@ -16,14 +16,14 @@ from petstore_api.models.circular_all_of_ref import CircularAllOfRef # TODO update the JSON string below json = "{}" # create an instance of CircularAllOfRef from a JSON string -circular_all_of_ref_instance = CircularAllOfRef.from_json(json) +circular_all_of_ref_instance = CircularAllOfRef.model_validate_json(json) # print the JSON string representation of the object -print(CircularAllOfRef.to_json()) +print(CircularAllOfRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -circular_all_of_ref_dict = circular_all_of_ref_instance.to_dict() +circular_all_of_ref_dict = circular_all_of_ref_instance.model_dump(by_alias=True) # create an instance of CircularAllOfRef from a dict -circular_all_of_ref_from_dict = CircularAllOfRef.from_dict(circular_all_of_ref_dict) +circular_all_of_ref_from_dict = CircularAllOfRef.model_validate(circular_all_of_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/CircularReferenceModel.md b/samples/openapi3/client/petstore/python/docs/CircularReferenceModel.md index 87216f7273ab..33ec5e9b09bf 100644 --- a/samples/openapi3/client/petstore/python/docs/CircularReferenceModel.md +++ b/samples/openapi3/client/petstore/python/docs/CircularReferenceModel.md @@ -16,14 +16,14 @@ from petstore_api.models.circular_reference_model import CircularReferenceModel # TODO update the JSON string below json = "{}" # create an instance of CircularReferenceModel from a JSON string -circular_reference_model_instance = CircularReferenceModel.from_json(json) +circular_reference_model_instance = CircularReferenceModel.model_validate_json(json) # print the JSON string representation of the object -print(CircularReferenceModel.to_json()) +print(CircularReferenceModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -circular_reference_model_dict = circular_reference_model_instance.to_dict() +circular_reference_model_dict = circular_reference_model_instance.model_dump(by_alias=True) # create an instance of CircularReferenceModel from a dict -circular_reference_model_from_dict = CircularReferenceModel.from_dict(circular_reference_model_dict) +circular_reference_model_from_dict = CircularReferenceModel.model_validate(circular_reference_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/ClassModel.md b/samples/openapi3/client/petstore/python/docs/ClassModel.md index ea76a5c157bf..9e69a69b5c27 100644 --- a/samples/openapi3/client/petstore/python/docs/ClassModel.md +++ b/samples/openapi3/client/petstore/python/docs/ClassModel.md @@ -16,14 +16,14 @@ from petstore_api.models.class_model import ClassModel # TODO update the JSON string below json = "{}" # create an instance of ClassModel from a JSON string -class_model_instance = ClassModel.from_json(json) +class_model_instance = ClassModel.model_validate_json(json) # print the JSON string representation of the object -print(ClassModel.to_json()) +print(ClassModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -class_model_dict = class_model_instance.to_dict() +class_model_dict = class_model_instance.model_dump(by_alias=True) # create an instance of ClassModel from a dict -class_model_from_dict = ClassModel.from_dict(class_model_dict) +class_model_from_dict = ClassModel.model_validate(class_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Client.md b/samples/openapi3/client/petstore/python/docs/Client.md index 22321c189150..6a9b3d800434 100644 --- a/samples/openapi3/client/petstore/python/docs/Client.md +++ b/samples/openapi3/client/petstore/python/docs/Client.md @@ -15,14 +15,14 @@ from petstore_api.models.client import Client # TODO update the JSON string below json = "{}" # create an instance of Client from a JSON string -client_instance = Client.from_json(json) +client_instance = Client.model_validate_json(json) # print the JSON string representation of the object -print(Client.to_json()) +print(Client.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -client_dict = client_instance.to_dict() +client_dict = client_instance.model_dump(by_alias=True) # create an instance of Client from a dict -client_from_dict = Client.from_dict(client_dict) +client_from_dict = Client.model_validate(client_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Color.md b/samples/openapi3/client/petstore/python/docs/Color.md index 9ac3ab2e91f4..088998e89af9 100644 --- a/samples/openapi3/client/petstore/python/docs/Color.md +++ b/samples/openapi3/client/petstore/python/docs/Color.md @@ -15,14 +15,14 @@ from petstore_api.models.color import Color # TODO update the JSON string below json = "{}" # create an instance of Color from a JSON string -color_instance = Color.from_json(json) +color_instance = Color.model_validate_json(json) # print the JSON string representation of the object -print(Color.to_json()) +print(Color.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -color_dict = color_instance.to_dict() +color_dict = color_instance.model_dump(by_alias=True) # create an instance of Color from a dict -color_from_dict = Color.from_dict(color_dict) +color_from_dict = Color.model_validate(color_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Creature.md b/samples/openapi3/client/petstore/python/docs/Creature.md index a4710214c198..bc746b2856e9 100644 --- a/samples/openapi3/client/petstore/python/docs/Creature.md +++ b/samples/openapi3/client/petstore/python/docs/Creature.md @@ -16,14 +16,14 @@ from petstore_api.models.creature import Creature # TODO update the JSON string below json = "{}" # create an instance of Creature from a JSON string -creature_instance = Creature.from_json(json) +creature_instance = Creature.model_validate_json(json) # print the JSON string representation of the object -print(Creature.to_json()) +print(Creature.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -creature_dict = creature_instance.to_dict() +creature_dict = creature_instance.model_dump(by_alias=True) # create an instance of Creature from a dict -creature_from_dict = Creature.from_dict(creature_dict) +creature_from_dict = Creature.model_validate(creature_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/CreatureInfo.md b/samples/openapi3/client/petstore/python/docs/CreatureInfo.md index db3b82bb9ff5..a355b9e52802 100644 --- a/samples/openapi3/client/petstore/python/docs/CreatureInfo.md +++ b/samples/openapi3/client/petstore/python/docs/CreatureInfo.md @@ -15,14 +15,14 @@ from petstore_api.models.creature_info import CreatureInfo # TODO update the JSON string below json = "{}" # create an instance of CreatureInfo from a JSON string -creature_info_instance = CreatureInfo.from_json(json) +creature_info_instance = CreatureInfo.model_validate_json(json) # print the JSON string representation of the object -print(CreatureInfo.to_json()) +print(CreatureInfo.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -creature_info_dict = creature_info_instance.to_dict() +creature_info_dict = creature_info_instance.model_dump(by_alias=True) # create an instance of CreatureInfo from a dict -creature_info_from_dict = CreatureInfo.from_dict(creature_info_dict) +creature_info_from_dict = CreatureInfo.model_validate(creature_info_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/DanishPig.md b/samples/openapi3/client/petstore/python/docs/DanishPig.md index 16941388832a..58902d70f7bd 100644 --- a/samples/openapi3/client/petstore/python/docs/DanishPig.md +++ b/samples/openapi3/client/petstore/python/docs/DanishPig.md @@ -16,14 +16,14 @@ from petstore_api.models.danish_pig import DanishPig # TODO update the JSON string below json = "{}" # create an instance of DanishPig from a JSON string -danish_pig_instance = DanishPig.from_json(json) +danish_pig_instance = DanishPig.model_validate_json(json) # print the JSON string representation of the object -print(DanishPig.to_json()) +print(DanishPig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -danish_pig_dict = danish_pig_instance.to_dict() +danish_pig_dict = danish_pig_instance.model_dump(by_alias=True) # create an instance of DanishPig from a dict -danish_pig_from_dict = DanishPig.from_dict(danish_pig_dict) +danish_pig_from_dict = DanishPig.model_validate(danish_pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/DeprecatedObject.md b/samples/openapi3/client/petstore/python/docs/DeprecatedObject.md index 6b362f379ba4..55abc18b24d6 100644 --- a/samples/openapi3/client/petstore/python/docs/DeprecatedObject.md +++ b/samples/openapi3/client/petstore/python/docs/DeprecatedObject.md @@ -15,14 +15,14 @@ from petstore_api.models.deprecated_object import DeprecatedObject # TODO update the JSON string below json = "{}" # create an instance of DeprecatedObject from a JSON string -deprecated_object_instance = DeprecatedObject.from_json(json) +deprecated_object_instance = DeprecatedObject.model_validate_json(json) # print the JSON string representation of the object -print(DeprecatedObject.to_json()) +print(DeprecatedObject.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -deprecated_object_dict = deprecated_object_instance.to_dict() +deprecated_object_dict = deprecated_object_instance.model_dump(by_alias=True) # create an instance of DeprecatedObject from a dict -deprecated_object_from_dict = DeprecatedObject.from_dict(deprecated_object_dict) +deprecated_object_from_dict = DeprecatedObject.model_validate(deprecated_object_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/DiscriminatorAllOfSub.md b/samples/openapi3/client/petstore/python/docs/DiscriminatorAllOfSub.md index f72b6e8e68ca..9453c541c53a 100644 --- a/samples/openapi3/client/petstore/python/docs/DiscriminatorAllOfSub.md +++ b/samples/openapi3/client/petstore/python/docs/DiscriminatorAllOfSub.md @@ -14,14 +14,14 @@ from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub # TODO update the JSON string below json = "{}" # create an instance of DiscriminatorAllOfSub from a JSON string -discriminator_all_of_sub_instance = DiscriminatorAllOfSub.from_json(json) +discriminator_all_of_sub_instance = DiscriminatorAllOfSub.model_validate_json(json) # print the JSON string representation of the object -print(DiscriminatorAllOfSub.to_json()) +print(DiscriminatorAllOfSub.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -discriminator_all_of_sub_dict = discriminator_all_of_sub_instance.to_dict() +discriminator_all_of_sub_dict = discriminator_all_of_sub_instance.model_dump(by_alias=True) # create an instance of DiscriminatorAllOfSub from a dict -discriminator_all_of_sub_from_dict = DiscriminatorAllOfSub.from_dict(discriminator_all_of_sub_dict) +discriminator_all_of_sub_from_dict = DiscriminatorAllOfSub.model_validate(discriminator_all_of_sub_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/DiscriminatorAllOfSuper.md b/samples/openapi3/client/petstore/python/docs/DiscriminatorAllOfSuper.md index 477c05bfc446..c83f6792acab 100644 --- a/samples/openapi3/client/petstore/python/docs/DiscriminatorAllOfSuper.md +++ b/samples/openapi3/client/petstore/python/docs/DiscriminatorAllOfSuper.md @@ -15,14 +15,14 @@ from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSup # TODO update the JSON string below json = "{}" # create an instance of DiscriminatorAllOfSuper from a JSON string -discriminator_all_of_super_instance = DiscriminatorAllOfSuper.from_json(json) +discriminator_all_of_super_instance = DiscriminatorAllOfSuper.model_validate_json(json) # print the JSON string representation of the object -print(DiscriminatorAllOfSuper.to_json()) +print(DiscriminatorAllOfSuper.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -discriminator_all_of_super_dict = discriminator_all_of_super_instance.to_dict() +discriminator_all_of_super_dict = discriminator_all_of_super_instance.model_dump(by_alias=True) # create an instance of DiscriminatorAllOfSuper from a dict -discriminator_all_of_super_from_dict = DiscriminatorAllOfSuper.from_dict(discriminator_all_of_super_dict) +discriminator_all_of_super_from_dict = DiscriminatorAllOfSuper.model_validate(discriminator_all_of_super_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Dog.md b/samples/openapi3/client/petstore/python/docs/Dog.md index ed23f613d01d..099b3f781b4b 100644 --- a/samples/openapi3/client/petstore/python/docs/Dog.md +++ b/samples/openapi3/client/petstore/python/docs/Dog.md @@ -15,14 +15,14 @@ from petstore_api.models.dog import Dog # TODO update the JSON string below json = "{}" # create an instance of Dog from a JSON string -dog_instance = Dog.from_json(json) +dog_instance = Dog.model_validate_json(json) # print the JSON string representation of the object -print(Dog.to_json()) +print(Dog.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -dog_dict = dog_instance.to_dict() +dog_dict = dog_instance.model_dump(by_alias=True) # create an instance of Dog from a dict -dog_from_dict = Dog.from_dict(dog_dict) +dog_from_dict = Dog.model_validate(dog_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/DummyModel.md b/samples/openapi3/client/petstore/python/docs/DummyModel.md index 01b675977f58..bf4ef8ec2b03 100644 --- a/samples/openapi3/client/petstore/python/docs/DummyModel.md +++ b/samples/openapi3/client/petstore/python/docs/DummyModel.md @@ -16,14 +16,14 @@ from petstore_api.models.dummy_model import DummyModel # TODO update the JSON string below json = "{}" # create an instance of DummyModel from a JSON string -dummy_model_instance = DummyModel.from_json(json) +dummy_model_instance = DummyModel.model_validate_json(json) # print the JSON string representation of the object -print(DummyModel.to_json()) +print(DummyModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -dummy_model_dict = dummy_model_instance.to_dict() +dummy_model_dict = dummy_model_instance.model_dump(by_alias=True) # create an instance of DummyModel from a dict -dummy_model_from_dict = DummyModel.from_dict(dummy_model_dict) +dummy_model_from_dict = DummyModel.model_validate(dummy_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/EnumArrays.md b/samples/openapi3/client/petstore/python/docs/EnumArrays.md index f44617497bce..fa9dc0d523a9 100644 --- a/samples/openapi3/client/petstore/python/docs/EnumArrays.md +++ b/samples/openapi3/client/petstore/python/docs/EnumArrays.md @@ -16,14 +16,14 @@ from petstore_api.models.enum_arrays import EnumArrays # TODO update the JSON string below json = "{}" # create an instance of EnumArrays from a JSON string -enum_arrays_instance = EnumArrays.from_json(json) +enum_arrays_instance = EnumArrays.model_validate_json(json) # print the JSON string representation of the object -print(EnumArrays.to_json()) +print(EnumArrays.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -enum_arrays_dict = enum_arrays_instance.to_dict() +enum_arrays_dict = enum_arrays_instance.model_dump(by_alias=True) # create an instance of EnumArrays from a dict -enum_arrays_from_dict = EnumArrays.from_dict(enum_arrays_dict) +enum_arrays_from_dict = EnumArrays.model_validate(enum_arrays_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/EnumRefWithDefaultValue.md b/samples/openapi3/client/petstore/python/docs/EnumRefWithDefaultValue.md index eeb0dc66969f..89bfb7c31366 100644 --- a/samples/openapi3/client/petstore/python/docs/EnumRefWithDefaultValue.md +++ b/samples/openapi3/client/petstore/python/docs/EnumRefWithDefaultValue.md @@ -15,14 +15,14 @@ from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultVa # TODO update the JSON string below json = "{}" # create an instance of EnumRefWithDefaultValue from a JSON string -enum_ref_with_default_value_instance = EnumRefWithDefaultValue.from_json(json) +enum_ref_with_default_value_instance = EnumRefWithDefaultValue.model_validate_json(json) # print the JSON string representation of the object -print(EnumRefWithDefaultValue.to_json()) +print(EnumRefWithDefaultValue.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -enum_ref_with_default_value_dict = enum_ref_with_default_value_instance.to_dict() +enum_ref_with_default_value_dict = enum_ref_with_default_value_instance.model_dump(by_alias=True) # create an instance of EnumRefWithDefaultValue from a dict -enum_ref_with_default_value_from_dict = EnumRefWithDefaultValue.from_dict(enum_ref_with_default_value_dict) +enum_ref_with_default_value_from_dict = EnumRefWithDefaultValue.model_validate(enum_ref_with_default_value_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/EnumTest.md b/samples/openapi3/client/petstore/python/docs/EnumTest.md index 9f96c605d888..c6127df54638 100644 --- a/samples/openapi3/client/petstore/python/docs/EnumTest.md +++ b/samples/openapi3/client/petstore/python/docs/EnumTest.md @@ -27,14 +27,14 @@ from petstore_api.models.enum_test import EnumTest # TODO update the JSON string below json = "{}" # create an instance of EnumTest from a JSON string -enum_test_instance = EnumTest.from_json(json) +enum_test_instance = EnumTest.model_validate_json(json) # print the JSON string representation of the object -print(EnumTest.to_json()) +print(EnumTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -enum_test_dict = enum_test_instance.to_dict() +enum_test_dict = enum_test_instance.model_dump(by_alias=True) # create an instance of EnumTest from a dict -enum_test_from_dict = EnumTest.from_dict(enum_test_dict) +enum_test_from_dict = EnumTest.model_validate(enum_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Feeding.md b/samples/openapi3/client/petstore/python/docs/Feeding.md index 9f92b5d964d3..177cae170e77 100644 --- a/samples/openapi3/client/petstore/python/docs/Feeding.md +++ b/samples/openapi3/client/petstore/python/docs/Feeding.md @@ -17,14 +17,14 @@ from petstore_api.models.feeding import Feeding # TODO update the JSON string below json = "{}" # create an instance of Feeding from a JSON string -feeding_instance = Feeding.from_json(json) +feeding_instance = Feeding.model_validate_json(json) # print the JSON string representation of the object -print(Feeding.to_json()) +print(Feeding.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -feeding_dict = feeding_instance.to_dict() +feeding_dict = feeding_instance.model_dump(by_alias=True) # create an instance of Feeding from a dict -feeding_from_dict = Feeding.from_dict(feeding_dict) +feeding_from_dict = Feeding.model_validate(feeding_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/File.md b/samples/openapi3/client/petstore/python/docs/File.md index 23f0567411ce..0b5942557efe 100644 --- a/samples/openapi3/client/petstore/python/docs/File.md +++ b/samples/openapi3/client/petstore/python/docs/File.md @@ -16,14 +16,14 @@ from petstore_api.models.file import File # TODO update the JSON string below json = "{}" # create an instance of File from a JSON string -file_instance = File.from_json(json) +file_instance = File.model_validate_json(json) # print the JSON string representation of the object -print(File.to_json()) +print(File.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -file_dict = file_instance.to_dict() +file_dict = file_instance.model_dump(by_alias=True) # create an instance of File from a dict -file_from_dict = File.from_dict(file_dict) +file_from_dict = File.model_validate(file_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/FileSchemaTestClass.md b/samples/openapi3/client/petstore/python/docs/FileSchemaTestClass.md index e1118042a8ec..917f4ce73382 100644 --- a/samples/openapi3/client/petstore/python/docs/FileSchemaTestClass.md +++ b/samples/openapi3/client/petstore/python/docs/FileSchemaTestClass.md @@ -16,14 +16,14 @@ from petstore_api.models.file_schema_test_class import FileSchemaTestClass # TODO update the JSON string below json = "{}" # create an instance of FileSchemaTestClass from a JSON string -file_schema_test_class_instance = FileSchemaTestClass.from_json(json) +file_schema_test_class_instance = FileSchemaTestClass.model_validate_json(json) # print the JSON string representation of the object -print(FileSchemaTestClass.to_json()) +print(FileSchemaTestClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -file_schema_test_class_dict = file_schema_test_class_instance.to_dict() +file_schema_test_class_dict = file_schema_test_class_instance.model_dump(by_alias=True) # create an instance of FileSchemaTestClass from a dict -file_schema_test_class_from_dict = FileSchemaTestClass.from_dict(file_schema_test_class_dict) +file_schema_test_class_from_dict = FileSchemaTestClass.model_validate(file_schema_test_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/FirstRef.md b/samples/openapi3/client/petstore/python/docs/FirstRef.md index 94b8ddc5ac22..51617b213a4f 100644 --- a/samples/openapi3/client/petstore/python/docs/FirstRef.md +++ b/samples/openapi3/client/petstore/python/docs/FirstRef.md @@ -16,14 +16,14 @@ from petstore_api.models.first_ref import FirstRef # TODO update the JSON string below json = "{}" # create an instance of FirstRef from a JSON string -first_ref_instance = FirstRef.from_json(json) +first_ref_instance = FirstRef.model_validate_json(json) # print the JSON string representation of the object -print(FirstRef.to_json()) +print(FirstRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -first_ref_dict = first_ref_instance.to_dict() +first_ref_dict = first_ref_instance.model_dump(by_alias=True) # create an instance of FirstRef from a dict -first_ref_from_dict = FirstRef.from_dict(first_ref_dict) +first_ref_from_dict = FirstRef.model_validate(first_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Foo.md b/samples/openapi3/client/petstore/python/docs/Foo.md index f635b0daa6db..e25a5a16bac5 100644 --- a/samples/openapi3/client/petstore/python/docs/Foo.md +++ b/samples/openapi3/client/petstore/python/docs/Foo.md @@ -15,14 +15,14 @@ from petstore_api.models.foo import Foo # TODO update the JSON string below json = "{}" # create an instance of Foo from a JSON string -foo_instance = Foo.from_json(json) +foo_instance = Foo.model_validate_json(json) # print the JSON string representation of the object -print(Foo.to_json()) +print(Foo.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -foo_dict = foo_instance.to_dict() +foo_dict = foo_instance.model_dump(by_alias=True) # create an instance of Foo from a dict -foo_from_dict = Foo.from_dict(foo_dict) +foo_from_dict = Foo.model_validate(foo_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/FooGetDefaultResponse.md b/samples/openapi3/client/petstore/python/docs/FooGetDefaultResponse.md index 8d84f795b00a..dab8d870b496 100644 --- a/samples/openapi3/client/petstore/python/docs/FooGetDefaultResponse.md +++ b/samples/openapi3/client/petstore/python/docs/FooGetDefaultResponse.md @@ -15,14 +15,14 @@ from petstore_api.models.foo_get_default_response import FooGetDefaultResponse # TODO update the JSON string below json = "{}" # create an instance of FooGetDefaultResponse from a JSON string -foo_get_default_response_instance = FooGetDefaultResponse.from_json(json) +foo_get_default_response_instance = FooGetDefaultResponse.model_validate_json(json) # print the JSON string representation of the object -print(FooGetDefaultResponse.to_json()) +print(FooGetDefaultResponse.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -foo_get_default_response_dict = foo_get_default_response_instance.to_dict() +foo_get_default_response_dict = foo_get_default_response_instance.model_dump(by_alias=True) # create an instance of FooGetDefaultResponse from a dict -foo_get_default_response_from_dict = FooGetDefaultResponse.from_dict(foo_get_default_response_dict) +foo_get_default_response_from_dict = FooGetDefaultResponse.model_validate(foo_get_default_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/FormatTest.md b/samples/openapi3/client/petstore/python/docs/FormatTest.md index 714d2401bbae..7b4bcb6513f8 100644 --- a/samples/openapi3/client/petstore/python/docs/FormatTest.md +++ b/samples/openapi3/client/petstore/python/docs/FormatTest.md @@ -31,14 +31,14 @@ from petstore_api.models.format_test import FormatTest # TODO update the JSON string below json = "{}" # create an instance of FormatTest from a JSON string -format_test_instance = FormatTest.from_json(json) +format_test_instance = FormatTest.model_validate_json(json) # print the JSON string representation of the object -print(FormatTest.to_json()) +print(FormatTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -format_test_dict = format_test_instance.to_dict() +format_test_dict = format_test_instance.model_dump(by_alias=True) # create an instance of FormatTest from a dict -format_test_from_dict = FormatTest.from_dict(format_test_dict) +format_test_from_dict = FormatTest.model_validate(format_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/HasOnlyReadOnly.md b/samples/openapi3/client/petstore/python/docs/HasOnlyReadOnly.md index fdc48781b15a..a2d020b6a2cb 100644 --- a/samples/openapi3/client/petstore/python/docs/HasOnlyReadOnly.md +++ b/samples/openapi3/client/petstore/python/docs/HasOnlyReadOnly.md @@ -16,14 +16,14 @@ from petstore_api.models.has_only_read_only import HasOnlyReadOnly # TODO update the JSON string below json = "{}" # create an instance of HasOnlyReadOnly from a JSON string -has_only_read_only_instance = HasOnlyReadOnly.from_json(json) +has_only_read_only_instance = HasOnlyReadOnly.model_validate_json(json) # print the JSON string representation of the object -print(HasOnlyReadOnly.to_json()) +print(HasOnlyReadOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -has_only_read_only_dict = has_only_read_only_instance.to_dict() +has_only_read_only_dict = has_only_read_only_instance.model_dump(by_alias=True) # create an instance of HasOnlyReadOnly from a dict -has_only_read_only_from_dict = HasOnlyReadOnly.from_dict(has_only_read_only_dict) +has_only_read_only_from_dict = HasOnlyReadOnly.model_validate(has_only_read_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/HealthCheckResult.md b/samples/openapi3/client/petstore/python/docs/HealthCheckResult.md index d4a2b187167f..49c69cf1d84b 100644 --- a/samples/openapi3/client/petstore/python/docs/HealthCheckResult.md +++ b/samples/openapi3/client/petstore/python/docs/HealthCheckResult.md @@ -16,14 +16,14 @@ from petstore_api.models.health_check_result import HealthCheckResult # TODO update the JSON string below json = "{}" # create an instance of HealthCheckResult from a JSON string -health_check_result_instance = HealthCheckResult.from_json(json) +health_check_result_instance = HealthCheckResult.model_validate_json(json) # print the JSON string representation of the object -print(HealthCheckResult.to_json()) +print(HealthCheckResult.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -health_check_result_dict = health_check_result_instance.to_dict() +health_check_result_dict = health_check_result_instance.model_dump(by_alias=True) # create an instance of HealthCheckResult from a dict -health_check_result_from_dict = HealthCheckResult.from_dict(health_check_result_dict) +health_check_result_from_dict = HealthCheckResult.model_validate(health_check_result_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/HuntingDog.md b/samples/openapi3/client/petstore/python/docs/HuntingDog.md index 6db6745dd022..a3a905d84550 100644 --- a/samples/openapi3/client/petstore/python/docs/HuntingDog.md +++ b/samples/openapi3/client/petstore/python/docs/HuntingDog.md @@ -15,14 +15,14 @@ from petstore_api.models.hunting_dog import HuntingDog # TODO update the JSON string below json = "{}" # create an instance of HuntingDog from a JSON string -hunting_dog_instance = HuntingDog.from_json(json) +hunting_dog_instance = HuntingDog.model_validate_json(json) # print the JSON string representation of the object -print(HuntingDog.to_json()) +print(HuntingDog.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -hunting_dog_dict = hunting_dog_instance.to_dict() +hunting_dog_dict = hunting_dog_instance.model_dump(by_alias=True) # create an instance of HuntingDog from a dict -hunting_dog_from_dict = HuntingDog.from_dict(hunting_dog_dict) +hunting_dog_from_dict = HuntingDog.model_validate(hunting_dog_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Info.md b/samples/openapi3/client/petstore/python/docs/Info.md index db88778a9143..753e1d770730 100644 --- a/samples/openapi3/client/petstore/python/docs/Info.md +++ b/samples/openapi3/client/petstore/python/docs/Info.md @@ -15,14 +15,14 @@ from petstore_api.models.info import Info # TODO update the JSON string below json = "{}" # create an instance of Info from a JSON string -info_instance = Info.from_json(json) +info_instance = Info.model_validate_json(json) # print the JSON string representation of the object -print(Info.to_json()) +print(Info.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -info_dict = info_instance.to_dict() +info_dict = info_instance.model_dump(by_alias=True) # create an instance of Info from a dict -info_from_dict = Info.from_dict(info_dict) +info_from_dict = Info.model_validate(info_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/InnerDictWithProperty.md b/samples/openapi3/client/petstore/python/docs/InnerDictWithProperty.md index 7b82ebb770b8..2a922855b34f 100644 --- a/samples/openapi3/client/petstore/python/docs/InnerDictWithProperty.md +++ b/samples/openapi3/client/petstore/python/docs/InnerDictWithProperty.md @@ -15,14 +15,14 @@ from petstore_api.models.inner_dict_with_property import InnerDictWithProperty # TODO update the JSON string below json = "{}" # create an instance of InnerDictWithProperty from a JSON string -inner_dict_with_property_instance = InnerDictWithProperty.from_json(json) +inner_dict_with_property_instance = InnerDictWithProperty.model_validate_json(json) # print the JSON string representation of the object -print(InnerDictWithProperty.to_json()) +print(InnerDictWithProperty.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -inner_dict_with_property_dict = inner_dict_with_property_instance.to_dict() +inner_dict_with_property_dict = inner_dict_with_property_instance.model_dump(by_alias=True) # create an instance of InnerDictWithProperty from a dict -inner_dict_with_property_from_dict = InnerDictWithProperty.from_dict(inner_dict_with_property_dict) +inner_dict_with_property_from_dict = InnerDictWithProperty.model_validate(inner_dict_with_property_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/InputAllOf.md b/samples/openapi3/client/petstore/python/docs/InputAllOf.md index 45298f5308fc..ee77a141784a 100644 --- a/samples/openapi3/client/petstore/python/docs/InputAllOf.md +++ b/samples/openapi3/client/petstore/python/docs/InputAllOf.md @@ -15,14 +15,14 @@ from petstore_api.models.input_all_of import InputAllOf # TODO update the JSON string below json = "{}" # create an instance of InputAllOf from a JSON string -input_all_of_instance = InputAllOf.from_json(json) +input_all_of_instance = InputAllOf.model_validate_json(json) # print the JSON string representation of the object -print(InputAllOf.to_json()) +print(InputAllOf.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -input_all_of_dict = input_all_of_instance.to_dict() +input_all_of_dict = input_all_of_instance.model_dump(by_alias=True) # create an instance of InputAllOf from a dict -input_all_of_from_dict = InputAllOf.from_dict(input_all_of_dict) +input_all_of_from_dict = InputAllOf.model_validate(input_all_of_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/IntOrString.md b/samples/openapi3/client/petstore/python/docs/IntOrString.md index b4070b9a8c79..6274e6fbc696 100644 --- a/samples/openapi3/client/petstore/python/docs/IntOrString.md +++ b/samples/openapi3/client/petstore/python/docs/IntOrString.md @@ -14,14 +14,14 @@ from petstore_api.models.int_or_string import IntOrString # TODO update the JSON string below json = "{}" # create an instance of IntOrString from a JSON string -int_or_string_instance = IntOrString.from_json(json) +int_or_string_instance = IntOrString.model_validate_json(json) # print the JSON string representation of the object -print(IntOrString.to_json()) +print(IntOrString.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -int_or_string_dict = int_or_string_instance.to_dict() +int_or_string_dict = int_or_string_instance.model_dump(by_alias=True) # create an instance of IntOrString from a dict -int_or_string_from_dict = IntOrString.from_dict(int_or_string_dict) +int_or_string_from_dict = IntOrString.model_validate(int_or_string_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/ListClass.md b/samples/openapi3/client/petstore/python/docs/ListClass.md index 01068b7d22c3..00e12b663833 100644 --- a/samples/openapi3/client/petstore/python/docs/ListClass.md +++ b/samples/openapi3/client/petstore/python/docs/ListClass.md @@ -15,14 +15,14 @@ from petstore_api.models.list_class import ListClass # TODO update the JSON string below json = "{}" # create an instance of ListClass from a JSON string -list_class_instance = ListClass.from_json(json) +list_class_instance = ListClass.model_validate_json(json) # print the JSON string representation of the object -print(ListClass.to_json()) +print(ListClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -list_class_dict = list_class_instance.to_dict() +list_class_dict = list_class_instance.model_dump(by_alias=True) # create an instance of ListClass from a dict -list_class_from_dict = ListClass.from_dict(list_class_dict) +list_class_from_dict = ListClass.model_validate(list_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/MapOfArrayOfModel.md b/samples/openapi3/client/petstore/python/docs/MapOfArrayOfModel.md index 71a4ef66b682..dbfba20ac23b 100644 --- a/samples/openapi3/client/petstore/python/docs/MapOfArrayOfModel.md +++ b/samples/openapi3/client/petstore/python/docs/MapOfArrayOfModel.md @@ -15,14 +15,14 @@ from petstore_api.models.map_of_array_of_model import MapOfArrayOfModel # TODO update the JSON string below json = "{}" # create an instance of MapOfArrayOfModel from a JSON string -map_of_array_of_model_instance = MapOfArrayOfModel.from_json(json) +map_of_array_of_model_instance = MapOfArrayOfModel.model_validate_json(json) # print the JSON string representation of the object -print(MapOfArrayOfModel.to_json()) +print(MapOfArrayOfModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -map_of_array_of_model_dict = map_of_array_of_model_instance.to_dict() +map_of_array_of_model_dict = map_of_array_of_model_instance.model_dump(by_alias=True) # create an instance of MapOfArrayOfModel from a dict -map_of_array_of_model_from_dict = MapOfArrayOfModel.from_dict(map_of_array_of_model_dict) +map_of_array_of_model_from_dict = MapOfArrayOfModel.model_validate(map_of_array_of_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/MapTest.md b/samples/openapi3/client/petstore/python/docs/MapTest.md index d04b82e9378c..61382a4e3cd8 100644 --- a/samples/openapi3/client/petstore/python/docs/MapTest.md +++ b/samples/openapi3/client/petstore/python/docs/MapTest.md @@ -18,14 +18,14 @@ from petstore_api.models.map_test import MapTest # TODO update the JSON string below json = "{}" # create an instance of MapTest from a JSON string -map_test_instance = MapTest.from_json(json) +map_test_instance = MapTest.model_validate_json(json) # print the JSON string representation of the object -print(MapTest.to_json()) +print(MapTest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -map_test_dict = map_test_instance.to_dict() +map_test_dict = map_test_instance.model_dump(by_alias=True) # create an instance of MapTest from a dict -map_test_from_dict = MapTest.from_dict(map_test_dict) +map_test_from_dict = MapTest.model_validate(map_test_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/openapi3/client/petstore/python/docs/MixedPropertiesAndAdditionalPropertiesClass.md index 84134317aefc..41ef9465d498 100644 --- a/samples/openapi3/client/petstore/python/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/openapi3/client/petstore/python/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -17,14 +17,14 @@ from petstore_api.models.mixed_properties_and_additional_properties_class import # TODO update the JSON string below json = "{}" # create an instance of MixedPropertiesAndAdditionalPropertiesClass from a JSON string -mixed_properties_and_additional_properties_class_instance = MixedPropertiesAndAdditionalPropertiesClass.from_json(json) +mixed_properties_and_additional_properties_class_instance = MixedPropertiesAndAdditionalPropertiesClass.model_validate_json(json) # print the JSON string representation of the object -print(MixedPropertiesAndAdditionalPropertiesClass.to_json()) +print(MixedPropertiesAndAdditionalPropertiesClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -mixed_properties_and_additional_properties_class_dict = mixed_properties_and_additional_properties_class_instance.to_dict() +mixed_properties_and_additional_properties_class_dict = mixed_properties_and_additional_properties_class_instance.model_dump(by_alias=True) # create an instance of MixedPropertiesAndAdditionalPropertiesClass from a dict -mixed_properties_and_additional_properties_class_from_dict = MixedPropertiesAndAdditionalPropertiesClass.from_dict(mixed_properties_and_additional_properties_class_dict) +mixed_properties_and_additional_properties_class_from_dict = MixedPropertiesAndAdditionalPropertiesClass.model_validate(mixed_properties_and_additional_properties_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Model200Response.md b/samples/openapi3/client/petstore/python/docs/Model200Response.md index 7fdbdefc6cec..56b765c788de 100644 --- a/samples/openapi3/client/petstore/python/docs/Model200Response.md +++ b/samples/openapi3/client/petstore/python/docs/Model200Response.md @@ -17,14 +17,14 @@ from petstore_api.models.model200_response import Model200Response # TODO update the JSON string below json = "{}" # create an instance of Model200Response from a JSON string -model200_response_instance = Model200Response.from_json(json) +model200_response_instance = Model200Response.model_validate_json(json) # print the JSON string representation of the object -print(Model200Response.to_json()) +print(Model200Response.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model200_response_dict = model200_response_instance.to_dict() +model200_response_dict = model200_response_instance.model_dump(by_alias=True) # create an instance of Model200Response from a dict -model200_response_from_dict = Model200Response.from_dict(model200_response_dict) +model200_response_from_dict = Model200Response.model_validate(model200_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/ModelApiResponse.md b/samples/openapi3/client/petstore/python/docs/ModelApiResponse.md index 5ddc0db2a0f3..1fe361910ecb 100644 --- a/samples/openapi3/client/petstore/python/docs/ModelApiResponse.md +++ b/samples/openapi3/client/petstore/python/docs/ModelApiResponse.md @@ -17,14 +17,14 @@ from petstore_api.models.model_api_response import ModelApiResponse # TODO update the JSON string below json = "{}" # create an instance of ModelApiResponse from a JSON string -model_api_response_instance = ModelApiResponse.from_json(json) +model_api_response_instance = ModelApiResponse.model_validate_json(json) # print the JSON string representation of the object -print(ModelApiResponse.to_json()) +print(ModelApiResponse.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model_api_response_dict = model_api_response_instance.to_dict() +model_api_response_dict = model_api_response_instance.model_dump(by_alias=True) # create an instance of ModelApiResponse from a dict -model_api_response_from_dict = ModelApiResponse.from_dict(model_api_response_dict) +model_api_response_from_dict = ModelApiResponse.model_validate(model_api_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/ModelField.md b/samples/openapi3/client/petstore/python/docs/ModelField.md index 9073b5dbdb00..8fa1be583ae3 100644 --- a/samples/openapi3/client/petstore/python/docs/ModelField.md +++ b/samples/openapi3/client/petstore/python/docs/ModelField.md @@ -15,14 +15,14 @@ from petstore_api.models.model_field import ModelField # TODO update the JSON string below json = "{}" # create an instance of ModelField from a JSON string -model_field_instance = ModelField.from_json(json) +model_field_instance = ModelField.model_validate_json(json) # print the JSON string representation of the object -print(ModelField.to_json()) +print(ModelField.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model_field_dict = model_field_instance.to_dict() +model_field_dict = model_field_instance.model_dump(by_alias=True) # create an instance of ModelField from a dict -model_field_from_dict = ModelField.from_dict(model_field_dict) +model_field_from_dict = ModelField.model_validate(model_field_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/ModelReturn.md b/samples/openapi3/client/petstore/python/docs/ModelReturn.md index 7d327053b0c3..fbda0142410b 100644 --- a/samples/openapi3/client/petstore/python/docs/ModelReturn.md +++ b/samples/openapi3/client/petstore/python/docs/ModelReturn.md @@ -16,14 +16,14 @@ from petstore_api.models.model_return import ModelReturn # TODO update the JSON string below json = "{}" # create an instance of ModelReturn from a JSON string -model_return_instance = ModelReturn.from_json(json) +model_return_instance = ModelReturn.model_validate_json(json) # print the JSON string representation of the object -print(ModelReturn.to_json()) +print(ModelReturn.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -model_return_dict = model_return_instance.to_dict() +model_return_dict = model_return_instance.model_dump(by_alias=True) # create an instance of ModelReturn from a dict -model_return_from_dict = ModelReturn.from_dict(model_return_dict) +model_return_from_dict = ModelReturn.model_validate(model_return_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/MultiArrays.md b/samples/openapi3/client/petstore/python/docs/MultiArrays.md index fea5139e7e73..5feb5eb83587 100644 --- a/samples/openapi3/client/petstore/python/docs/MultiArrays.md +++ b/samples/openapi3/client/petstore/python/docs/MultiArrays.md @@ -16,14 +16,14 @@ from petstore_api.models.multi_arrays import MultiArrays # TODO update the JSON string below json = "{}" # create an instance of MultiArrays from a JSON string -multi_arrays_instance = MultiArrays.from_json(json) +multi_arrays_instance = MultiArrays.model_validate_json(json) # print the JSON string representation of the object -print(MultiArrays.to_json()) +print(MultiArrays.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -multi_arrays_dict = multi_arrays_instance.to_dict() +multi_arrays_dict = multi_arrays_instance.model_dump(by_alias=True) # create an instance of MultiArrays from a dict -multi_arrays_from_dict = MultiArrays.from_dict(multi_arrays_dict) +multi_arrays_from_dict = MultiArrays.model_validate(multi_arrays_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Name.md b/samples/openapi3/client/petstore/python/docs/Name.md index 5a04ec1ada06..fe30c2a76d97 100644 --- a/samples/openapi3/client/petstore/python/docs/Name.md +++ b/samples/openapi3/client/petstore/python/docs/Name.md @@ -19,14 +19,14 @@ from petstore_api.models.name import Name # TODO update the JSON string below json = "{}" # create an instance of Name from a JSON string -name_instance = Name.from_json(json) +name_instance = Name.model_validate_json(json) # print the JSON string representation of the object -print(Name.to_json()) +print(Name.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -name_dict = name_instance.to_dict() +name_dict = name_instance.model_dump(by_alias=True) # create an instance of Name from a dict -name_from_dict = Name.from_dict(name_dict) +name_from_dict = Name.model_validate(name_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/NullableClass.md b/samples/openapi3/client/petstore/python/docs/NullableClass.md index 0387dcc2c67a..fafc21b70778 100644 --- a/samples/openapi3/client/petstore/python/docs/NullableClass.md +++ b/samples/openapi3/client/petstore/python/docs/NullableClass.md @@ -27,14 +27,14 @@ from petstore_api.models.nullable_class import NullableClass # TODO update the JSON string below json = "{}" # create an instance of NullableClass from a JSON string -nullable_class_instance = NullableClass.from_json(json) +nullable_class_instance = NullableClass.model_validate_json(json) # print the JSON string representation of the object -print(NullableClass.to_json()) +print(NullableClass.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -nullable_class_dict = nullable_class_instance.to_dict() +nullable_class_dict = nullable_class_instance.model_dump(by_alias=True) # create an instance of NullableClass from a dict -nullable_class_from_dict = NullableClass.from_dict(nullable_class_dict) +nullable_class_from_dict = NullableClass.model_validate(nullable_class_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/NullableProperty.md b/samples/openapi3/client/petstore/python/docs/NullableProperty.md index 30edaf4844b2..1738420f6e1c 100644 --- a/samples/openapi3/client/petstore/python/docs/NullableProperty.md +++ b/samples/openapi3/client/petstore/python/docs/NullableProperty.md @@ -16,14 +16,14 @@ from petstore_api.models.nullable_property import NullableProperty # TODO update the JSON string below json = "{}" # create an instance of NullableProperty from a JSON string -nullable_property_instance = NullableProperty.from_json(json) +nullable_property_instance = NullableProperty.model_validate_json(json) # print the JSON string representation of the object -print(NullableProperty.to_json()) +print(NullableProperty.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -nullable_property_dict = nullable_property_instance.to_dict() +nullable_property_dict = nullable_property_instance.model_dump(by_alias=True) # create an instance of NullableProperty from a dict -nullable_property_from_dict = NullableProperty.from_dict(nullable_property_dict) +nullable_property_from_dict = NullableProperty.model_validate(nullable_property_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/NumberOnly.md b/samples/openapi3/client/petstore/python/docs/NumberOnly.md index 415dd25585d4..739426b7c295 100644 --- a/samples/openapi3/client/petstore/python/docs/NumberOnly.md +++ b/samples/openapi3/client/petstore/python/docs/NumberOnly.md @@ -15,14 +15,14 @@ from petstore_api.models.number_only import NumberOnly # TODO update the JSON string below json = "{}" # create an instance of NumberOnly from a JSON string -number_only_instance = NumberOnly.from_json(json) +number_only_instance = NumberOnly.model_validate_json(json) # print the JSON string representation of the object -print(NumberOnly.to_json()) +print(NumberOnly.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -number_only_dict = number_only_instance.to_dict() +number_only_dict = number_only_instance.model_dump(by_alias=True) # create an instance of NumberOnly from a dict -number_only_from_dict = NumberOnly.from_dict(number_only_dict) +number_only_from_dict = NumberOnly.model_validate(number_only_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/ObjectToTestAdditionalProperties.md b/samples/openapi3/client/petstore/python/docs/ObjectToTestAdditionalProperties.md index f6bc34c98e65..eec52f82c2ca 100644 --- a/samples/openapi3/client/petstore/python/docs/ObjectToTestAdditionalProperties.md +++ b/samples/openapi3/client/petstore/python/docs/ObjectToTestAdditionalProperties.md @@ -16,14 +16,14 @@ from petstore_api.models.object_to_test_additional_properties import ObjectToTes # TODO update the JSON string below json = "{}" # create an instance of ObjectToTestAdditionalProperties from a JSON string -object_to_test_additional_properties_instance = ObjectToTestAdditionalProperties.from_json(json) +object_to_test_additional_properties_instance = ObjectToTestAdditionalProperties.model_validate_json(json) # print the JSON string representation of the object -print(ObjectToTestAdditionalProperties.to_json()) +print(ObjectToTestAdditionalProperties.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -object_to_test_additional_properties_dict = object_to_test_additional_properties_instance.to_dict() +object_to_test_additional_properties_dict = object_to_test_additional_properties_instance.model_dump(by_alias=True) # create an instance of ObjectToTestAdditionalProperties from a dict -object_to_test_additional_properties_from_dict = ObjectToTestAdditionalProperties.from_dict(object_to_test_additional_properties_dict) +object_to_test_additional_properties_from_dict = ObjectToTestAdditionalProperties.model_validate(object_to_test_additional_properties_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/ObjectWithDeprecatedFields.md b/samples/openapi3/client/petstore/python/docs/ObjectWithDeprecatedFields.md index 6dbd2ace04f1..6329b1899970 100644 --- a/samples/openapi3/client/petstore/python/docs/ObjectWithDeprecatedFields.md +++ b/samples/openapi3/client/petstore/python/docs/ObjectWithDeprecatedFields.md @@ -18,14 +18,14 @@ from petstore_api.models.object_with_deprecated_fields import ObjectWithDeprecat # TODO update the JSON string below json = "{}" # create an instance of ObjectWithDeprecatedFields from a JSON string -object_with_deprecated_fields_instance = ObjectWithDeprecatedFields.from_json(json) +object_with_deprecated_fields_instance = ObjectWithDeprecatedFields.model_validate_json(json) # print the JSON string representation of the object -print(ObjectWithDeprecatedFields.to_json()) +print(ObjectWithDeprecatedFields.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -object_with_deprecated_fields_dict = object_with_deprecated_fields_instance.to_dict() +object_with_deprecated_fields_dict = object_with_deprecated_fields_instance.model_dump(by_alias=True) # create an instance of ObjectWithDeprecatedFields from a dict -object_with_deprecated_fields_from_dict = ObjectWithDeprecatedFields.from_dict(object_with_deprecated_fields_dict) +object_with_deprecated_fields_from_dict = ObjectWithDeprecatedFields.model_validate(object_with_deprecated_fields_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/OneOfEnumString.md b/samples/openapi3/client/petstore/python/docs/OneOfEnumString.md index 1d385c092934..e435ccb90c73 100644 --- a/samples/openapi3/client/petstore/python/docs/OneOfEnumString.md +++ b/samples/openapi3/client/petstore/python/docs/OneOfEnumString.md @@ -15,14 +15,14 @@ from petstore_api.models.one_of_enum_string import OneOfEnumString # TODO update the JSON string below json = "{}" # create an instance of OneOfEnumString from a JSON string -one_of_enum_string_instance = OneOfEnumString.from_json(json) +one_of_enum_string_instance = OneOfEnumString.model_validate_json(json) # print the JSON string representation of the object -print(OneOfEnumString.to_json()) +print(OneOfEnumString.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -one_of_enum_string_dict = one_of_enum_string_instance.to_dict() +one_of_enum_string_dict = one_of_enum_string_instance.model_dump(by_alias=True) # create an instance of OneOfEnumString from a dict -one_of_enum_string_from_dict = OneOfEnumString.from_dict(one_of_enum_string_dict) +one_of_enum_string_from_dict = OneOfEnumString.model_validate(one_of_enum_string_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Order.md b/samples/openapi3/client/petstore/python/docs/Order.md index 00526b8d04b9..8d4b8ac2983f 100644 --- a/samples/openapi3/client/petstore/python/docs/Order.md +++ b/samples/openapi3/client/petstore/python/docs/Order.md @@ -20,14 +20,14 @@ from petstore_api.models.order import Order # TODO update the JSON string below json = "{}" # create an instance of Order from a JSON string -order_instance = Order.from_json(json) +order_instance = Order.model_validate_json(json) # print the JSON string representation of the object -print(Order.to_json()) +print(Order.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -order_dict = order_instance.to_dict() +order_dict = order_instance.model_dump(by_alias=True) # create an instance of Order from a dict -order_from_dict = Order.from_dict(order_dict) +order_from_dict = Order.model_validate(order_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/OuterComposite.md b/samples/openapi3/client/petstore/python/docs/OuterComposite.md index c8242c2d2653..bff67df11388 100644 --- a/samples/openapi3/client/petstore/python/docs/OuterComposite.md +++ b/samples/openapi3/client/petstore/python/docs/OuterComposite.md @@ -17,14 +17,14 @@ from petstore_api.models.outer_composite import OuterComposite # TODO update the JSON string below json = "{}" # create an instance of OuterComposite from a JSON string -outer_composite_instance = OuterComposite.from_json(json) +outer_composite_instance = OuterComposite.model_validate_json(json) # print the JSON string representation of the object -print(OuterComposite.to_json()) +print(OuterComposite.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -outer_composite_dict = outer_composite_instance.to_dict() +outer_composite_dict = outer_composite_instance.model_dump(by_alias=True) # create an instance of OuterComposite from a dict -outer_composite_from_dict = OuterComposite.from_dict(outer_composite_dict) +outer_composite_from_dict = OuterComposite.model_validate(outer_composite_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/OuterObjectWithEnumProperty.md b/samples/openapi3/client/petstore/python/docs/OuterObjectWithEnumProperty.md index 6137dbd98da6..39611a8868a7 100644 --- a/samples/openapi3/client/petstore/python/docs/OuterObjectWithEnumProperty.md +++ b/samples/openapi3/client/petstore/python/docs/OuterObjectWithEnumProperty.md @@ -16,14 +16,14 @@ from petstore_api.models.outer_object_with_enum_property import OuterObjectWithE # TODO update the JSON string below json = "{}" # create an instance of OuterObjectWithEnumProperty from a JSON string -outer_object_with_enum_property_instance = OuterObjectWithEnumProperty.from_json(json) +outer_object_with_enum_property_instance = OuterObjectWithEnumProperty.model_validate_json(json) # print the JSON string representation of the object -print(OuterObjectWithEnumProperty.to_json()) +print(OuterObjectWithEnumProperty.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -outer_object_with_enum_property_dict = outer_object_with_enum_property_instance.to_dict() +outer_object_with_enum_property_dict = outer_object_with_enum_property_instance.model_dump(by_alias=True) # create an instance of OuterObjectWithEnumProperty from a dict -outer_object_with_enum_property_from_dict = OuterObjectWithEnumProperty.from_dict(outer_object_with_enum_property_dict) +outer_object_with_enum_property_from_dict = OuterObjectWithEnumProperty.model_validate(outer_object_with_enum_property_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Parent.md b/samples/openapi3/client/petstore/python/docs/Parent.md index 7387f9250aad..700d8446226c 100644 --- a/samples/openapi3/client/petstore/python/docs/Parent.md +++ b/samples/openapi3/client/petstore/python/docs/Parent.md @@ -15,14 +15,14 @@ from petstore_api.models.parent import Parent # TODO update the JSON string below json = "{}" # create an instance of Parent from a JSON string -parent_instance = Parent.from_json(json) +parent_instance = Parent.model_validate_json(json) # print the JSON string representation of the object -print(Parent.to_json()) +print(Parent.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -parent_dict = parent_instance.to_dict() +parent_dict = parent_instance.model_dump(by_alias=True) # create an instance of Parent from a dict -parent_from_dict = Parent.from_dict(parent_dict) +parent_from_dict = Parent.model_validate(parent_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/ParentWithOptionalDict.md b/samples/openapi3/client/petstore/python/docs/ParentWithOptionalDict.md index bfc8688ea26f..7af4744a1016 100644 --- a/samples/openapi3/client/petstore/python/docs/ParentWithOptionalDict.md +++ b/samples/openapi3/client/petstore/python/docs/ParentWithOptionalDict.md @@ -15,14 +15,14 @@ from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict # TODO update the JSON string below json = "{}" # create an instance of ParentWithOptionalDict from a JSON string -parent_with_optional_dict_instance = ParentWithOptionalDict.from_json(json) +parent_with_optional_dict_instance = ParentWithOptionalDict.model_validate_json(json) # print the JSON string representation of the object -print(ParentWithOptionalDict.to_json()) +print(ParentWithOptionalDict.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -parent_with_optional_dict_dict = parent_with_optional_dict_instance.to_dict() +parent_with_optional_dict_dict = parent_with_optional_dict_instance.model_dump(by_alias=True) # create an instance of ParentWithOptionalDict from a dict -parent_with_optional_dict_from_dict = ParentWithOptionalDict.from_dict(parent_with_optional_dict_dict) +parent_with_optional_dict_from_dict = ParentWithOptionalDict.model_validate(parent_with_optional_dict_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Pet.md b/samples/openapi3/client/petstore/python/docs/Pet.md index 5329cf2fb925..e09f1b8b22ff 100644 --- a/samples/openapi3/client/petstore/python/docs/Pet.md +++ b/samples/openapi3/client/petstore/python/docs/Pet.md @@ -20,14 +20,14 @@ from petstore_api.models.pet import Pet # TODO update the JSON string below json = "{}" # create an instance of Pet from a JSON string -pet_instance = Pet.from_json(json) +pet_instance = Pet.model_validate_json(json) # print the JSON string representation of the object -print(Pet.to_json()) +print(Pet.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -pet_dict = pet_instance.to_dict() +pet_dict = pet_instance.model_dump(by_alias=True) # create an instance of Pet from a dict -pet_from_dict = Pet.from_dict(pet_dict) +pet_from_dict = Pet.model_validate(pet_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Pig.md b/samples/openapi3/client/petstore/python/docs/Pig.md index 625930676083..8c9de7a86c8a 100644 --- a/samples/openapi3/client/petstore/python/docs/Pig.md +++ b/samples/openapi3/client/petstore/python/docs/Pig.md @@ -17,14 +17,14 @@ from petstore_api.models.pig import Pig # TODO update the JSON string below json = "{}" # create an instance of Pig from a JSON string -pig_instance = Pig.from_json(json) +pig_instance = Pig.model_validate_json(json) # print the JSON string representation of the object -print(Pig.to_json()) +print(Pig.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -pig_dict = pig_instance.to_dict() +pig_dict = pig_instance.model_dump(by_alias=True) # create an instance of Pig from a dict -pig_from_dict = Pig.from_dict(pig_dict) +pig_from_dict = Pig.model_validate(pig_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/PonySizes.md b/samples/openapi3/client/petstore/python/docs/PonySizes.md index ced44c872060..03af5df5ed23 100644 --- a/samples/openapi3/client/petstore/python/docs/PonySizes.md +++ b/samples/openapi3/client/petstore/python/docs/PonySizes.md @@ -15,14 +15,14 @@ from petstore_api.models.pony_sizes import PonySizes # TODO update the JSON string below json = "{}" # create an instance of PonySizes from a JSON string -pony_sizes_instance = PonySizes.from_json(json) +pony_sizes_instance = PonySizes.model_validate_json(json) # print the JSON string representation of the object -print(PonySizes.to_json()) +print(PonySizes.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -pony_sizes_dict = pony_sizes_instance.to_dict() +pony_sizes_dict = pony_sizes_instance.model_dump(by_alias=True) # create an instance of PonySizes from a dict -pony_sizes_from_dict = PonySizes.from_dict(pony_sizes_dict) +pony_sizes_from_dict = PonySizes.model_validate(pony_sizes_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/PoopCleaning.md b/samples/openapi3/client/petstore/python/docs/PoopCleaning.md index 8f9c25e08316..b58624f40112 100644 --- a/samples/openapi3/client/petstore/python/docs/PoopCleaning.md +++ b/samples/openapi3/client/petstore/python/docs/PoopCleaning.md @@ -17,14 +17,14 @@ from petstore_api.models.poop_cleaning import PoopCleaning # TODO update the JSON string below json = "{}" # create an instance of PoopCleaning from a JSON string -poop_cleaning_instance = PoopCleaning.from_json(json) +poop_cleaning_instance = PoopCleaning.model_validate_json(json) # print the JSON string representation of the object -print(PoopCleaning.to_json()) +print(PoopCleaning.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -poop_cleaning_dict = poop_cleaning_instance.to_dict() +poop_cleaning_dict = poop_cleaning_instance.model_dump(by_alias=True) # create an instance of PoopCleaning from a dict -poop_cleaning_from_dict = PoopCleaning.from_dict(poop_cleaning_dict) +poop_cleaning_from_dict = PoopCleaning.model_validate(poop_cleaning_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/PrimitiveString.md b/samples/openapi3/client/petstore/python/docs/PrimitiveString.md index 85ceb632e167..c2296ead4a1a 100644 --- a/samples/openapi3/client/petstore/python/docs/PrimitiveString.md +++ b/samples/openapi3/client/petstore/python/docs/PrimitiveString.md @@ -15,14 +15,14 @@ from petstore_api.models.primitive_string import PrimitiveString # TODO update the JSON string below json = "{}" # create an instance of PrimitiveString from a JSON string -primitive_string_instance = PrimitiveString.from_json(json) +primitive_string_instance = PrimitiveString.model_validate_json(json) # print the JSON string representation of the object -print(PrimitiveString.to_json()) +print(PrimitiveString.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -primitive_string_dict = primitive_string_instance.to_dict() +primitive_string_dict = primitive_string_instance.model_dump(by_alias=True) # create an instance of PrimitiveString from a dict -primitive_string_from_dict = PrimitiveString.from_dict(primitive_string_dict) +primitive_string_from_dict = PrimitiveString.model_validate(primitive_string_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/PropertyMap.md b/samples/openapi3/client/petstore/python/docs/PropertyMap.md index a55a0e5c6f01..3982b35d5724 100644 --- a/samples/openapi3/client/petstore/python/docs/PropertyMap.md +++ b/samples/openapi3/client/petstore/python/docs/PropertyMap.md @@ -15,14 +15,14 @@ from petstore_api.models.property_map import PropertyMap # TODO update the JSON string below json = "{}" # create an instance of PropertyMap from a JSON string -property_map_instance = PropertyMap.from_json(json) +property_map_instance = PropertyMap.model_validate_json(json) # print the JSON string representation of the object -print(PropertyMap.to_json()) +print(PropertyMap.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -property_map_dict = property_map_instance.to_dict() +property_map_dict = property_map_instance.model_dump(by_alias=True) # create an instance of PropertyMap from a dict -property_map_from_dict = PropertyMap.from_dict(property_map_dict) +property_map_from_dict = PropertyMap.model_validate(property_map_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/PropertyNameCollision.md b/samples/openapi3/client/petstore/python/docs/PropertyNameCollision.md index 40c233670dd0..e98d6ad2aa59 100644 --- a/samples/openapi3/client/petstore/python/docs/PropertyNameCollision.md +++ b/samples/openapi3/client/petstore/python/docs/PropertyNameCollision.md @@ -17,14 +17,14 @@ from petstore_api.models.property_name_collision import PropertyNameCollision # TODO update the JSON string below json = "{}" # create an instance of PropertyNameCollision from a JSON string -property_name_collision_instance = PropertyNameCollision.from_json(json) +property_name_collision_instance = PropertyNameCollision.model_validate_json(json) # print the JSON string representation of the object -print(PropertyNameCollision.to_json()) +print(PropertyNameCollision.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -property_name_collision_dict = property_name_collision_instance.to_dict() +property_name_collision_dict = property_name_collision_instance.model_dump(by_alias=True) # create an instance of PropertyNameCollision from a dict -property_name_collision_from_dict = PropertyNameCollision.from_dict(property_name_collision_dict) +property_name_collision_from_dict = PropertyNameCollision.model_validate(property_name_collision_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/ReadOnlyFirst.md b/samples/openapi3/client/petstore/python/docs/ReadOnlyFirst.md index 686ec5da41c9..51831854b601 100644 --- a/samples/openapi3/client/petstore/python/docs/ReadOnlyFirst.md +++ b/samples/openapi3/client/petstore/python/docs/ReadOnlyFirst.md @@ -16,14 +16,14 @@ from petstore_api.models.read_only_first import ReadOnlyFirst # TODO update the JSON string below json = "{}" # create an instance of ReadOnlyFirst from a JSON string -read_only_first_instance = ReadOnlyFirst.from_json(json) +read_only_first_instance = ReadOnlyFirst.model_validate_json(json) # print the JSON string representation of the object -print(ReadOnlyFirst.to_json()) +print(ReadOnlyFirst.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -read_only_first_dict = read_only_first_instance.to_dict() +read_only_first_dict = read_only_first_instance.model_dump(by_alias=True) # create an instance of ReadOnlyFirst from a dict -read_only_first_from_dict = ReadOnlyFirst.from_dict(read_only_first_dict) +read_only_first_from_dict = ReadOnlyFirst.model_validate(read_only_first_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/SecondCircularAllOfRef.md b/samples/openapi3/client/petstore/python/docs/SecondCircularAllOfRef.md index 65ebdd4c7e1d..173a4eb5fd68 100644 --- a/samples/openapi3/client/petstore/python/docs/SecondCircularAllOfRef.md +++ b/samples/openapi3/client/petstore/python/docs/SecondCircularAllOfRef.md @@ -16,14 +16,14 @@ from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRe # TODO update the JSON string below json = "{}" # create an instance of SecondCircularAllOfRef from a JSON string -second_circular_all_of_ref_instance = SecondCircularAllOfRef.from_json(json) +second_circular_all_of_ref_instance = SecondCircularAllOfRef.model_validate_json(json) # print the JSON string representation of the object -print(SecondCircularAllOfRef.to_json()) +print(SecondCircularAllOfRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -second_circular_all_of_ref_dict = second_circular_all_of_ref_instance.to_dict() +second_circular_all_of_ref_dict = second_circular_all_of_ref_instance.model_dump(by_alias=True) # create an instance of SecondCircularAllOfRef from a dict -second_circular_all_of_ref_from_dict = SecondCircularAllOfRef.from_dict(second_circular_all_of_ref_dict) +second_circular_all_of_ref_from_dict = SecondCircularAllOfRef.model_validate(second_circular_all_of_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/SecondRef.md b/samples/openapi3/client/petstore/python/docs/SecondRef.md index dfb1a0ac6db5..87c1e1d4bb3a 100644 --- a/samples/openapi3/client/petstore/python/docs/SecondRef.md +++ b/samples/openapi3/client/petstore/python/docs/SecondRef.md @@ -16,14 +16,14 @@ from petstore_api.models.second_ref import SecondRef # TODO update the JSON string below json = "{}" # create an instance of SecondRef from a JSON string -second_ref_instance = SecondRef.from_json(json) +second_ref_instance = SecondRef.model_validate_json(json) # print the JSON string representation of the object -print(SecondRef.to_json()) +print(SecondRef.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -second_ref_dict = second_ref_instance.to_dict() +second_ref_dict = second_ref_instance.model_dump(by_alias=True) # create an instance of SecondRef from a dict -second_ref_from_dict = SecondRef.from_dict(second_ref_dict) +second_ref_from_dict = SecondRef.model_validate(second_ref_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/SelfReferenceModel.md b/samples/openapi3/client/petstore/python/docs/SelfReferenceModel.md index 208cdac04b6f..68c6e661ac94 100644 --- a/samples/openapi3/client/petstore/python/docs/SelfReferenceModel.md +++ b/samples/openapi3/client/petstore/python/docs/SelfReferenceModel.md @@ -16,14 +16,14 @@ from petstore_api.models.self_reference_model import SelfReferenceModel # TODO update the JSON string below json = "{}" # create an instance of SelfReferenceModel from a JSON string -self_reference_model_instance = SelfReferenceModel.from_json(json) +self_reference_model_instance = SelfReferenceModel.model_validate_json(json) # print the JSON string representation of the object -print(SelfReferenceModel.to_json()) +print(SelfReferenceModel.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -self_reference_model_dict = self_reference_model_instance.to_dict() +self_reference_model_dict = self_reference_model_instance.model_dump(by_alias=True) # create an instance of SelfReferenceModel from a dict -self_reference_model_from_dict = SelfReferenceModel.from_dict(self_reference_model_dict) +self_reference_model_from_dict = SelfReferenceModel.model_validate(self_reference_model_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/SpecialModelName.md b/samples/openapi3/client/petstore/python/docs/SpecialModelName.md index 35303f34efd2..0e99036d92f4 100644 --- a/samples/openapi3/client/petstore/python/docs/SpecialModelName.md +++ b/samples/openapi3/client/petstore/python/docs/SpecialModelName.md @@ -15,14 +15,14 @@ from petstore_api.models.special_model_name import SpecialModelName # TODO update the JSON string below json = "{}" # create an instance of SpecialModelName from a JSON string -special_model_name_instance = SpecialModelName.from_json(json) +special_model_name_instance = SpecialModelName.model_validate_json(json) # print the JSON string representation of the object -print(SpecialModelName.to_json()) +print(SpecialModelName.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -special_model_name_dict = special_model_name_instance.to_dict() +special_model_name_dict = special_model_name_instance.model_dump(by_alias=True) # create an instance of SpecialModelName from a dict -special_model_name_from_dict = SpecialModelName.from_dict(special_model_name_dict) +special_model_name_from_dict = SpecialModelName.model_validate(special_model_name_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/SpecialName.md b/samples/openapi3/client/petstore/python/docs/SpecialName.md index ccc550b16e33..5d00c8517aaa 100644 --- a/samples/openapi3/client/petstore/python/docs/SpecialName.md +++ b/samples/openapi3/client/petstore/python/docs/SpecialName.md @@ -17,14 +17,14 @@ from petstore_api.models.special_name import SpecialName # TODO update the JSON string below json = "{}" # create an instance of SpecialName from a JSON string -special_name_instance = SpecialName.from_json(json) +special_name_instance = SpecialName.model_validate_json(json) # print the JSON string representation of the object -print(SpecialName.to_json()) +print(SpecialName.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -special_name_dict = special_name_instance.to_dict() +special_name_dict = special_name_instance.model_dump(by_alias=True) # create an instance of SpecialName from a dict -special_name_from_dict = SpecialName.from_dict(special_name_dict) +special_name_from_dict = SpecialName.model_validate(special_name_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Tag.md b/samples/openapi3/client/petstore/python/docs/Tag.md index 4106d9cfe5db..98068caba254 100644 --- a/samples/openapi3/client/petstore/python/docs/Tag.md +++ b/samples/openapi3/client/petstore/python/docs/Tag.md @@ -16,14 +16,14 @@ from petstore_api.models.tag import Tag # TODO update the JSON string below json = "{}" # create an instance of Tag from a JSON string -tag_instance = Tag.from_json(json) +tag_instance = Tag.model_validate_json(json) # print the JSON string representation of the object -print(Tag.to_json()) +print(Tag.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -tag_dict = tag_instance.to_dict() +tag_dict = tag_instance.model_dump(by_alias=True) # create an instance of Tag from a dict -tag_from_dict = Tag.from_dict(tag_dict) +tag_from_dict = Tag.model_validate(tag_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Task.md b/samples/openapi3/client/petstore/python/docs/Task.md index 85fa2776a059..92aed88f998b 100644 --- a/samples/openapi3/client/petstore/python/docs/Task.md +++ b/samples/openapi3/client/petstore/python/docs/Task.md @@ -17,14 +17,14 @@ from petstore_api.models.task import Task # TODO update the JSON string below json = "{}" # create an instance of Task from a JSON string -task_instance = Task.from_json(json) +task_instance = Task.model_validate_json(json) # print the JSON string representation of the object -print(Task.to_json()) +print(Task.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -task_dict = task_instance.to_dict() +task_dict = task_instance.model_dump(by_alias=True) # create an instance of Task from a dict -task_from_dict = Task.from_dict(task_dict) +task_from_dict = Task.model_validate(task_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/TaskActivity.md b/samples/openapi3/client/petstore/python/docs/TaskActivity.md index e905a477292d..3f8e10cf7ae5 100644 --- a/samples/openapi3/client/petstore/python/docs/TaskActivity.md +++ b/samples/openapi3/client/petstore/python/docs/TaskActivity.md @@ -17,14 +17,14 @@ from petstore_api.models.task_activity import TaskActivity # TODO update the JSON string below json = "{}" # create an instance of TaskActivity from a JSON string -task_activity_instance = TaskActivity.from_json(json) +task_activity_instance = TaskActivity.model_validate_json(json) # print the JSON string representation of the object -print(TaskActivity.to_json()) +print(TaskActivity.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -task_activity_dict = task_activity_instance.to_dict() +task_activity_dict = task_activity_instance.model_dump(by_alias=True) # create an instance of TaskActivity from a dict -task_activity_from_dict = TaskActivity.from_dict(task_activity_dict) +task_activity_from_dict = TaskActivity.model_validate(task_activity_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/TestErrorResponsesWithModel400Response.md b/samples/openapi3/client/petstore/python/docs/TestErrorResponsesWithModel400Response.md index be416bbad0f7..ba20c0666f90 100644 --- a/samples/openapi3/client/petstore/python/docs/TestErrorResponsesWithModel400Response.md +++ b/samples/openapi3/client/petstore/python/docs/TestErrorResponsesWithModel400Response.md @@ -15,14 +15,14 @@ from petstore_api.models.test_error_responses_with_model400_response import Test # TODO update the JSON string below json = "{}" # create an instance of TestErrorResponsesWithModel400Response from a JSON string -test_error_responses_with_model400_response_instance = TestErrorResponsesWithModel400Response.from_json(json) +test_error_responses_with_model400_response_instance = TestErrorResponsesWithModel400Response.model_validate_json(json) # print the JSON string representation of the object -print(TestErrorResponsesWithModel400Response.to_json()) +print(TestErrorResponsesWithModel400Response.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_error_responses_with_model400_response_dict = test_error_responses_with_model400_response_instance.to_dict() +test_error_responses_with_model400_response_dict = test_error_responses_with_model400_response_instance.model_dump(by_alias=True) # create an instance of TestErrorResponsesWithModel400Response from a dict -test_error_responses_with_model400_response_from_dict = TestErrorResponsesWithModel400Response.from_dict(test_error_responses_with_model400_response_dict) +test_error_responses_with_model400_response_from_dict = TestErrorResponsesWithModel400Response.model_validate(test_error_responses_with_model400_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/TestErrorResponsesWithModel404Response.md b/samples/openapi3/client/petstore/python/docs/TestErrorResponsesWithModel404Response.md index 1c984f847bf1..d229d30e7b39 100644 --- a/samples/openapi3/client/petstore/python/docs/TestErrorResponsesWithModel404Response.md +++ b/samples/openapi3/client/petstore/python/docs/TestErrorResponsesWithModel404Response.md @@ -15,14 +15,14 @@ from petstore_api.models.test_error_responses_with_model404_response import Test # TODO update the JSON string below json = "{}" # create an instance of TestErrorResponsesWithModel404Response from a JSON string -test_error_responses_with_model404_response_instance = TestErrorResponsesWithModel404Response.from_json(json) +test_error_responses_with_model404_response_instance = TestErrorResponsesWithModel404Response.model_validate_json(json) # print the JSON string representation of the object -print(TestErrorResponsesWithModel404Response.to_json()) +print(TestErrorResponsesWithModel404Response.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_error_responses_with_model404_response_dict = test_error_responses_with_model404_response_instance.to_dict() +test_error_responses_with_model404_response_dict = test_error_responses_with_model404_response_instance.model_dump(by_alias=True) # create an instance of TestErrorResponsesWithModel404Response from a dict -test_error_responses_with_model404_response_from_dict = TestErrorResponsesWithModel404Response.from_dict(test_error_responses_with_model404_response_dict) +test_error_responses_with_model404_response_from_dict = TestErrorResponsesWithModel404Response.model_validate(test_error_responses_with_model404_response_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/TestInlineFreeformAdditionalPropertiesRequest.md b/samples/openapi3/client/petstore/python/docs/TestInlineFreeformAdditionalPropertiesRequest.md index 511132d689be..6fd235e60800 100644 --- a/samples/openapi3/client/petstore/python/docs/TestInlineFreeformAdditionalPropertiesRequest.md +++ b/samples/openapi3/client/petstore/python/docs/TestInlineFreeformAdditionalPropertiesRequest.md @@ -15,14 +15,14 @@ from petstore_api.models.test_inline_freeform_additional_properties_request impo # TODO update the JSON string below json = "{}" # create an instance of TestInlineFreeformAdditionalPropertiesRequest from a JSON string -test_inline_freeform_additional_properties_request_instance = TestInlineFreeformAdditionalPropertiesRequest.from_json(json) +test_inline_freeform_additional_properties_request_instance = TestInlineFreeformAdditionalPropertiesRequest.model_validate_json(json) # print the JSON string representation of the object -print(TestInlineFreeformAdditionalPropertiesRequest.to_json()) +print(TestInlineFreeformAdditionalPropertiesRequest.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_inline_freeform_additional_properties_request_dict = test_inline_freeform_additional_properties_request_instance.to_dict() +test_inline_freeform_additional_properties_request_dict = test_inline_freeform_additional_properties_request_instance.model_dump(by_alias=True) # create an instance of TestInlineFreeformAdditionalPropertiesRequest from a dict -test_inline_freeform_additional_properties_request_from_dict = TestInlineFreeformAdditionalPropertiesRequest.from_dict(test_inline_freeform_additional_properties_request_dict) +test_inline_freeform_additional_properties_request_from_dict = TestInlineFreeformAdditionalPropertiesRequest.model_validate(test_inline_freeform_additional_properties_request_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/TestModelWithEnumDefault.md b/samples/openapi3/client/petstore/python/docs/TestModelWithEnumDefault.md index 7d46e86deba4..d98d6ad35cb3 100644 --- a/samples/openapi3/client/petstore/python/docs/TestModelWithEnumDefault.md +++ b/samples/openapi3/client/petstore/python/docs/TestModelWithEnumDefault.md @@ -19,14 +19,14 @@ from petstore_api.models.test_model_with_enum_default import TestModelWithEnumDe # TODO update the JSON string below json = "{}" # create an instance of TestModelWithEnumDefault from a JSON string -test_model_with_enum_default_instance = TestModelWithEnumDefault.from_json(json) +test_model_with_enum_default_instance = TestModelWithEnumDefault.model_validate_json(json) # print the JSON string representation of the object -print(TestModelWithEnumDefault.to_json()) +print(TestModelWithEnumDefault.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_model_with_enum_default_dict = test_model_with_enum_default_instance.to_dict() +test_model_with_enum_default_dict = test_model_with_enum_default_instance.model_dump(by_alias=True) # create an instance of TestModelWithEnumDefault from a dict -test_model_with_enum_default_from_dict = TestModelWithEnumDefault.from_dict(test_model_with_enum_default_dict) +test_model_with_enum_default_from_dict = TestModelWithEnumDefault.model_validate(test_model_with_enum_default_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/TestObjectForMultipartRequestsRequestMarker.md b/samples/openapi3/client/petstore/python/docs/TestObjectForMultipartRequestsRequestMarker.md index ff0ca9ee00ac..4ef346d455be 100644 --- a/samples/openapi3/client/petstore/python/docs/TestObjectForMultipartRequestsRequestMarker.md +++ b/samples/openapi3/client/petstore/python/docs/TestObjectForMultipartRequestsRequestMarker.md @@ -15,14 +15,14 @@ from petstore_api.models.test_object_for_multipart_requests_request_marker impor # TODO update the JSON string below json = "{}" # create an instance of TestObjectForMultipartRequestsRequestMarker from a JSON string -test_object_for_multipart_requests_request_marker_instance = TestObjectForMultipartRequestsRequestMarker.from_json(json) +test_object_for_multipart_requests_request_marker_instance = TestObjectForMultipartRequestsRequestMarker.model_validate_json(json) # print the JSON string representation of the object -print(TestObjectForMultipartRequestsRequestMarker.to_json()) +print(TestObjectForMultipartRequestsRequestMarker.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -test_object_for_multipart_requests_request_marker_dict = test_object_for_multipart_requests_request_marker_instance.to_dict() +test_object_for_multipart_requests_request_marker_dict = test_object_for_multipart_requests_request_marker_instance.model_dump(by_alias=True) # create an instance of TestObjectForMultipartRequestsRequestMarker from a dict -test_object_for_multipart_requests_request_marker_from_dict = TestObjectForMultipartRequestsRequestMarker.from_dict(test_object_for_multipart_requests_request_marker_dict) +test_object_for_multipart_requests_request_marker_from_dict = TestObjectForMultipartRequestsRequestMarker.model_validate(test_object_for_multipart_requests_request_marker_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Tiger.md b/samples/openapi3/client/petstore/python/docs/Tiger.md index f1cf2133f0f7..bf096ee0be68 100644 --- a/samples/openapi3/client/petstore/python/docs/Tiger.md +++ b/samples/openapi3/client/petstore/python/docs/Tiger.md @@ -15,14 +15,14 @@ from petstore_api.models.tiger import Tiger # TODO update the JSON string below json = "{}" # create an instance of Tiger from a JSON string -tiger_instance = Tiger.from_json(json) +tiger_instance = Tiger.model_validate_json(json) # print the JSON string representation of the object -print(Tiger.to_json()) +print(Tiger.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -tiger_dict = tiger_instance.to_dict() +tiger_dict = tiger_instance.model_dump(by_alias=True) # create an instance of Tiger from a dict -tiger_from_dict = Tiger.from_dict(tiger_dict) +tiger_from_dict = Tiger.model_validate(tiger_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/UnnamedDictWithAdditionalModelListProperties.md b/samples/openapi3/client/petstore/python/docs/UnnamedDictWithAdditionalModelListProperties.md index 68cd00ab0a7a..a8d992c4e033 100644 --- a/samples/openapi3/client/petstore/python/docs/UnnamedDictWithAdditionalModelListProperties.md +++ b/samples/openapi3/client/petstore/python/docs/UnnamedDictWithAdditionalModelListProperties.md @@ -15,14 +15,14 @@ from petstore_api.models.unnamed_dict_with_additional_model_list_properties impo # TODO update the JSON string below json = "{}" # create an instance of UnnamedDictWithAdditionalModelListProperties from a JSON string -unnamed_dict_with_additional_model_list_properties_instance = UnnamedDictWithAdditionalModelListProperties.from_json(json) +unnamed_dict_with_additional_model_list_properties_instance = UnnamedDictWithAdditionalModelListProperties.model_validate_json(json) # print the JSON string representation of the object -print(UnnamedDictWithAdditionalModelListProperties.to_json()) +print(UnnamedDictWithAdditionalModelListProperties.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -unnamed_dict_with_additional_model_list_properties_dict = unnamed_dict_with_additional_model_list_properties_instance.to_dict() +unnamed_dict_with_additional_model_list_properties_dict = unnamed_dict_with_additional_model_list_properties_instance.model_dump(by_alias=True) # create an instance of UnnamedDictWithAdditionalModelListProperties from a dict -unnamed_dict_with_additional_model_list_properties_from_dict = UnnamedDictWithAdditionalModelListProperties.from_dict(unnamed_dict_with_additional_model_list_properties_dict) +unnamed_dict_with_additional_model_list_properties_from_dict = UnnamedDictWithAdditionalModelListProperties.model_validate(unnamed_dict_with_additional_model_list_properties_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/UnnamedDictWithAdditionalStringListProperties.md b/samples/openapi3/client/petstore/python/docs/UnnamedDictWithAdditionalStringListProperties.md index 045b0e22ad09..44aa893d69a7 100644 --- a/samples/openapi3/client/petstore/python/docs/UnnamedDictWithAdditionalStringListProperties.md +++ b/samples/openapi3/client/petstore/python/docs/UnnamedDictWithAdditionalStringListProperties.md @@ -15,14 +15,14 @@ from petstore_api.models.unnamed_dict_with_additional_string_list_properties imp # TODO update the JSON string below json = "{}" # create an instance of UnnamedDictWithAdditionalStringListProperties from a JSON string -unnamed_dict_with_additional_string_list_properties_instance = UnnamedDictWithAdditionalStringListProperties.from_json(json) +unnamed_dict_with_additional_string_list_properties_instance = UnnamedDictWithAdditionalStringListProperties.model_validate_json(json) # print the JSON string representation of the object -print(UnnamedDictWithAdditionalStringListProperties.to_json()) +print(UnnamedDictWithAdditionalStringListProperties.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -unnamed_dict_with_additional_string_list_properties_dict = unnamed_dict_with_additional_string_list_properties_instance.to_dict() +unnamed_dict_with_additional_string_list_properties_dict = unnamed_dict_with_additional_string_list_properties_instance.model_dump(by_alias=True) # create an instance of UnnamedDictWithAdditionalStringListProperties from a dict -unnamed_dict_with_additional_string_list_properties_from_dict = UnnamedDictWithAdditionalStringListProperties.from_dict(unnamed_dict_with_additional_string_list_properties_dict) +unnamed_dict_with_additional_string_list_properties_from_dict = UnnamedDictWithAdditionalStringListProperties.model_validate(unnamed_dict_with_additional_string_list_properties_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/UploadFileWithAdditionalPropertiesRequestObject.md b/samples/openapi3/client/petstore/python/docs/UploadFileWithAdditionalPropertiesRequestObject.md index 141027780371..096740ca96c2 100644 --- a/samples/openapi3/client/petstore/python/docs/UploadFileWithAdditionalPropertiesRequestObject.md +++ b/samples/openapi3/client/petstore/python/docs/UploadFileWithAdditionalPropertiesRequestObject.md @@ -16,14 +16,14 @@ from petstore_api.models.upload_file_with_additional_properties_request_object i # TODO update the JSON string below json = "{}" # create an instance of UploadFileWithAdditionalPropertiesRequestObject from a JSON string -upload_file_with_additional_properties_request_object_instance = UploadFileWithAdditionalPropertiesRequestObject.from_json(json) +upload_file_with_additional_properties_request_object_instance = UploadFileWithAdditionalPropertiesRequestObject.model_validate_json(json) # print the JSON string representation of the object -print(UploadFileWithAdditionalPropertiesRequestObject.to_json()) +print(UploadFileWithAdditionalPropertiesRequestObject.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -upload_file_with_additional_properties_request_object_dict = upload_file_with_additional_properties_request_object_instance.to_dict() +upload_file_with_additional_properties_request_object_dict = upload_file_with_additional_properties_request_object_instance.model_dump(by_alias=True) # create an instance of UploadFileWithAdditionalPropertiesRequestObject from a dict -upload_file_with_additional_properties_request_object_from_dict = UploadFileWithAdditionalPropertiesRequestObject.from_dict(upload_file_with_additional_properties_request_object_dict) +upload_file_with_additional_properties_request_object_from_dict = UploadFileWithAdditionalPropertiesRequestObject.model_validate(upload_file_with_additional_properties_request_object_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/User.md b/samples/openapi3/client/petstore/python/docs/User.md index c45d26d27043..1986137ecc70 100644 --- a/samples/openapi3/client/petstore/python/docs/User.md +++ b/samples/openapi3/client/petstore/python/docs/User.md @@ -22,14 +22,14 @@ from petstore_api.models.user import User # TODO update the JSON string below json = "{}" # create an instance of User from a JSON string -user_instance = User.from_json(json) +user_instance = User.model_validate_json(json) # print the JSON string representation of the object -print(User.to_json()) +print(User.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -user_dict = user_instance.to_dict() +user_dict = user_instance.model_dump(by_alias=True) # create an instance of User from a dict -user_from_dict = User.from_dict(user_dict) +user_from_dict = User.model_validate(user_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/WithNestedOneOf.md b/samples/openapi3/client/petstore/python/docs/WithNestedOneOf.md index e7bbbc28fc2d..63b0f83540d1 100644 --- a/samples/openapi3/client/petstore/python/docs/WithNestedOneOf.md +++ b/samples/openapi3/client/petstore/python/docs/WithNestedOneOf.md @@ -17,14 +17,14 @@ from petstore_api.models.with_nested_one_of import WithNestedOneOf # TODO update the JSON string below json = "{}" # create an instance of WithNestedOneOf from a JSON string -with_nested_one_of_instance = WithNestedOneOf.from_json(json) +with_nested_one_of_instance = WithNestedOneOf.model_validate_json(json) # print the JSON string representation of the object -print(WithNestedOneOf.to_json()) +print(WithNestedOneOf.model_dump_json(by_alias=True, exclude_unset=True)) # convert the object into a dict -with_nested_one_of_dict = with_nested_one_of_instance.to_dict() +with_nested_one_of_dict = with_nested_one_of_instance.model_dump(by_alias=True) # create an instance of WithNestedOneOf from a dict -with_nested_one_of_from_dict = WithNestedOneOf.from_dict(with_nested_one_of_dict) +with_nested_one_of_from_dict = WithNestedOneOf.model_validate(with_nested_one_of_dict) ``` [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 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 07328c8975e3..1e19c6d880d1 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 @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field from typing_extensions import Annotated 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 3be576102f96..5f05c540a238 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 @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from petstore_api.models.foo_get_default_response import FooGetDefaultResponse 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 17761ab9bd0e..6d99595e3059 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 @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from datetime import date, datetime from pydantic import Field, StrictBool, StrictBytes, StrictFloat, StrictInt, StrictStr, field_validator 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 558590bab2de..c5596bef9393 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 @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field from typing_extensions import Annotated diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/import_test_datetime_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/import_test_datetime_api.py index 6d9829ac664e..a59a3c99cbc4 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/import_test_datetime_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/import_test_datetime_api.py @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from datetime import datetime 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 5925ad96e7e0..21539d3dde23 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 @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field, StrictBytes, StrictInt, StrictStr, field_validator from typing import List, Optional, Tuple, Union 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 942f7bc25a33..edb9dce2f565 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 @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field, StrictInt, StrictStr from typing import Dict 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 b2a4ced88095..b19c4fb54a4f 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 @@ -14,7 +14,7 @@ import warnings from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union -from typing_extensions import Annotated +from typing import Annotated from pydantic import Field, StrictStr from typing import List diff --git a/samples/openapi3/client/petstore/python/petstore_api/api_client.py b/samples/openapi3/client/petstore/python/petstore_api/api_client.py index 9f1cbc811db7..28d7bf8e8cd8 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api_client.py @@ -312,7 +312,7 @@ def response_deserialize( return_data = self.__deserialize_file(response_data) elif response_type is not None: match = None - content_type = response_data.headers.get('content-type') + content_type = response_data.getheader('content-type') if content_type is not None: match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type) encoding = match.group(1) if match else "utf-8" @@ -329,7 +329,7 @@ def response_deserialize( return ApiResponse( status_code = response_data.status, data = return_data, - headers = response_data.headers, + headers = response_data.getheaders(), raw_data = response_data.data ) @@ -380,13 +380,10 @@ def sanitize_for_serialization(self, obj): # and attributes which value is not None. # Convert attribute name to json key in # model definition for request. - if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')): - obj_dict = obj.to_dict() - else: - obj_dict = obj.__dict__ + obj_dict = obj.model_dump(by_alias=True, exclude_none=True) if isinstance(obj_dict, list): - # here we handle instances that can either be a list or something else, and only became a real list by calling to_dict() + # here we handle instances that can either be a list or something else, and only became a real list by calling model_dump(by_alias=True) return self.sanitize_for_serialization(obj_dict) return { @@ -708,7 +705,7 @@ def __deserialize_file(self, response): os.close(fd) os.remove(path) - content_disposition = response.headers.get("Content-Disposition") + content_disposition = response.getheader("Content-Disposition") if content_disposition: m = re.search( r'filename=[\'"]?([^\'"\s]+)[\'"]?', @@ -808,4 +805,4 @@ def __deserialize_model(self, data, klass): :return: model object. """ - return klass.from_dict(data) + return klass.model_validate(data) diff --git a/samples/openapi3/client/petstore/python/petstore_api/configuration.py b/samples/openapi3/client/petstore/python/petstore_api/configuration.py index 0bd1cbdcadd2..5a5242c4ea31 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python/petstore_api/configuration.py @@ -18,8 +18,7 @@ from logging import FileHandler import multiprocessing import sys -from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union -from typing_extensions import NotRequired, Self +from typing import Any, ClassVar, Dict, List, Literal, NotRequired, Optional, TypedDict, Union, Self import urllib3 diff --git a/samples/openapi3/client/petstore/python/petstore_api/exceptions.py b/samples/openapi3/client/petstore/python/petstore_api/exceptions.py index cb0ecfbf7018..a5d2c10c55be 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/exceptions.py +++ b/samples/openapi3/client/petstore/python/petstore_api/exceptions.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """ OpenAPI Petstore @@ -11,8 +9,8 @@ Do not edit the class manually. """ # noqa: E501 -from typing import Any, Optional -from typing_extensions import Self + +from typing import Any, Optional, Self class OpenApiException(Exception): """The base exception class for all OpenAPIExceptions""" @@ -104,9 +102,9 @@ def __init__(self, msg, path_to_item=None) -> None: class ApiException(OpenApiException): def __init__( - self, - status=None, - reason=None, + self, + status=None, + reason=None, http_resp=None, *, body: Optional[str] = None, @@ -128,14 +126,14 @@ def __init__( self.body = http_resp.data.decode('utf-8') except Exception: pass - self.headers = http_resp.headers + self.headers = http_resp.getheaders() @classmethod def from_response( - cls, - *, - http_resp, - body: Optional[str], + cls, + *, + http_resp, + body: Optional[str], data: Optional[Any], ) -> Self: if http_resp.status == 400: @@ -169,11 +167,8 @@ def __str__(self): error_message += "HTTP response headers: {0}\n".format( self.headers) - if self.body: - error_message += "HTTP response body: {0}\n".format(self.body) - - if self.data: - error_message += "HTTP response data: {0}\n".format(self.data) + if self.data or self.body: + error_message += "HTTP response body: {0}\n".format(self.data or self.body) return error_message 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 291b5e55e353..9986695fc1ec 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesAnyType(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesAnyType from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesAnyType from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 220f23a423b4..de26ad42fa5a 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesClass(BaseModel): """ @@ -42,61 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "map_property": obj.get("map_property"), - "map_of_map_property": obj.get("map_of_map_property") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 00707c3c4818..a514124192f5 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesObject(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesObject from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesObject from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 d8049b519ed0..a01f7169f6a4 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AdditionalPropertiesWithDescriptionOnly(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AdditionalPropertiesWithDescriptionOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AdditionalPropertiesWithDescriptionOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/all_of_super_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/all_of_super_model.py index b63bba1206a2..f3ef47ec2415 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/all_of_super_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/all_of_super_model.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AllOfSuperModel(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AllOfSuperModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AllOfSuperModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_name": obj.get("_name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 e3fa084b0709..7f23c83d6dbf 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.single_ref_type import SingleRefType -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class AllOfWithSingleRef(BaseModel): """ @@ -43,61 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of AllOfWithSingleRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of AllOfWithSingleRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "username": obj.get("username"), - "SingleRefType": obj.get("SingleRefType") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 131ad8d0ed60..3b28901459f4 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/animal.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/animal.py @@ -20,8 +20,8 @@ from importlib import import_module from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional, Union -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -65,55 +65,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[Cat, Dog]]: - """Create an instance of Animal from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[Cat, Dog]]: - """Create an instance of Animal from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'Cat': - return import_module("petstore_api.models.cat").Cat.from_dict(obj) - if object_type == 'Dog': - return import_module("petstore_api.models.dog").Dog.from_dict(obj) - - raise ValueError("Animal failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) 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 f6d277e79498..8e0c6051da74 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 @@ -20,137 +20,30 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import List, Optional from typing_extensions import Annotated -from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict -from typing_extensions import Literal, Self -from pydantic import Field +from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict, Literal, Self +from pydantic import Field, RootModel ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"] -class AnyOfColor(BaseModel): + +class AnyOfColor(RootModel[Union[List[int], str]]): """ Any of RGB array, RGBA array, or hex string. """ - # data type: List[int] - 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_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: - actual_instance: Optional[Union[List[int], str]] = None - else: - actual_instance: Any = None - any_of_schemas: Set[str] = { "List[int]", "str" } - - model_config = { - "validate_assignment": True, - "protected_namespaces": (), - } - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_anyof(cls, v): - instance = AnyOfColor.model_construct() - error_messages = [] - # validate data type: List[int] - try: - instance.anyof_schema_1_validator = v - return v - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: List[int] - try: - instance.anyof_schema_2_validator = v - return v - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: str - try: - instance.anyof_schema_3_validator = v - return v - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - if error_messages: - # no match - raise ValueError("No match found when setting the actual_instance in AnyOfColor with anyOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - # deserialize data into List[int] - try: - # validation - instance.anyof_schema_1_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.anyof_schema_1_validator - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into List[int] - try: - # validation - instance.anyof_schema_2_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.anyof_schema_2_validator - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into str - try: - # validation - instance.anyof_schema_3_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.anyof_schema_3_validator - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if error_messages: - # no match - raise ValueError("No match found when deserializing the JSON string into AnyOfColor with anyOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + root: Union[List[int], str] = Field( + ... + ) + + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") 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 c949e136f415..df3bae10d3a6 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 @@ -21,114 +21,30 @@ from typing import Optional from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig -from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict -from typing_extensions import Literal, Self -from pydantic import Field +from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict, Literal, Self +from pydantic import Field, RootModel ANYOFPIG_ANY_OF_SCHEMAS = ["BasquePig", "DanishPig"] -class AnyOfPig(BaseModel): + +class AnyOfPig(RootModel[Union[BasquePig, DanishPig]]): """ AnyOfPig """ - # data type: BasquePig - anyof_schema_1_validator: Optional[BasquePig] = None - # data type: DanishPig - anyof_schema_2_validator: Optional[DanishPig] = None - if TYPE_CHECKING: - actual_instance: Optional[Union[BasquePig, DanishPig]] = None - else: - actual_instance: Any = None - any_of_schemas: Set[str] = { "BasquePig", "DanishPig" } - - model_config = { - "validate_assignment": True, - "protected_namespaces": (), - } - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_anyof(cls, v): - instance = AnyOfPig.model_construct() - error_messages = [] - # validate data type: BasquePig - if not isinstance(v, BasquePig): - error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`") - else: - return v - - # validate data type: DanishPig - if not isinstance(v, DanishPig): - error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`") - else: - return v - - if error_messages: - # no match - raise ValueError("No match found when setting the actual_instance in AnyOfPig with anyOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - # anyof_schema_1_validator: Optional[BasquePig] = None - try: - instance.actual_instance = BasquePig.from_json(json_str) - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # anyof_schema_2_validator: Optional[DanishPig] = None - try: - instance.actual_instance = DanishPig.from_json(json_str) - return instance - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if error_messages: - # no match - raise ValueError("No match found when deserializing the JSON string into AnyOfPig with anyOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], BasquePig, DanishPig]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + root: Union[BasquePig, DanishPig] = Field( + ... + ) + + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") 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 80d4aa689164..4db366070a84 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayOfArrayOfModel(BaseModel): """ @@ -42,72 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in another_property (list of list) - _items = [] - if self.another_property: - for _item_another_property in self.another_property: - if _item_another_property: - _items.append( - [_inner_item.to_dict() for _inner_item in _item_another_property if _inner_item is not None] - ) - _dict['another_property'] = _items - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "another_property": [ - [Tag.from_dict(_inner_item) for _inner_item in _item] - for _item in obj["another_property"] - ] if obj.get("another_property") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 847ae88c4ffa..f9178dcf1dc8 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictFloat from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayOfArrayOfNumberOnly(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfNumberOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayOfArrayOfNumberOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "ArrayArrayNumber": obj.get("ArrayArrayNumber") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 4634914c33eb..54c3b8a8e843 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictFloat from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayOfNumberOnly(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayOfNumberOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayOfNumberOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "ArrayNumber": obj.get("ArrayNumber") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 9cadd4e7beb7..d44a7bc9d98f 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 @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from typing_extensions import Annotated from petstore_api.models.read_only_first import ReadOnlyFirst -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ArrayTest(BaseModel): """ @@ -46,75 +46,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ArrayTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in array_array_of_model (list of list) - _items = [] - if self.array_array_of_model: - for _item_array_array_of_model in self.array_array_of_model: - if _item_array_array_of_model: - _items.append( - [_inner_item.to_dict() for _inner_item in _item_array_array_of_model if _inner_item is not None] - ) - _dict['array_array_of_model'] = _items - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ArrayTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "array_of_string": obj.get("array_of_string"), - "array_of_nullable_float": obj.get("array_of_nullable_float"), - "array_array_of_integer": obj.get("array_array_of_integer"), - "array_array_of_model": [ - [ReadOnlyFirst.from_dict(_inner_item) for _inner_item in _item] - for _item in obj["array_array_of_model"] - ] if obj.get("array_array_of_model") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/base_discriminator.py b/samples/openapi3/client/petstore/python/petstore_api/models/base_discriminator.py index 40b49a2fca7f..f4255f6ed26c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/base_discriminator.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/base_discriminator.py @@ -20,8 +20,8 @@ from importlib import import_module from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional, Union -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -64,55 +64,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[PrimitiveString, Info]]: - """Create an instance of BaseDiscriminator from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[PrimitiveString, Info]]: - """Create an instance of BaseDiscriminator from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'PrimitiveString': - return import_module("petstore_api.models.primitive_string").PrimitiveString.from_dict(obj) - if object_type == 'Info': - return import_module("petstore_api.models.info").Info.from_dict(obj) - - raise ValueError("BaseDiscriminator failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) 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 4a5b9e3bcb9d..557bef94ca91 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class BasquePig(BaseModel): """ @@ -42,61 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of BasquePig from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of BasquePig from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "color": obj.get("color") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/bathing.py b/samples/openapi3/client/petstore/python/petstore_api/models/bathing.py index 289d9d4670ab..56d8a286ef7d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/bathing.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/bathing.py @@ -19,15 +19,21 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Bathing(BaseModel): """ Bathing """ # noqa: E501 - task_name: StrictStr - function_name: StrictStr + task_name: Literal['cleaning_deep'] = Field( + ..., + description="task_name of the Bathing" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Bathing" + ) content: StrictStr additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -57,62 +63,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Bathing from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Bathing from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "task_name": obj.get("task_name"), - "function_name": obj.get("function_name"), - "content": obj.get("content") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 d98aa21e532d..51b26b53289a 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Capitalization(BaseModel): """ @@ -46,65 +46,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Capitalization from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Capitalization from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "smallCamel": obj.get("smallCamel"), - "CapitalCamel": obj.get("CapitalCamel"), - "small_Snake": obj.get("small_Snake"), - "Capital_Snake": obj.get("Capital_Snake"), - "SCA_ETH_Flow_Points": obj.get("SCA_ETH_Flow_Points"), - "ATT_NAME": obj.get("ATT_NAME") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 86002178c904..6a81ff03f877 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/cat.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/cat.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict, StrictBool from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.animal import Animal -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Cat(Animal): """ @@ -42,62 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Cat from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Cat from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "color": obj.get("color") if obj.get("color") is not None else 'red', - "declawed": obj.get("declawed") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 c659f1845726..9e6ea156d85a 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/category.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/category.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Category(BaseModel): """ @@ -42,61 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Category from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Category from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") if obj.get("name") is not None else 'default-name' - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/circular_all_of_ref.py b/samples/openapi3/client/petstore/python/petstore_api/models/circular_all_of_ref.py index d3b6cbe57ea1..cab8f24cdaa9 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/circular_all_of_ref.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/circular_all_of_ref.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class CircularAllOfRef(BaseModel): """ @@ -42,69 +42,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of CircularAllOfRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in second_circular_all_of_ref (list) - _items = [] - if self.second_circular_all_of_ref: - for _item_second_circular_all_of_ref in self.second_circular_all_of_ref: - if _item_second_circular_all_of_ref: - _items.append(_item_second_circular_all_of_ref.to_dict()) - _dict['secondCircularAllOfRef'] = _items - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of CircularAllOfRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_name": obj.get("_name"), - "secondCircularAllOfRef": [SecondCircularAllOfRef.from_dict(_item) for _item in obj["secondCircularAllOfRef"]] if obj.get("secondCircularAllOfRef") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj from petstore_api.models.second_circular_all_of_ref import SecondCircularAllOfRef # TODO: Rewrite to not use raise_errors 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 8c118f3c09b2..d9b322b55545 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class CircularReferenceModel(BaseModel): """ @@ -42,65 +42,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of CircularReferenceModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of nested - if self.nested: - _dict['nested'] = self.nested.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of CircularReferenceModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "nested": FirstRef.from_dict(obj["nested"]) if obj.get("nested") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj from petstore_api.models.first_ref import FirstRef # TODO: Rewrite to not use raise_errors 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 06f8f91b83cb..b9ab6eb6a718 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ClassModel(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ClassModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ClassModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_class": obj.get("_class") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 d3376d62357b..58f46fa71338 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/client.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Client(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Client from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Client from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "client": obj.get("client") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 bb740fb597d4..7fe333c7a3b9 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/color.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/color.py @@ -18,150 +18,27 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Any, List, Optional from typing_extensions import Annotated -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self COLOR_ONE_OF_SCHEMAS = ["List[int]", "str"] -class Color(BaseModel): +class Color(RootModel[Union[List[int], str]]): """ 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_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_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: Set[str] = { "List[int]", "str" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[List[int], str] = Field( + ... ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - if v is None: - return v - - instance = Color.model_construct() - error_messages = [] - match = 0 - # validate data type: List[int] - try: - instance.oneof_schema_1_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: List[int] - try: - instance.oneof_schema_2_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: str - try: - instance.oneof_schema_3_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: Optional[str]) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - if json_str is None: - return instance - - error_messages = [] - match = 0 - - # deserialize data into List[int] - try: - # validation - instance.oneof_schema_1_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_1_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into List[int] - try: - # validation - instance.oneof_schema_2_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_2_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into str - try: - # validation - instance.oneof_schema_3_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_3_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") 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 ce6a70327b1a..a087df77dbde 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/creature.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/creature.py @@ -21,8 +21,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Union from petstore_api.models.creature_info import CreatureInfo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -65,56 +65,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[HuntingDog]]: - """Create an instance of Creature from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of info - if self.info: - _dict['info'] = self.info.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[HuntingDog]]: - """Create an instance of Creature from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'HuntingDog': - return import_module("petstore_api.models.hunting_dog").HuntingDog.from_dict(obj) - - raise ValueError("Creature failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) 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 e7fef158a580..ab35ccf566ed 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class CreatureInfo(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of CreatureInfo from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of CreatureInfo from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 df4a80d33908..ebe9dd758e04 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DanishPig(BaseModel): """ @@ -42,61 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DanishPig from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DanishPig from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "size": obj.get("size") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/data_output_format.py b/samples/openapi3/client/petstore/python/petstore_api/models/data_output_format.py index ee3df76c5169..e32ebe9a5ee4 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/data_output_format.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/data_output_format.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class DataOutputFormat(StrEnum): -class DataOutputFormat(str, Enum): """ DataOutputFormat """ - """ - allowed enum values - """ + # Allowed enum values JSON = 'JSON' CSV = 'CSV' XML = 'XML' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of DataOutputFormat from a JSON string""" return cls(json.loads(json_str)) - 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 ad0ec89a5b7a..bed31b70ad2c 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DeprecatedObject(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DeprecatedObject from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DeprecatedObject from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/discriminator_all_of_sub.py b/samples/openapi3/client/petstore/python/petstore_api/models/discriminator_all_of_sub.py index 9723d2e28c74..fc3cc32bba36 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/discriminator_all_of_sub.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/discriminator_all_of_sub.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict from typing import Any, ClassVar, Dict, List from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DiscriminatorAllOfSub(DiscriminatorAllOfSuper): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DiscriminatorAllOfSub from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DiscriminatorAllOfSub from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "elementType": obj.get("elementType") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/discriminator_all_of_super.py b/samples/openapi3/client/petstore/python/petstore_api/models/discriminator_all_of_super.py index e3d62831065a..44d0e9c5a4a8 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/discriminator_all_of_super.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/discriminator_all_of_super.py @@ -20,8 +20,8 @@ from importlib import import_module from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Union -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -63,53 +63,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Union[DiscriminatorAllOfSub]]: - """Create an instance of DiscriminatorAllOfSuper from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[DiscriminatorAllOfSub]]: - """Create an instance of DiscriminatorAllOfSuper from a dict""" - # look up the object type based on discriminator mapping - object_type = cls.get_discriminator_value(obj) - if object_type == 'DiscriminatorAllOfSub': - return import_module("petstore_api.models.discriminator_all_of_sub").DiscriminatorAllOfSub.from_dict(obj) - - raise ValueError("DiscriminatorAllOfSuper failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) 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 cde0f5d27e0c..c4ea2a0f0ddf 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/dog.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/dog.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.animal import Animal -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Dog(Animal): """ @@ -42,62 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Dog from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Dog from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "className": obj.get("className"), - "color": obj.get("color") if obj.get("color") is not None else 'red', - "breed": obj.get("breed") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 47fdb81a397a..b1ae29288bd6 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class DummyModel(BaseModel): """ @@ -42,65 +42,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of DummyModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of self_ref - if self.self_ref: - _dict['self_ref'] = self.self_ref.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of DummyModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "category": obj.get("category"), - "self_ref": SelfReferenceModel.from_dict(obj["self_ref"]) if obj.get("self_ref") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj from petstore_api.models.self_reference_model import SelfReferenceModel # TODO: Rewrite to not use raise_errors 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 17d3e0afd2df..0d50b57b3b07 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,15 +19,17 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class EnumArrays(BaseModel): """ EnumArrays """ # noqa: E501 - just_symbol: Optional[StrictStr] = None - array_enum: Optional[List[StrictStr]] = None + just_symbol: Optional[Just_symbolEnum] = Field( + None, + description="just_symbol of the EnumArrays" + ) additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["just_symbol", "array_enum"] @@ -63,61 +65,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of EnumArrays from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of EnumArrays from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "just_symbol": obj.get("just_symbol"), - "array_enum": obj.get("array_enum") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_class.py index 1ba5af8036df..b4e61d237db8 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_class.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumClass(StrEnum): -class EnumClass(str, Enum): """ EnumClass """ - """ - allowed enum values - """ + # Allowed enum values ABC = '_abc' MINUS_EFG = '-efg' LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS = '(xyz)' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumClass from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_number_vendor_ext.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_number_vendor_ext.py index 5588de5c7043..91d2161cbc6d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_number_vendor_ext.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_number_vendor_ext.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumNumberVendorExt(IntEnum): -class EnumNumberVendorExt(int, Enum): """ EnumNumberVendorExt """ - """ - allowed enum values - """ + # Allowed enum values FortyTwo = 42 Eigtheen = 18 FiftySix = 56 @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumNumberVendorExt from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_ref_with_default_value.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_ref_with_default_value.py index d864e80d0a73..3d04280d92cc 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_ref_with_default_value.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_ref_with_default_value.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.data_output_format import DataOutputFormat -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class EnumRefWithDefaultValue(BaseModel): """ @@ -42,60 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of EnumRefWithDefaultValue from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of EnumRefWithDefaultValue from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "report_format": obj.get("report_format") if obj.get("report_format") is not None else DataOutputFormat.JSON - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_string1.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_string1.py index 678b4e12661f..d6970ff8346f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_string1.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_string1.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumString1(StrEnum): -class EnumString1(str, Enum): """ EnumString1 """ - """ - allowed enum values - """ + # Allowed enum values A = 'a' B = 'b' @@ -34,4 +32,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumString1 from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_string2.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_string2.py index a959f554e0af..c4fc722f826a 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_string2.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_string2.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumString2(StrEnum): -class EnumString2(str, Enum): """ EnumString2 """ - """ - allowed enum values - """ + # Allowed enum values C = 'c' D = 'd' @@ -34,4 +32,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumString2 from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_string_vendor_ext.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_string_vendor_ext.py index 821812e9b088..175ace79326f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_string_vendor_ext.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_string_vendor_ext.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class EnumStringVendorExt(StrEnum): -class EnumStringVendorExt(str, Enum): """ EnumStringVendorExt """ - """ - allowed enum values - """ + # Allowed enum values FOO_XEnumVarname = 'FOO' BarVar_XEnumVarname = 'Bar' bazVar_XEnumVarname = 'baz' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of EnumStringVendorExt from a JSON string""" return cls(json.loads(json_str)) - 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 d39c2c95775e..81e6523384b2 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 @@ -25,20 +25,41 @@ from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue from petstore_api.models.outer_enum_integer import OuterEnumInteger from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntegerDefaultValue -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class EnumTest(BaseModel): """ EnumTest """ # noqa: E501 - enum_string: Optional[StrictStr] = None - enum_string_required: StrictStr - enum_integer_default: Optional[StrictInt] = 5 - enum_integer: Optional[StrictInt] = None - enum_number: Optional[StrictFloat] = None - enum_string_single_member: Optional[StrictStr] = None - enum_integer_single_member: Optional[StrictInt] = None + enum_string: Optional[Enum_stringEnum] = Field( + None, + description="enum_string of the EnumTest" + ) + enum_string_required: Enum_string_requiredEnum = Field( + ..., + description="enum_string_required of the EnumTest" + ) + enum_integer_default: Optional[Enum_integer_defaultEnum] = Field( + None, + description="enum_integer_default of the EnumTest" + ) + enum_integer: Optional[Enum_integerEnum] = Field( + None, + description="enum_integer of the EnumTest" + ) + enum_number: Optional[Enum_numberEnum] = Field( + None, + description="enum_number of the EnumTest" + ) + enum_string_single_member: Literal['abc'] = Field( + None, + description="enum_string_single_member of the EnumTest" + ) + enum_integer_single_member: Literal['100'] = Field( + None, + description="enum_integer_single_member of the EnumTest" + ) outer_enum: Optional[OuterEnum] = Field(default=None, alias="outerEnum") outer_enum_integer: Optional[OuterEnumInteger] = Field(default=None, alias="outerEnumInteger") outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=OuterEnumDefaultValue.PLACED, alias="outerEnumDefaultValue") @@ -126,77 +147,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of EnumTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - # set to None if outer_enum (nullable) is None - # 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of EnumTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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, - "enum_integer": obj.get("enum_integer"), - "enum_number": obj.get("enum_number"), - "enum_string_single_member": obj.get("enum_string_single_member"), - "enum_integer_single_member": obj.get("enum_integer_single_member"), - "outerEnum": obj.get("outerEnum"), - "outerEnumInteger": obj.get("outerEnumInteger"), - "outerEnumDefaultValue": obj.get("outerEnumDefaultValue") if obj.get("outerEnumDefaultValue") is not None else OuterEnumDefaultValue.PLACED, - "outerEnumIntegerDefaultValue": obj.get("outerEnumIntegerDefaultValue") if obj.get("outerEnumIntegerDefaultValue") is not None else OuterEnumIntegerDefaultValue.NUMBER_0, - "enumNumberVendorExt": obj.get("enumNumberVendorExt"), - "enumStringVendorExt": obj.get("enumStringVendorExt") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/feeding.py b/samples/openapi3/client/petstore/python/petstore_api/models/feeding.py index 5c406bc9e65e..4105e2913921 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/feeding.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/feeding.py @@ -19,15 +19,21 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Feeding(BaseModel): """ Feeding """ # noqa: E501 - task_name: StrictStr - function_name: StrictStr + task_name: Literal['cleaning'] = Field( + ..., + description="task_name of the Feeding" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Feeding" + ) content: StrictStr additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -57,62 +63,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Feeding from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Feeding from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "task_name": obj.get("task_name"), - "function_name": obj.get("function_name"), - "content": obj.get("content") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 4c661cadabc4..5b0f97a3d1f0 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/file.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/file.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class File(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of File from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of File from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "sourceURI": obj.get("sourceURI") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 09a543010f4d..8a6e72a5a457 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.file import File -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FileSchemaTestClass(BaseModel): """ @@ -43,71 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FileSchemaTestClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of file - if self.file: - _dict['file'] = self.file.to_dict() - # override the default output from pydantic by calling `to_dict()` of each item in files (list) - _items = [] - if self.files: - for _item_files in self.files: - if _item_files: - _items.append(_item_files.to_dict()) - _dict['files'] = _items - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FileSchemaTestClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "file": File.from_dict(obj["file"]) if obj.get("file") is not None else None, - "files": [File.from_dict(_item) for _item in obj["files"]] if obj.get("files") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 7680dfdf418c..86df2c1c6205 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FirstRef(BaseModel): """ @@ -42,65 +42,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FirstRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of self_ref - if self.self_ref: - _dict['self_ref'] = self.self_ref.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FirstRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "category": obj.get("category"), - "self_ref": SecondRef.from_dict(obj["self_ref"]) if obj.get("self_ref") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj from petstore_api.models.second_ref import SecondRef # TODO: Rewrite to not use raise_errors 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 81e3839ea17c..73b9f4512aaf 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/foo.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/foo.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Foo(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Foo from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Foo from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "bar": obj.get("bar") if obj.get("bar") is not None else 'bar' - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 4cd23db39125..15a78079f4fa 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.foo import Foo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FooGetDefaultResponse(BaseModel): """ @@ -42,63 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FooGetDefaultResponse from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of string - if self.string: - _dict['string'] = self.string.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FooGetDefaultResponse from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "string": Foo.from_dict(obj["string"]) if obj.get("string") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 4aca97f91c48..20b38c1af87b 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 @@ -23,8 +23,8 @@ from typing import Any, ClassVar, Dict, List, Optional, Tuple, Union from typing_extensions import Annotated from uuid import UUID -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class FormatTest(BaseModel): """ @@ -101,76 +101,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of FormatTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of FormatTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "integer": obj.get("integer"), - "int32": obj.get("int32"), - "int64": obj.get("int64"), - "number": obj.get("number"), - "float": obj.get("float"), - "double": obj.get("double"), - "decimal": obj.get("decimal"), - "string": obj.get("string"), - "string_with_double_quote_pattern": obj.get("string_with_double_quote_pattern"), - "byte": obj.get("byte"), - "binary": obj.get("binary"), - "date": obj.get("date"), - "dateTime": obj.get("dateTime"), - "uuid": obj.get("uuid"), - "password": obj.get("password"), - "pattern_with_digits": obj.get("pattern_with_digits"), - "pattern_with_digits_and_delimiter": obj.get("pattern_with_digits_and_delimiter") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 77360fedbae5..df61369961f9 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class HasOnlyReadOnly(BaseModel): """ @@ -42,65 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of HasOnlyReadOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * OpenAPI `readOnly` fields are excluded. - * OpenAPI `readOnly` fields are excluded. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "bar", - "foo", - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of HasOnlyReadOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "bar": obj.get("bar"), - "foo": obj.get("foo") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 59f444aedaa3..8e5a35a68b5e 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class HealthCheckResult(BaseModel): """ @@ -41,65 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of HealthCheckResult from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - # set to None if nullable_message (nullable) is None - # 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of HealthCheckResult from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "NullableMessage": obj.get("NullableMessage") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/hunting_dog.py b/samples/openapi3/client/petstore/python/petstore_api/models/hunting_dog.py index f7d03f4044ea..1f111dd5f9fc 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/hunting_dog.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/hunting_dog.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.creature import Creature from petstore_api.models.creature_info import CreatureInfo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class HuntingDog(Creature): """ @@ -43,65 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of HuntingDog from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of info - if self.info: - _dict['info'] = self.info.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of HuntingDog from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "info": CreatureInfo.from_dict(obj["info"]) if obj.get("info") is not None else None, - "type": obj.get("type"), - "isTrained": obj.get("isTrained") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/info.py b/samples/openapi3/client/petstore/python/petstore_api/models/info.py index 94e663b3aaab..eefe81adf411 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/info.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/info.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.base_discriminator import BaseDiscriminator -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Info(BaseDiscriminator): """ @@ -42,64 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Info from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of val - if self.val: - _dict['val'] = self.val.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Info from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_typeName": obj.get("_typeName"), - "val": BaseDiscriminator.from_dict(obj["val"]) if obj.get("val") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 b43fa8b19fef..565a461bea8e 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class InnerDictWithProperty(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of InnerDictWithProperty from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of InnerDictWithProperty from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "aProperty": obj.get("aProperty") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/input_all_of.py b/samples/openapi3/client/petstore/python/petstore_api/models/input_all_of.py index e4a81ff70006..36c28f74d15a 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/input_all_of.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/input_all_of.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class InputAllOf(BaseModel): """ @@ -42,72 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of InputAllOf from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in some_data (dict) - _field_dict = {} - if self.some_data: - for _key_some_data in self.some_data: - if self.some_data[_key_some_data]: - _field_dict[_key_some_data] = self.some_data[_key_some_data].to_dict() - _dict['some_data'] = _field_dict - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of InputAllOf from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "some_data": dict( - (_k, Tag.from_dict(_v)) - for _k, _v in obj["some_data"].items() - ) - if obj.get("some_data") is not None - else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 f2a5a0a2d4a3..63f94b788677 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 @@ -18,127 +18,27 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Any, List, Optional from typing_extensions import Annotated -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self INTORSTRING_ONE_OF_SCHEMAS = ["int", "str"] -class IntOrString(BaseModel): +class IntOrString(RootModel[Union[int, str]]): """ IntOrString """ - # data type: int - oneof_schema_1_validator: Optional[Annotated[int, Field(strict=True, ge=10)]] = None - # data type: str - oneof_schema_2_validator: Optional[StrictStr] = None - actual_instance: Optional[Union[int, str]] = None - one_of_schemas: Set[str] = { "int", "str" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[int, str] = Field( + ... ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - instance = IntOrString.model_construct() - error_messages = [] - match = 0 - # validate data type: int - try: - instance.oneof_schema_1_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # validate data type: str - try: - instance.oneof_schema_2_validator = v - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # deserialize data into int - try: - # validation - instance.oneof_schema_1_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_1_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into str - try: - # validation - instance.oneof_schema_2_validator = json.loads(json_str) - # assign value to actual_instance - instance.actual_instance = instance.oneof_schema_2_validator - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], int, str]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/list_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/list_class.py index e00f3d820b88..c3219f03314c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/list_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/list_class.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ListClass(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ListClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ListClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "123-list": obj.get("123-list") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 68816ab29531..97c5b812f6bb 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MapOfArrayOfModel(BaseModel): """ @@ -42,76 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MapOfArrayOfModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in shop_id_to_org_online_lip_map (dict of array) - _field_dict_of_array = {} - if self.shop_id_to_org_online_lip_map: - for _key_shop_id_to_org_online_lip_map in self.shop_id_to_org_online_lip_map: - if self.shop_id_to_org_online_lip_map[_key_shop_id_to_org_online_lip_map] is not None: - _field_dict_of_array[_key_shop_id_to_org_online_lip_map] = [ - _item.to_dict() for _item in self.shop_id_to_org_online_lip_map[_key_shop_id_to_org_online_lip_map] - ] - _dict['shopIdToOrgOnlineLipMap'] = _field_dict_of_array - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MapOfArrayOfModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "shopIdToOrgOnlineLipMap": dict( - (_k, - [Tag.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("shopIdToOrgOnlineLipMap", {}).items() - ) - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 4cefd36427f9..51deeba849bf 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,15 +19,18 @@ from pydantic import BaseModel, ConfigDict, StrictBool, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MapTest(BaseModel): """ MapTest """ # noqa: E501 map_map_of_string: Optional[Dict[str, Dict[str, StrictStr]]] = None - map_of_enum_string: Optional[Dict[str, StrictStr]] = None + map_of_enum_string: Optional[Dict[str, str]] = Field( + None, + description="map_of_enum_string of the MapTest" + ) direct_map: Optional[Dict[str, StrictBool]] = None indirect_map: Optional[Dict[str, StrictBool]] = None additional_properties: Dict[str, Any] = {} @@ -55,63 +58,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MapTest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MapTest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.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"), - "indirect_map": obj.get("indirect_map") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 c21f442bb798..7275fe85f367 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 @@ -22,8 +22,8 @@ from typing import Any, ClassVar, Dict, List, Optional from uuid import UUID from petstore_api.models.animal import Animal -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): """ @@ -46,74 +46,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MixedPropertiesAndAdditionalPropertiesClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in map (dict) - _field_dict = {} - if self.map: - for _key_map in self.map: - if self.map[_key_map]: - _field_dict[_key_map] = self.map[_key_map].to_dict() - _dict['map'] = _field_dict - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MixedPropertiesAndAdditionalPropertiesClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "uuid": obj.get("uuid"), - "dateTime": obj.get("dateTime"), - "map": dict( - (_k, Animal.from_dict(_v)) - for _k, _v in obj["map"].items() - ) - if obj.get("map") is not None - else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 60e43a0e28e6..318bdc6f7854 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Model200Response(BaseModel): """ @@ -42,61 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Model200Response from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Model200Response from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name"), - "class": obj.get("class") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/model_api_response.py b/samples/openapi3/client/petstore/python/petstore_api/models/model_api_response.py index 7141160c57d9..9a6114ad8c63 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/model_api_response.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/model_api_response.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ModelApiResponse(BaseModel): """ @@ -43,62 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ModelApiResponse from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ModelApiResponse from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "code": obj.get("code"), - "type": obj.get("type"), - "message": obj.get("message") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/model_field.py b/samples/openapi3/client/petstore/python/petstore_api/models/model_field.py index d7b03848fe16..e0625b2fb00b 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/model_field.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/model_field.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ModelField(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ModelField from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ModelField from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "field": obj.get("field") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 3f2558bc6e7d..6802ace821de 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ModelReturn(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ModelReturn from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ModelReturn from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "return": obj.get("return") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/multi_arrays.py b/samples/openapi3/client/petstore/python/petstore_api/models/multi_arrays.py index 80fa67f8a11c..afbf2b94be61 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/multi_arrays.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/multi_arrays.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.file import File from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class MultiArrays(BaseModel): """ @@ -44,75 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of MultiArrays from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in tags (list) - _items = [] - if self.tags: - for _item_tags in self.tags: - if _item_tags: - _items.append(_item_tags.to_dict()) - _dict['tags'] = _items - # override the default output from pydantic by calling `to_dict()` of each item in files (list) - _items = [] - if self.files: - for _item_files in self.files: - if _item_files: - _items.append(_item_files.to_dict()) - _dict['files'] = _items - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of MultiArrays from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "tags": [Tag.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None, - "files": [File.from_dict(_item) for _item in obj["files"]] if obj.get("files") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 01b02f834137..7c81c2a4afb4 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/name.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/name.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Name(BaseModel): """ @@ -44,67 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Name from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * OpenAPI `readOnly` fields are excluded. - * OpenAPI `readOnly` fields are excluded. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "snake_case", - "var_123_number", - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Name from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name"), - "snake_case": obj.get("snake_case"), - "property": obj.get("property"), - "123Number": obj.get("123Number") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 cb27fbf691c2..8ecb7bfd27b8 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 @@ -20,8 +20,8 @@ from datetime import date, datetime from pydantic import BaseModel, ConfigDict, StrictBool, StrictFloat, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class NullableClass(BaseModel): """ @@ -54,127 +54,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of NullableClass from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - # set to None if required_integer_prop (nullable) is None - # 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 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 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 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 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 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 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 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 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 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 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of NullableClass from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "required_integer_prop": obj.get("required_integer_prop"), - "integer_prop": obj.get("integer_prop"), - "number_prop": obj.get("number_prop"), - "boolean_prop": obj.get("boolean_prop"), - "string_prop": obj.get("string_prop"), - "date_prop": obj.get("date_prop"), - "datetime_prop": obj.get("datetime_prop"), - "array_nullable_prop": obj.get("array_nullable_prop"), - "array_and_items_nullable_prop": obj.get("array_and_items_nullable_prop"), - "array_items_nullable": obj.get("array_items_nullable"), - "object_nullable_prop": obj.get("object_nullable_prop"), - "object_and_items_nullable_prop": obj.get("object_and_items_nullable_prop"), - "object_items_nullable": obj.get("object_items_nullable") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 e73cd1509c90..a48bc3dd705e 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, field_validator from typing import Any, ClassVar, Dict, List, Optional from typing_extensions import Annotated -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class NullableProperty(BaseModel): """ @@ -53,66 +53,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of NullableProperty from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - # set to None if name (nullable) is None - # and model_fields_set contains the field - if self.name is None and "name" in self.model_fields_set: - _dict['name'] = None - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of NullableProperty from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 f74010e908bb..3753e92311f8 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictFloat from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class NumberOnly(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of NumberOnly from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of NumberOnly from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "JustNumber": obj.get("JustNumber") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 097bdd34e2be..874115c4d65a 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictBool from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ObjectToTestAdditionalProperties(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ObjectToTestAdditionalProperties from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ObjectToTestAdditionalProperties from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "property": obj.get("property") if obj.get("property") is not None else False - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 0c0cc840680b..6d5be11528f1 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.deprecated_object import DeprecatedObject -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ObjectWithDeprecatedFields(BaseModel): """ @@ -45,66 +45,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ObjectWithDeprecatedFields from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of deprecated_ref - if self.deprecated_ref: - _dict['deprecatedRef'] = self.deprecated_ref.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ObjectWithDeprecatedFields from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "uuid": obj.get("uuid"), - "id": obj.get("id"), - "deprecatedRef": DeprecatedObject.from_dict(obj["deprecatedRef"]) if obj.get("deprecatedRef") is not None else None, - "bars": obj.get("bars") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 f180178737db..71f902b5e94a 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,119 +19,27 @@ from typing import Any, List, Optional from petstore_api.models.enum_string1 import EnumString1 from petstore_api.models.enum_string2 import EnumString2 -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self ONEOFENUMSTRING_ONE_OF_SCHEMAS = ["EnumString1", "EnumString2"] -class OneOfEnumString(BaseModel): +class OneOfEnumString(RootModel[Union[EnumString1, EnumString2]]): """ oneOf enum strings """ - # data type: EnumString1 - oneof_schema_1_validator: Optional[EnumString1] = None - # data type: EnumString2 - oneof_schema_2_validator: Optional[EnumString2] = None - actual_instance: Optional[Union[EnumString1, EnumString2]] = None - one_of_schemas: Set[str] = { "EnumString1", "EnumString2" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[EnumString1, EnumString2] = Field( + ... ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - instance = OneOfEnumString.model_construct() - error_messages = [] - match = 0 - # validate data type: EnumString1 - if not isinstance(v, EnumString1): - error_messages.append(f"Error! Input type `{type(v)}` is not `EnumString1`") - else: - match += 1 - # validate data type: EnumString2 - if not isinstance(v, EnumString2): - error_messages.append(f"Error! Input type `{type(v)}` is not `EnumString2`") - else: - match += 1 - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in OneOfEnumString with oneOf schemas: EnumString1, EnumString2. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in OneOfEnumString with oneOf schemas: EnumString1, EnumString2. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # deserialize data into EnumString1 - try: - instance.actual_instance = EnumString1.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into EnumString2 - try: - instance.actual_instance = EnumString2.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into OneOfEnumString with oneOf schemas: EnumString1, EnumString2. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into OneOfEnumString with oneOf schemas: EnumString1, EnumString2. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], EnumString1, EnumString2]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") 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 12dd1ef117d2..33ab402180fc 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/order.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/order.py @@ -20,8 +20,8 @@ from datetime import datetime from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Order(BaseModel): """ @@ -31,7 +31,10 @@ class Order(BaseModel): pet_id: Optional[StrictInt] = Field(default=None, alias="petId") quantity: Optional[StrictInt] = None ship_date: Optional[datetime] = Field(default=None, alias="shipDate") - status: Optional[StrictStr] = Field(default=None, description="Order Status") + status: Optional[StatusEnum] = Field( + None, + description="Order Status" + ) complete: Optional[StrictBool] = False additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["id", "petId", "quantity", "shipDate", "status", "complete"] @@ -57,65 +60,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Order from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Order from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "petId": obj.get("petId"), - "quantity": obj.get("quantity"), - "shipDate": obj.get("shipDate"), - "status": obj.get("status"), - "complete": obj.get("complete") if obj.get("complete") is not None else False - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 5242660b636b..35cd37ef677d 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictBool, StrictFloat, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class OuterComposite(BaseModel): """ @@ -43,62 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of OuterComposite from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of OuterComposite from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "my_number": obj.get("my_number"), - "my_string": obj.get("my_string"), - "my_boolean": obj.get("my_boolean") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum.py index ac48cc0dc4d8..ee5753ebef43 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnum(StrEnum): -class OuterEnum(str, Enum): """ OuterEnum """ - """ - allowed enum values - """ + # Allowed enum values PLACED = 'placed' APPROVED = 'approved' DELIVERED = 'delivered' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnum from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_default_value.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_default_value.py index 99d6fd5fc042..7b013c460e2b 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_default_value.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_default_value.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnumDefaultValue(StrEnum): -class OuterEnumDefaultValue(str, Enum): """ OuterEnumDefaultValue """ - """ - allowed enum values - """ + # Allowed enum values PLACED = 'placed' APPROVED = 'approved' DELIVERED = 'delivered' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnumDefaultValue from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer.py index b771b7a61f55..03ee644405ed 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnumInteger(IntEnum): -class OuterEnumInteger(int, Enum): """ OuterEnumInteger """ - """ - allowed enum values - """ + # Allowed enum values NUMBER_0 = 0 NUMBER_1 = 1 NUMBER_2 = 2 @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnumInteger from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer_default_value.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer_default_value.py index 8df41b2bd320..55735ba9b13f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer_default_value.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer_default_value.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class OuterEnumIntegerDefaultValue(IntEnum): -class OuterEnumIntegerDefaultValue(int, Enum): """ OuterEnumIntegerDefaultValue """ - """ - allowed enum values - """ + # Allowed enum values NUMBER_MINUS_1 = -1 NUMBER_0 = 0 NUMBER_1 = 1 @@ -36,4 +34,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of OuterEnumIntegerDefaultValue from a JSON string""" return cls(json.loads(json_str)) - 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 f8d215a21c94..a795684bf7c9 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 @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.outer_enum import OuterEnum from petstore_api.models.outer_enum_integer import OuterEnumInteger -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class OuterObjectWithEnumProperty(BaseModel): """ @@ -44,66 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of OuterObjectWithEnumProperty from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - # set to None if str_value (nullable) is None - # 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 - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of OuterObjectWithEnumProperty from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "str_value": obj.get("str_value"), - "value": obj.get("value") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 8a30758ab8fd..a9a75ad1c0ad 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/parent.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/parent.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.inner_dict_with_property import InnerDictWithProperty -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Parent(BaseModel): """ @@ -42,72 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Parent from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in optional_dict (dict) - _field_dict = {} - if self.optional_dict: - for _key_optional_dict in self.optional_dict: - if self.optional_dict[_key_optional_dict]: - _field_dict[_key_optional_dict] = self.optional_dict[_key_optional_dict].to_dict() - _dict['optionalDict'] = _field_dict - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Parent from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "optionalDict": dict( - (_k, InnerDictWithProperty.from_dict(_v)) - for _k, _v in obj["optionalDict"].items() - ) - if obj.get("optionalDict") is not None - else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 509693dd1441..a264218563b6 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.inner_dict_with_property import InnerDictWithProperty -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ParentWithOptionalDict(BaseModel): """ @@ -42,72 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ParentWithOptionalDict from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in optional_dict (dict) - _field_dict = {} - if self.optional_dict: - for _key_optional_dict in self.optional_dict: - if self.optional_dict[_key_optional_dict]: - _field_dict[_key_optional_dict] = self.optional_dict[_key_optional_dict].to_dict() - _dict['optionalDict'] = _field_dict - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ParentWithOptionalDict from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "optionalDict": dict( - (_k, InnerDictWithProperty.from_dict(_v)) - for _k, _v in obj["optionalDict"].items() - ) - if obj.get("optionalDict") is not None - else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 48f0c2fceeb7..91af8ee6ba46 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/pet.py @@ -22,8 +22,8 @@ from typing_extensions import Annotated from petstore_api.models.category import Category from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Pet(BaseModel): """ @@ -34,7 +34,10 @@ class Pet(BaseModel): name: StrictStr 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") + status: Optional[StatusEnum] = Field( + None, + description="pet status in the store" + ) additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["id", "category", "name", "photoUrls", "tags", "status"] @@ -59,75 +62,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Pet from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of category - if self.category: - _dict['category'] = self.category.to_dict() - # override the default output from pydantic by calling `to_dict()` of each item in tags (list) - _items = [] - if self.tags: - for _item_tags in self.tags: - if _item_tags: - _items.append(_item_tags.to_dict()) - _dict['tags'] = _items - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Pet from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "category": Category.from_dict(obj["category"]) if obj.get("category") is not None else None, - "name": obj.get("name"), - "photoUrls": obj.get("photoUrls"), - "tags": [Tag.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None, - "status": obj.get("status") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 06798245b8fe..5daca5745f89 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/pig.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/pig.py @@ -19,137 +19,27 @@ from typing import Any, List, Optional from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self PIG_ONE_OF_SCHEMAS = ["BasquePig", "DanishPig"] -class Pig(BaseModel): +class Pig(RootModel[Union[BasquePig, DanishPig]]): """ Pig """ - # data type: BasquePig - oneof_schema_1_validator: Optional[BasquePig] = None - # data type: DanishPig - oneof_schema_2_validator: Optional[DanishPig] = None - actual_instance: Optional[Union[BasquePig, DanishPig]] = None - one_of_schemas: Set[str] = { "BasquePig", "DanishPig" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[BasquePig, DanishPig] = Field( + ..., discriminator="class_name" ) - - discriminator_value_class_map: Dict[str, str] = { - } - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - instance = Pig.model_construct() - error_messages = [] - match = 0 - # validate data type: BasquePig - if not isinstance(v, BasquePig): - error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`") - else: - match += 1 - # validate data type: DanishPig - if not isinstance(v, DanishPig): - error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`") - else: - match += 1 - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # use oneOf discriminator to lookup the data type - _data_type = json.loads(json_str).get("className") - if not _data_type: - raise ValueError("Failed to lookup data type from the field `className` in the input.") - - # check if data type is `BasquePig` - if _data_type == "BasquePig": - instance.actual_instance = BasquePig.from_json(json_str) - return instance - - # check if data type is `DanishPig` - if _data_type == "DanishPig": - instance.actual_instance = DanishPig.from_json(json_str) - return instance - - # deserialize data into BasquePig - try: - instance.actual_instance = BasquePig.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into DanishPig - try: - instance.actual_instance = DanishPig.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], BasquePig, DanishPig]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/pony_sizes.py b/samples/openapi3/client/petstore/python/petstore_api/models/pony_sizes.py index 74efce9a4d06..83152c982e7b 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/pony_sizes.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/pony_sizes.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.type import Type -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PonySizes(BaseModel): """ @@ -42,60 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PonySizes from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PonySizes from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "type": obj.get("type") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/poop_cleaning.py b/samples/openapi3/client/petstore/python/petstore_api/models/poop_cleaning.py index 76eb72a941bf..37e10750fad4 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/poop_cleaning.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/poop_cleaning.py @@ -19,15 +19,21 @@ from pydantic import BaseModel, ConfigDict, StrictStr, field_validator from typing import Any, ClassVar, Dict, List -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PoopCleaning(BaseModel): """ PoopCleaning """ # noqa: E501 - task_name: StrictStr - function_name: StrictStr + task_name: Literal['cleaning'] = Field( + ..., + description="task_name of the PoopCleaning" + ) + function_name: Literal['care'] = Field( + ..., + description="function_name of the PoopCleaning" + ) content: StrictStr additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -57,62 +63,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PoopCleaning from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PoopCleaning from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "task_name": obj.get("task_name"), - "function_name": obj.get("function_name"), - "content": obj.get("content") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/primitive_string.py b/samples/openapi3/client/petstore/python/petstore_api/models/primitive_string.py index f7a971519f2f..ee3c056b5623 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/primitive_string.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/primitive_string.py @@ -20,8 +20,8 @@ from pydantic import ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.base_discriminator import BaseDiscriminator -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PrimitiveString(BaseDiscriminator): """ @@ -42,61 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PrimitiveString from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PrimitiveString from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_typeName": obj.get("_typeName"), - "_value": obj.get("_value") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/property_map.py b/samples/openapi3/client/petstore/python/petstore_api/models/property_map.py index 0da2a14293de..4a43d9e24edc 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/property_map.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/property_map.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.tag import Tag -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PropertyMap(BaseModel): """ @@ -42,72 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PropertyMap from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in some_data (dict) - _field_dict = {} - if self.some_data: - for _key_some_data in self.some_data: - if self.some_data[_key_some_data]: - _field_dict[_key_some_data] = self.some_data[_key_some_data].to_dict() - _dict['some_data'] = _field_dict - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PropertyMap from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "some_data": dict( - (_k, Tag.from_dict(_v)) - for _k, _v in obj["some_data"].items() - ) - if obj.get("some_data") is not None - else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 d07aef22cd82..b6d487528a02 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class PropertyNameCollision(BaseModel): """ @@ -43,62 +43,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of PropertyNameCollision from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of PropertyNameCollision from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_type": obj.get("_type"), - "type": obj.get("type"), - "type_": obj.get("type_") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 5a4155fcfa13..603220f24d18 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class ReadOnlyFirst(BaseModel): """ @@ -42,63 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of ReadOnlyFirst from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * OpenAPI `readOnly` fields are excluded. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "bar", - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of ReadOnlyFirst from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "bar": obj.get("bar"), - "baz": obj.get("baz") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/second_circular_all_of_ref.py b/samples/openapi3/client/petstore/python/petstore_api/models/second_circular_all_of_ref.py index 13d6327314c3..990b82832e77 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/second_circular_all_of_ref.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/second_circular_all_of_ref.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SecondCircularAllOfRef(BaseModel): """ @@ -42,69 +42,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SecondCircularAllOfRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each item in circular_all_of_ref (list) - _items = [] - if self.circular_all_of_ref: - for _item_circular_all_of_ref in self.circular_all_of_ref: - if _item_circular_all_of_ref: - _items.append(_item_circular_all_of_ref.to_dict()) - _dict['circularAllOfRef'] = _items - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SecondCircularAllOfRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "_name": obj.get("_name"), - "circularAllOfRef": [CircularAllOfRef.from_dict(_item) for _item in obj["circularAllOfRef"]] if obj.get("circularAllOfRef") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj from petstore_api.models.circular_all_of_ref import CircularAllOfRef # TODO: Rewrite to not use raise_errors 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 701e0dccaacf..a63609d87b58 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SecondRef(BaseModel): """ @@ -42,65 +42,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SecondRef from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of circular_ref - if self.circular_ref: - _dict['circular_ref'] = self.circular_ref.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SecondRef from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "category": obj.get("category"), - "circular_ref": CircularReferenceModel.from_dict(obj["circular_ref"]) if obj.get("circular_ref") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj from petstore_api.models.circular_reference_model import CircularReferenceModel # TODO: Rewrite to not use raise_errors 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 0273b10dada6..52b57d85f2f0 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SelfReferenceModel(BaseModel): """ @@ -42,65 +42,6 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SelfReferenceModel from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of nested - if self.nested: - _dict['nested'] = self.nested.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SelfReferenceModel from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "nested": DummyModel.from_dict(obj["nested"]) if obj.get("nested") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj from petstore_api.models.dummy_model import DummyModel # TODO: Rewrite to not use raise_errors diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/single_ref_type.py b/samples/openapi3/client/petstore/python/petstore_api/models/single_ref_type.py index 91ab07e2535c..32b33b2271fe 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/single_ref_type.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/single_ref_type.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class SingleRefType(StrEnum): -class SingleRefType(str, Enum): """ SingleRefType """ - """ - allowed enum values - """ + # Allowed enum values ADMIN = 'admin' USER = 'user' @@ -34,4 +32,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of SingleRefType from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/special_character_enum.py b/samples/openapi3/client/petstore/python/petstore_api/models/special_character_enum.py index 1d85fd148d4b..bf8d0a25df90 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/special_character_enum.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/special_character_enum.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class SpecialCharacterEnum(StrEnum): -class SpecialCharacterEnum(str, Enum): """ SpecialCharacterEnum """ - """ - allowed enum values - """ + # Allowed enum values ENUM_456 = '456' ENUM_123ABC = '123abc' UNDERSCORE = '_' @@ -42,4 +40,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of SpecialCharacterEnum from a JSON string""" return cls(json.loads(json_str)) - 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 84686054875a..2b034d4781fc 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SpecialModelName(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SpecialModelName from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SpecialModelName from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "$special[property.name]": obj.get("$special[property.name]") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 e43761d33dfc..009e9faef3e5 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 @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.category import Category -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class SpecialName(BaseModel): """ @@ -29,7 +29,10 @@ class SpecialName(BaseModel): """ # noqa: E501 var_property: Optional[StrictInt] = Field(default=None, alias="property") var_async: Optional[Category] = Field(default=None, alias="async") - var_schema: Optional[StrictStr] = Field(default=None, description="pet status in the store", alias="schema") + var_schema: Optional[Var_schemaEnum] = Field( + None, + description="pet status in the store" + ) additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["property", "async", "schema"] @@ -54,65 +57,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of SpecialName from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of var_async - if self.var_async: - _dict['async'] = self.var_async.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of SpecialName from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "property": obj.get("property"), - "async": Category.from_dict(obj["async"]) if obj.get("async") is not None else None, - "schema": obj.get("schema") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 b3893aecb683..83d45ff62847 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/tag.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/tag.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Tag(BaseModel): """ @@ -42,61 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Tag from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Tag from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/task.py b/samples/openapi3/client/petstore/python/petstore_api/models/task.py index a8e0fa11ff84..ce18bee68e6c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/task.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/task.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List from uuid import UUID from petstore_api.models.task_activity import TaskActivity -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Task(BaseModel): """ @@ -44,64 +44,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Task from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of activity - if self.activity: - _dict['activity'] = self.activity.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Task from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "activity": TaskActivity.from_dict(obj["activity"]) if obj.get("activity") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/task_activity.py b/samples/openapi3/client/petstore/python/petstore_api/models/task_activity.py index cc1e1fc5a60f..d7b8b1e71af3 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/task_activity.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/task_activity.py @@ -20,132 +20,27 @@ from petstore_api.models.bathing import Bathing from petstore_api.models.feeding import Feeding from petstore_api.models.poop_cleaning import PoopCleaning -from pydantic import StrictStr, Field -from typing import Union, List, Set, Optional, Dict -from typing_extensions import Literal, Self +from pydantic import BaseModel, ConfigDict, StrictStr, Field, RootModel, model_validator +from typing import Any, Union, List, Set, Optional, Dict, Union, Literal, Self TASKACTIVITY_ONE_OF_SCHEMAS = ["Bathing", "Feeding", "PoopCleaning"] -class TaskActivity(BaseModel): +class TaskActivity(RootModel[Union[Bathing, Feeding, PoopCleaning]]): """ TaskActivity """ - # data type: PoopCleaning - oneof_schema_1_validator: Optional[PoopCleaning] = None - # data type: Feeding - oneof_schema_2_validator: Optional[Feeding] = None - # data type: Bathing - oneof_schema_3_validator: Optional[Bathing] = None - actual_instance: Optional[Union[Bathing, Feeding, PoopCleaning]] = None - one_of_schemas: Set[str] = { "Bathing", "Feeding", "PoopCleaning" } - - model_config = ConfigDict( - validate_assignment=True, - protected_namespaces=(), + root: Union[Bathing, Feeding, PoopCleaning] = Field( + ... ) - - def __init__(self, *args, **kwargs) -> None: - if args: - if len(args) > 1: - raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") - if kwargs: - raise ValueError("If a position argument is used, keyword arguments cannot be used.") - super().__init__(actual_instance=args[0]) - else: - super().__init__(**kwargs) - - @field_validator('actual_instance') - def actual_instance_must_validate_oneof(cls, v): - instance = TaskActivity.model_construct() - error_messages = [] - match = 0 - # validate data type: PoopCleaning - if not isinstance(v, PoopCleaning): - error_messages.append(f"Error! Input type `{type(v)}` is not `PoopCleaning`") - else: - match += 1 - # validate data type: Feeding - if not isinstance(v, Feeding): - error_messages.append(f"Error! Input type `{type(v)}` is not `Feeding`") - else: - match += 1 - # validate data type: Bathing - if not isinstance(v, Bathing): - error_messages.append(f"Error! Input type `{type(v)}` is not `Bathing`") - else: - match += 1 - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when setting `actual_instance` in TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when setting `actual_instance` in TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - else: - return v - - @classmethod - def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: - return cls.from_json(json.dumps(obj)) - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Returns the object represented by the json string""" - instance = cls.model_construct() - error_messages = [] - match = 0 - - # deserialize data into PoopCleaning - try: - instance.actual_instance = PoopCleaning.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into Feeding - try: - instance.actual_instance = Feeding.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - # deserialize data into Bathing - try: - instance.actual_instance = Bathing.from_json(json_str) - match += 1 - except (ValidationError, ValueError) as e: - error_messages.append(str(e)) - - if match > 1: - # more than 1 match - raise ValueError("Multiple matches found when deserializing the JSON string into TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - elif match == 0: - # no match - raise ValueError("No match found when deserializing the JSON string into TaskActivity with oneOf schemas: Bathing, Feeding, PoopCleaning. Details: " + ", ".join(error_messages)) - else: - return instance - - def to_json(self) -> str: - """Returns the JSON representation of the actual instance""" - if self.actual_instance is None: - return "null" - - if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): - return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) - - def to_dict(self) -> Optional[Union[Dict[str, Any], Bathing, Feeding, PoopCleaning]]: - """Returns the dict representation of the actual instance""" - if self.actual_instance is None: - return None - - if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): - return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance - - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) - + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ + if name in self.__dict__: + return super().__getattribute__(name) + if hasattr(self, 'root') and self.root is not None: + return getattr(self.root, name) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/test_enum.py b/samples/openapi3/client/petstore/python/petstore_api/models/test_enum.py index 8eae227a84e9..331f0fd597bd 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/test_enum.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/test_enum.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class TestEnum(StrEnum): -class TestEnum(str, Enum): """ TestEnum """ - """ - allowed enum values - """ + # Allowed enum values ONE = 'ONE' TWO = 'TWO' THREE = 'THREE' @@ -36,4 +34,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of TestEnum from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/test_enum_with_default.py b/samples/openapi3/client/petstore/python/petstore_api/models/test_enum_with_default.py index 9304d3ab8497..0f3d74610b96 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/test_enum_with_default.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/test_enum_with_default.py @@ -14,18 +14,16 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self +class TestEnumWithDefault(StrEnum): -class TestEnumWithDefault(str, Enum): """ TestEnumWithDefault """ - """ - allowed enum values - """ + # Allowed enum values EIN = 'EIN' ZWEI = 'ZWEI' DREI = 'DREI' @@ -35,4 +33,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of TestEnumWithDefault from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/test_error_responses_with_model400_response.py b/samples/openapi3/client/petstore/python/petstore_api/models/test_error_responses_with_model400_response.py index f5fe068c9111..b9aba57407ee 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/test_error_responses_with_model400_response.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/test_error_responses_with_model400_response.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestErrorResponsesWithModel400Response(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel400Response from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel400Response from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "reason400": obj.get("reason400") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/test_error_responses_with_model404_response.py b/samples/openapi3/client/petstore/python/petstore_api/models/test_error_responses_with_model404_response.py index 39e6c512ed3e..c71e043f9977 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/test_error_responses_with_model404_response.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/test_error_responses_with_model404_response.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestErrorResponsesWithModel404Response(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel404Response from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestErrorResponsesWithModel404Response from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "reason404": obj.get("reason404") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 7b93d84864f2..ef3e742d900f 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 @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestInlineFreeformAdditionalPropertiesRequest from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestInlineFreeformAdditionalPropertiesRequest from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "someProperty": obj.get("someProperty") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/test_model_with_enum_default.py b/samples/openapi3/client/petstore/python/petstore_api/models/test_model_with_enum_default.py index 4bff5e699a37..a0144b2722d6 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/test_model_with_enum_default.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/test_model_with_enum_default.py @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.test_enum import TestEnum from petstore_api.models.test_enum_with_default import TestEnumWithDefault -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestModelWithEnumDefault(BaseModel): """ @@ -32,7 +32,10 @@ class TestModelWithEnumDefault(BaseModel): test_string: Optional[StrictStr] = None test_enum_with_default: Optional[TestEnumWithDefault] = TestEnumWithDefault.ZWEI test_string_with_default: Optional[StrictStr] = 'ahoy matey' - test_inline_defined_enum_with_default: Optional[StrictStr] = 'B' + test_inline_defined_enum_with_default: Optional[Test_inline_defined_enum_with_defaultEnum] = Field( + None, + description="test_inline_defined_enum_with_default of the TestModelWithEnumDefault" + ) additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["test_enum", "test_string", "test_enum_with_default", "test_string_with_default", "test_inline_defined_enum_with_default"] @@ -57,64 +60,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestModelWithEnumDefault from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestModelWithEnumDefault from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "test_enum": obj.get("test_enum"), - "test_string": obj.get("test_string"), - "test_enum_with_default": obj.get("test_enum_with_default") if obj.get("test_enum_with_default") is not None else TestEnumWithDefault.ZWEI, - "test_string_with_default": obj.get("test_string_with_default") if obj.get("test_string_with_default") is not None else 'ahoy matey', - "test_inline_defined_enum_with_default": obj.get("test_inline_defined_enum_with_default") if obj.get("test_inline_defined_enum_with_default") is not None else 'B' - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/test_object_for_multipart_requests_request_marker.py b/samples/openapi3/client/petstore/python/petstore_api/models/test_object_for_multipart_requests_request_marker.py index c31d72482d59..add356ef35d9 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/test_object_for_multipart_requests_request_marker.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/test_object_for_multipart_requests_request_marker.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class TestObjectForMultipartRequestsRequestMarker(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of TestObjectForMultipartRequestsRequestMarker from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of TestObjectForMultipartRequestsRequestMarker from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 c2dab004fe1a..4ea2db55add2 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/tiger.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/tiger.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class Tiger(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of Tiger from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of Tiger from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "skill": obj.get("skill") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/type.py b/samples/openapi3/client/petstore/python/petstore_api/models/type.py index 35a847de894f..3ab767b6125b 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/type.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/type.py @@ -14,18 +14,17 @@ from __future__ import annotations import json -from enum import Enum -from typing_extensions import Self +from enum import Enum, StrEnum, IntEnum +from typing import Self -class Type(int, Enum): +class Type(Enum): + """ Type """ - """ - allowed enum values - """ + # Allowed enum values NUMBER_2_DOT_0 = 2.0 NUMBER_1_DOT_0 = 1.0 NUMBER_0_DOT_5 = 0.5 @@ -36,4 +35,3 @@ def from_json(cls, json_str: str) -> Self: """Create an instance of Type from a JSON string""" return cls(json.loads(json_str)) - diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py b/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py index e5b5cb4ddeda..715c752174a9 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py @@ -20,8 +20,8 @@ from pydantic import BaseModel, ConfigDict, Field from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.creature_info import CreatureInfo -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class UnnamedDictWithAdditionalModelListProperties(BaseModel): """ @@ -42,76 +42,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalModelListProperties from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of each value in dict_property (dict of array) - _field_dict_of_array = {} - if self.dict_property: - for _key_dict_property in self.dict_property: - if self.dict_property[_key_dict_property] is not None: - _field_dict_of_array[_key_dict_property] = [ - _item.to_dict() for _item in self.dict_property[_key_dict_property] - ] - _dict['dictProperty'] = _field_dict_of_array - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalModelListProperties from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "dictProperty": dict( - (_k, - [CreatureInfo.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("dictProperty", {}).items() - ) - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py b/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py index f4c7625325c8..e870fc2c8c5a 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class UnnamedDictWithAdditionalStringListProperties(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalStringListProperties from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of UnnamedDictWithAdditionalStringListProperties from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "dictProperty": obj.get("dictProperty") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/upload_file_with_additional_properties_request_object.py b/samples/openapi3/client/petstore/python/petstore_api/models/upload_file_with_additional_properties_request_object.py index 6d79131bfe79..ce2388786f9e 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/upload_file_with_additional_properties_request_object.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/upload_file_with_additional_properties_request_object.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class UploadFileWithAdditionalPropertiesRequestObject(BaseModel): """ @@ -41,60 +41,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of UploadFileWithAdditionalPropertiesRequestObject from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of UploadFileWithAdditionalPropertiesRequestObject from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "name": obj.get("name") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 ceeb6d4ae54c..c39fb5355ec7 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/user.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/user.py @@ -19,8 +19,8 @@ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class User(BaseModel): """ @@ -48,67 +48,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of User from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of User from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "id": obj.get("id"), - "username": obj.get("username"), - "firstName": obj.get("firstName"), - "lastName": obj.get("lastName"), - "email": obj.get("email"), - "password": obj.get("password"), - "phone": obj.get("phone"), - "userStatus": obj.get("userStatus") - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj 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 eb7e90879e90..48bd6d586129 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 @@ -21,8 +21,8 @@ from typing import Any, ClassVar, Dict, List, Optional from petstore_api.models.one_of_enum_string import OneOfEnumString from petstore_api.models.pig import Pig -from typing import Optional, Set -from typing_extensions import Self +from typing import Optional, Set, Literal, Self +from pydantic import Field class WithNestedOneOf(BaseModel): """ @@ -45,68 +45,5 @@ def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.model_dump(by_alias=True)) - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) - - @classmethod - def from_json(cls, json_str: str) -> Optional[Self]: - """Create an instance of WithNestedOneOf from a JSON string""" - return cls.from_dict(json.loads(json_str)) - - def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `None` is only added to the output dict for nullable fields that - were set at model initialization. Other fields with value `None` - are ignored. - * Fields in `self.additional_properties` are added to the output dict. - """ - excluded_fields: Set[str] = set([ - "additional_properties", - ]) - - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - # override the default output from pydantic by calling `to_dict()` of nested_pig - if self.nested_pig: - _dict['nested_pig'] = self.nested_pig.to_dict() - # override the default output from pydantic by calling `to_dict()` of nested_oneof_enum_string - if self.nested_oneof_enum_string: - _dict['nested_oneof_enum_string'] = self.nested_oneof_enum_string.to_dict() - # puts key-value pairs in additional_properties in the top level - if self.additional_properties is not None: - for _key, _value in self.additional_properties.items(): - _dict[_key] = _value - - return _dict - - @classmethod - def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: - """Create an instance of WithNestedOneOf from a dict""" - if obj is None: - return None - - if not isinstance(obj, dict): - return cls.model_validate(obj) - - _obj = cls.model_validate({ - "size": obj.get("size"), - "nested_pig": Pig.from_dict(obj["nested_pig"]) if obj.get("nested_pig") is not None else None, - "nested_oneof_enum_string": OneOfEnumString.from_dict(obj["nested_oneof_enum_string"]) if obj.get("nested_oneof_enum_string") is not None else None - }) - # store additional fields in additional_properties - for _key in obj.keys(): - if _key not in cls.__properties: - _obj.additional_properties[_key] = obj.get(_key) - - return _obj diff --git a/samples/openapi3/client/petstore/python/pyproject.toml b/samples/openapi3/client/petstore/python/pyproject.toml index eed3d1a1ac49..a4ee37d24b50 100644 --- a/samples/openapi3/client/petstore/python/pyproject.toml +++ b/samples/openapi3/client/petstore/python/pyproject.toml @@ -8,7 +8,7 @@ authors = [ license = { text = "Apache-2.0" } readme = "README.md" keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"] -requires-python = ">=3.9" +requires-python = ">=3.11" dependencies = [ "urllib3 (>=2.1.0,<3.0.0)", diff --git a/samples/openapi3/client/petstore/python/setup.py b/samples/openapi3/client/petstore/python/setup.py index 35e7395c2b0c..5f62e953eef2 100755 --- a/samples/openapi3/client/petstore/python/setup.py +++ b/samples/openapi3/client/petstore/python/setup.py @@ -1,5 +1,3 @@ -# coding: utf-8 - """ OpenAPI Petstore @@ -12,6 +10,7 @@ """ # noqa: E501 + from setuptools import setup, find_packages # noqa: H301 # To install the library, run the following @@ -22,7 +21,7 @@ # http://pypi.python.org/pypi/setuptools NAME = "petstore-api" VERSION = "1.0.0" -PYTHON_REQUIRES = ">= 3.9" +PYTHON_REQUIRES = ">= 3.11" REQUIRES = [ "urllib3 >= 2.1.0, < 3.0.0", "python-dateutil >= 2.8.2",