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..2593a9ac378b 100644 --- a/modules/openapi-generator/src/main/resources/python/model_anyof.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_anyof.mustache @@ -1,177 +1,39 @@ from __future__ import annotations -from inspect import getfullargspec -import json -import pprint -import re # noqa: F401 {{#vendorExtensions.x-py-other-imports}} {{{.}}} {{/vendorExtensions.x-py-other-imports}} {{#vendorExtensions.x-py-model-imports}} {{{.}}} {{/vendorExtensions.x-py-model-imports}} +from pydantic import Field, RootModel from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict from typing_extensions import Literal, Self -from pydantic import Field {{#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}} """ + root: Union[{{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}{{#isNullable}}, None{{/isNullable}}] = Field( + {{#isNullable}}None{{/isNullable}}{{^isNullable}}...{{/isNullable}}{{#discriminator}}{{/discriminator}} + ) -{{#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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..5cc9d273dfb3 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({{#lambda.snakecase}}{{classname}}{{/lambda.snakecase}}_instance.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_generic.mustache b/modules/openapi-generator/src/main/resources/python/model_generic.mustache index 70804d448de0..72c10fba004c 100644 --- a/modules/openapi-generator/src/main/resources/python/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_generic.mustache @@ -10,7 +10,8 @@ import json {{{.}}} {{/vendorExtensions.x-py-model-imports}} from typing import Optional, Set -from typing_extensions import Self +from typing_extensions import Self, Literal +from pydantic import Field {{#hasChildren}} {{#discriminator}} @@ -28,7 +29,41 @@ 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}}", + alias="{{{baseName}}}" + ) + {{/-last}} + {{^-last}} + {{! Multiple value enum - use Literal for inline enums }} + {{name}}: {{#required}}Literal[{{#allowableValues}}{{#enumVars}}{{#isString}}{{{value}}}{{/isString}}{{^isString}}{{{value}}}{{/isString}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]{{/required}}{{^required}}Optional[Literal[{{#allowableValues}}{{#enumVars}}{{#isString}}{{{value}}}{{/isString}}{{^isString}}{{{value}}}{{/isString}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]]{{/required}} = Field( + {{#required}}...{{/required}}{{^required}}None{{/required}}, + description="{{description}}{{^description}}{{{name}}} of the {{classname}}{{/description}}" + ) + {{/-last}} + {{/-first}} + {{/values}} + {{/isArray}} + {{#isArray}} + {{! Array enum - use List[Literal] }} + {{name}}: {{#required}}List[Literal[{{#allowableValues}}{{#enumVars}}{{#isString}}{{{value}}}{{/isString}}{{^isString}}{{{value}}}{{/isString}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]]{{/required}}{{^required}}Optional[List[Literal[{{#allowableValues}}{{#enumVars}}{{#isString}}{{{value}}}{{/isString}}{{^isString}}{{{value}}}{{/isString}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]]]{{/required}} = Field( + {{#required}}...{{/required}}{{^required}}None{{/required}}, + description="{{description}}{{^description}}{{{name}}} of the {{classname}}{{/description}}" + ) + {{/isArray}} + {{/allowableValues}} + {{/isEnum}} + {{^isEnum}} {{name}}: {{{vendorExtensions.x-py-typing}}} + {{/isEnum}} {{/vars}} {{#isAdditionalPropertiesTrue}} additional_properties: Dict[str, Any] = {} @@ -76,18 +111,18 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{#isContainer}} {{#isArray}} for i in value: - if i not in set([{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]): - raise ValueError("each list item must be one of ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})") + if i not in set([{{#allowableValues}}{{#enumVars}}{{#isString}}{{{value}}}{{/isString}}{{^isString}}{{{value}}}{{/isString}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]): + raise ValueError("each list item must be one of ({{#allowableValues}}{{#enumVars}}{{#isString}}{{{value}}}{{/isString}}{{^isString}}{{{value}}}{{/isString}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})") {{/isArray}} {{#isMap}} for i in value.values(): - if i not in set([{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]): - raise ValueError("dict values must be one of enum values ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})") + if i not in set([{{#allowableValues}}{{#enumVars}}{{#isString}}{{{value}}}{{/isString}}{{^isString}}{{{value}}}{{/isString}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]): + raise ValueError("dict values must be one of enum values ({{#allowableValues}}{{#enumVars}}{{#isString}}{{{value}}}{{/isString}}{{^isString}}{{{value}}}{{/isString}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})") {{/isMap}} {{/isContainer}} {{^isContainer}} - if value not in set([{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]): - raise ValueError("must be one of enum values ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})") + if value not in set([{{#allowableValues}}{{#enumVars}}{{#isString}}{{{value}}}{{/isString}}{{^isString}}{{{value}}}{{/isString}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]): + raise ValueError("must be one of enum values ({{#allowableValues}}{{#enumVars}}{{#isString}}{{{value}}}{{/isString}}{{^isString}}{{{value}}}{{/isString}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})") {{/isContainer}} return value {{/isEnum}} @@ -121,278 +156,28 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{/discriminator}} {{/hasChildren}} - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_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}} + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) - 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 + def from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) - if not isinstance(obj, dict): - return cls.model_validate(obj) + def to_dict(self) -> Dict[str, Any]: + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - {{#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) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - {{/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) + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - {{/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..ab97fda35dea 100644 --- a/modules/openapi-generator/src/main/resources/python/model_oneof.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_oneof.mustache @@ -1,204 +1,39 @@ from __future__ import annotations -import json -import pprint {{#vendorExtensions.x-py-other-imports}} {{{.}}} {{/vendorExtensions.x-py-other-imports}} {{#vendorExtensions.x-py-model-imports}} {{{.}}} {{/vendorExtensions.x-py-model-imports}} -from pydantic import StrictStr, Field +from pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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}}{{#isNullable}}, None{{/isNullable}}] = Field( + {{#isNullable}}None{{/isNullable}}{{^isNullable}}...{{/isNullable}}{{#discriminator}}{{/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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Bird.md b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/docs/Bird.md index e61d8458c978..b288e5d280c3 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_instance.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..ca4428075dc4 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_instance.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..662bd88a9bec 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(data_query_instance.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..a2a4d3703f37 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(default_value_instance.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..f1883e65d024 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(number_properties_only_instance.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..026ef653d443 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_instance.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..c72cdf145b32 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_instance.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..3abb8b678e2c 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_instance.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..0c5dee4f8f69 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(test_form_object_multipart_request_marker_instance.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..9cda4fca20c8 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(test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance.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..6af94f3aed1a 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(test_query_style_form_explode_true_array_string_query_object_parameter_instance.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/models/bird.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/bird.py index 9bb24b9e6d80..ab504ea13788 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 @@ -21,7 +21,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_extensions import Self, Literal +from pydantic import Field class Bird(BaseModel): """ @@ -38,58 +39,27 @@ class Bird(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b5d1feff8954 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 @@ -21,7 +21,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_extensions import Self, Literal +from pydantic import Field class Category(BaseModel): """ @@ -38,58 +39,27 @@ class Category(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..469701d7adc1 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 @@ -23,7 +23,8 @@ 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_extensions import Self, Literal +from pydantic import Field class DataQuery(Query): """ @@ -41,61 +42,27 @@ class DataQuery(Query): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..3afdd3cf4086 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 @@ -22,14 +22,18 @@ 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_extensions import Self, Literal +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_enum_default: Optional[List[Literal['success', 'failure', 'unclassified']]] = Field( + None, + description="array_string_enum_default of the DefaultValue" + ) array_string_default: Optional[List[StrictStr]] = None array_integer_default: Optional[List[StrictInt]] = None array_string: Optional[List[StrictStr]] = None @@ -56,79 +60,27 @@ def array_string_enum_default_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..54924629f13c 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class NumberPropertiesOnly(BaseModel): """ @@ -40,59 +41,27 @@ class NumberPropertiesOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d1447ef248bf 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 @@ -23,7 +23,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Pet(BaseModel): """ @@ -34,7 +35,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[Literal['available', 'pending', 'sold']] = Field( + None, + description="pet status in the store" + ) __properties: ClassVar[List[str]] = ["id", "name", "category", "photoUrls", "tags", "status"] @field_validator('status') @@ -54,72 +58,27 @@ def status_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..a9db31353813 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 @@ -21,14 +21,18 @@ 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_extensions import Self, Literal +from pydantic import Field class Query(BaseModel): """ Query """ # noqa: E501 id: Optional[StrictInt] = Field(default=None, description="Query") - outcomes: Optional[List[StrictStr]] = None + outcomes: Optional[List[Literal['SUCCESS', 'FAILURE', 'SKIPPED']]] = Field( + None, + description="outcomes of the Query" + ) __properties: ClassVar[List[str]] = ["id", "outcomes"] @field_validator('outcomes') @@ -49,42 +53,27 @@ def outcomes_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/tag.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/tag.py index 5ec177ca73ae..ec088768dc6e 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 @@ -21,7 +21,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_extensions import Self, Literal +from pydantic import Field class Tag(BaseModel): """ @@ -38,58 +39,27 @@ class Tag(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6fc587105874 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 @@ -21,7 +21,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_extensions import Self, Literal +from pydantic import Field class TestFormObjectMultipartRequestMarker(BaseModel): """ @@ -37,57 +38,27 @@ class TestFormObjectMultipartRequestMarker(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..52a77611a10f 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 @@ -21,7 +21,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_extensions import Self, Literal +from pydantic import Field class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseModel): """ @@ -40,60 +41,27 @@ class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseMod ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..688824243b4e 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 @@ -21,7 +21,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_extensions import Self, Literal +from pydantic import Field class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel): """ @@ -37,57 +38,27 @@ class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/docs/Bird.md b/samples/client/echo_api/python/docs/Bird.md index e61d8458c978..b288e5d280c3 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_instance.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..ca4428075dc4 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_instance.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..662bd88a9bec 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(data_query_instance.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..a2a4d3703f37 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(default_value_instance.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..f1883e65d024 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(number_properties_only_instance.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..026ef653d443 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_instance.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..c72cdf145b32 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_instance.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..3abb8b678e2c 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_instance.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..0c5dee4f8f69 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(test_form_object_multipart_request_marker_instance.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..9cda4fca20c8 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(test_query_style_deep_object_explode_true_object_all_of_query_object_parameter_instance.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..6af94f3aed1a 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(test_query_style_form_explode_true_array_string_query_object_parameter_instance.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/models/bird.py b/samples/client/echo_api/python/openapi_client/models/bird.py index 9f0dd625119d..ab504ea13788 100644 --- a/samples/client/echo_api/python/openapi_client/models/bird.py +++ b/samples/client/echo_api/python/openapi_client/models/bird.py @@ -21,7 +21,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_extensions import Self, Literal +from pydantic import Field class Bird(BaseModel): """ @@ -38,53 +39,27 @@ class Bird(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b5d1feff8954 100644 --- a/samples/client/echo_api/python/openapi_client/models/category.py +++ b/samples/client/echo_api/python/openapi_client/models/category.py @@ -21,7 +21,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_extensions import Self, Literal +from pydantic import Field class Category(BaseModel): """ @@ -38,53 +39,27 @@ class Category(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..469701d7adc1 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 @@ -23,7 +23,8 @@ 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_extensions import Self, Literal +from pydantic import Field class DataQuery(Query): """ @@ -41,56 +42,27 @@ class DataQuery(Query): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..3afdd3cf4086 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 @@ -22,14 +22,18 @@ 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_extensions import Self, Literal +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_enum_default: Optional[List[Literal['success', 'failure', 'unclassified']]] = Field( + None, + description="array_string_enum_default of the DefaultValue" + ) array_string_default: Optional[List[StrictStr]] = None array_integer_default: Optional[List[StrictInt]] = None array_string: Optional[List[StrictStr]] = None @@ -56,74 +60,27 @@ def array_string_enum_default_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..54924629f13c 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class NumberPropertiesOnly(BaseModel): """ @@ -40,54 +41,27 @@ class NumberPropertiesOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d1447ef248bf 100644 --- a/samples/client/echo_api/python/openapi_client/models/pet.py +++ b/samples/client/echo_api/python/openapi_client/models/pet.py @@ -23,7 +23,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Pet(BaseModel): """ @@ -34,7 +35,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[Literal['available', 'pending', 'sold']] = Field( + None, + description="pet status in the store" + ) __properties: ClassVar[List[str]] = ["id", "name", "category", "photoUrls", "tags", "status"] @field_validator('status') @@ -54,67 +58,27 @@ def status_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..a9db31353813 100644 --- a/samples/client/echo_api/python/openapi_client/models/query.py +++ b/samples/client/echo_api/python/openapi_client/models/query.py @@ -21,14 +21,18 @@ 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_extensions import Self, Literal +from pydantic import Field class Query(BaseModel): """ Query """ # noqa: E501 id: Optional[StrictInt] = Field(default=None, description="Query") - outcomes: Optional[List[StrictStr]] = None + outcomes: Optional[List[Literal['SUCCESS', 'FAILURE', 'SKIPPED']]] = Field( + None, + description="outcomes of the Query" + ) __properties: ClassVar[List[str]] = ["id", "outcomes"] @field_validator('outcomes') @@ -49,42 +53,27 @@ def outcomes_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/tag.py b/samples/client/echo_api/python/openapi_client/models/tag.py index feec4b3f31cc..ec088768dc6e 100644 --- a/samples/client/echo_api/python/openapi_client/models/tag.py +++ b/samples/client/echo_api/python/openapi_client/models/tag.py @@ -21,7 +21,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_extensions import Self, Literal +from pydantic import Field class Tag(BaseModel): """ @@ -38,53 +39,27 @@ class Tag(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6fc587105874 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 @@ -21,7 +21,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_extensions import Self, Literal +from pydantic import Field class TestFormObjectMultipartRequestMarker(BaseModel): """ @@ -37,52 +38,27 @@ class TestFormObjectMultipartRequestMarker(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..52a77611a10f 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 @@ -21,7 +21,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_extensions import Self, Literal +from pydantic import Field class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseModel): """ @@ -40,55 +41,27 @@ class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseMod ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..688824243b4e 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 @@ -21,7 +21,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_extensions import Self, Literal +from pydantic import Field class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel): """ @@ -37,52 +38,27 @@ class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesAnyType.md b/samples/openapi3/client/petstore/python-aiohttp/docs/AdditionalPropertiesAnyType.md index 314cba3a614c..b94c1e6d7d19 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(additional_properties_any_type_instance.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..4c880d6853e8 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(additional_properties_class_instance.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..bf6743709338 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(additional_properties_object_instance.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..1cb2a02f7584 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(additional_properties_with_description_only_instance.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..88cb95097517 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(all_of_super_model_instance.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..dd0f755dfe65 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(all_of_with_single_ref_instance.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..fcded75f52be 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_instance.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..02aab883b2b0 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(any_of_color_instance.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..db2878121f29 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(any_of_pig_instance.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..e8274d8fbb52 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(array_of_array_of_model_instance.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..8931a1c7e467 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(array_of_array_of_number_only_instance.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..a709583be699 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(array_of_number_only_instance.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..a99eb056c5ca 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(array_test_instance.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..0482396cbcf8 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(base_discriminator_instance.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..9844d05b3740 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(basque_pig_instance.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..2c8d8332629b 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_instance.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..55fcc0c01cb2 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_instance.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..0845d68bd487 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_instance.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..8a14791c7925 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_instance.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..f937a53cfe3c 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(circular_all_of_ref_instance.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..9a39f46e5d7d 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(circular_reference_model_instance.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..50fbfefa7661 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(class_model_instance.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..160a80da457f 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_instance.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..1425ff185040 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_instance.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..eb0ba3b2f127 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_instance.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..156d93939201 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(creature_info_instance.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..5eac27f79e79 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(danish_pig_instance.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..ff3aa9812e2d 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(deprecated_object_instance.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..aa7af45b99fa 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(discriminator_all_of_sub_instance.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..c21e5b2296ac 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(discriminator_all_of_super_instance.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..2065d42f5f6b 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_instance.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..dfe28d9f75b1 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(dummy_model_instance.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..bf8b1a6cd05c 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(enum_arrays_instance.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..cbe6845479eb 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(enum_ref_with_default_value_instance.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..6ce4891aa9d5 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(enum_test_instance.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..773d1373cca0 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_instance.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..3fe748f4f30f 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_instance.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..78bc4ae135da 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(file_schema_test_class_instance.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..6da6650e5df7 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(first_ref_instance.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..c11ae111ee22 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_instance.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..aaccf08bfd2e 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(foo_get_default_response_instance.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..98c3dc89570d 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(format_test_instance.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..66dca11251aa 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(has_only_read_only_instance.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..522156ae5b16 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(health_check_result_instance.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..114dfc8575d9 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(hunting_dog_instance.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..160c3633247c 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_instance.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..79234d754027 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(inner_dict_with_property_instance.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..32d4100ac9de 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(input_all_of_instance.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..ea8e06339493 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(int_or_string_instance.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..8bc905105efe 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(list_class_instance.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..acea13d9a9f5 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(map_of_array_of_model_instance.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..fa4501d24286 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(map_test_instance.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..fb354956720a 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(mixed_properties_and_additional_properties_class_instance.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..6cffad7a6d3a 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(model200_response_instance.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..4fdaa910bce4 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(model_api_response_instance.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..43f064bd85a4 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(model_field_instance.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..236b2bb971ee 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(model_return_instance.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..9cf5c5bb1faa 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(multi_arrays_instance.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..f9d2da4cccd2 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_instance.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..cd84aa96eb19 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(nullable_class_instance.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..c0ef9b80fcb5 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(nullable_property_instance.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..f1caf70ea2b7 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(number_only_instance.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..f201a9627dc3 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(object_to_test_additional_properties_instance.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..86cce93ba775 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(object_with_deprecated_fields_instance.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..f5410bc8d0f3 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_instance.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..9df82e2abc87 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(outer_composite_instance.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..d23ccc3757bb 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(outer_object_with_enum_property_instance.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..21df089ea756 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_instance.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..a6ee19fd1a74 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(parent_with_optional_dict_instance.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..179b71891d9d 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_instance.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..2e275198c547 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_instance.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..6bb28b418b6d 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(pony_sizes_instance.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..3bf20593f929 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(poop_cleaning_instance.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..a1a9a3dc81b6 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(primitive_string_instance.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..5fcda1f7803d 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(property_map_instance.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..a4a8405fe847 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(property_name_collision_instance.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..e55fe102b673 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(read_only_first_instance.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..47fb4daf97a4 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(second_circular_all_of_ref_instance.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..fa0b9f285e0c 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(second_ref_instance.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..af3c77d0524b 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(self_reference_model_instance.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..589dbeb14b94 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(special_model_name_instance.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..19da9016451c 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(special_name_instance.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..66339d14c875 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_instance.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..229ed6510a11 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_instance.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..c025d32ba436 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(task_activity_instance.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..fed06705b55b 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(test_error_responses_with_model400_response_instance.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..8813e0792d22 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(test_error_responses_with_model404_response_instance.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..870cd8850e6b 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(test_inline_freeform_additional_properties_request_instance.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..1f63056fe0f1 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(test_model_with_enum_default_instance.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..bb685d44835a 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(test_object_for_multipart_requests_request_marker_instance.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..90c7d8770979 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_instance.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..0b411bf5df7b 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(unnamed_dict_with_additional_model_list_properties_instance.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..def639720586 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(unnamed_dict_with_additional_string_list_properties_instance.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..35be1642e660 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(upload_file_with_additional_properties_request_object_instance.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..8f4ae3d04712 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_instance.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..12d648bb920d 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(with_nested_one_of_instance.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/models/additional_properties_any_type.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_any_type.py index 291b5e55e353..bc200fb99195 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesAnyType(BaseModel): """ @@ -37,64 +38,27 @@ class AdditionalPropertiesAnyType(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b07374ffccd7 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesClass(BaseModel): """ @@ -37,53 +38,27 @@ class AdditionalPropertiesClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..94c9c90a088b 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesObject(BaseModel): """ @@ -37,64 +38,27 @@ class AdditionalPropertiesObject(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..1f589af3b288 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesWithDescriptionOnly(BaseModel): """ @@ -37,64 +38,27 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..0b30cd2e8be0 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class AllOfSuperModel(BaseModel): """ @@ -36,52 +37,27 @@ class AllOfSuperModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..71025d084c28 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class AllOfWithSingleRef(BaseModel): """ @@ -38,53 +39,27 @@ class AllOfWithSingleRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..fe4451ba83d3 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -60,52 +61,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..970bd7582756 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 @@ -13,144 +13,37 @@ from __future__ import annotations -from inspect import getfullargspec -import json -import pprint -import re # noqa: F401 from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import List, Optional from typing_extensions import Annotated +from pydantic import Field, RootModel from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict from typing_extensions import Literal, Self -from pydantic import Field 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. """ + root: Union[List[int], str] = Field( + ... + ) - # 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..a90287e17b02 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 @@ -13,122 +13,38 @@ from __future__ import annotations -from inspect import getfullargspec -import json -import pprint -import re # noqa: F401 from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Optional from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig +from pydantic import Field, RootModel from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict from typing_extensions import Literal, Self -from pydantic import Field ANYOFPIG_ANY_OF_SCHEMAS = ["BasquePig", "DanishPig"] -class AnyOfPig(BaseModel): + +class AnyOfPig(RootModel[Union[BasquePig, DanishPig]]): """ AnyOfPig """ + root: Union[BasquePig, DanishPig] = Field( + ... + ) - # 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..6fa4d4a454b0 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ArrayOfArrayOfModel(BaseModel): """ @@ -37,64 +38,27 @@ class ArrayOfArrayOfModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..028601c27645 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ArrayOfArrayOfNumberOnly(BaseModel): """ @@ -36,52 +37,27 @@ class ArrayOfArrayOfNumberOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..bae55244e51b 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ArrayOfNumberOnly(BaseModel): """ @@ -36,52 +37,27 @@ class ArrayOfNumberOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..8488d796deeb 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ArrayTest(BaseModel): """ @@ -41,67 +42,27 @@ class ArrayTest(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..25e061a0493c 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -59,52 +60,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..80fbbc69f0ba 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class BasquePig(BaseModel): """ @@ -37,53 +38,27 @@ class BasquePig(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..ea5d5fed0fad 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 @@ -20,14 +20,23 @@ 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_extensions import Self, Literal +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", + alias="task_name" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Bathing", + alias="function_name" + ) content: StrictStr __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -52,54 +61,27 @@ def function_name_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d28295ae3750 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class Capitalization(BaseModel): """ @@ -41,57 +42,27 @@ class Capitalization(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..bd1f68423276 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Cat(Animal): """ @@ -37,54 +38,27 @@ class Cat(Animal): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..4509cf9404d8 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Category(BaseModel): """ @@ -37,53 +38,27 @@ class Category(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6cf2bba58527 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class CircularAllOfRef(BaseModel): """ @@ -37,61 +38,28 @@ class CircularAllOfRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..388aeb6934cb 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class CircularReferenceModel(BaseModel): """ @@ -37,57 +38,28 @@ class CircularReferenceModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..621e72a9bcba 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ClassModel(BaseModel): """ @@ -36,52 +37,27 @@ class ClassModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..384583d040ea 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Client(BaseModel): """ @@ -36,52 +37,27 @@ class Client(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..608ec222a231 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 @@ -13,155 +13,37 @@ from __future__ import annotations -import json -import pprint 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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, None] = Field( + None ) + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..213596b2ac25 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -60,53 +61,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..2ab71554ced0 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class CreatureInfo(BaseModel): """ @@ -36,52 +37,27 @@ class CreatureInfo(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..f2c4f78ed091 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class DanishPig(BaseModel): """ @@ -37,53 +38,27 @@ class DanishPig(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/deprecated_object.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/deprecated_object.py index bb4747a1e18c..4f0467c1c95a 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class DeprecatedObject(BaseModel): """ @@ -36,52 +37,27 @@ class DeprecatedObject(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..0844ee6a4927 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class DiscriminatorAllOfSub(DiscriminatorAllOfSuper): """ @@ -36,52 +37,27 @@ class DiscriminatorAllOfSub(DiscriminatorAllOfSuper): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..36aea7a9805f 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -58,50 +59,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..3f54b5b2768a 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Dog(Animal): """ @@ -37,54 +38,27 @@ class Dog(Animal): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..1e4a8d9a6a08 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class DummyModel(BaseModel): """ @@ -37,57 +38,28 @@ class DummyModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..2ab5d04d5471 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 @@ -20,14 +20,21 @@ 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_extensions import Self, Literal +from pydantic import Field class EnumArrays(BaseModel): """ EnumArrays """ # noqa: E501 - just_symbol: Optional[StrictStr] = None - array_enum: Optional[List[StrictStr]] = None + just_symbol: Optional[Literal['>=', '$']] = Field( + None, + description="just_symbol of the EnumArrays" + ) + array_enum: Optional[List[Literal['fish', 'crab']]] = Field( + None, + description="array_enum of the EnumArrays" + ) __properties: ClassVar[List[str]] = ["just_symbol", "array_enum"] @field_validator('just_symbol') @@ -58,53 +65,27 @@ def array_enum_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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_ref_with_default_value.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_ref_with_default_value.py index 9d97e3fd16d4..781f8b14d449 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class EnumRefWithDefaultValue(BaseModel): """ @@ -37,52 +38,27 @@ class EnumRefWithDefaultValue(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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_test.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py index b7e6ec36230f..3cb0baf0f32f 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 @@ -26,19 +26,43 @@ 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_extensions import Self, Literal +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[Literal['UPPER', 'lower', '']] = Field( + None, + description="enum_string of the EnumTest" + ) + enum_string_required: Literal['UPPER', 'lower', ''] = Field( + ..., + description="enum_string_required of the EnumTest" + ) + enum_integer_default: Optional[Literal[1, 5, 14]] = Field( + None, + description="enum_integer_default of the EnumTest" + ) + enum_integer: Optional[Literal[1, -1]] = Field( + None, + description="enum_integer of the EnumTest" + ) + enum_number: Optional[Literal[1.1, -1.2]] = Field( + None, + description="enum_number of the EnumTest" + ) + enum_string_single_member: Literal['abc'] = Field( + None, + description="enum_string_single_member of the EnumTest", + alias="enum_string_single_member" + ) + enum_integer_single_member: Literal['100'] = Field( + None, + description="enum_integer_single_member of the EnumTest", + alias="enum_integer_single_member" + ) 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") @@ -121,69 +145,27 @@ def enum_integer_single_member_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..47265928799b 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 @@ -20,14 +20,23 @@ 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_extensions import Self, Literal +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", + alias="task_name" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Feeding", + alias="function_name" + ) content: StrictStr __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -52,54 +61,27 @@ def function_name_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..02bef49b7f62 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class File(BaseModel): """ @@ -36,52 +37,27 @@ class File(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..c940688cf137 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class FileSchemaTestClass(BaseModel): """ @@ -38,63 +39,27 @@ class FileSchemaTestClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..cf3dd91f5b20 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class FirstRef(BaseModel): """ @@ -37,57 +38,28 @@ class FirstRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..7c3d514c1475 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Foo(BaseModel): """ @@ -36,52 +37,27 @@ class Foo(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..cc8fb33b1baf 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class FooGetDefaultResponse(BaseModel): """ @@ -37,55 +38,27 @@ class FooGetDefaultResponse(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..cacfdaab97eb 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 @@ -24,7 +24,8 @@ from typing_extensions import Annotated from uuid import UUID from typing import Optional, Set -from typing_extensions import Self +from typing_extensions import Self, Literal +from pydantic import Field class FormatTest(BaseModel): """ @@ -96,68 +97,27 @@ def pattern_with_digits_and_delimiter_validate_regular_expression(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6066f46682c6 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class HasOnlyReadOnly(BaseModel): """ @@ -37,57 +38,27 @@ class HasOnlyReadOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6f829c83f0ad 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class HealthCheckResult(BaseModel): """ @@ -36,57 +37,27 @@ class HealthCheckResult(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..cd2436271ec9 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class HuntingDog(Creature): """ @@ -38,57 +39,27 @@ class HuntingDog(Creature): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..1af076053369 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Info(BaseDiscriminator): """ @@ -37,56 +38,27 @@ class Info(BaseDiscriminator): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..ea4cde3995b8 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class InnerDictWithProperty(BaseModel): """ @@ -36,52 +37,27 @@ class InnerDictWithProperty(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..44abab5b841d 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class InputAllOf(BaseModel): """ @@ -37,64 +38,27 @@ class InputAllOf(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b57c4c9d0f36 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 @@ -13,132 +13,37 @@ from __future__ import annotations -import json -import pprint 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..a6f8bfcd619b 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ListClass(BaseModel): """ @@ -36,52 +37,27 @@ class ListClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..2fd3f9b22d21 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class MapOfArrayOfModel(BaseModel): """ @@ -37,68 +38,27 @@ class MapOfArrayOfModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..148b4b11e2a3 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 @@ -20,14 +20,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_extensions import Self, Literal +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[Literal['UPPER', 'lower']] = 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"] @@ -50,55 +54,27 @@ def map_of_enum_string_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..10295e10dbb4 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 @@ -23,7 +23,8 @@ from uuid import UUID from petstore_api.models.animal import Animal from typing import Optional, Set -from typing_extensions import Self +from typing_extensions import Self, Literal +from pydantic import Field class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): """ @@ -41,66 +42,27 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..7f5963510c12 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class Model200Response(BaseModel): """ @@ -37,53 +38,27 @@ class Model200Response(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..7783a8200a82 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class ModelApiResponse(BaseModel): """ @@ -38,54 +39,27 @@ class ModelApiResponse(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..eabf59f93c8d 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ModelField(BaseModel): """ @@ -36,52 +37,27 @@ class ModelField(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..a79d088d17da 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ModelReturn(BaseModel): """ @@ -36,52 +37,27 @@ class ModelReturn(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..db9b94cd8582 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class MultiArrays(BaseModel): """ @@ -39,67 +40,27 @@ class MultiArrays(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..9af8ee448a6a 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class Name(BaseModel): """ @@ -39,59 +40,27 @@ class Name(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..78404ee41ec6 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class NullableClass(BaseModel): """ @@ -50,131 +51,27 @@ class NullableClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..8f0e6a41984f 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class NullableProperty(BaseModel): """ @@ -48,58 +49,27 @@ def name_validate_regular_expression(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b6c02228c5e2 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class NumberOnly(BaseModel): """ @@ -36,52 +37,27 @@ class NumberOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..79c42917a8b8 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ObjectToTestAdditionalProperties(BaseModel): """ @@ -36,52 +37,27 @@ class ObjectToTestAdditionalProperties(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..da291134461c 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ObjectWithDeprecatedFields(BaseModel): """ @@ -40,58 +41,27 @@ class ObjectWithDeprecatedFields(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/order.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/order.py index f742027e088a..7a3b7c57c7e7 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Order(BaseModel): """ @@ -31,7 +32,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[Literal['placed', 'approved', 'delivered']] = Field( + None, + description="Order Status" + ) complete: Optional[StrictBool] = False __properties: ClassVar[List[str]] = ["id", "petId", "quantity", "shipDate", "status", "complete"] @@ -52,57 +56,27 @@ def status_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..f3adc7c3b8de 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class OuterComposite(BaseModel): """ @@ -38,54 +39,27 @@ class OuterComposite(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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_object_with_enum_property.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_object_with_enum_property.py index 4f453c2a8d0c..624e3331542e 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class OuterObjectWithEnumProperty(BaseModel): """ @@ -39,58 +40,27 @@ class OuterObjectWithEnumProperty(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..24a1886628ce 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Parent(BaseModel): """ @@ -37,64 +38,27 @@ class Parent(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..256b0df2a1dc 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ParentWithOptionalDict(BaseModel): """ @@ -37,64 +38,27 @@ class ParentWithOptionalDict(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..ea13c5465e3b 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 @@ -23,7 +23,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Pet(BaseModel): """ @@ -34,7 +35,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[Literal['available', 'pending', 'sold']] = Field( + None, + description="pet status in the store" + ) __properties: ClassVar[List[str]] = ["id", "category", "name", "photoUrls", "tags", "status"] @field_validator('status') @@ -54,67 +58,27 @@ def status_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..4cc32f18c42d 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 @@ -13,128 +13,38 @@ from __future__ import annotations -import json -import pprint from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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( + ... ) + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..b7bc4533ca78 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class PonySizes(BaseModel): """ @@ -37,52 +38,27 @@ class PonySizes(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..8e6803afdcbb 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 @@ -20,14 +20,23 @@ 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_extensions import Self, Literal +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", + alias="task_name" + ) + function_name: Literal['care'] = Field( + ..., + description="function_name of the PoopCleaning", + alias="function_name" + ) content: StrictStr __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -52,54 +61,27 @@ def function_name_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..809a7741366c 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class PrimitiveString(BaseDiscriminator): """ @@ -37,53 +38,27 @@ class PrimitiveString(BaseDiscriminator): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..336223a9c4df 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class PropertyMap(BaseModel): """ @@ -37,64 +38,27 @@ class PropertyMap(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..4ac90edf7de2 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class PropertyNameCollision(BaseModel): """ @@ -38,54 +39,27 @@ class PropertyNameCollision(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..e629b9f1a094 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class ReadOnlyFirst(BaseModel): """ @@ -37,55 +38,27 @@ class ReadOnlyFirst(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d2551e5802ac 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class SecondCircularAllOfRef(BaseModel): """ @@ -37,61 +38,28 @@ class SecondCircularAllOfRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..2507e2b84d4a 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class SecondRef(BaseModel): """ @@ -37,57 +38,28 @@ class SecondRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..286894e0d559 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class SelfReferenceModel(BaseModel): """ @@ -37,57 +38,28 @@ class SelfReferenceModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/special_model_name.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_model_name.py index 0336e24d17da..13d5b24c52e0 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class SpecialModelName(BaseModel): """ @@ -36,52 +37,27 @@ class SpecialModelName(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..c54f89dfc489 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class SpecialName(BaseModel): """ @@ -29,7 +30,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[Literal['available', 'pending', 'sold']] = Field( + None, + description="pet status in the store" + ) __properties: ClassVar[List[str]] = ["property", "async", "schema"] @field_validator('var_schema') @@ -49,57 +53,27 @@ def var_schema_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..f14a2afd272f 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Tag(BaseModel): """ @@ -37,53 +38,27 @@ class Tag(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..158c3b99686b 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 @@ -22,7 +22,8 @@ from uuid import UUID from petstore_api.models.task_activity import TaskActivity from typing import Optional, Set -from typing_extensions import Self +from typing_extensions import Self, Literal +from pydantic import Field class Task(BaseModel): """ @@ -39,56 +40,27 @@ class Task(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..15b92f1829bf 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 @@ -13,139 +13,39 @@ from __future__ import annotations -import json -import pprint from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Any, List, Optional 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") 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..4f377a4a4d36 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class TestErrorResponsesWithModel400Response(BaseModel): """ @@ -36,52 +37,27 @@ class TestErrorResponsesWithModel400Response(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..313c499def30 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class TestErrorResponsesWithModel404Response(BaseModel): """ @@ -36,52 +37,27 @@ class TestErrorResponsesWithModel404Response(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d67bb5ef1f35 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): """ @@ -37,64 +38,27 @@ class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6e09516062ae 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class TestModelWithEnumDefault(BaseModel): """ @@ -32,7 +33,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[Literal['A', 'B', 'C']] = 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') @@ -52,56 +56,27 @@ def test_inline_defined_enum_with_default_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..2bb14ff8d58e 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class TestObjectForMultipartRequestsRequestMarker(BaseModel): """ @@ -36,52 +37,27 @@ class TestObjectForMultipartRequestsRequestMarker(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..153a9f22de54 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Tiger(BaseModel): """ @@ -36,52 +37,27 @@ class Tiger(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/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..9ca067dbfe25 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class UnnamedDictWithAdditionalModelListProperties(BaseModel): """ @@ -37,68 +38,27 @@ class UnnamedDictWithAdditionalModelListProperties(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..72e05f458f96 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class UnnamedDictWithAdditionalStringListProperties(BaseModel): """ @@ -36,52 +37,27 @@ class UnnamedDictWithAdditionalStringListProperties(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..5bd3022c1efe 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class UploadFileWithAdditionalPropertiesRequestObject(BaseModel): """ @@ -36,52 +37,27 @@ class UploadFileWithAdditionalPropertiesRequestObject(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..2868cbf027c6 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class User(BaseModel): """ @@ -43,59 +44,27 @@ class User(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..4aba1b28f89e 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class WithNestedOneOf(BaseModel): """ @@ -40,57 +41,27 @@ class WithNestedOneOf(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/docs/AdditionalPropertiesAnyType.md b/samples/openapi3/client/petstore/python-httpx/docs/AdditionalPropertiesAnyType.md index 314cba3a614c..b94c1e6d7d19 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(additional_properties_any_type_instance.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..4c880d6853e8 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(additional_properties_class_instance.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..bf6743709338 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(additional_properties_object_instance.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..1cb2a02f7584 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(additional_properties_with_description_only_instance.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..88cb95097517 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(all_of_super_model_instance.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..dd0f755dfe65 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(all_of_with_single_ref_instance.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..fcded75f52be 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_instance.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..02aab883b2b0 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(any_of_color_instance.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..db2878121f29 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(any_of_pig_instance.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..e8274d8fbb52 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(array_of_array_of_model_instance.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..8931a1c7e467 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(array_of_array_of_number_only_instance.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..a709583be699 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(array_of_number_only_instance.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..a99eb056c5ca 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(array_test_instance.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..0482396cbcf8 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(base_discriminator_instance.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..9844d05b3740 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(basque_pig_instance.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..2c8d8332629b 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_instance.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..55fcc0c01cb2 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_instance.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..0845d68bd487 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_instance.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..8a14791c7925 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_instance.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..f937a53cfe3c 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(circular_all_of_ref_instance.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..9a39f46e5d7d 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(circular_reference_model_instance.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..50fbfefa7661 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(class_model_instance.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..160a80da457f 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_instance.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..1425ff185040 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_instance.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..eb0ba3b2f127 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_instance.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..156d93939201 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(creature_info_instance.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..5eac27f79e79 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(danish_pig_instance.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..ff3aa9812e2d 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(deprecated_object_instance.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..aa7af45b99fa 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(discriminator_all_of_sub_instance.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..c21e5b2296ac 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(discriminator_all_of_super_instance.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..2065d42f5f6b 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_instance.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..dfe28d9f75b1 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(dummy_model_instance.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..bf8b1a6cd05c 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(enum_arrays_instance.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..cbe6845479eb 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(enum_ref_with_default_value_instance.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..6ce4891aa9d5 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(enum_test_instance.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..773d1373cca0 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_instance.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..3fe748f4f30f 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_instance.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..78bc4ae135da 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(file_schema_test_class_instance.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..6da6650e5df7 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(first_ref_instance.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..c11ae111ee22 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_instance.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..aaccf08bfd2e 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(foo_get_default_response_instance.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..98c3dc89570d 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(format_test_instance.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..66dca11251aa 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(has_only_read_only_instance.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..522156ae5b16 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(health_check_result_instance.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..114dfc8575d9 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(hunting_dog_instance.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..160c3633247c 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_instance.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..79234d754027 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(inner_dict_with_property_instance.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..32d4100ac9de 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(input_all_of_instance.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..ea8e06339493 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(int_or_string_instance.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..8bc905105efe 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(list_class_instance.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..acea13d9a9f5 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(map_of_array_of_model_instance.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..fa4501d24286 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(map_test_instance.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..fb354956720a 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(mixed_properties_and_additional_properties_class_instance.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..6cffad7a6d3a 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(model200_response_instance.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..4fdaa910bce4 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(model_api_response_instance.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..43f064bd85a4 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(model_field_instance.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..236b2bb971ee 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(model_return_instance.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..9cf5c5bb1faa 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(multi_arrays_instance.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..f9d2da4cccd2 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_instance.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..cd84aa96eb19 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(nullable_class_instance.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..c0ef9b80fcb5 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(nullable_property_instance.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..f1caf70ea2b7 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(number_only_instance.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..f201a9627dc3 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(object_to_test_additional_properties_instance.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..86cce93ba775 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(object_with_deprecated_fields_instance.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..f5410bc8d0f3 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_instance.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..9df82e2abc87 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(outer_composite_instance.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..d23ccc3757bb 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(outer_object_with_enum_property_instance.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..21df089ea756 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_instance.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..a6ee19fd1a74 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(parent_with_optional_dict_instance.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..179b71891d9d 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_instance.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..2e275198c547 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_instance.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..6bb28b418b6d 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(pony_sizes_instance.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..3bf20593f929 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(poop_cleaning_instance.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..a1a9a3dc81b6 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(primitive_string_instance.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..5fcda1f7803d 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(property_map_instance.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..a4a8405fe847 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(property_name_collision_instance.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..e55fe102b673 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(read_only_first_instance.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..47fb4daf97a4 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(second_circular_all_of_ref_instance.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..fa0b9f285e0c 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(second_ref_instance.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..af3c77d0524b 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(self_reference_model_instance.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..589dbeb14b94 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(special_model_name_instance.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..19da9016451c 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(special_name_instance.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..66339d14c875 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_instance.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..229ed6510a11 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_instance.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..c025d32ba436 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(task_activity_instance.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..fed06705b55b 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(test_error_responses_with_model400_response_instance.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..8813e0792d22 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(test_error_responses_with_model404_response_instance.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..870cd8850e6b 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(test_inline_freeform_additional_properties_request_instance.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..1f63056fe0f1 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(test_model_with_enum_default_instance.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..bb685d44835a 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(test_object_for_multipart_requests_request_marker_instance.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..90c7d8770979 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_instance.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..0b411bf5df7b 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(unnamed_dict_with_additional_model_list_properties_instance.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..def639720586 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(unnamed_dict_with_additional_string_list_properties_instance.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..35be1642e660 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(upload_file_with_additional_properties_request_object_instance.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..8f4ae3d04712 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_instance.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..12d648bb920d 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(with_nested_one_of_instance.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/models/additional_properties_any_type.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/additional_properties_any_type.py index 291b5e55e353..bc200fb99195 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesAnyType(BaseModel): """ @@ -37,64 +38,27 @@ class AdditionalPropertiesAnyType(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b07374ffccd7 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesClass(BaseModel): """ @@ -37,53 +38,27 @@ class AdditionalPropertiesClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..94c9c90a088b 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesObject(BaseModel): """ @@ -37,64 +38,27 @@ class AdditionalPropertiesObject(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..1f589af3b288 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesWithDescriptionOnly(BaseModel): """ @@ -37,64 +38,27 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..0b30cd2e8be0 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class AllOfSuperModel(BaseModel): """ @@ -36,52 +37,27 @@ class AllOfSuperModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..71025d084c28 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class AllOfWithSingleRef(BaseModel): """ @@ -38,53 +39,27 @@ class AllOfWithSingleRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..fe4451ba83d3 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -60,52 +61,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..970bd7582756 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 @@ -13,144 +13,37 @@ from __future__ import annotations -from inspect import getfullargspec -import json -import pprint -import re # noqa: F401 from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import List, Optional from typing_extensions import Annotated +from pydantic import Field, RootModel from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict from typing_extensions import Literal, Self -from pydantic import Field 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. """ + root: Union[List[int], str] = Field( + ... + ) - # 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..a90287e17b02 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 @@ -13,122 +13,38 @@ from __future__ import annotations -from inspect import getfullargspec -import json -import pprint -import re # noqa: F401 from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Optional from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig +from pydantic import Field, RootModel from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict from typing_extensions import Literal, Self -from pydantic import Field ANYOFPIG_ANY_OF_SCHEMAS = ["BasquePig", "DanishPig"] -class AnyOfPig(BaseModel): + +class AnyOfPig(RootModel[Union[BasquePig, DanishPig]]): """ AnyOfPig """ + root: Union[BasquePig, DanishPig] = Field( + ... + ) - # 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..6fa4d4a454b0 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ArrayOfArrayOfModel(BaseModel): """ @@ -37,64 +38,27 @@ class ArrayOfArrayOfModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..028601c27645 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ArrayOfArrayOfNumberOnly(BaseModel): """ @@ -36,52 +37,27 @@ class ArrayOfArrayOfNumberOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..bae55244e51b 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ArrayOfNumberOnly(BaseModel): """ @@ -36,52 +37,27 @@ class ArrayOfNumberOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..8488d796deeb 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ArrayTest(BaseModel): """ @@ -41,67 +42,27 @@ class ArrayTest(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..25e061a0493c 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -59,52 +60,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..80fbbc69f0ba 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class BasquePig(BaseModel): """ @@ -37,53 +38,27 @@ class BasquePig(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..ea5d5fed0fad 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 @@ -20,14 +20,23 @@ 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_extensions import Self, Literal +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", + alias="task_name" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Bathing", + alias="function_name" + ) content: StrictStr __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -52,54 +61,27 @@ def function_name_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d28295ae3750 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class Capitalization(BaseModel): """ @@ -41,57 +42,27 @@ class Capitalization(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..bd1f68423276 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Cat(Animal): """ @@ -37,54 +38,27 @@ class Cat(Animal): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..4509cf9404d8 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Category(BaseModel): """ @@ -37,53 +38,27 @@ class Category(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6cf2bba58527 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class CircularAllOfRef(BaseModel): """ @@ -37,61 +38,28 @@ class CircularAllOfRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..388aeb6934cb 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class CircularReferenceModel(BaseModel): """ @@ -37,57 +38,28 @@ class CircularReferenceModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..621e72a9bcba 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ClassModel(BaseModel): """ @@ -36,52 +37,27 @@ class ClassModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..384583d040ea 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Client(BaseModel): """ @@ -36,52 +37,27 @@ class Client(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..608ec222a231 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 @@ -13,155 +13,37 @@ from __future__ import annotations -import json -import pprint 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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, None] = Field( + None ) + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..213596b2ac25 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -60,53 +61,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..2ab71554ced0 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class CreatureInfo(BaseModel): """ @@ -36,52 +37,27 @@ class CreatureInfo(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..f2c4f78ed091 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class DanishPig(BaseModel): """ @@ -37,53 +38,27 @@ class DanishPig(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/deprecated_object.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/deprecated_object.py index bb4747a1e18c..4f0467c1c95a 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class DeprecatedObject(BaseModel): """ @@ -36,52 +37,27 @@ class DeprecatedObject(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..0844ee6a4927 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class DiscriminatorAllOfSub(DiscriminatorAllOfSuper): """ @@ -36,52 +37,27 @@ class DiscriminatorAllOfSub(DiscriminatorAllOfSuper): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..36aea7a9805f 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -58,50 +59,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..3f54b5b2768a 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Dog(Animal): """ @@ -37,54 +38,27 @@ class Dog(Animal): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..1e4a8d9a6a08 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class DummyModel(BaseModel): """ @@ -37,57 +38,28 @@ class DummyModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..2ab5d04d5471 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 @@ -20,14 +20,21 @@ 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_extensions import Self, Literal +from pydantic import Field class EnumArrays(BaseModel): """ EnumArrays """ # noqa: E501 - just_symbol: Optional[StrictStr] = None - array_enum: Optional[List[StrictStr]] = None + just_symbol: Optional[Literal['>=', '$']] = Field( + None, + description="just_symbol of the EnumArrays" + ) + array_enum: Optional[List[Literal['fish', 'crab']]] = Field( + None, + description="array_enum of the EnumArrays" + ) __properties: ClassVar[List[str]] = ["just_symbol", "array_enum"] @field_validator('just_symbol') @@ -58,53 +65,27 @@ def array_enum_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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_ref_with_default_value.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_ref_with_default_value.py index 9d97e3fd16d4..781f8b14d449 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class EnumRefWithDefaultValue(BaseModel): """ @@ -37,52 +38,27 @@ class EnumRefWithDefaultValue(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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_test.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/enum_test.py index b7e6ec36230f..3cb0baf0f32f 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 @@ -26,19 +26,43 @@ 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_extensions import Self, Literal +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[Literal['UPPER', 'lower', '']] = Field( + None, + description="enum_string of the EnumTest" + ) + enum_string_required: Literal['UPPER', 'lower', ''] = Field( + ..., + description="enum_string_required of the EnumTest" + ) + enum_integer_default: Optional[Literal[1, 5, 14]] = Field( + None, + description="enum_integer_default of the EnumTest" + ) + enum_integer: Optional[Literal[1, -1]] = Field( + None, + description="enum_integer of the EnumTest" + ) + enum_number: Optional[Literal[1.1, -1.2]] = Field( + None, + description="enum_number of the EnumTest" + ) + enum_string_single_member: Literal['abc'] = Field( + None, + description="enum_string_single_member of the EnumTest", + alias="enum_string_single_member" + ) + enum_integer_single_member: Literal['100'] = Field( + None, + description="enum_integer_single_member of the EnumTest", + alias="enum_integer_single_member" + ) 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") @@ -121,69 +145,27 @@ def enum_integer_single_member_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..47265928799b 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 @@ -20,14 +20,23 @@ 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_extensions import Self, Literal +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", + alias="task_name" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Feeding", + alias="function_name" + ) content: StrictStr __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -52,54 +61,27 @@ def function_name_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..02bef49b7f62 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class File(BaseModel): """ @@ -36,52 +37,27 @@ class File(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..c940688cf137 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class FileSchemaTestClass(BaseModel): """ @@ -38,63 +39,27 @@ class FileSchemaTestClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..cf3dd91f5b20 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class FirstRef(BaseModel): """ @@ -37,57 +38,28 @@ class FirstRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..7c3d514c1475 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Foo(BaseModel): """ @@ -36,52 +37,27 @@ class Foo(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..cc8fb33b1baf 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class FooGetDefaultResponse(BaseModel): """ @@ -37,55 +38,27 @@ class FooGetDefaultResponse(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..cacfdaab97eb 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 @@ -24,7 +24,8 @@ from typing_extensions import Annotated from uuid import UUID from typing import Optional, Set -from typing_extensions import Self +from typing_extensions import Self, Literal +from pydantic import Field class FormatTest(BaseModel): """ @@ -96,68 +97,27 @@ def pattern_with_digits_and_delimiter_validate_regular_expression(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6066f46682c6 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class HasOnlyReadOnly(BaseModel): """ @@ -37,57 +38,27 @@ class HasOnlyReadOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6f829c83f0ad 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class HealthCheckResult(BaseModel): """ @@ -36,57 +37,27 @@ class HealthCheckResult(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..cd2436271ec9 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class HuntingDog(Creature): """ @@ -38,57 +39,27 @@ class HuntingDog(Creature): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..1af076053369 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Info(BaseDiscriminator): """ @@ -37,56 +38,27 @@ class Info(BaseDiscriminator): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..ea4cde3995b8 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class InnerDictWithProperty(BaseModel): """ @@ -36,52 +37,27 @@ class InnerDictWithProperty(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..44abab5b841d 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class InputAllOf(BaseModel): """ @@ -37,64 +38,27 @@ class InputAllOf(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b57c4c9d0f36 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 @@ -13,132 +13,37 @@ from __future__ import annotations -import json -import pprint 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..a6f8bfcd619b 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ListClass(BaseModel): """ @@ -36,52 +37,27 @@ class ListClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..2fd3f9b22d21 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class MapOfArrayOfModel(BaseModel): """ @@ -37,68 +38,27 @@ class MapOfArrayOfModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..148b4b11e2a3 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 @@ -20,14 +20,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_extensions import Self, Literal +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[Literal['UPPER', 'lower']] = 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"] @@ -50,55 +54,27 @@ def map_of_enum_string_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..10295e10dbb4 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 @@ -23,7 +23,8 @@ from uuid import UUID from petstore_api.models.animal import Animal from typing import Optional, Set -from typing_extensions import Self +from typing_extensions import Self, Literal +from pydantic import Field class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): """ @@ -41,66 +42,27 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..7f5963510c12 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class Model200Response(BaseModel): """ @@ -37,53 +38,27 @@ class Model200Response(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..7783a8200a82 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class ModelApiResponse(BaseModel): """ @@ -38,54 +39,27 @@ class ModelApiResponse(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..eabf59f93c8d 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ModelField(BaseModel): """ @@ -36,52 +37,27 @@ class ModelField(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..a79d088d17da 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ModelReturn(BaseModel): """ @@ -36,52 +37,27 @@ class ModelReturn(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..db9b94cd8582 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class MultiArrays(BaseModel): """ @@ -39,67 +40,27 @@ class MultiArrays(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..9af8ee448a6a 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class Name(BaseModel): """ @@ -39,59 +40,27 @@ class Name(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..78404ee41ec6 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class NullableClass(BaseModel): """ @@ -50,131 +51,27 @@ class NullableClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..8f0e6a41984f 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class NullableProperty(BaseModel): """ @@ -48,58 +49,27 @@ def name_validate_regular_expression(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b6c02228c5e2 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class NumberOnly(BaseModel): """ @@ -36,52 +37,27 @@ class NumberOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..79c42917a8b8 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ObjectToTestAdditionalProperties(BaseModel): """ @@ -36,52 +37,27 @@ class ObjectToTestAdditionalProperties(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..da291134461c 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ObjectWithDeprecatedFields(BaseModel): """ @@ -40,58 +41,27 @@ class ObjectWithDeprecatedFields(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/order.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/order.py index f742027e088a..7a3b7c57c7e7 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Order(BaseModel): """ @@ -31,7 +32,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[Literal['placed', 'approved', 'delivered']] = Field( + None, + description="Order Status" + ) complete: Optional[StrictBool] = False __properties: ClassVar[List[str]] = ["id", "petId", "quantity", "shipDate", "status", "complete"] @@ -52,57 +56,27 @@ def status_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..f3adc7c3b8de 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class OuterComposite(BaseModel): """ @@ -38,54 +39,27 @@ class OuterComposite(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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_object_with_enum_property.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/outer_object_with_enum_property.py index 4f453c2a8d0c..624e3331542e 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class OuterObjectWithEnumProperty(BaseModel): """ @@ -39,58 +40,27 @@ class OuterObjectWithEnumProperty(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..24a1886628ce 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Parent(BaseModel): """ @@ -37,64 +38,27 @@ class Parent(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..256b0df2a1dc 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ParentWithOptionalDict(BaseModel): """ @@ -37,64 +38,27 @@ class ParentWithOptionalDict(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..ea13c5465e3b 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 @@ -23,7 +23,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Pet(BaseModel): """ @@ -34,7 +35,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[Literal['available', 'pending', 'sold']] = Field( + None, + description="pet status in the store" + ) __properties: ClassVar[List[str]] = ["id", "category", "name", "photoUrls", "tags", "status"] @field_validator('status') @@ -54,67 +58,27 @@ def status_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..4cc32f18c42d 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 @@ -13,128 +13,38 @@ from __future__ import annotations -import json -import pprint from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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( + ... ) + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..b7bc4533ca78 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class PonySizes(BaseModel): """ @@ -37,52 +38,27 @@ class PonySizes(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..8e6803afdcbb 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 @@ -20,14 +20,23 @@ 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_extensions import Self, Literal +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", + alias="task_name" + ) + function_name: Literal['care'] = Field( + ..., + description="function_name of the PoopCleaning", + alias="function_name" + ) content: StrictStr __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -52,54 +61,27 @@ def function_name_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..809a7741366c 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class PrimitiveString(BaseDiscriminator): """ @@ -37,53 +38,27 @@ class PrimitiveString(BaseDiscriminator): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..336223a9c4df 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class PropertyMap(BaseModel): """ @@ -37,64 +38,27 @@ class PropertyMap(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..4ac90edf7de2 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class PropertyNameCollision(BaseModel): """ @@ -38,54 +39,27 @@ class PropertyNameCollision(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..e629b9f1a094 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class ReadOnlyFirst(BaseModel): """ @@ -37,55 +38,27 @@ class ReadOnlyFirst(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d2551e5802ac 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class SecondCircularAllOfRef(BaseModel): """ @@ -37,61 +38,28 @@ class SecondCircularAllOfRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..2507e2b84d4a 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class SecondRef(BaseModel): """ @@ -37,57 +38,28 @@ class SecondRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..286894e0d559 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class SelfReferenceModel(BaseModel): """ @@ -37,57 +38,28 @@ class SelfReferenceModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/special_model_name.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/special_model_name.py index 0336e24d17da..13d5b24c52e0 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class SpecialModelName(BaseModel): """ @@ -36,52 +37,27 @@ class SpecialModelName(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..c54f89dfc489 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class SpecialName(BaseModel): """ @@ -29,7 +30,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[Literal['available', 'pending', 'sold']] = Field( + None, + description="pet status in the store" + ) __properties: ClassVar[List[str]] = ["property", "async", "schema"] @field_validator('var_schema') @@ -49,57 +53,27 @@ def var_schema_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..f14a2afd272f 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Tag(BaseModel): """ @@ -37,53 +38,27 @@ class Tag(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..158c3b99686b 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 @@ -22,7 +22,8 @@ from uuid import UUID from petstore_api.models.task_activity import TaskActivity from typing import Optional, Set -from typing_extensions import Self +from typing_extensions import Self, Literal +from pydantic import Field class Task(BaseModel): """ @@ -39,56 +40,27 @@ class Task(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..15b92f1829bf 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 @@ -13,139 +13,39 @@ from __future__ import annotations -import json -import pprint from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Any, List, Optional 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") 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..4f377a4a4d36 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class TestErrorResponsesWithModel400Response(BaseModel): """ @@ -36,52 +37,27 @@ class TestErrorResponsesWithModel400Response(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..313c499def30 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class TestErrorResponsesWithModel404Response(BaseModel): """ @@ -36,52 +37,27 @@ class TestErrorResponsesWithModel404Response(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d67bb5ef1f35 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): """ @@ -37,64 +38,27 @@ class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6e09516062ae 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class TestModelWithEnumDefault(BaseModel): """ @@ -32,7 +33,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[Literal['A', 'B', 'C']] = 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') @@ -52,56 +56,27 @@ def test_inline_defined_enum_with_default_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..2bb14ff8d58e 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class TestObjectForMultipartRequestsRequestMarker(BaseModel): """ @@ -36,52 +37,27 @@ class TestObjectForMultipartRequestsRequestMarker(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..153a9f22de54 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Tiger(BaseModel): """ @@ -36,52 +37,27 @@ class Tiger(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/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..9ca067dbfe25 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class UnnamedDictWithAdditionalModelListProperties(BaseModel): """ @@ -37,68 +38,27 @@ class UnnamedDictWithAdditionalModelListProperties(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..72e05f458f96 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class UnnamedDictWithAdditionalStringListProperties(BaseModel): """ @@ -36,52 +37,27 @@ class UnnamedDictWithAdditionalStringListProperties(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..5bd3022c1efe 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class UploadFileWithAdditionalPropertiesRequestObject(BaseModel): """ @@ -36,52 +37,27 @@ class UploadFileWithAdditionalPropertiesRequestObject(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..2868cbf027c6 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class User(BaseModel): """ @@ -43,59 +44,27 @@ class User(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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([ - ]) + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) - _dict = self.model_dump( - by_alias=True, - exclude=excluded_fields, - exclude_none=True, - ) - return _dict + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..4aba1b28f89e 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class WithNestedOneOf(BaseModel): """ @@ -40,57 +41,27 @@ class WithNestedOneOf(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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-lazyImports/docs/AdditionalPropertiesAnyType.md b/samples/openapi3/client/petstore/python-lazyImports/docs/AdditionalPropertiesAnyType.md index 314cba3a614c..b94c1e6d7d19 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(additional_properties_any_type_instance.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..4c880d6853e8 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(additional_properties_class_instance.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..bf6743709338 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(additional_properties_object_instance.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..1cb2a02f7584 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(additional_properties_with_description_only_instance.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..88cb95097517 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(all_of_super_model_instance.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..dd0f755dfe65 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(all_of_with_single_ref_instance.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..fcded75f52be 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_instance.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..02aab883b2b0 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(any_of_color_instance.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..db2878121f29 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(any_of_pig_instance.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..e8274d8fbb52 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(array_of_array_of_model_instance.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..8931a1c7e467 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(array_of_array_of_number_only_instance.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..a709583be699 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(array_of_number_only_instance.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..a99eb056c5ca 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(array_test_instance.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..0482396cbcf8 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(base_discriminator_instance.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..9844d05b3740 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(basque_pig_instance.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..2c8d8332629b 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_instance.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..55fcc0c01cb2 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_instance.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..0845d68bd487 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_instance.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..8a14791c7925 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_instance.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..f937a53cfe3c 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(circular_all_of_ref_instance.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..9a39f46e5d7d 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(circular_reference_model_instance.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..50fbfefa7661 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(class_model_instance.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..160a80da457f 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_instance.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..1425ff185040 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_instance.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..eb0ba3b2f127 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_instance.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..156d93939201 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(creature_info_instance.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..5eac27f79e79 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(danish_pig_instance.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..ff3aa9812e2d 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(deprecated_object_instance.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..aa7af45b99fa 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(discriminator_all_of_sub_instance.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..c21e5b2296ac 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(discriminator_all_of_super_instance.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..2065d42f5f6b 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_instance.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..dfe28d9f75b1 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(dummy_model_instance.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..bf8b1a6cd05c 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(enum_arrays_instance.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..cbe6845479eb 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(enum_ref_with_default_value_instance.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..6ce4891aa9d5 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(enum_test_instance.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..773d1373cca0 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_instance.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..3fe748f4f30f 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_instance.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..78bc4ae135da 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(file_schema_test_class_instance.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..6da6650e5df7 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(first_ref_instance.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..c11ae111ee22 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_instance.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..aaccf08bfd2e 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(foo_get_default_response_instance.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..98c3dc89570d 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(format_test_instance.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..66dca11251aa 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(has_only_read_only_instance.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..522156ae5b16 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(health_check_result_instance.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..114dfc8575d9 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(hunting_dog_instance.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..160c3633247c 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_instance.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..79234d754027 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(inner_dict_with_property_instance.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..32d4100ac9de 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(input_all_of_instance.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..ea8e06339493 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(int_or_string_instance.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..8bc905105efe 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(list_class_instance.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..acea13d9a9f5 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(map_of_array_of_model_instance.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..fa4501d24286 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(map_test_instance.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..fb354956720a 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(mixed_properties_and_additional_properties_class_instance.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..6cffad7a6d3a 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(model200_response_instance.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..4fdaa910bce4 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(model_api_response_instance.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..43f064bd85a4 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(model_field_instance.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..236b2bb971ee 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(model_return_instance.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..9cf5c5bb1faa 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(multi_arrays_instance.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..f9d2da4cccd2 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_instance.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..cd84aa96eb19 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(nullable_class_instance.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..c0ef9b80fcb5 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(nullable_property_instance.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..f1caf70ea2b7 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(number_only_instance.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..f201a9627dc3 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(object_to_test_additional_properties_instance.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..86cce93ba775 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(object_with_deprecated_fields_instance.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..69f4f99d32e4 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(one_of_enum_string_instance.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..f5410bc8d0f3 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_instance.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..9df82e2abc87 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(outer_composite_instance.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..d23ccc3757bb 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(outer_object_with_enum_property_instance.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..21df089ea756 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_instance.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..a6ee19fd1a74 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(parent_with_optional_dict_instance.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..179b71891d9d 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_instance.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..2e275198c547 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_instance.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..6bb28b418b6d 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(pony_sizes_instance.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..3bf20593f929 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(poop_cleaning_instance.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..a1a9a3dc81b6 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(primitive_string_instance.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..5fcda1f7803d 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(property_map_instance.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..a4a8405fe847 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(property_name_collision_instance.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..e55fe102b673 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(read_only_first_instance.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..47fb4daf97a4 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(second_circular_all_of_ref_instance.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..fa0b9f285e0c 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(second_ref_instance.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..af3c77d0524b 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(self_reference_model_instance.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..589dbeb14b94 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(special_model_name_instance.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..19da9016451c 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(special_name_instance.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..66339d14c875 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_instance.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..229ed6510a11 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_instance.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..c025d32ba436 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(task_activity_instance.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..fed06705b55b 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(test_error_responses_with_model400_response_instance.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..8813e0792d22 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(test_error_responses_with_model404_response_instance.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..870cd8850e6b 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(test_inline_freeform_additional_properties_request_instance.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..1f63056fe0f1 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(test_model_with_enum_default_instance.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..bb685d44835a 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(test_object_for_multipart_requests_request_marker_instance.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..90c7d8770979 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_instance.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..0b411bf5df7b 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(unnamed_dict_with_additional_model_list_properties_instance.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..def639720586 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(unnamed_dict_with_additional_string_list_properties_instance.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..35be1642e660 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(upload_file_with_additional_properties_request_object_instance.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..8f4ae3d04712 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_instance.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..12d648bb920d 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(with_nested_one_of_instance.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/models/additional_properties_any_type.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/additional_properties_any_type.py index 291b5e55e353..bc200fb99195 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesAnyType(BaseModel): """ @@ -37,64 +38,27 @@ class AdditionalPropertiesAnyType(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..41db98c3e62f 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesClass(BaseModel): """ @@ -38,65 +39,27 @@ class AdditionalPropertiesClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..94c9c90a088b 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesObject(BaseModel): """ @@ -37,64 +38,27 @@ class AdditionalPropertiesObject(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..1f589af3b288 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesWithDescriptionOnly(BaseModel): """ @@ -37,64 +38,27 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..401413233f21 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class AllOfSuperModel(BaseModel): """ @@ -37,64 +38,27 @@ class AllOfSuperModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..5dfadd977245 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class AllOfWithSingleRef(BaseModel): """ @@ -39,65 +40,27 @@ class AllOfWithSingleRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..28b17142a816 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -61,59 +62,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..970bd7582756 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 @@ -13,144 +13,37 @@ from __future__ import annotations -from inspect import getfullargspec -import json -import pprint -import re # noqa: F401 from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import List, Optional from typing_extensions import Annotated +from pydantic import Field, RootModel from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict from typing_extensions import Literal, Self -from pydantic import Field 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. """ + root: Union[List[int], str] = Field( + ... + ) - # 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..a90287e17b02 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 @@ -13,122 +13,38 @@ from __future__ import annotations -from inspect import getfullargspec -import json -import pprint -import re # noqa: F401 from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Optional from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig +from pydantic import Field, RootModel from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict from typing_extensions import Literal, Self -from pydantic import Field ANYOFPIG_ANY_OF_SCHEMAS = ["BasquePig", "DanishPig"] -class AnyOfPig(BaseModel): + +class AnyOfPig(RootModel[Union[BasquePig, DanishPig]]): """ AnyOfPig """ + root: Union[BasquePig, DanishPig] = Field( + ... + ) - # 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..9505ce0b6c35 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ArrayOfArrayOfModel(BaseModel): """ @@ -38,76 +39,27 @@ class ArrayOfArrayOfModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..7776dfd14a7a 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ArrayOfArrayOfNumberOnly(BaseModel): """ @@ -37,64 +38,27 @@ class ArrayOfArrayOfNumberOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..c6d99aec508e 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ArrayOfNumberOnly(BaseModel): """ @@ -37,64 +38,27 @@ class ArrayOfNumberOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..9a52407bb57e 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ArrayTest(BaseModel): """ @@ -42,79 +43,27 @@ class ArrayTest(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6770a2e587a4 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -60,59 +61,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..3166836059f5 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class BasquePig(BaseModel): """ @@ -38,65 +39,27 @@ class BasquePig(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..c0288ed8f985 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 @@ -20,14 +20,23 @@ 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_extensions import Self, Literal +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", + alias="task_name" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Bathing", + alias="function_name" + ) content: StrictStr additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -53,66 +62,27 @@ def function_name_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6865ed963c9a 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class Capitalization(BaseModel): """ @@ -42,69 +43,27 @@ class Capitalization(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..8c81c11b1b29 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Cat(Animal): """ @@ -38,66 +39,27 @@ class Cat(Animal): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..614f25486a89 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Category(BaseModel): """ @@ -38,65 +39,27 @@ class Category(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..e1bcb36e7e68 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class CircularAllOfRef(BaseModel): """ @@ -38,73 +39,28 @@ class CircularAllOfRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..616bd5a7dd49 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class CircularReferenceModel(BaseModel): """ @@ -38,69 +39,28 @@ class CircularReferenceModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..264a218d6dd8 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ClassModel(BaseModel): """ @@ -37,64 +38,27 @@ class ClassModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..aa893e0d6104 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Client(BaseModel): """ @@ -37,64 +38,27 @@ class Client(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..608ec222a231 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 @@ -13,155 +13,37 @@ from __future__ import annotations -import json -import pprint 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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, None] = Field( + None ) + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..a2698a0a3164 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -61,60 +62,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..8b607b1d2065 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class CreatureInfo(BaseModel): """ @@ -37,64 +38,27 @@ class CreatureInfo(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..afd589a99cfc 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class DanishPig(BaseModel): """ @@ -38,65 +39,27 @@ class DanishPig(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/deprecated_object.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/deprecated_object.py index ad0ec89a5b7a..1717b330ec9e 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class DeprecatedObject(BaseModel): """ @@ -37,64 +38,27 @@ class DeprecatedObject(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b2bf6bef8628 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class DiscriminatorAllOfSub(DiscriminatorAllOfSuper): """ @@ -37,64 +38,27 @@ class DiscriminatorAllOfSub(DiscriminatorAllOfSuper): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..f9839d6f278f 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -59,57 +60,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..496d3f95f3ba 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Dog(Animal): """ @@ -38,66 +39,27 @@ class Dog(Animal): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b99f6a904ce7 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class DummyModel(BaseModel): """ @@ -38,69 +39,28 @@ class DummyModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..e56c6b336ea0 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 @@ -20,14 +20,21 @@ 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_extensions import Self, Literal +from pydantic import Field class EnumArrays(BaseModel): """ EnumArrays """ # noqa: E501 - just_symbol: Optional[StrictStr] = None - array_enum: Optional[List[StrictStr]] = None + just_symbol: Optional[Literal['>=', '$']] = Field( + None, + description="just_symbol of the EnumArrays" + ) + array_enum: Optional[List[Literal['fish', 'crab']]] = Field( + None, + description="array_enum of the EnumArrays" + ) additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["just_symbol", "array_enum"] @@ -59,65 +66,27 @@ def array_enum_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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_ref_with_default_value.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_ref_with_default_value.py index d864e80d0a73..2ad94c2c5de1 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class EnumRefWithDefaultValue(BaseModel): """ @@ -38,64 +39,27 @@ class EnumRefWithDefaultValue(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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_test.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/enum_test.py index d39c2c95775e..b508224d8b85 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 @@ -26,19 +26,43 @@ 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_extensions import Self, Literal +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[Literal['UPPER', 'lower', '']] = Field( + None, + description="enum_string of the EnumTest" + ) + enum_string_required: Literal['UPPER', 'lower', ''] = Field( + ..., + description="enum_string_required of the EnumTest" + ) + enum_integer_default: Optional[Literal[1, 5, 14]] = Field( + None, + description="enum_integer_default of the EnumTest" + ) + enum_integer: Optional[Literal[1, -1]] = Field( + None, + description="enum_integer of the EnumTest" + ) + enum_number: Optional[Literal[1.1, -1.2]] = Field( + None, + description="enum_number of the EnumTest" + ) + enum_string_single_member: Literal['abc'] = Field( + None, + description="enum_string_single_member of the EnumTest", + alias="enum_string_single_member" + ) + enum_integer_single_member: Literal['100'] = Field( + None, + description="enum_integer_single_member of the EnumTest", + alias="enum_integer_single_member" + ) 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") @@ -122,81 +146,27 @@ def enum_integer_single_member_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..ca42b4335639 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 @@ -20,14 +20,23 @@ 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_extensions import Self, Literal +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", + alias="task_name" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Feeding", + alias="function_name" + ) content: StrictStr additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -53,66 +62,27 @@ def function_name_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..554374cfbe07 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class File(BaseModel): """ @@ -37,64 +38,27 @@ class File(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d74d8dbae883 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class FileSchemaTestClass(BaseModel): """ @@ -39,75 +40,27 @@ class FileSchemaTestClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..fdf46e6260a9 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class FirstRef(BaseModel): """ @@ -38,69 +39,28 @@ class FirstRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..e77a2905c9f4 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Foo(BaseModel): """ @@ -37,64 +38,27 @@ class Foo(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b0db656eacfa 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class FooGetDefaultResponse(BaseModel): """ @@ -38,67 +39,27 @@ class FooGetDefaultResponse(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..759262062e78 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 @@ -24,7 +24,8 @@ from typing_extensions import Annotated from uuid import UUID from typing import Optional, Set -from typing_extensions import Self +from typing_extensions import Self, Literal +from pydantic import Field class FormatTest(BaseModel): """ @@ -97,80 +98,27 @@ def pattern_with_digits_and_delimiter_validate_regular_expression(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..c92fae193e56 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class HasOnlyReadOnly(BaseModel): """ @@ -38,69 +39,27 @@ class HasOnlyReadOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d062a5dfe853 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class HealthCheckResult(BaseModel): """ @@ -37,69 +38,27 @@ class HealthCheckResult(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..5e743ec84873 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class HuntingDog(Creature): """ @@ -39,69 +40,27 @@ class HuntingDog(Creature): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..2771d60c2318 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Info(BaseDiscriminator): """ @@ -38,68 +39,27 @@ class Info(BaseDiscriminator): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..9dcc377719e8 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class InnerDictWithProperty(BaseModel): """ @@ -37,64 +38,27 @@ class InnerDictWithProperty(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..60c833c81dcb 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class InputAllOf(BaseModel): """ @@ -38,76 +39,27 @@ class InputAllOf(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b57c4c9d0f36 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 @@ -13,132 +13,37 @@ from __future__ import annotations -import json -import pprint 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..c0c5fc4dae85 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ListClass(BaseModel): """ @@ -37,64 +38,27 @@ class ListClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..5e7a0bbfff9a 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class MapOfArrayOfModel(BaseModel): """ @@ -38,80 +39,27 @@ class MapOfArrayOfModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..5b46fae4b015 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 @@ -20,14 +20,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_extensions import Self, Literal +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[Literal['UPPER', 'lower']] = 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] = {} @@ -51,67 +55,27 @@ def map_of_enum_string_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..e7a6eb1c4604 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 @@ -23,7 +23,8 @@ from uuid import UUID from petstore_api.models.animal import Animal from typing import Optional, Set -from typing_extensions import Self +from typing_extensions import Self, Literal +from pydantic import Field class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): """ @@ -42,78 +43,27 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..ae0d0de0a380 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class Model200Response(BaseModel): """ @@ -38,65 +39,27 @@ class Model200Response(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..f27857d233e2 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class ModelApiResponse(BaseModel): """ @@ -39,66 +40,27 @@ class ModelApiResponse(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..672d5a2c1bab 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ModelField(BaseModel): """ @@ -37,64 +38,27 @@ class ModelField(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..affff9bc82a2 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ModelReturn(BaseModel): """ @@ -37,64 +38,27 @@ class ModelReturn(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..f4429792f542 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class MultiArrays(BaseModel): """ @@ -40,79 +41,27 @@ class MultiArrays(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..7392bcd94a96 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class Name(BaseModel): """ @@ -40,71 +41,27 @@ class Name(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..836632f92186 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class NullableClass(BaseModel): """ @@ -50,131 +51,27 @@ class NullableClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..a2100a9d605c 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class NullableProperty(BaseModel): """ @@ -49,70 +50,27 @@ def name_validate_regular_expression(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..8015d2627315 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class NumberOnly(BaseModel): """ @@ -37,64 +38,27 @@ class NumberOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..a0b501f4510e 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ObjectToTestAdditionalProperties(BaseModel): """ @@ -37,64 +38,27 @@ class ObjectToTestAdditionalProperties(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..607178e61b3e 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ObjectWithDeprecatedFields(BaseModel): """ @@ -41,70 +42,27 @@ class ObjectWithDeprecatedFields(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..e2b2780beece 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 @@ -13,125 +13,38 @@ from __future__ import annotations -import json -import pprint from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..bb5cf7cebd8b 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Order(BaseModel): """ @@ -31,7 +32,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[Literal['placed', 'approved', 'delivered']] = Field( + None, + description="Order Status" + ) complete: Optional[StrictBool] = False additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["id", "petId", "quantity", "shipDate", "status", "complete"] @@ -53,69 +57,27 @@ def status_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..f3c5a1d1a290 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class OuterComposite(BaseModel): """ @@ -39,66 +40,27 @@ class OuterComposite(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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_object_with_enum_property.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/outer_object_with_enum_property.py index f8d215a21c94..98d966c63f88 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class OuterObjectWithEnumProperty(BaseModel): """ @@ -40,70 +41,27 @@ class OuterObjectWithEnumProperty(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..67019aee1760 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Parent(BaseModel): """ @@ -38,76 +39,27 @@ class Parent(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..595d04b48cac 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ParentWithOptionalDict(BaseModel): """ @@ -38,76 +39,27 @@ class ParentWithOptionalDict(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d10aa6bea0b3 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 @@ -23,7 +23,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Pet(BaseModel): """ @@ -34,7 +35,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[Literal['available', 'pending', 'sold']] = Field( + None, + description="pet status in the store" + ) additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["id", "category", "name", "photoUrls", "tags", "status"] @@ -55,79 +59,27 @@ def status_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..4cc32f18c42d 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 @@ -13,143 +13,38 @@ from __future__ import annotations -import json -import pprint from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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( + ... ) + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..8330edb586e5 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class PonySizes(BaseModel): """ @@ -38,64 +39,27 @@ class PonySizes(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6404380de0bf 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 @@ -20,14 +20,23 @@ 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_extensions import Self, Literal +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", + alias="task_name" + ) + function_name: Literal['care'] = Field( + ..., + description="function_name of the PoopCleaning", + alias="function_name" + ) content: StrictStr additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -53,66 +62,27 @@ def function_name_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..1dd55054ae68 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class PrimitiveString(BaseDiscriminator): """ @@ -38,65 +39,27 @@ class PrimitiveString(BaseDiscriminator): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..ff945938c081 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class PropertyMap(BaseModel): """ @@ -38,76 +39,27 @@ class PropertyMap(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..17e3f07aeca9 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class PropertyNameCollision(BaseModel): """ @@ -39,66 +40,27 @@ class PropertyNameCollision(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..696299173423 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class ReadOnlyFirst(BaseModel): """ @@ -38,67 +39,27 @@ class ReadOnlyFirst(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..7c460b2215df 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class SecondCircularAllOfRef(BaseModel): """ @@ -38,73 +39,28 @@ class SecondCircularAllOfRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d034d43bf66f 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class SecondRef(BaseModel): """ @@ -38,69 +39,28 @@ class SecondRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..bf9197fce99f 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class SelfReferenceModel(BaseModel): """ @@ -38,69 +39,28 @@ class SelfReferenceModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/special_model_name.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/special_model_name.py index 84686054875a..e75daa66036b 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class SpecialModelName(BaseModel): """ @@ -37,64 +38,27 @@ class SpecialModelName(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..cb154e1ce529 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class SpecialName(BaseModel): """ @@ -29,7 +30,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[Literal['available', 'pending', 'sold']] = Field( + None, + description="pet status in the store" + ) additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["property", "async", "schema"] @@ -50,69 +54,27 @@ def var_schema_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..e5c4b57a1731 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Tag(BaseModel): """ @@ -38,65 +39,27 @@ class Tag(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..68ad30765acc 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 @@ -22,7 +22,8 @@ from uuid import UUID from petstore_api.models.task_activity import TaskActivity from typing import Optional, Set -from typing_extensions import Self +from typing_extensions import Self, Literal +from pydantic import Field class Task(BaseModel): """ @@ -40,68 +41,27 @@ class Task(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..15b92f1829bf 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 @@ -13,139 +13,39 @@ from __future__ import annotations -import json -import pprint from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Any, List, Optional 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") 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..4039342bc999 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class TestErrorResponsesWithModel400Response(BaseModel): """ @@ -37,64 +38,27 @@ class TestErrorResponsesWithModel400Response(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..93d9932f5b99 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class TestErrorResponsesWithModel404Response(BaseModel): """ @@ -37,64 +38,27 @@ class TestErrorResponsesWithModel404Response(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d67bb5ef1f35 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): """ @@ -37,64 +38,27 @@ class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..36ecd8a5abbb 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class TestModelWithEnumDefault(BaseModel): """ @@ -32,7 +33,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[Literal['A', 'B', 'C']] = 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"] @@ -53,68 +57,27 @@ def test_inline_defined_enum_with_default_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..427a35ab86d8 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class TestObjectForMultipartRequestsRequestMarker(BaseModel): """ @@ -37,64 +38,27 @@ class TestObjectForMultipartRequestsRequestMarker(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..897f0f0b897f 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Tiger(BaseModel): """ @@ -37,64 +38,27 @@ class Tiger(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/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..5f8e42159a24 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class UnnamedDictWithAdditionalModelListProperties(BaseModel): """ @@ -38,80 +39,27 @@ class UnnamedDictWithAdditionalModelListProperties(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..c4e874f931ca 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class UnnamedDictWithAdditionalStringListProperties(BaseModel): """ @@ -37,64 +38,27 @@ class UnnamedDictWithAdditionalStringListProperties(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..fefa4c26d8f9 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class UploadFileWithAdditionalPropertiesRequestObject(BaseModel): """ @@ -37,64 +38,27 @@ class UploadFileWithAdditionalPropertiesRequestObject(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..a65ce66ddb99 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class User(BaseModel): """ @@ -44,71 +45,27 @@ class User(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d1d79b8f0b04 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class WithNestedOneOf(BaseModel): """ @@ -41,72 +42,27 @@ class WithNestedOneOf(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/docs/AdditionalPropertiesAnyType.md b/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesAnyType.md index 314cba3a614c..b94c1e6d7d19 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(additional_properties_any_type_instance.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..4c880d6853e8 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(additional_properties_class_instance.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..bf6743709338 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(additional_properties_object_instance.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..1cb2a02f7584 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(additional_properties_with_description_only_instance.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..88cb95097517 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(all_of_super_model_instance.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..dd0f755dfe65 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(all_of_with_single_ref_instance.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..fcded75f52be 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_instance.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..02aab883b2b0 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(any_of_color_instance.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..db2878121f29 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(any_of_pig_instance.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..e8274d8fbb52 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(array_of_array_of_model_instance.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..8931a1c7e467 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(array_of_array_of_number_only_instance.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..a709583be699 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(array_of_number_only_instance.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..a99eb056c5ca 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(array_test_instance.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..0482396cbcf8 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(base_discriminator_instance.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..9844d05b3740 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(basque_pig_instance.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..2c8d8332629b 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_instance.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..55fcc0c01cb2 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_instance.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..0845d68bd487 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_instance.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..8a14791c7925 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_instance.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..f937a53cfe3c 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(circular_all_of_ref_instance.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..9a39f46e5d7d 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(circular_reference_model_instance.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..50fbfefa7661 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(class_model_instance.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..160a80da457f 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_instance.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..1425ff185040 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_instance.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..eb0ba3b2f127 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_instance.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..156d93939201 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(creature_info_instance.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..5eac27f79e79 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(danish_pig_instance.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..ff3aa9812e2d 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(deprecated_object_instance.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..aa7af45b99fa 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(discriminator_all_of_sub_instance.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..c21e5b2296ac 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(discriminator_all_of_super_instance.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..2065d42f5f6b 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_instance.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..dfe28d9f75b1 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(dummy_model_instance.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..bf8b1a6cd05c 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(enum_arrays_instance.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..cbe6845479eb 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(enum_ref_with_default_value_instance.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..6ce4891aa9d5 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(enum_test_instance.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..773d1373cca0 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_instance.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..3fe748f4f30f 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_instance.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..78bc4ae135da 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(file_schema_test_class_instance.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..6da6650e5df7 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(first_ref_instance.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..c11ae111ee22 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_instance.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..aaccf08bfd2e 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(foo_get_default_response_instance.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..98c3dc89570d 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(format_test_instance.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..66dca11251aa 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(has_only_read_only_instance.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..522156ae5b16 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(health_check_result_instance.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..114dfc8575d9 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(hunting_dog_instance.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..160c3633247c 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_instance.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..79234d754027 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(inner_dict_with_property_instance.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..32d4100ac9de 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(input_all_of_instance.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..ea8e06339493 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(int_or_string_instance.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..8bc905105efe 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(list_class_instance.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..acea13d9a9f5 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(map_of_array_of_model_instance.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..fa4501d24286 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(map_test_instance.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..fb354956720a 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(mixed_properties_and_additional_properties_class_instance.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..6cffad7a6d3a 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(model200_response_instance.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..4fdaa910bce4 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(model_api_response_instance.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..43f064bd85a4 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(model_field_instance.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..236b2bb971ee 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(model_return_instance.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..9cf5c5bb1faa 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(multi_arrays_instance.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..f9d2da4cccd2 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_instance.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..cd84aa96eb19 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(nullable_class_instance.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..c0ef9b80fcb5 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(nullable_property_instance.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..f1caf70ea2b7 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(number_only_instance.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..f201a9627dc3 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(object_to_test_additional_properties_instance.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..86cce93ba775 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(object_with_deprecated_fields_instance.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..69f4f99d32e4 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(one_of_enum_string_instance.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..f5410bc8d0f3 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_instance.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..9df82e2abc87 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(outer_composite_instance.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..d23ccc3757bb 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(outer_object_with_enum_property_instance.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..21df089ea756 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_instance.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..a6ee19fd1a74 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(parent_with_optional_dict_instance.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..179b71891d9d 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_instance.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..2e275198c547 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_instance.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..6bb28b418b6d 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(pony_sizes_instance.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..3bf20593f929 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(poop_cleaning_instance.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..a1a9a3dc81b6 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(primitive_string_instance.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..5fcda1f7803d 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(property_map_instance.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..a4a8405fe847 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(property_name_collision_instance.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..e55fe102b673 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(read_only_first_instance.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..47fb4daf97a4 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(second_circular_all_of_ref_instance.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..fa0b9f285e0c 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(second_ref_instance.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..af3c77d0524b 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(self_reference_model_instance.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..589dbeb14b94 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(special_model_name_instance.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..19da9016451c 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(special_name_instance.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..66339d14c875 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_instance.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..229ed6510a11 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_instance.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..c025d32ba436 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(task_activity_instance.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..fed06705b55b 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(test_error_responses_with_model400_response_instance.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..8813e0792d22 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(test_error_responses_with_model404_response_instance.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..870cd8850e6b 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(test_inline_freeform_additional_properties_request_instance.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..1f63056fe0f1 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(test_model_with_enum_default_instance.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..bb685d44835a 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(test_object_for_multipart_requests_request_marker_instance.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..90c7d8770979 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_instance.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..0b411bf5df7b 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(unnamed_dict_with_additional_model_list_properties_instance.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..def639720586 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(unnamed_dict_with_additional_string_list_properties_instance.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..35be1642e660 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(upload_file_with_additional_properties_request_object_instance.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..8f4ae3d04712 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_instance.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..12d648bb920d 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(with_nested_one_of_instance.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/models/additional_properties_any_type.py b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_any_type.py index 291b5e55e353..bc200fb99195 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesAnyType(BaseModel): """ @@ -37,64 +38,27 @@ class AdditionalPropertiesAnyType(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..41db98c3e62f 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesClass(BaseModel): """ @@ -38,65 +39,27 @@ class AdditionalPropertiesClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..94c9c90a088b 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesObject(BaseModel): """ @@ -37,64 +38,27 @@ class AdditionalPropertiesObject(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..1f589af3b288 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class AdditionalPropertiesWithDescriptionOnly(BaseModel): """ @@ -37,64 +38,27 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..401413233f21 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class AllOfSuperModel(BaseModel): """ @@ -37,64 +38,27 @@ class AllOfSuperModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..5dfadd977245 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class AllOfWithSingleRef(BaseModel): """ @@ -39,65 +40,27 @@ class AllOfWithSingleRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..28b17142a816 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/animal.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/animal.py @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -61,59 +62,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..970bd7582756 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 @@ -13,144 +13,37 @@ from __future__ import annotations -from inspect import getfullargspec -import json -import pprint -import re # noqa: F401 from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import List, Optional from typing_extensions import Annotated +from pydantic import Field, RootModel from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict from typing_extensions import Literal, Self -from pydantic import Field 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. """ + root: Union[List[int], str] = Field( + ... + ) - # 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..a90287e17b02 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 @@ -13,122 +13,38 @@ from __future__ import annotations -from inspect import getfullargspec -import json -import pprint -import re # noqa: F401 from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Optional from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig +from pydantic import Field, RootModel from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict from typing_extensions import Literal, Self -from pydantic import Field ANYOFPIG_ANY_OF_SCHEMAS = ["BasquePig", "DanishPig"] -class AnyOfPig(BaseModel): + +class AnyOfPig(RootModel[Union[BasquePig, DanishPig]]): """ AnyOfPig """ + root: Union[BasquePig, DanishPig] = Field( + ... + ) - # 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..9505ce0b6c35 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ArrayOfArrayOfModel(BaseModel): """ @@ -38,76 +39,27 @@ class ArrayOfArrayOfModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..7776dfd14a7a 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ArrayOfArrayOfNumberOnly(BaseModel): """ @@ -37,64 +38,27 @@ class ArrayOfArrayOfNumberOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..c6d99aec508e 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ArrayOfNumberOnly(BaseModel): """ @@ -37,64 +38,27 @@ class ArrayOfNumberOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..9a52407bb57e 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ArrayTest(BaseModel): """ @@ -42,79 +43,27 @@ class ArrayTest(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6770a2e587a4 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -60,59 +61,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..3166836059f5 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class BasquePig(BaseModel): """ @@ -38,65 +39,27 @@ class BasquePig(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..c0288ed8f985 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/bathing.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/bathing.py @@ -20,14 +20,23 @@ 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_extensions import Self, Literal +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", + alias="task_name" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Bathing", + alias="function_name" + ) content: StrictStr additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -53,66 +62,27 @@ def function_name_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6865ed963c9a 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class Capitalization(BaseModel): """ @@ -42,69 +43,27 @@ class Capitalization(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..8c81c11b1b29 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/cat.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/cat.py @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Cat(Animal): """ @@ -38,66 +39,27 @@ class Cat(Animal): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..614f25486a89 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/category.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/category.py @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Category(BaseModel): """ @@ -38,65 +39,27 @@ class Category(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..e1bcb36e7e68 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class CircularAllOfRef(BaseModel): """ @@ -38,73 +39,28 @@ class CircularAllOfRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..616bd5a7dd49 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class CircularReferenceModel(BaseModel): """ @@ -38,69 +39,28 @@ class CircularReferenceModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..264a218d6dd8 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ClassModel(BaseModel): """ @@ -37,64 +38,27 @@ class ClassModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..aa893e0d6104 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/client.py @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Client(BaseModel): """ @@ -37,64 +38,27 @@ class Client(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..608ec222a231 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/color.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/color.py @@ -13,155 +13,37 @@ from __future__ import annotations -import json -import pprint 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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, None] = Field( + None ) + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..a2698a0a3164 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/creature.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/creature.py @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -61,60 +62,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..8b607b1d2065 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class CreatureInfo(BaseModel): """ @@ -37,64 +38,27 @@ class CreatureInfo(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..afd589a99cfc 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class DanishPig(BaseModel): """ @@ -38,65 +39,27 @@ class DanishPig(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/deprecated_object.py b/samples/openapi3/client/petstore/python/petstore_api/models/deprecated_object.py index ad0ec89a5b7a..1717b330ec9e 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class DeprecatedObject(BaseModel): """ @@ -37,64 +38,27 @@ class DeprecatedObject(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b2bf6bef8628 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class DiscriminatorAllOfSub(DiscriminatorAllOfSuper): """ @@ -37,64 +38,27 @@ class DiscriminatorAllOfSub(DiscriminatorAllOfSuper): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..f9839d6f278f 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -59,57 +60,27 @@ def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: else: return None - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..496d3f95f3ba 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/dog.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/dog.py @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Dog(Animal): """ @@ -38,66 +39,27 @@ class Dog(Animal): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b99f6a904ce7 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class DummyModel(BaseModel): """ @@ -38,69 +39,28 @@ class DummyModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..e56c6b336ea0 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 @@ -20,14 +20,21 @@ 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_extensions import Self, Literal +from pydantic import Field class EnumArrays(BaseModel): """ EnumArrays """ # noqa: E501 - just_symbol: Optional[StrictStr] = None - array_enum: Optional[List[StrictStr]] = None + just_symbol: Optional[Literal['>=', '$']] = Field( + None, + description="just_symbol of the EnumArrays" + ) + array_enum: Optional[List[Literal['fish', 'crab']]] = Field( + None, + description="array_enum of the EnumArrays" + ) additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["just_symbol", "array_enum"] @@ -59,65 +66,27 @@ def array_enum_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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_ref_with_default_value.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_ref_with_default_value.py index d864e80d0a73..2ad94c2c5de1 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class EnumRefWithDefaultValue(BaseModel): """ @@ -38,64 +39,27 @@ class EnumRefWithDefaultValue(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py index d39c2c95775e..b508224d8b85 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 @@ -26,19 +26,43 @@ 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_extensions import Self, Literal +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[Literal['UPPER', 'lower', '']] = Field( + None, + description="enum_string of the EnumTest" + ) + enum_string_required: Literal['UPPER', 'lower', ''] = Field( + ..., + description="enum_string_required of the EnumTest" + ) + enum_integer_default: Optional[Literal[1, 5, 14]] = Field( + None, + description="enum_integer_default of the EnumTest" + ) + enum_integer: Optional[Literal[1, -1]] = Field( + None, + description="enum_integer of the EnumTest" + ) + enum_number: Optional[Literal[1.1, -1.2]] = Field( + None, + description="enum_number of the EnumTest" + ) + enum_string_single_member: Literal['abc'] = Field( + None, + description="enum_string_single_member of the EnumTest", + alias="enum_string_single_member" + ) + enum_integer_single_member: Literal['100'] = Field( + None, + description="enum_integer_single_member of the EnumTest", + alias="enum_integer_single_member" + ) 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") @@ -122,81 +146,27 @@ def enum_integer_single_member_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..ca42b4335639 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/feeding.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/feeding.py @@ -20,14 +20,23 @@ 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_extensions import Self, Literal +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", + alias="task_name" + ) + function_name: Literal['care_nourish'] = Field( + ..., + description="function_name of the Feeding", + alias="function_name" + ) content: StrictStr additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -53,66 +62,27 @@ def function_name_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..554374cfbe07 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/file.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/file.py @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class File(BaseModel): """ @@ -37,64 +38,27 @@ class File(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d74d8dbae883 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class FileSchemaTestClass(BaseModel): """ @@ -39,75 +40,27 @@ class FileSchemaTestClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..fdf46e6260a9 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class FirstRef(BaseModel): """ @@ -38,69 +39,28 @@ class FirstRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..e77a2905c9f4 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/foo.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/foo.py @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Foo(BaseModel): """ @@ -37,64 +38,27 @@ class Foo(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b0db656eacfa 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class FooGetDefaultResponse(BaseModel): """ @@ -38,67 +39,27 @@ class FooGetDefaultResponse(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..759262062e78 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 @@ -24,7 +24,8 @@ from typing_extensions import Annotated from uuid import UUID from typing import Optional, Set -from typing_extensions import Self +from typing_extensions import Self, Literal +from pydantic import Field class FormatTest(BaseModel): """ @@ -97,80 +98,27 @@ def pattern_with_digits_and_delimiter_validate_regular_expression(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..c92fae193e56 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class HasOnlyReadOnly(BaseModel): """ @@ -38,69 +39,27 @@ class HasOnlyReadOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d062a5dfe853 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class HealthCheckResult(BaseModel): """ @@ -37,69 +38,27 @@ class HealthCheckResult(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..5e743ec84873 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class HuntingDog(Creature): """ @@ -39,69 +40,27 @@ class HuntingDog(Creature): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..2771d60c2318 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/info.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/info.py @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Info(BaseDiscriminator): """ @@ -38,68 +39,27 @@ class Info(BaseDiscriminator): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..9dcc377719e8 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class InnerDictWithProperty(BaseModel): """ @@ -37,64 +38,27 @@ class InnerDictWithProperty(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..60c833c81dcb 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class InputAllOf(BaseModel): """ @@ -38,76 +39,27 @@ class InputAllOf(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..b57c4c9d0f36 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 @@ -13,132 +13,37 @@ from __future__ import annotations -import json -import pprint 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..c0c5fc4dae85 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ListClass(BaseModel): """ @@ -37,64 +38,27 @@ class ListClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..5e7a0bbfff9a 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class MapOfArrayOfModel(BaseModel): """ @@ -38,80 +39,27 @@ class MapOfArrayOfModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..5b46fae4b015 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 @@ -20,14 +20,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_extensions import Self, Literal +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[Literal['UPPER', 'lower']] = 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] = {} @@ -51,67 +55,27 @@ def map_of_enum_string_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..e7a6eb1c4604 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 @@ -23,7 +23,8 @@ from uuid import UUID from petstore_api.models.animal import Animal from typing import Optional, Set -from typing_extensions import Self +from typing_extensions import Self, Literal +from pydantic import Field class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): """ @@ -42,78 +43,27 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..ae0d0de0a380 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class Model200Response(BaseModel): """ @@ -38,65 +39,27 @@ class Model200Response(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..f27857d233e2 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class ModelApiResponse(BaseModel): """ @@ -39,66 +40,27 @@ class ModelApiResponse(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..672d5a2c1bab 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ModelField(BaseModel): """ @@ -37,64 +38,27 @@ class ModelField(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..affff9bc82a2 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ModelReturn(BaseModel): """ @@ -37,64 +38,27 @@ class ModelReturn(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..f4429792f542 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class MultiArrays(BaseModel): """ @@ -40,79 +41,27 @@ class MultiArrays(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..7392bcd94a96 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/name.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/name.py @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class Name(BaseModel): """ @@ -40,71 +41,27 @@ class Name(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..836632f92186 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class NullableClass(BaseModel): """ @@ -50,131 +51,27 @@ class NullableClass(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..a2100a9d605c 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class NullableProperty(BaseModel): """ @@ -49,70 +50,27 @@ def name_validate_regular_expression(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..8015d2627315 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class NumberOnly(BaseModel): """ @@ -37,64 +38,27 @@ class NumberOnly(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..a0b501f4510e 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class ObjectToTestAdditionalProperties(BaseModel): """ @@ -37,64 +38,27 @@ class ObjectToTestAdditionalProperties(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..607178e61b3e 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ObjectWithDeprecatedFields(BaseModel): """ @@ -41,70 +42,27 @@ class ObjectWithDeprecatedFields(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..e2b2780beece 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 @@ -13,125 +13,38 @@ from __future__ import annotations -import json -import pprint from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..bb5cf7cebd8b 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/order.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/order.py @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Order(BaseModel): """ @@ -31,7 +32,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[Literal['placed', 'approved', 'delivered']] = Field( + None, + description="Order Status" + ) complete: Optional[StrictBool] = False additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["id", "petId", "quantity", "shipDate", "status", "complete"] @@ -53,69 +57,27 @@ def status_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..f3c5a1d1a290 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class OuterComposite(BaseModel): """ @@ -39,66 +40,27 @@ class OuterComposite(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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_object_with_enum_property.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_object_with_enum_property.py index f8d215a21c94..98d966c63f88 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class OuterObjectWithEnumProperty(BaseModel): """ @@ -40,70 +41,27 @@ class OuterObjectWithEnumProperty(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..67019aee1760 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/parent.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/parent.py @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Parent(BaseModel): """ @@ -38,76 +39,27 @@ class Parent(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..595d04b48cac 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class ParentWithOptionalDict(BaseModel): """ @@ -38,76 +39,27 @@ class ParentWithOptionalDict(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d10aa6bea0b3 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/pet.py @@ -23,7 +23,8 @@ 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_extensions import Self, Literal +from pydantic import Field class Pet(BaseModel): """ @@ -34,7 +35,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[Literal['available', 'pending', 'sold']] = Field( + None, + description="pet status in the store" + ) additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["id", "category", "name", "photoUrls", "tags", "status"] @@ -55,79 +59,27 @@ def status_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..4cc32f18c42d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/pig.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/pig.py @@ -13,143 +13,38 @@ from __future__ import annotations -import json -import pprint from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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( + ... ) + def __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + 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..8330edb586e5 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class PonySizes(BaseModel): """ @@ -38,64 +39,27 @@ class PonySizes(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..6404380de0bf 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 @@ -20,14 +20,23 @@ 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_extensions import Self, Literal +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", + alias="task_name" + ) + function_name: Literal['care'] = Field( + ..., + description="function_name of the PoopCleaning", + alias="function_name" + ) content: StrictStr additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["task_name", "function_name", "content"] @@ -53,66 +62,27 @@ def function_name_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..1dd55054ae68 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class PrimitiveString(BaseDiscriminator): """ @@ -38,65 +39,27 @@ class PrimitiveString(BaseDiscriminator): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..ff945938c081 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class PropertyMap(BaseModel): """ @@ -38,76 +39,27 @@ class PropertyMap(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..17e3f07aeca9 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class PropertyNameCollision(BaseModel): """ @@ -39,66 +40,27 @@ class PropertyNameCollision(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..696299173423 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class ReadOnlyFirst(BaseModel): """ @@ -38,67 +39,27 @@ class ReadOnlyFirst(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..7c460b2215df 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class SecondCircularAllOfRef(BaseModel): """ @@ -38,73 +39,28 @@ class SecondCircularAllOfRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d034d43bf66f 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class SecondRef(BaseModel): """ @@ -38,69 +39,28 @@ class SecondRef(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..bf9197fce99f 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class SelfReferenceModel(BaseModel): """ @@ -38,69 +39,28 @@ class SelfReferenceModel(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/special_model_name.py b/samples/openapi3/client/petstore/python/petstore_api/models/special_model_name.py index 84686054875a..e75daa66036b 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class SpecialModelName(BaseModel): """ @@ -37,64 +38,27 @@ class SpecialModelName(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..cb154e1ce529 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class SpecialName(BaseModel): """ @@ -29,7 +30,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[Literal['available', 'pending', 'sold']] = Field( + None, + description="pet status in the store" + ) additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["property", "async", "schema"] @@ -50,69 +54,27 @@ def var_schema_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..e5c4b57a1731 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/tag.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/tag.py @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Tag(BaseModel): """ @@ -38,65 +39,27 @@ class Tag(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..68ad30765acc 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/task.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/task.py @@ -22,7 +22,8 @@ from uuid import UUID from petstore_api.models.task_activity import TaskActivity from typing import Optional, Set -from typing_extensions import Self +from typing_extensions import Self, Literal +from pydantic import Field class Task(BaseModel): """ @@ -40,68 +41,27 @@ class Task(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..15b92f1829bf 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 @@ -13,139 +13,39 @@ from __future__ import annotations -import json -import pprint from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator from typing import Any, List, Optional 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 pydantic import StrictStr, Field, RootModel from typing import Union, List, Set, Optional, Dict from typing_extensions import 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 __getattr__(self, name): + """ + Delegate attribute access to the root model if the attribute + doesn't exist on the main class. + """ - 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 name in self.__dict__: + return super().__getattribute__(name) - 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 + root = self.__dict__.get('root') + if root is not None: + return getattr(root, name) - def to_str(self) -> str: - """Returns the string representation of the actual instance""" - return pprint.pformat(self.model_dump()) + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") 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..4039342bc999 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class TestErrorResponsesWithModel400Response(BaseModel): """ @@ -37,64 +38,27 @@ class TestErrorResponsesWithModel400Response(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..93d9932f5b99 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class TestErrorResponsesWithModel404Response(BaseModel): """ @@ -37,64 +38,27 @@ class TestErrorResponsesWithModel404Response(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d67bb5ef1f35 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): """ @@ -37,64 +38,27 @@ class TestInlineFreeformAdditionalPropertiesRequest(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..36ecd8a5abbb 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class TestModelWithEnumDefault(BaseModel): """ @@ -32,7 +33,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[Literal['A', 'B', 'C']] = 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"] @@ -53,68 +57,27 @@ def test_inline_defined_enum_with_default_validate_enum(cls, value): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..427a35ab86d8 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class TestObjectForMultipartRequestsRequestMarker(BaseModel): """ @@ -37,64 +38,27 @@ class TestObjectForMultipartRequestsRequestMarker(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..897f0f0b897f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/tiger.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/tiger.py @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class Tiger(BaseModel): """ @@ -37,64 +38,27 @@ class Tiger(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/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..5f8e42159a24 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 @@ -21,7 +21,8 @@ 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_extensions import Self, Literal +from pydantic import Field class UnnamedDictWithAdditionalModelListProperties(BaseModel): """ @@ -38,80 +39,27 @@ class UnnamedDictWithAdditionalModelListProperties(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..c4e874f931ca 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 @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class UnnamedDictWithAdditionalStringListProperties(BaseModel): """ @@ -37,64 +38,27 @@ class UnnamedDictWithAdditionalStringListProperties(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..fefa4c26d8f9 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 @@ -20,7 +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_extensions import Self, Literal +from pydantic import Field class UploadFileWithAdditionalPropertiesRequestObject(BaseModel): """ @@ -37,64 +38,27 @@ class UploadFileWithAdditionalPropertiesRequestObject(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..a65ce66ddb99 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/user.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/user.py @@ -20,7 +20,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_extensions import Self, Literal +from pydantic import Field class User(BaseModel): """ @@ -44,71 +45,27 @@ class User(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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..d1d79b8f0b04 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 @@ -22,7 +22,8 @@ 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_extensions import Self, Literal +from pydantic import Field class WithNestedOneOf(BaseModel): """ @@ -41,72 +42,27 @@ class WithNestedOneOf(BaseModel): ) - def to_str(self) -> str: - """Returns the string representation of the model using alias""" - return pprint.pformat(self.model_dump(by_alias=True)) - - def to_json(self) -> str: - """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + """Returns the object represented by the Dict""" + return cls.model_validate(obj, strict=True) @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 from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + return cls.model_validate_json(json_str) def to_dict(self) -> Dict[str, Any]: - """Return the dictionary representation of the model using alias. - - This has the following differences from calling pydantic's - `self.model_dump(by_alias=True)`: - - * `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 + """Returns the dict representation of the actual instance""" + return self.model_dump(by_alias=True, exclude_unset=True) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + return json.dumps(self.model_dump(by_alias=True, exclude_unset=True, mode="json")) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.to_json()) - @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/uv.lock b/samples/openapi3/client/petstore/python/uv.lock new file mode 100644 index 000000000000..b69bb2b44825 --- /dev/null +++ b/samples/openapi3/client/petstore/python/uv.lock @@ -0,0 +1,281 @@ +version = 1 +revision = 3 +requires-python = ">=3.9" + +[[package]] +name = "annotated-types" +version = "0.7.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/ee/67/531ea369ba64dcff5ec9c3402f9f51bf748cec26dde048a2f973a4eea7f5/annotated_types-0.7.0.tar.gz", hash = "sha256:aff07c09a53a08bc8cfccb9c85b05f1aa9a2a6f23728d790723543408344ce89", size = 16081, upload-time = "2024-05-20T21:33:25.928Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/78/b6/6307fbef88d9b5ee7421e68d78a9f162e0da4900bc5f5793f6d3d0e34fb8/annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53", size = 13643, upload-time = "2024-05-20T21:33:24.1Z" }, +] + +[[package]] +name = "pem" +version = "23.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/05/86/16c0b6789816f8d53f2f208b5a090c9197da8a6dae4d490554bb1bedbb09/pem-23.1.0.tar.gz", hash = "sha256:06503ff2441a111f853ce4e8b9eb9d5fedb488ebdbf560115d3dd53a1b4afc73", size = 43796, upload-time = "2023-06-21T10:24:40.539Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/c9/97/8299a481ae6c08494b5d53511e6a4746775d8a354c685c69d8796b2ed482/pem-23.1.0-py3-none-any.whl", hash = "sha256:78bbb1e75b737891350cb9499cbba31da5d59545f360f44163c0bc751cad55d3", size = 9195, upload-time = "2023-06-21T10:24:39.164Z" }, +] + +[[package]] +name = "petstore-api" +version = "1.0.0" +source = { editable = "." } +dependencies = [ + { name = "pem" }, + { name = "pycryptodome" }, + { name = "pydantic" }, + { name = "python-dateutil" }, + { name = "typing-extensions" }, + { name = "urllib3" }, +] + +[package.metadata] +requires-dist = [ + { name = "pem", specifier = ">=19.3.0" }, + { name = "pycryptodome", specifier = ">=3.9.0" }, + { name = "pydantic", specifier = ">=2" }, + { name = "python-dateutil", specifier = ">=2.8.2" }, + { name = "typing-extensions", specifier = ">=4.7.1" }, + { name = "urllib3", specifier = ">=2.1.0,<3.0.0" }, +] + +[[package]] +name = "pycryptodome" +version = "3.23.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/8e/a6/8452177684d5e906854776276ddd34eca30d1b1e15aa1ee9cefc289a33f5/pycryptodome-3.23.0.tar.gz", hash = "sha256:447700a657182d60338bab09fdb27518f8856aecd80ae4c6bdddb67ff5da44ef", size = 4921276, upload-time = "2025-05-17T17:21:45.242Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/04/5d/bdb09489b63cd34a976cc9e2a8d938114f7a53a74d3dd4f125ffa49dce82/pycryptodome-3.23.0-cp313-cp313t-macosx_10_13_universal2.whl", hash = "sha256:0011f7f00cdb74879142011f95133274741778abba114ceca229adbf8e62c3e4", size = 2495152, upload-time = "2025-05-17T17:20:20.833Z" }, + { url = "https://files.pythonhosted.org/packages/a7/ce/7840250ed4cc0039c433cd41715536f926d6e86ce84e904068eb3244b6a6/pycryptodome-3.23.0-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:90460fc9e088ce095f9ee8356722d4f10f86e5be06e2354230a9880b9c549aae", size = 1639348, upload-time = "2025-05-17T17:20:23.171Z" }, + { url = "https://files.pythonhosted.org/packages/ee/f0/991da24c55c1f688d6a3b5a11940567353f74590734ee4a64294834ae472/pycryptodome-3.23.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4764e64b269fc83b00f682c47443c2e6e85b18273712b98aa43bcb77f8570477", size = 2184033, upload-time = "2025-05-17T17:20:25.424Z" }, + { url = "https://files.pythonhosted.org/packages/54/16/0e11882deddf00f68b68dd4e8e442ddc30641f31afeb2bc25588124ac8de/pycryptodome-3.23.0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eb8f24adb74984aa0e5d07a2368ad95276cf38051fe2dc6605cbcf482e04f2a7", size = 2270142, upload-time = "2025-05-17T17:20:27.808Z" }, + { url = "https://files.pythonhosted.org/packages/d5/fc/4347fea23a3f95ffb931f383ff28b3f7b1fe868739182cb76718c0da86a1/pycryptodome-3.23.0-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d97618c9c6684a97ef7637ba43bdf6663a2e2e77efe0f863cce97a76af396446", size = 2309384, upload-time = "2025-05-17T17:20:30.765Z" }, + { url = "https://files.pythonhosted.org/packages/6e/d9/c5261780b69ce66d8cfab25d2797bd6e82ba0241804694cd48be41add5eb/pycryptodome-3.23.0-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:9a53a4fe5cb075075d515797d6ce2f56772ea7e6a1e5e4b96cf78a14bac3d265", size = 2183237, upload-time = "2025-05-17T17:20:33.736Z" }, + { url = "https://files.pythonhosted.org/packages/5a/6f/3af2ffedd5cfa08c631f89452c6648c4d779e7772dfc388c77c920ca6bbf/pycryptodome-3.23.0-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:763d1d74f56f031788e5d307029caef067febf890cd1f8bf61183ae142f1a77b", size = 2343898, upload-time = "2025-05-17T17:20:36.086Z" }, + { url = "https://files.pythonhosted.org/packages/9a/dc/9060d807039ee5de6e2f260f72f3d70ac213993a804f5e67e0a73a56dd2f/pycryptodome-3.23.0-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:954af0e2bd7cea83ce72243b14e4fb518b18f0c1649b576d114973e2073b273d", size = 2269197, upload-time = "2025-05-17T17:20:38.414Z" }, + { url = "https://files.pythonhosted.org/packages/f9/34/e6c8ca177cb29dcc4967fef73f5de445912f93bd0343c9c33c8e5bf8cde8/pycryptodome-3.23.0-cp313-cp313t-win32.whl", hash = "sha256:257bb3572c63ad8ba40b89f6fc9d63a2a628e9f9708d31ee26560925ebe0210a", size = 1768600, upload-time = "2025-05-17T17:20:40.688Z" }, + { url = "https://files.pythonhosted.org/packages/e4/1d/89756b8d7ff623ad0160f4539da571d1f594d21ee6d68be130a6eccb39a4/pycryptodome-3.23.0-cp313-cp313t-win_amd64.whl", hash = "sha256:6501790c5b62a29fcb227bd6b62012181d886a767ce9ed03b303d1f22eb5c625", size = 1799740, upload-time = "2025-05-17T17:20:42.413Z" }, + { url = "https://files.pythonhosted.org/packages/5d/61/35a64f0feaea9fd07f0d91209e7be91726eb48c0f1bfc6720647194071e4/pycryptodome-3.23.0-cp313-cp313t-win_arm64.whl", hash = "sha256:9a77627a330ab23ca43b48b130e202582e91cc69619947840ea4d2d1be21eb39", size = 1703685, upload-time = "2025-05-17T17:20:44.388Z" }, + { url = "https://files.pythonhosted.org/packages/db/6c/a1f71542c969912bb0e106f64f60a56cc1f0fabecf9396f45accbe63fa68/pycryptodome-3.23.0-cp37-abi3-macosx_10_9_universal2.whl", hash = "sha256:187058ab80b3281b1de11c2e6842a357a1f71b42cb1e15bce373f3d238135c27", size = 2495627, upload-time = "2025-05-17T17:20:47.139Z" }, + { url = "https://files.pythonhosted.org/packages/6e/4e/a066527e079fc5002390c8acdd3aca431e6ea0a50ffd7201551175b47323/pycryptodome-3.23.0-cp37-abi3-macosx_10_9_x86_64.whl", hash = "sha256:cfb5cd445280c5b0a4e6187a7ce8de5a07b5f3f897f235caa11f1f435f182843", size = 1640362, upload-time = "2025-05-17T17:20:50.392Z" }, + { url = "https://files.pythonhosted.org/packages/50/52/adaf4c8c100a8c49d2bd058e5b551f73dfd8cb89eb4911e25a0c469b6b4e/pycryptodome-3.23.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:67bd81fcbe34f43ad9422ee8fd4843c8e7198dd88dd3d40e6de42ee65fbe1490", size = 2182625, upload-time = "2025-05-17T17:20:52.866Z" }, + { url = "https://files.pythonhosted.org/packages/5f/e9/a09476d436d0ff1402ac3867d933c61805ec2326c6ea557aeeac3825604e/pycryptodome-3.23.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c8987bd3307a39bc03df5c8e0e3d8be0c4c3518b7f044b0f4c15d1aa78f52575", size = 2268954, upload-time = "2025-05-17T17:20:55.027Z" }, + { url = "https://files.pythonhosted.org/packages/f9/c5/ffe6474e0c551d54cab931918127c46d70cab8f114e0c2b5a3c071c2f484/pycryptodome-3.23.0-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:aa0698f65e5b570426fc31b8162ed4603b0c2841cbb9088e2b01641e3065915b", size = 2308534, upload-time = "2025-05-17T17:20:57.279Z" }, + { url = "https://files.pythonhosted.org/packages/18/28/e199677fc15ecf43010f2463fde4c1a53015d1fe95fb03bca2890836603a/pycryptodome-3.23.0-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:53ecbafc2b55353edcebd64bf5da94a2a2cdf5090a6915bcca6eca6cc452585a", size = 2181853, upload-time = "2025-05-17T17:20:59.322Z" }, + { url = "https://files.pythonhosted.org/packages/ce/ea/4fdb09f2165ce1365c9eaefef36625583371ee514db58dc9b65d3a255c4c/pycryptodome-3.23.0-cp37-abi3-musllinux_1_2_i686.whl", hash = "sha256:156df9667ad9f2ad26255926524e1c136d6664b741547deb0a86a9acf5ea631f", size = 2342465, upload-time = "2025-05-17T17:21:03.83Z" }, + { url = "https://files.pythonhosted.org/packages/22/82/6edc3fc42fe9284aead511394bac167693fb2b0e0395b28b8bedaa07ef04/pycryptodome-3.23.0-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:dea827b4d55ee390dc89b2afe5927d4308a8b538ae91d9c6f7a5090f397af1aa", size = 2267414, upload-time = "2025-05-17T17:21:06.72Z" }, + { url = "https://files.pythonhosted.org/packages/59/fe/aae679b64363eb78326c7fdc9d06ec3de18bac68be4b612fc1fe8902693c/pycryptodome-3.23.0-cp37-abi3-win32.whl", hash = "sha256:507dbead45474b62b2bbe318eb1c4c8ee641077532067fec9c1aa82c31f84886", size = 1768484, upload-time = "2025-05-17T17:21:08.535Z" }, + { url = "https://files.pythonhosted.org/packages/54/2f/e97a1b8294db0daaa87012c24a7bb714147c7ade7656973fd6c736b484ff/pycryptodome-3.23.0-cp37-abi3-win_amd64.whl", hash = "sha256:c75b52aacc6c0c260f204cbdd834f76edc9fb0d8e0da9fbf8352ef58202564e2", size = 1799636, upload-time = "2025-05-17T17:21:10.393Z" }, + { url = "https://files.pythonhosted.org/packages/18/3d/f9441a0d798bf2b1e645adc3265e55706aead1255ccdad3856dbdcffec14/pycryptodome-3.23.0-cp37-abi3-win_arm64.whl", hash = "sha256:11eeeb6917903876f134b56ba11abe95c0b0fd5e3330def218083c7d98bbcb3c", size = 1703675, upload-time = "2025-05-17T17:21:13.146Z" }, + { url = "https://files.pythonhosted.org/packages/d9/12/e33935a0709c07de084d7d58d330ec3f4daf7910a18e77937affdb728452/pycryptodome-3.23.0-pp310-pypy310_pp73-macosx_10_15_x86_64.whl", hash = "sha256:ddb95b49df036ddd264a0ad246d1be5b672000f12d6961ea2c267083a5e19379", size = 1623886, upload-time = "2025-05-17T17:21:20.614Z" }, + { url = "https://files.pythonhosted.org/packages/22/0b/aa8f9419f25870889bebf0b26b223c6986652bdf071f000623df11212c90/pycryptodome-3.23.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d8e95564beb8782abfd9e431c974e14563a794a4944c29d6d3b7b5ea042110b4", size = 1672151, upload-time = "2025-05-17T17:21:22.666Z" }, + { url = "https://files.pythonhosted.org/packages/d4/5e/63f5cbde2342b7f70a39e591dbe75d9809d6338ce0b07c10406f1a140cdc/pycryptodome-3.23.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:14e15c081e912c4b0d75632acd8382dfce45b258667aa3c67caf7a4d4c13f630", size = 1664461, upload-time = "2025-05-17T17:21:25.225Z" }, + { url = "https://files.pythonhosted.org/packages/d6/92/608fbdad566ebe499297a86aae5f2a5263818ceeecd16733006f1600403c/pycryptodome-3.23.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a7fc76bf273353dc7e5207d172b83f569540fc9a28d63171061c42e361d22353", size = 1702440, upload-time = "2025-05-17T17:21:27.991Z" }, + { url = "https://files.pythonhosted.org/packages/d1/92/2eadd1341abd2989cce2e2740b4423608ee2014acb8110438244ee97d7ff/pycryptodome-3.23.0-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:45c69ad715ca1a94f778215a11e66b7ff989d792a4d63b68dc586a1da1392ff5", size = 1803005, upload-time = "2025-05-17T17:21:31.37Z" }, + { url = "https://files.pythonhosted.org/packages/dc/c4/6925ad41576d3e84f03aaf9a0411667af861f9fa2c87553c7dd5bde01518/pycryptodome-3.23.0-pp39-pypy39_pp73-macosx_10_15_x86_64.whl", hash = "sha256:865d83c906b0fc6a59b510deceee656b6bc1c4fa0d82176e2b77e97a420a996a", size = 1623768, upload-time = "2025-05-17T17:21:33.418Z" }, + { url = "https://files.pythonhosted.org/packages/a8/14/d6c6a3098ddf2624068f041c5639be5092ad4ae1a411842369fd56765994/pycryptodome-3.23.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:89d4d56153efc4d81defe8b65fd0821ef8b2d5ddf8ed19df31ba2f00872b8002", size = 1672070, upload-time = "2025-05-17T17:21:35.565Z" }, + { url = "https://files.pythonhosted.org/packages/20/89/5d29c8f178fea7c92fd20d22f9ddd532a5e3ac71c574d555d2362aaa832a/pycryptodome-3.23.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e3f2d0aaf8080bda0587d58fc9fe4766e012441e2eed4269a77de6aea981c8be", size = 1664359, upload-time = "2025-05-17T17:21:37.551Z" }, + { url = "https://files.pythonhosted.org/packages/38/bc/a287d41b4421ad50eafb02313137d0276d6aeffab90a91e2b08f64140852/pycryptodome-3.23.0-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:64093fc334c1eccfd3933c134c4457c34eaca235eeae49d69449dc4728079339", size = 1702359, upload-time = "2025-05-17T17:21:39.827Z" }, + { url = "https://files.pythonhosted.org/packages/2b/62/2392b7879f4d2c1bfa20815720b89d464687877851716936b9609959c201/pycryptodome-3.23.0-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:ce64e84a962b63a47a592690bdc16a7eaf709d2c2697ababf24a0def566899a6", size = 1802461, upload-time = "2025-05-17T17:21:41.722Z" }, +] + +[[package]] +name = "pydantic" +version = "2.12.5" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "annotated-types" }, + { name = "pydantic-core" }, + { name = "typing-extensions" }, + { name = "typing-inspection" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/69/44/36f1a6e523abc58ae5f928898e4aca2e0ea509b5aa6f6f392a5d882be928/pydantic-2.12.5.tar.gz", hash = "sha256:4d351024c75c0f085a9febbb665ce8c0c6ec5d30e903bdb6394b7ede26aebb49", size = 821591, upload-time = "2025-11-26T15:11:46.471Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/5a/87/b70ad306ebb6f9b585f114d0ac2137d792b48be34d732d60e597c2f8465a/pydantic-2.12.5-py3-none-any.whl", hash = "sha256:e561593fccf61e8a20fc46dfc2dfe075b8be7d0188df33f221ad1f0139180f9d", size = 463580, upload-time = "2025-11-26T15:11:44.605Z" }, +] + +[[package]] +name = "pydantic-core" +version = "2.41.5" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/71/70/23b021c950c2addd24ec408e9ab05d59b035b39d97cdc1130e1bce647bb6/pydantic_core-2.41.5.tar.gz", hash = "sha256:08daa51ea16ad373ffd5e7606252cc32f07bc72b28284b6bc9c6df804816476e", size = 460952, upload-time = "2025-11-04T13:43:49.098Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/c6/90/32c9941e728d564b411d574d8ee0cf09b12ec978cb22b294995bae5549a5/pydantic_core-2.41.5-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:77b63866ca88d804225eaa4af3e664c5faf3568cea95360d21f4725ab6e07146", size = 2107298, upload-time = "2025-11-04T13:39:04.116Z" }, + { url = "https://files.pythonhosted.org/packages/fb/a8/61c96a77fe28993d9a6fb0f4127e05430a267b235a124545d79fea46dd65/pydantic_core-2.41.5-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:dfa8a0c812ac681395907e71e1274819dec685fec28273a28905df579ef137e2", size = 1901475, upload-time = "2025-11-04T13:39:06.055Z" }, + { url = "https://files.pythonhosted.org/packages/5d/b6/338abf60225acc18cdc08b4faef592d0310923d19a87fba1faf05af5346e/pydantic_core-2.41.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5921a4d3ca3aee735d9fd163808f5e8dd6c6972101e4adbda9a4667908849b97", size = 1918815, upload-time = "2025-11-04T13:39:10.41Z" }, + { url = "https://files.pythonhosted.org/packages/d1/1c/2ed0433e682983d8e8cba9c8d8ef274d4791ec6a6f24c58935b90e780e0a/pydantic_core-2.41.5-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:e25c479382d26a2a41b7ebea1043564a937db462816ea07afa8a44c0866d52f9", size = 2065567, upload-time = "2025-11-04T13:39:12.244Z" }, + { url = "https://files.pythonhosted.org/packages/b3/24/cf84974ee7d6eae06b9e63289b7b8f6549d416b5c199ca2d7ce13bbcf619/pydantic_core-2.41.5-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:f547144f2966e1e16ae626d8ce72b4cfa0caedc7fa28052001c94fb2fcaa1c52", size = 2230442, upload-time = "2025-11-04T13:39:13.962Z" }, + { url = "https://files.pythonhosted.org/packages/fd/21/4e287865504b3edc0136c89c9c09431be326168b1eb7841911cbc877a995/pydantic_core-2.41.5-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:6f52298fbd394f9ed112d56f3d11aabd0d5bd27beb3084cc3d8ad069483b8941", size = 2350956, upload-time = "2025-11-04T13:39:15.889Z" }, + { url = "https://files.pythonhosted.org/packages/a8/76/7727ef2ffa4b62fcab916686a68a0426b9b790139720e1934e8ba797e238/pydantic_core-2.41.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:100baa204bb412b74fe285fb0f3a385256dad1d1879f0a5cb1499ed2e83d132a", size = 2068253, upload-time = "2025-11-04T13:39:17.403Z" }, + { url = "https://files.pythonhosted.org/packages/d5/8c/a4abfc79604bcb4c748e18975c44f94f756f08fb04218d5cb87eb0d3a63e/pydantic_core-2.41.5-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:05a2c8852530ad2812cb7914dc61a1125dc4e06252ee98e5638a12da6cc6fb6c", size = 2177050, upload-time = "2025-11-04T13:39:19.351Z" }, + { url = "https://files.pythonhosted.org/packages/67/b1/de2e9a9a79b480f9cb0b6e8b6ba4c50b18d4e89852426364c66aa82bb7b3/pydantic_core-2.41.5-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:29452c56df2ed968d18d7e21f4ab0ac55e71dc59524872f6fc57dcf4a3249ed2", size = 2147178, upload-time = "2025-11-04T13:39:21Z" }, + { url = "https://files.pythonhosted.org/packages/16/c1/dfb33f837a47b20417500efaa0378adc6635b3c79e8369ff7a03c494b4ac/pydantic_core-2.41.5-cp310-cp310-musllinux_1_1_armv7l.whl", hash = "sha256:d5160812ea7a8a2ffbe233d8da666880cad0cbaf5d4de74ae15c313213d62556", size = 2341833, upload-time = "2025-11-04T13:39:22.606Z" }, + { url = "https://files.pythonhosted.org/packages/47/36/00f398642a0f4b815a9a558c4f1dca1b4020a7d49562807d7bc9ff279a6c/pydantic_core-2.41.5-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:df3959765b553b9440adfd3c795617c352154e497a4eaf3752555cfb5da8fc49", size = 2321156, upload-time = "2025-11-04T13:39:25.843Z" }, + { url = "https://files.pythonhosted.org/packages/7e/70/cad3acd89fde2010807354d978725ae111ddf6d0ea46d1ea1775b5c1bd0c/pydantic_core-2.41.5-cp310-cp310-win32.whl", hash = "sha256:1f8d33a7f4d5a7889e60dc39856d76d09333d8a6ed0f5f1190635cbec70ec4ba", size = 1989378, upload-time = "2025-11-04T13:39:27.92Z" }, + { url = "https://files.pythonhosted.org/packages/76/92/d338652464c6c367e5608e4488201702cd1cbb0f33f7b6a85a60fe5f3720/pydantic_core-2.41.5-cp310-cp310-win_amd64.whl", hash = "sha256:62de39db01b8d593e45871af2af9e497295db8d73b085f6bfd0b18c83c70a8f9", size = 2013622, upload-time = "2025-11-04T13:39:29.848Z" }, + { url = "https://files.pythonhosted.org/packages/e8/72/74a989dd9f2084b3d9530b0915fdda64ac48831c30dbf7c72a41a5232db8/pydantic_core-2.41.5-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:a3a52f6156e73e7ccb0f8cced536adccb7042be67cb45f9562e12b319c119da6", size = 2105873, upload-time = "2025-11-04T13:39:31.373Z" }, + { url = "https://files.pythonhosted.org/packages/12/44/37e403fd9455708b3b942949e1d7febc02167662bf1a7da5b78ee1ea2842/pydantic_core-2.41.5-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:7f3bf998340c6d4b0c9a2f02d6a400e51f123b59565d74dc60d252ce888c260b", size = 1899826, upload-time = "2025-11-04T13:39:32.897Z" }, + { url = "https://files.pythonhosted.org/packages/33/7f/1d5cab3ccf44c1935a359d51a8a2a9e1a654b744b5e7f80d41b88d501eec/pydantic_core-2.41.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:378bec5c66998815d224c9ca994f1e14c0c21cb95d2f52b6021cc0b2a58f2a5a", size = 1917869, upload-time = "2025-11-04T13:39:34.469Z" }, + { url = "https://files.pythonhosted.org/packages/6e/6a/30d94a9674a7fe4f4744052ed6c5e083424510be1e93da5bc47569d11810/pydantic_core-2.41.5-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:e7b576130c69225432866fe2f4a469a85a54ade141d96fd396dffcf607b558f8", size = 2063890, upload-time = "2025-11-04T13:39:36.053Z" }, + { url = "https://files.pythonhosted.org/packages/50/be/76e5d46203fcb2750e542f32e6c371ffa9b8ad17364cf94bb0818dbfb50c/pydantic_core-2.41.5-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6cb58b9c66f7e4179a2d5e0f849c48eff5c1fca560994d6eb6543abf955a149e", size = 2229740, upload-time = "2025-11-04T13:39:37.753Z" }, + { url = "https://files.pythonhosted.org/packages/d3/ee/fed784df0144793489f87db310a6bbf8118d7b630ed07aa180d6067e653a/pydantic_core-2.41.5-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:88942d3a3dff3afc8288c21e565e476fc278902ae4d6d134f1eeda118cc830b1", size = 2350021, upload-time = "2025-11-04T13:39:40.94Z" }, + { url = "https://files.pythonhosted.org/packages/c8/be/8fed28dd0a180dca19e72c233cbf58efa36df055e5b9d90d64fd1740b828/pydantic_core-2.41.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f31d95a179f8d64d90f6831d71fa93290893a33148d890ba15de25642c5d075b", size = 2066378, upload-time = "2025-11-04T13:39:42.523Z" }, + { url = "https://files.pythonhosted.org/packages/b0/3b/698cf8ae1d536a010e05121b4958b1257f0b5522085e335360e53a6b1c8b/pydantic_core-2.41.5-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:c1df3d34aced70add6f867a8cf413e299177e0c22660cc767218373d0779487b", size = 2175761, upload-time = "2025-11-04T13:39:44.553Z" }, + { url = "https://files.pythonhosted.org/packages/b8/ba/15d537423939553116dea94ce02f9c31be0fa9d0b806d427e0308ec17145/pydantic_core-2.41.5-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:4009935984bd36bd2c774e13f9a09563ce8de4abaa7226f5108262fa3e637284", size = 2146303, upload-time = "2025-11-04T13:39:46.238Z" }, + { url = "https://files.pythonhosted.org/packages/58/7f/0de669bf37d206723795f9c90c82966726a2ab06c336deba4735b55af431/pydantic_core-2.41.5-cp311-cp311-musllinux_1_1_armv7l.whl", hash = "sha256:34a64bc3441dc1213096a20fe27e8e128bd3ff89921706e83c0b1ac971276594", size = 2340355, upload-time = "2025-11-04T13:39:48.002Z" }, + { url = "https://files.pythonhosted.org/packages/e5/de/e7482c435b83d7e3c3ee5ee4451f6e8973cff0eb6007d2872ce6383f6398/pydantic_core-2.41.5-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:c9e19dd6e28fdcaa5a1de679aec4141f691023916427ef9bae8584f9c2fb3b0e", size = 2319875, upload-time = "2025-11-04T13:39:49.705Z" }, + { url = "https://files.pythonhosted.org/packages/fe/e6/8c9e81bb6dd7560e33b9053351c29f30c8194b72f2d6932888581f503482/pydantic_core-2.41.5-cp311-cp311-win32.whl", hash = "sha256:2c010c6ded393148374c0f6f0bf89d206bf3217f201faa0635dcd56bd1520f6b", size = 1987549, upload-time = "2025-11-04T13:39:51.842Z" }, + { url = "https://files.pythonhosted.org/packages/11/66/f14d1d978ea94d1bc21fc98fcf570f9542fe55bfcc40269d4e1a21c19bf7/pydantic_core-2.41.5-cp311-cp311-win_amd64.whl", hash = "sha256:76ee27c6e9c7f16f47db7a94157112a2f3a00e958bc626e2f4ee8bec5c328fbe", size = 2011305, upload-time = "2025-11-04T13:39:53.485Z" }, + { url = "https://files.pythonhosted.org/packages/56/d8/0e271434e8efd03186c5386671328154ee349ff0354d83c74f5caaf096ed/pydantic_core-2.41.5-cp311-cp311-win_arm64.whl", hash = "sha256:4bc36bbc0b7584de96561184ad7f012478987882ebf9f9c389b23f432ea3d90f", size = 1972902, upload-time = "2025-11-04T13:39:56.488Z" }, + { url = "https://files.pythonhosted.org/packages/5f/5d/5f6c63eebb5afee93bcaae4ce9a898f3373ca23df3ccaef086d0233a35a7/pydantic_core-2.41.5-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:f41a7489d32336dbf2199c8c0a215390a751c5b014c2c1c5366e817202e9cdf7", size = 2110990, upload-time = "2025-11-04T13:39:58.079Z" }, + { url = "https://files.pythonhosted.org/packages/aa/32/9c2e8ccb57c01111e0fd091f236c7b371c1bccea0fa85247ac55b1e2b6b6/pydantic_core-2.41.5-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:070259a8818988b9a84a449a2a7337c7f430a22acc0859c6b110aa7212a6d9c0", size = 1896003, upload-time = "2025-11-04T13:39:59.956Z" }, + { url = "https://files.pythonhosted.org/packages/68/b8/a01b53cb0e59139fbc9e4fda3e9724ede8de279097179be4ff31f1abb65a/pydantic_core-2.41.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e96cea19e34778f8d59fe40775a7a574d95816eb150850a85a7a4c8f4b94ac69", size = 1919200, upload-time = "2025-11-04T13:40:02.241Z" }, + { url = "https://files.pythonhosted.org/packages/38/de/8c36b5198a29bdaade07b5985e80a233a5ac27137846f3bc2d3b40a47360/pydantic_core-2.41.5-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:ed2e99c456e3fadd05c991f8f437ef902e00eedf34320ba2b0842bd1c3ca3a75", size = 2052578, upload-time = "2025-11-04T13:40:04.401Z" }, + { url = "https://files.pythonhosted.org/packages/00/b5/0e8e4b5b081eac6cb3dbb7e60a65907549a1ce035a724368c330112adfdd/pydantic_core-2.41.5-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:65840751b72fbfd82c3c640cff9284545342a4f1eb1586ad0636955b261b0b05", size = 2208504, upload-time = "2025-11-04T13:40:06.072Z" }, + { url = "https://files.pythonhosted.org/packages/77/56/87a61aad59c7c5b9dc8caad5a41a5545cba3810c3e828708b3d7404f6cef/pydantic_core-2.41.5-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e536c98a7626a98feb2d3eaf75944ef6f3dbee447e1f841eae16f2f0a72d8ddc", size = 2335816, upload-time = "2025-11-04T13:40:07.835Z" }, + { url = "https://files.pythonhosted.org/packages/0d/76/941cc9f73529988688a665a5c0ecff1112b3d95ab48f81db5f7606f522d3/pydantic_core-2.41.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eceb81a8d74f9267ef4081e246ffd6d129da5d87e37a77c9bde550cb04870c1c", size = 2075366, upload-time = "2025-11-04T13:40:09.804Z" }, + { url = "https://files.pythonhosted.org/packages/d3/43/ebef01f69baa07a482844faaa0a591bad1ef129253ffd0cdaa9d8a7f72d3/pydantic_core-2.41.5-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:d38548150c39b74aeeb0ce8ee1d8e82696f4a4e16ddc6de7b1d8823f7de4b9b5", size = 2171698, upload-time = "2025-11-04T13:40:12.004Z" }, + { url = "https://files.pythonhosted.org/packages/b1/87/41f3202e4193e3bacfc2c065fab7706ebe81af46a83d3e27605029c1f5a6/pydantic_core-2.41.5-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:c23e27686783f60290e36827f9c626e63154b82b116d7fe9adba1fda36da706c", size = 2132603, upload-time = "2025-11-04T13:40:13.868Z" }, + { url = "https://files.pythonhosted.org/packages/49/7d/4c00df99cb12070b6bccdef4a195255e6020a550d572768d92cc54dba91a/pydantic_core-2.41.5-cp312-cp312-musllinux_1_1_armv7l.whl", hash = "sha256:482c982f814460eabe1d3bb0adfdc583387bd4691ef00b90575ca0d2b6fe2294", size = 2329591, upload-time = "2025-11-04T13:40:15.672Z" }, + { url = "https://files.pythonhosted.org/packages/cc/6a/ebf4b1d65d458f3cda6a7335d141305dfa19bdc61140a884d165a8a1bbc7/pydantic_core-2.41.5-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:bfea2a5f0b4d8d43adf9d7b8bf019fb46fdd10a2e5cde477fbcb9d1fa08c68e1", size = 2319068, upload-time = "2025-11-04T13:40:17.532Z" }, + { url = "https://files.pythonhosted.org/packages/49/3b/774f2b5cd4192d5ab75870ce4381fd89cf218af999515baf07e7206753f0/pydantic_core-2.41.5-cp312-cp312-win32.whl", hash = "sha256:b74557b16e390ec12dca509bce9264c3bbd128f8a2c376eaa68003d7f327276d", size = 1985908, upload-time = "2025-11-04T13:40:19.309Z" }, + { url = "https://files.pythonhosted.org/packages/86/45/00173a033c801cacf67c190fef088789394feaf88a98a7035b0e40d53dc9/pydantic_core-2.41.5-cp312-cp312-win_amd64.whl", hash = "sha256:1962293292865bca8e54702b08a4f26da73adc83dd1fcf26fbc875b35d81c815", size = 2020145, upload-time = "2025-11-04T13:40:21.548Z" }, + { url = "https://files.pythonhosted.org/packages/f9/22/91fbc821fa6d261b376a3f73809f907cec5ca6025642c463d3488aad22fb/pydantic_core-2.41.5-cp312-cp312-win_arm64.whl", hash = "sha256:1746d4a3d9a794cacae06a5eaaccb4b8643a131d45fbc9af23e353dc0a5ba5c3", size = 1976179, upload-time = "2025-11-04T13:40:23.393Z" }, + { url = "https://files.pythonhosted.org/packages/87/06/8806241ff1f70d9939f9af039c6c35f2360cf16e93c2ca76f184e76b1564/pydantic_core-2.41.5-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:941103c9be18ac8daf7b7adca8228f8ed6bb7a1849020f643b3a14d15b1924d9", size = 2120403, upload-time = "2025-11-04T13:40:25.248Z" }, + { url = "https://files.pythonhosted.org/packages/94/02/abfa0e0bda67faa65fef1c84971c7e45928e108fe24333c81f3bfe35d5f5/pydantic_core-2.41.5-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:112e305c3314f40c93998e567879e887a3160bb8689ef3d2c04b6cc62c33ac34", size = 1896206, upload-time = "2025-11-04T13:40:27.099Z" }, + { url = "https://files.pythonhosted.org/packages/15/df/a4c740c0943e93e6500f9eb23f4ca7ec9bf71b19e608ae5b579678c8d02f/pydantic_core-2.41.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0cbaad15cb0c90aa221d43c00e77bb33c93e8d36e0bf74760cd00e732d10a6a0", size = 1919307, upload-time = "2025-11-04T13:40:29.806Z" }, + { url = "https://files.pythonhosted.org/packages/9a/e3/6324802931ae1d123528988e0e86587c2072ac2e5394b4bc2bc34b61ff6e/pydantic_core-2.41.5-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:03ca43e12fab6023fc79d28ca6b39b05f794ad08ec2feccc59a339b02f2b3d33", size = 2063258, upload-time = "2025-11-04T13:40:33.544Z" }, + { url = "https://files.pythonhosted.org/packages/c9/d4/2230d7151d4957dd79c3044ea26346c148c98fbf0ee6ebd41056f2d62ab5/pydantic_core-2.41.5-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:dc799088c08fa04e43144b164feb0c13f9a0bc40503f8df3e9fde58a3c0c101e", size = 2214917, upload-time = "2025-11-04T13:40:35.479Z" }, + { url = "https://files.pythonhosted.org/packages/e6/9f/eaac5df17a3672fef0081b6c1bb0b82b33ee89aa5cec0d7b05f52fd4a1fa/pydantic_core-2.41.5-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:97aeba56665b4c3235a0e52b2c2f5ae9cd071b8a8310ad27bddb3f7fb30e9aa2", size = 2332186, upload-time = "2025-11-04T13:40:37.436Z" }, + { url = "https://files.pythonhosted.org/packages/cf/4e/35a80cae583a37cf15604b44240e45c05e04e86f9cfd766623149297e971/pydantic_core-2.41.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:406bf18d345822d6c21366031003612b9c77b3e29ffdb0f612367352aab7d586", size = 2073164, upload-time = "2025-11-04T13:40:40.289Z" }, + { url = "https://files.pythonhosted.org/packages/bf/e3/f6e262673c6140dd3305d144d032f7bd5f7497d3871c1428521f19f9efa2/pydantic_core-2.41.5-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:b93590ae81f7010dbe380cdeab6f515902ebcbefe0b9327cc4804d74e93ae69d", size = 2179146, upload-time = "2025-11-04T13:40:42.809Z" }, + { url = "https://files.pythonhosted.org/packages/75/c7/20bd7fc05f0c6ea2056a4565c6f36f8968c0924f19b7d97bbfea55780e73/pydantic_core-2.41.5-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:01a3d0ab748ee531f4ea6c3e48ad9dac84ddba4b0d82291f87248f2f9de8d740", size = 2137788, upload-time = "2025-11-04T13:40:44.752Z" }, + { url = "https://files.pythonhosted.org/packages/3a/8d/34318ef985c45196e004bc46c6eab2eda437e744c124ef0dbe1ff2c9d06b/pydantic_core-2.41.5-cp313-cp313-musllinux_1_1_armv7l.whl", hash = "sha256:6561e94ba9dacc9c61bce40e2d6bdc3bfaa0259d3ff36ace3b1e6901936d2e3e", size = 2340133, upload-time = "2025-11-04T13:40:46.66Z" }, + { url = "https://files.pythonhosted.org/packages/9c/59/013626bf8c78a5a5d9350d12e7697d3d4de951a75565496abd40ccd46bee/pydantic_core-2.41.5-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:915c3d10f81bec3a74fbd4faebe8391013ba61e5a1a8d48c4455b923bdda7858", size = 2324852, upload-time = "2025-11-04T13:40:48.575Z" }, + { url = "https://files.pythonhosted.org/packages/1a/d9/c248c103856f807ef70c18a4f986693a46a8ffe1602e5d361485da502d20/pydantic_core-2.41.5-cp313-cp313-win32.whl", hash = "sha256:650ae77860b45cfa6e2cdafc42618ceafab3a2d9a3811fcfbd3bbf8ac3c40d36", size = 1994679, upload-time = "2025-11-04T13:40:50.619Z" }, + { url = "https://files.pythonhosted.org/packages/9e/8b/341991b158ddab181cff136acd2552c9f35bd30380422a639c0671e99a91/pydantic_core-2.41.5-cp313-cp313-win_amd64.whl", hash = "sha256:79ec52ec461e99e13791ec6508c722742ad745571f234ea6255bed38c6480f11", size = 2019766, upload-time = "2025-11-04T13:40:52.631Z" }, + { url = "https://files.pythonhosted.org/packages/73/7d/f2f9db34af103bea3e09735bb40b021788a5e834c81eedb541991badf8f5/pydantic_core-2.41.5-cp313-cp313-win_arm64.whl", hash = "sha256:3f84d5c1b4ab906093bdc1ff10484838aca54ef08de4afa9de0f5f14d69639cd", size = 1981005, upload-time = "2025-11-04T13:40:54.734Z" }, + { url = "https://files.pythonhosted.org/packages/ea/28/46b7c5c9635ae96ea0fbb779e271a38129df2550f763937659ee6c5dbc65/pydantic_core-2.41.5-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:3f37a19d7ebcdd20b96485056ba9e8b304e27d9904d233d7b1015db320e51f0a", size = 2119622, upload-time = "2025-11-04T13:40:56.68Z" }, + { url = "https://files.pythonhosted.org/packages/74/1a/145646e5687e8d9a1e8d09acb278c8535ebe9e972e1f162ed338a622f193/pydantic_core-2.41.5-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:1d1d9764366c73f996edd17abb6d9d7649a7eb690006ab6adbda117717099b14", size = 1891725, upload-time = "2025-11-04T13:40:58.807Z" }, + { url = "https://files.pythonhosted.org/packages/23/04/e89c29e267b8060b40dca97bfc64a19b2a3cf99018167ea1677d96368273/pydantic_core-2.41.5-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:25e1c2af0fce638d5f1988b686f3b3ea8cd7de5f244ca147c777769e798a9cd1", size = 1915040, upload-time = "2025-11-04T13:41:00.853Z" }, + { url = "https://files.pythonhosted.org/packages/84/a3/15a82ac7bd97992a82257f777b3583d3e84bdb06ba6858f745daa2ec8a85/pydantic_core-2.41.5-cp314-cp314-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:506d766a8727beef16b7adaeb8ee6217c64fc813646b424d0804d67c16eddb66", size = 2063691, upload-time = "2025-11-04T13:41:03.504Z" }, + { url = "https://files.pythonhosted.org/packages/74/9b/0046701313c6ef08c0c1cf0e028c67c770a4e1275ca73131563c5f2a310a/pydantic_core-2.41.5-cp314-cp314-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:4819fa52133c9aa3c387b3328f25c1facc356491e6135b459f1de698ff64d869", size = 2213897, upload-time = "2025-11-04T13:41:05.804Z" }, + { url = "https://files.pythonhosted.org/packages/8a/cd/6bac76ecd1b27e75a95ca3a9a559c643b3afcd2dd62086d4b7a32a18b169/pydantic_core-2.41.5-cp314-cp314-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2b761d210c9ea91feda40d25b4efe82a1707da2ef62901466a42492c028553a2", size = 2333302, upload-time = "2025-11-04T13:41:07.809Z" }, + { url = "https://files.pythonhosted.org/packages/4c/d2/ef2074dc020dd6e109611a8be4449b98cd25e1b9b8a303c2f0fca2f2bcf7/pydantic_core-2.41.5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:22f0fb8c1c583a3b6f24df2470833b40207e907b90c928cc8d3594b76f874375", size = 2064877, upload-time = "2025-11-04T13:41:09.827Z" }, + { url = "https://files.pythonhosted.org/packages/18/66/e9db17a9a763d72f03de903883c057b2592c09509ccfe468187f2a2eef29/pydantic_core-2.41.5-cp314-cp314-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:2782c870e99878c634505236d81e5443092fba820f0373997ff75f90f68cd553", size = 2180680, upload-time = "2025-11-04T13:41:12.379Z" }, + { url = "https://files.pythonhosted.org/packages/d3/9e/3ce66cebb929f3ced22be85d4c2399b8e85b622db77dad36b73c5387f8f8/pydantic_core-2.41.5-cp314-cp314-musllinux_1_1_aarch64.whl", hash = "sha256:0177272f88ab8312479336e1d777f6b124537d47f2123f89cb37e0accea97f90", size = 2138960, upload-time = "2025-11-04T13:41:14.627Z" }, + { url = "https://files.pythonhosted.org/packages/a6/62/205a998f4327d2079326b01abee48e502ea739d174f0a89295c481a2272e/pydantic_core-2.41.5-cp314-cp314-musllinux_1_1_armv7l.whl", hash = "sha256:63510af5e38f8955b8ee5687740d6ebf7c2a0886d15a6d65c32814613681bc07", size = 2339102, upload-time = "2025-11-04T13:41:16.868Z" }, + { url = "https://files.pythonhosted.org/packages/3c/0d/f05e79471e889d74d3d88f5bd20d0ed189ad94c2423d81ff8d0000aab4ff/pydantic_core-2.41.5-cp314-cp314-musllinux_1_1_x86_64.whl", hash = "sha256:e56ba91f47764cc14f1daacd723e3e82d1a89d783f0f5afe9c364b8bb491ccdb", size = 2326039, upload-time = "2025-11-04T13:41:18.934Z" }, + { url = "https://files.pythonhosted.org/packages/ec/e1/e08a6208bb100da7e0c4b288eed624a703f4d129bde2da475721a80cab32/pydantic_core-2.41.5-cp314-cp314-win32.whl", hash = "sha256:aec5cf2fd867b4ff45b9959f8b20ea3993fc93e63c7363fe6851424c8a7e7c23", size = 1995126, upload-time = "2025-11-04T13:41:21.418Z" }, + { url = "https://files.pythonhosted.org/packages/48/5d/56ba7b24e9557f99c9237e29f5c09913c81eeb2f3217e40e922353668092/pydantic_core-2.41.5-cp314-cp314-win_amd64.whl", hash = "sha256:8e7c86f27c585ef37c35e56a96363ab8de4e549a95512445b85c96d3e2f7c1bf", size = 2015489, upload-time = "2025-11-04T13:41:24.076Z" }, + { url = "https://files.pythonhosted.org/packages/4e/bb/f7a190991ec9e3e0ba22e4993d8755bbc4a32925c0b5b42775c03e8148f9/pydantic_core-2.41.5-cp314-cp314-win_arm64.whl", hash = "sha256:e672ba74fbc2dc8eea59fb6d4aed6845e6905fc2a8afe93175d94a83ba2a01a0", size = 1977288, upload-time = "2025-11-04T13:41:26.33Z" }, + { url = "https://files.pythonhosted.org/packages/92/ed/77542d0c51538e32e15afe7899d79efce4b81eee631d99850edc2f5e9349/pydantic_core-2.41.5-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:8566def80554c3faa0e65ac30ab0932b9e3a5cd7f8323764303d468e5c37595a", size = 2120255, upload-time = "2025-11-04T13:41:28.569Z" }, + { url = "https://files.pythonhosted.org/packages/bb/3d/6913dde84d5be21e284439676168b28d8bbba5600d838b9dca99de0fad71/pydantic_core-2.41.5-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:b80aa5095cd3109962a298ce14110ae16b8c1aece8b72f9dafe81cf597ad80b3", size = 1863760, upload-time = "2025-11-04T13:41:31.055Z" }, + { url = "https://files.pythonhosted.org/packages/5a/f0/e5e6b99d4191da102f2b0eb9687aaa7f5bea5d9964071a84effc3e40f997/pydantic_core-2.41.5-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3006c3dd9ba34b0c094c544c6006cc79e87d8612999f1a5d43b769b89181f23c", size = 1878092, upload-time = "2025-11-04T13:41:33.21Z" }, + { url = "https://files.pythonhosted.org/packages/71/48/36fb760642d568925953bcc8116455513d6e34c4beaa37544118c36aba6d/pydantic_core-2.41.5-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:72f6c8b11857a856bcfa48c86f5368439f74453563f951e473514579d44aa612", size = 2053385, upload-time = "2025-11-04T13:41:35.508Z" }, + { url = "https://files.pythonhosted.org/packages/20/25/92dc684dd8eb75a234bc1c764b4210cf2646479d54b47bf46061657292a8/pydantic_core-2.41.5-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:5cb1b2f9742240e4bb26b652a5aeb840aa4b417c7748b6f8387927bc6e45e40d", size = 2218832, upload-time = "2025-11-04T13:41:37.732Z" }, + { url = "https://files.pythonhosted.org/packages/e2/09/f53e0b05023d3e30357d82eb35835d0f6340ca344720a4599cd663dca599/pydantic_core-2.41.5-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:bd3d54f38609ff308209bd43acea66061494157703364ae40c951f83ba99a1a9", size = 2327585, upload-time = "2025-11-04T13:41:40Z" }, + { url = "https://files.pythonhosted.org/packages/aa/4e/2ae1aa85d6af35a39b236b1b1641de73f5a6ac4d5a7509f77b814885760c/pydantic_core-2.41.5-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2ff4321e56e879ee8d2a879501c8e469414d948f4aba74a2d4593184eb326660", size = 2041078, upload-time = "2025-11-04T13:41:42.323Z" }, + { url = "https://files.pythonhosted.org/packages/cd/13/2e215f17f0ef326fc72afe94776edb77525142c693767fc347ed6288728d/pydantic_core-2.41.5-cp314-cp314t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:d0d2568a8c11bf8225044aa94409e21da0cb09dcdafe9ecd10250b2baad531a9", size = 2173914, upload-time = "2025-11-04T13:41:45.221Z" }, + { url = "https://files.pythonhosted.org/packages/02/7a/f999a6dcbcd0e5660bc348a3991c8915ce6599f4f2c6ac22f01d7a10816c/pydantic_core-2.41.5-cp314-cp314t-musllinux_1_1_aarch64.whl", hash = "sha256:a39455728aabd58ceabb03c90e12f71fd30fa69615760a075b9fec596456ccc3", size = 2129560, upload-time = "2025-11-04T13:41:47.474Z" }, + { url = "https://files.pythonhosted.org/packages/3a/b1/6c990ac65e3b4c079a4fb9f5b05f5b013afa0f4ed6780a3dd236d2cbdc64/pydantic_core-2.41.5-cp314-cp314t-musllinux_1_1_armv7l.whl", hash = "sha256:239edca560d05757817c13dc17c50766136d21f7cd0fac50295499ae24f90fdf", size = 2329244, upload-time = "2025-11-04T13:41:49.992Z" }, + { url = "https://files.pythonhosted.org/packages/d9/02/3c562f3a51afd4d88fff8dffb1771b30cfdfd79befd9883ee094f5b6c0d8/pydantic_core-2.41.5-cp314-cp314t-musllinux_1_1_x86_64.whl", hash = "sha256:2a5e06546e19f24c6a96a129142a75cee553cc018ffee48a460059b1185f4470", size = 2331955, upload-time = "2025-11-04T13:41:54.079Z" }, + { url = "https://files.pythonhosted.org/packages/5c/96/5fb7d8c3c17bc8c62fdb031c47d77a1af698f1d7a406b0f79aaa1338f9ad/pydantic_core-2.41.5-cp314-cp314t-win32.whl", hash = "sha256:b4ececa40ac28afa90871c2cc2b9ffd2ff0bf749380fbdf57d165fd23da353aa", size = 1988906, upload-time = "2025-11-04T13:41:56.606Z" }, + { url = "https://files.pythonhosted.org/packages/22/ed/182129d83032702912c2e2d8bbe33c036f342cc735737064668585dac28f/pydantic_core-2.41.5-cp314-cp314t-win_amd64.whl", hash = "sha256:80aa89cad80b32a912a65332f64a4450ed00966111b6615ca6816153d3585a8c", size = 1981607, upload-time = "2025-11-04T13:41:58.889Z" }, + { url = "https://files.pythonhosted.org/packages/9f/ed/068e41660b832bb0b1aa5b58011dea2a3fe0ba7861ff38c4d4904c1c1a99/pydantic_core-2.41.5-cp314-cp314t-win_arm64.whl", hash = "sha256:35b44f37a3199f771c3eaa53051bc8a70cd7b54f333531c59e29fd4db5d15008", size = 1974769, upload-time = "2025-11-04T13:42:01.186Z" }, + { url = "https://files.pythonhosted.org/packages/54/db/160dffb57ed9a3705c4cbcbff0ac03bdae45f1ca7d58ab74645550df3fbd/pydantic_core-2.41.5-cp39-cp39-macosx_10_12_x86_64.whl", hash = "sha256:8bfeaf8735be79f225f3fefab7f941c712aaca36f1128c9d7e2352ee1aa87bdf", size = 2107999, upload-time = "2025-11-04T13:42:03.885Z" }, + { url = "https://files.pythonhosted.org/packages/a3/7d/88e7de946f60d9263cc84819f32513520b85c0f8322f9b8f6e4afc938383/pydantic_core-2.41.5-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:346285d28e4c8017da95144c7f3acd42740d637ff41946af5ce6e5e420502dd5", size = 1929745, upload-time = "2025-11-04T13:42:06.075Z" }, + { url = "https://files.pythonhosted.org/packages/d5/c2/aef51e5b283780e85e99ff19db0f05842d2d4a8a8cd15e63b0280029b08f/pydantic_core-2.41.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a75dafbf87d6276ddc5b2bf6fae5254e3d0876b626eb24969a574fff9149ee5d", size = 1920220, upload-time = "2025-11-04T13:42:08.457Z" }, + { url = "https://files.pythonhosted.org/packages/c7/97/492ab10f9ac8695cd76b2fdb24e9e61f394051df71594e9bcc891c9f586e/pydantic_core-2.41.5-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:7b93a4d08587e2b7e7882de461e82b6ed76d9026ce91ca7915e740ecc7855f60", size = 2067296, upload-time = "2025-11-04T13:42:10.817Z" }, + { url = "https://files.pythonhosted.org/packages/ec/23/984149650e5269c59a2a4c41d234a9570adc68ab29981825cfaf4cfad8f4/pydantic_core-2.41.5-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e8465ab91a4bd96d36dde3263f06caa6a8a6019e4113f24dc753d79a8b3a3f82", size = 2231548, upload-time = "2025-11-04T13:42:13.843Z" }, + { url = "https://files.pythonhosted.org/packages/71/0c/85bcbb885b9732c28bec67a222dbed5ed2d77baee1f8bba2002e8cd00c5c/pydantic_core-2.41.5-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:299e0a22e7ae2b85c1a57f104538b2656e8ab1873511fd718a1c1c6f149b77b5", size = 2362571, upload-time = "2025-11-04T13:42:16.208Z" }, + { url = "https://files.pythonhosted.org/packages/c0/4a/412d2048be12c334003e9b823a3fa3d038e46cc2d64dd8aab50b31b65499/pydantic_core-2.41.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:707625ef0983fcfb461acfaf14de2067c5942c6bb0f3b4c99158bed6fedd3cf3", size = 2068175, upload-time = "2025-11-04T13:42:18.911Z" }, + { url = "https://files.pythonhosted.org/packages/73/f4/c58b6a776b502d0a5540ad02e232514285513572060f0d78f7832ca3c98b/pydantic_core-2.41.5-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:f41eb9797986d6ebac5e8edff36d5cef9de40def462311b3eb3eeded1431e425", size = 2177203, upload-time = "2025-11-04T13:42:22.578Z" }, + { url = "https://files.pythonhosted.org/packages/ed/ae/f06ea4c7e7a9eead3d165e7623cd2ea0cb788e277e4f935af63fc98fa4e6/pydantic_core-2.41.5-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:0384e2e1021894b1ff5a786dbf94771e2986ebe2869533874d7e43bc79c6f504", size = 2148191, upload-time = "2025-11-04T13:42:24.89Z" }, + { url = "https://files.pythonhosted.org/packages/c1/57/25a11dcdc656bf5f8b05902c3c2934ac3ea296257cc4a3f79a6319e61856/pydantic_core-2.41.5-cp39-cp39-musllinux_1_1_armv7l.whl", hash = "sha256:f0cd744688278965817fd0839c4a4116add48d23890d468bc436f78beb28abf5", size = 2343907, upload-time = "2025-11-04T13:42:27.683Z" }, + { url = "https://files.pythonhosted.org/packages/96/82/e33d5f4933d7a03327c0c43c65d575e5919d4974ffc026bc917a5f7b9f61/pydantic_core-2.41.5-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:753e230374206729bf0a807954bcc6c150d3743928a73faffee51ac6557a03c3", size = 2322174, upload-time = "2025-11-04T13:42:30.776Z" }, + { url = "https://files.pythonhosted.org/packages/81/45/4091be67ce9f469e81656f880f3506f6a5624121ec5eb3eab37d7581897d/pydantic_core-2.41.5-cp39-cp39-win32.whl", hash = "sha256:873e0d5b4fb9b89ef7c2d2a963ea7d02879d9da0da8d9d4933dee8ee86a8b460", size = 1990353, upload-time = "2025-11-04T13:42:33.111Z" }, + { url = "https://files.pythonhosted.org/packages/44/8a/a98aede18db6e9cd5d66bcacd8a409fcf8134204cdede2e7de35c5a2c5ef/pydantic_core-2.41.5-cp39-cp39-win_amd64.whl", hash = "sha256:e4f4a984405e91527a0d62649ee21138f8e3d0ef103be488c1dc11a80d7f184b", size = 2015698, upload-time = "2025-11-04T13:42:35.484Z" }, + { url = "https://files.pythonhosted.org/packages/11/72/90fda5ee3b97e51c494938a4a44c3a35a9c96c19bba12372fb9c634d6f57/pydantic_core-2.41.5-graalpy311-graalpy242_311_native-macosx_10_12_x86_64.whl", hash = "sha256:b96d5f26b05d03cc60f11a7761a5ded1741da411e7fe0909e27a5e6a0cb7b034", size = 2115441, upload-time = "2025-11-04T13:42:39.557Z" }, + { url = "https://files.pythonhosted.org/packages/1f/53/8942f884fa33f50794f119012dc6a1a02ac43a56407adaac20463df8e98f/pydantic_core-2.41.5-graalpy311-graalpy242_311_native-macosx_11_0_arm64.whl", hash = "sha256:634e8609e89ceecea15e2d61bc9ac3718caaaa71963717bf3c8f38bfde64242c", size = 1930291, upload-time = "2025-11-04T13:42:42.169Z" }, + { url = "https://files.pythonhosted.org/packages/79/c8/ecb9ed9cd942bce09fc888ee960b52654fbdbede4ba6c2d6e0d3b1d8b49c/pydantic_core-2.41.5-graalpy311-graalpy242_311_native-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:93e8740d7503eb008aa2df04d3b9735f845d43ae845e6dcd2be0b55a2da43cd2", size = 1948632, upload-time = "2025-11-04T13:42:44.564Z" }, + { url = "https://files.pythonhosted.org/packages/2e/1b/687711069de7efa6af934e74f601e2a4307365e8fdc404703afc453eab26/pydantic_core-2.41.5-graalpy311-graalpy242_311_native-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f15489ba13d61f670dcc96772e733aad1a6f9c429cc27574c6cdaed82d0146ad", size = 2138905, upload-time = "2025-11-04T13:42:47.156Z" }, + { url = "https://files.pythonhosted.org/packages/09/32/59b0c7e63e277fa7911c2fc70ccfb45ce4b98991e7ef37110663437005af/pydantic_core-2.41.5-graalpy312-graalpy250_312_native-macosx_10_12_x86_64.whl", hash = "sha256:7da7087d756b19037bc2c06edc6c170eeef3c3bafcb8f532ff17d64dc427adfd", size = 2110495, upload-time = "2025-11-04T13:42:49.689Z" }, + { url = "https://files.pythonhosted.org/packages/aa/81/05e400037eaf55ad400bcd318c05bb345b57e708887f07ddb2d20e3f0e98/pydantic_core-2.41.5-graalpy312-graalpy250_312_native-macosx_11_0_arm64.whl", hash = "sha256:aabf5777b5c8ca26f7824cb4a120a740c9588ed58df9b2d196ce92fba42ff8dc", size = 1915388, upload-time = "2025-11-04T13:42:52.215Z" }, + { url = "https://files.pythonhosted.org/packages/6e/0d/e3549b2399f71d56476b77dbf3cf8937cec5cd70536bdc0e374a421d0599/pydantic_core-2.41.5-graalpy312-graalpy250_312_native-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c007fe8a43d43b3969e8469004e9845944f1a80e6acd47c150856bb87f230c56", size = 1942879, upload-time = "2025-11-04T13:42:56.483Z" }, + { url = "https://files.pythonhosted.org/packages/f7/07/34573da085946b6a313d7c42f82f16e8920bfd730665de2d11c0c37a74b5/pydantic_core-2.41.5-graalpy312-graalpy250_312_native-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:76d0819de158cd855d1cbb8fcafdf6f5cf1eb8e470abe056d5d161106e38062b", size = 2139017, upload-time = "2025-11-04T13:42:59.471Z" }, + { url = "https://files.pythonhosted.org/packages/e6/b0/1a2aa41e3b5a4ba11420aba2d091b2d17959c8d1519ece3627c371951e73/pydantic_core-2.41.5-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:b5819cd790dbf0c5eb9f82c73c16b39a65dd6dd4d1439dcdea7816ec9adddab8", size = 2103351, upload-time = "2025-11-04T13:43:02.058Z" }, + { url = "https://files.pythonhosted.org/packages/a4/ee/31b1f0020baaf6d091c87900ae05c6aeae101fa4e188e1613c80e4f1ea31/pydantic_core-2.41.5-pp310-pypy310_pp73-macosx_11_0_arm64.whl", hash = "sha256:5a4e67afbc95fa5c34cf27d9089bca7fcab4e51e57278d710320a70b956d1b9a", size = 1925363, upload-time = "2025-11-04T13:43:05.159Z" }, + { url = "https://files.pythonhosted.org/packages/e1/89/ab8e86208467e467a80deaca4e434adac37b10a9d134cd2f99b28a01e483/pydantic_core-2.41.5-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ece5c59f0ce7d001e017643d8d24da587ea1f74f6993467d85ae8a5ef9d4f42b", size = 2135615, upload-time = "2025-11-04T13:43:08.116Z" }, + { url = "https://files.pythonhosted.org/packages/99/0a/99a53d06dd0348b2008f2f30884b34719c323f16c3be4e6cc1203b74a91d/pydantic_core-2.41.5-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:16f80f7abe3351f8ea6858914ddc8c77e02578544a0ebc15b4c2e1a0e813b0b2", size = 2175369, upload-time = "2025-11-04T13:43:12.49Z" }, + { url = "https://files.pythonhosted.org/packages/6d/94/30ca3b73c6d485b9bb0bc66e611cff4a7138ff9736b7e66bcf0852151636/pydantic_core-2.41.5-pp310-pypy310_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:33cb885e759a705b426baada1fe68cbb0a2e68e34c5d0d0289a364cf01709093", size = 2144218, upload-time = "2025-11-04T13:43:15.431Z" }, + { url = "https://files.pythonhosted.org/packages/87/57/31b4f8e12680b739a91f472b5671294236b82586889ef764b5fbc6669238/pydantic_core-2.41.5-pp310-pypy310_pp73-musllinux_1_1_armv7l.whl", hash = "sha256:c8d8b4eb992936023be7dee581270af5c6e0697a8559895f527f5b7105ecd36a", size = 2329951, upload-time = "2025-11-04T13:43:18.062Z" }, + { url = "https://files.pythonhosted.org/packages/7d/73/3c2c8edef77b8f7310e6fb012dbc4b8551386ed575b9eb6fb2506e28a7eb/pydantic_core-2.41.5-pp310-pypy310_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:242a206cd0318f95cd21bdacff3fcc3aab23e79bba5cac3db5a841c9ef9c6963", size = 2318428, upload-time = "2025-11-04T13:43:20.679Z" }, + { url = "https://files.pythonhosted.org/packages/2f/02/8559b1f26ee0d502c74f9cca5c0d2fd97e967e083e006bbbb4e97f3a043a/pydantic_core-2.41.5-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:d3a978c4f57a597908b7e697229d996d77a6d3c94901e9edee593adada95ce1a", size = 2147009, upload-time = "2025-11-04T13:43:23.286Z" }, + { url = "https://files.pythonhosted.org/packages/5f/9b/1b3f0e9f9305839d7e84912f9e8bfbd191ed1b1ef48083609f0dabde978c/pydantic_core-2.41.5-pp311-pypy311_pp73-macosx_10_12_x86_64.whl", hash = "sha256:b2379fa7ed44ddecb5bfe4e48577d752db9fc10be00a6b7446e9663ba143de26", size = 2101980, upload-time = "2025-11-04T13:43:25.97Z" }, + { url = "https://files.pythonhosted.org/packages/a4/ed/d71fefcb4263df0da6a85b5d8a7508360f2f2e9b3bf5814be9c8bccdccc1/pydantic_core-2.41.5-pp311-pypy311_pp73-macosx_11_0_arm64.whl", hash = "sha256:266fb4cbf5e3cbd0b53669a6d1b039c45e3ce651fd5442eff4d07c2cc8d66808", size = 1923865, upload-time = "2025-11-04T13:43:28.763Z" }, + { url = "https://files.pythonhosted.org/packages/ce/3a/626b38db460d675f873e4444b4bb030453bbe7b4ba55df821d026a0493c4/pydantic_core-2.41.5-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:58133647260ea01e4d0500089a8c4f07bd7aa6ce109682b1426394988d8aaacc", size = 2134256, upload-time = "2025-11-04T13:43:31.71Z" }, + { url = "https://files.pythonhosted.org/packages/83/d9/8412d7f06f616bbc053d30cb4e5f76786af3221462ad5eee1f202021eb4e/pydantic_core-2.41.5-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:287dad91cfb551c363dc62899a80e9e14da1f0e2b6ebde82c806612ca2a13ef1", size = 2174762, upload-time = "2025-11-04T13:43:34.744Z" }, + { url = "https://files.pythonhosted.org/packages/55/4c/162d906b8e3ba3a99354e20faa1b49a85206c47de97a639510a0e673f5da/pydantic_core-2.41.5-pp311-pypy311_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:03b77d184b9eb40240ae9fd676ca364ce1085f203e1b1256f8ab9984dca80a84", size = 2143141, upload-time = "2025-11-04T13:43:37.701Z" }, + { url = "https://files.pythonhosted.org/packages/1f/f2/f11dd73284122713f5f89fc940f370d035fa8e1e078d446b3313955157fe/pydantic_core-2.41.5-pp311-pypy311_pp73-musllinux_1_1_armv7l.whl", hash = "sha256:a668ce24de96165bb239160b3d854943128f4334822900534f2fe947930e5770", size = 2330317, upload-time = "2025-11-04T13:43:40.406Z" }, + { url = "https://files.pythonhosted.org/packages/88/9d/b06ca6acfe4abb296110fb1273a4d848a0bfb2ff65f3ee92127b3244e16b/pydantic_core-2.41.5-pp311-pypy311_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:f14f8f046c14563f8eb3f45f499cc658ab8d10072961e07225e507adb700e93f", size = 2316992, upload-time = "2025-11-04T13:43:43.602Z" }, + { url = "https://files.pythonhosted.org/packages/36/c7/cfc8e811f061c841d7990b0201912c3556bfeb99cdcb7ed24adc8d6f8704/pydantic_core-2.41.5-pp311-pypy311_pp73-win_amd64.whl", hash = "sha256:56121965f7a4dc965bff783d70b907ddf3d57f6eba29b6d2e5dabfaf07799c51", size = 2145302, upload-time = "2025-11-04T13:43:46.64Z" }, +] + +[[package]] +name = "python-dateutil" +version = "2.9.0.post0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "six" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/66/c0/0c8b6ad9f17a802ee498c46e004a0eb49bc148f2fd230864601a86dcf6db/python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3", size = 342432, upload-time = "2024-03-01T18:36:20.211Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427", size = 229892, upload-time = "2024-03-01T18:36:18.57Z" }, +] + +[[package]] +name = "six" +version = "1.17.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/94/e7/b2c673351809dca68a0e064b6af791aa332cf192da575fd474ed7d6f16a2/six-1.17.0.tar.gz", hash = "sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81", size = 34031, upload-time = "2024-12-04T17:35:28.174Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl", hash = "sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274", size = 11050, upload-time = "2024-12-04T17:35:26.475Z" }, +] + +[[package]] +name = "typing-extensions" +version = "4.15.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/72/94/1a15dd82efb362ac84269196e94cf00f187f7ed21c242792a923cdb1c61f/typing_extensions-4.15.0.tar.gz", hash = "sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466", size = 109391, upload-time = "2025-08-25T13:49:26.313Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/18/67/36e9267722cc04a6b9f15c7f3441c2363321a3ea07da7ae0c0707beb2a9c/typing_extensions-4.15.0-py3-none-any.whl", hash = "sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548", size = 44614, upload-time = "2025-08-25T13:49:24.86Z" }, +] + +[[package]] +name = "typing-inspection" +version = "0.4.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/55/e3/70399cb7dd41c10ac53367ae42139cf4b1ca5f36bb3dc6c9d33acdb43655/typing_inspection-0.4.2.tar.gz", hash = "sha256:ba561c48a67c5958007083d386c3295464928b01faa735ab8547c5692e87f464", size = 75949, upload-time = "2025-10-01T02:14:41.687Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/dc/9b/47798a6c91d8bdb567fe2698fe81e0c6b7cb7ef4d13da4114b41d239f65d/typing_inspection-0.4.2-py3-none-any.whl", hash = "sha256:4ed1cacbdc298c220f1bd249ed5287caa16f34d44ef4e9c3d0cbad5b521545e7", size = 14611, upload-time = "2025-10-01T02:14:40.154Z" }, +] + +[[package]] +name = "urllib3" +version = "2.6.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/c7/24/5f1b3bdffd70275f6661c76461e25f024d5a38a46f04aaca912426a2b1d3/urllib3-2.6.3.tar.gz", hash = "sha256:1b62b6884944a57dbe321509ab94fd4d3b307075e0c2eae991ac71ee15ad38ed", size = 435556, upload-time = "2026-01-07T16:24:43.925Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/39/08/aaaad47bc4e9dc8c725e68f9d04865dbcb2052843ff09c97b08904852d84/urllib3-2.6.3-py3-none-any.whl", hash = "sha256:bf272323e553dfb2e87d9bfd225ca7b0f467b919d7bbd355436d3fd37cb0acd4", size = 131584, upload-time = "2026-01-07T16:24:42.685Z" }, +]