mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-19 02:57:04 +00:00
python: type generated client using Self (#16693)
* python: type generated client using Self This doesn't offer a clear win but this helps for: * Using modern types and making the typing intent clearer * Decreasing the need for `from __future__ import annotations`, since a class can now refer to itself without using its name * Using more `cls` to automatically refer to the class, instead of respecifying the class name every time Self is available from Python 3.11 and is provided in typing_extensions (since 4.0.0) as a fallback for older versions See: https://peps.python.org/pep-0673/ See: https://github.com/python/typing_extensions/blob/main/CHANGELOG.md#added-in-version-400 * generate code
This commit is contained in:
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class AdditionalPropertiesAnyType(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class AdditionalPropertiesAnyType(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> AdditionalPropertiesAnyType:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of AdditionalPropertiesAnyType from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -64,15 +69,15 @@ class AdditionalPropertiesAnyType(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> AdditionalPropertiesAnyType:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of AdditionalPropertiesAnyType from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return AdditionalPropertiesAnyType.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = AdditionalPropertiesAnyType.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"name": obj.get("name")
|
||||
})
|
||||
# store additional fields in additional_properties
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Dict, Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class AdditionalPropertiesClass(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class AdditionalPropertiesClass(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> AdditionalPropertiesClass:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of AdditionalPropertiesClass from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class AdditionalPropertiesClass(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> AdditionalPropertiesClass:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of AdditionalPropertiesClass from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return AdditionalPropertiesClass.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = AdditionalPropertiesClass.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"map_property": obj.get("map_property"),
|
||||
"map_of_map_property": obj.get("map_of_map_property")
|
||||
})
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class AdditionalPropertiesObject(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class AdditionalPropertiesObject(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> AdditionalPropertiesObject:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of AdditionalPropertiesObject from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -64,15 +69,15 @@ class AdditionalPropertiesObject(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> AdditionalPropertiesObject:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of AdditionalPropertiesObject from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return AdditionalPropertiesObject.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = AdditionalPropertiesObject.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"name": obj.get("name")
|
||||
})
|
||||
# store additional fields in additional_properties
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class AdditionalPropertiesWithDescriptionOnly(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> AdditionalPropertiesWithDescriptionOnly:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of AdditionalPropertiesWithDescriptionOnly from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -64,15 +69,15 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> AdditionalPropertiesWithDescriptionOnly:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of AdditionalPropertiesWithDescriptionOnly from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return AdditionalPropertiesWithDescriptionOnly.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = AdditionalPropertiesWithDescriptionOnly.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"name": obj.get("name")
|
||||
})
|
||||
# store additional fields in additional_properties
|
||||
|
||||
@@ -22,6 +22,11 @@ from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from pydantic import Field
|
||||
from petstore_api.models.single_ref_type import SingleRefType
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class AllOfWithSingleRef(BaseModel):
|
||||
"""
|
||||
@@ -47,7 +52,7 @@ class AllOfWithSingleRef(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> AllOfWithSingleRef:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of AllOfWithSingleRef from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -60,15 +65,15 @@ class AllOfWithSingleRef(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> AllOfWithSingleRef:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of AllOfWithSingleRef from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return AllOfWithSingleRef.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = AllOfWithSingleRef.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"username": obj.get("username"),
|
||||
"SingleRefType": obj.get("SingleRefType")
|
||||
})
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional, Union
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Animal(BaseModel):
|
||||
"""
|
||||
@@ -63,7 +68,7 @@ class Animal(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Union(Cat, Dog):
|
||||
def from_json(cls, json_str: str) -> Union[Self, Self]:
|
||||
"""Create an instance of Animal from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -76,7 +81,7 @@ class Animal(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Union(Cat, Dog):
|
||||
def from_dict(cls, obj: dict) -> Union[Self, Self]:
|
||||
"""Create an instance of Animal from a dict"""
|
||||
# look up the object type based on discriminator mapping
|
||||
object_type = cls.get_discriminator_value(obj)
|
||||
|
||||
@@ -25,6 +25,10 @@ from typing_extensions import Annotated
|
||||
from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict
|
||||
from typing_extensions import Literal
|
||||
from pydantic import StrictStr, Field
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"]
|
||||
|
||||
@@ -88,13 +92,13 @@ class AnyOfColor(BaseModel):
|
||||
return v
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> AnyOfColor:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
return cls.from_json(json.dumps(obj))
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> AnyOfColor:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Returns the object represented by the json string"""
|
||||
instance = AnyOfColor.model_construct()
|
||||
instance = cls.model_construct()
|
||||
error_messages = []
|
||||
# deserialize data into List[int]
|
||||
try:
|
||||
|
||||
@@ -25,6 +25,10 @@ from petstore_api.models.danish_pig import DanishPig
|
||||
from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict
|
||||
from typing_extensions import Literal
|
||||
from pydantic import StrictStr, Field
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
ANYOFPIG_ANY_OF_SCHEMAS = ["BasquePig", "DanishPig"]
|
||||
|
||||
@@ -80,13 +84,13 @@ class AnyOfPig(BaseModel):
|
||||
return v
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> AnyOfPig:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
return cls.from_json(json.dumps(obj))
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> AnyOfPig:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Returns the object represented by the json string"""
|
||||
instance = AnyOfPig.model_construct()
|
||||
instance = cls.model_construct()
|
||||
error_messages = []
|
||||
# anyof_schema_1_validator: Optional[BasquePig] = None
|
||||
try:
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class ApiResponse(BaseModel):
|
||||
"""
|
||||
@@ -46,7 +51,7 @@ class ApiResponse(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> ApiResponse:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of ApiResponse from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -59,15 +64,15 @@ class ApiResponse(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> ApiResponse:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of ApiResponse from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return ApiResponse.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = ApiResponse.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"code": obj.get("code"),
|
||||
"type": obj.get("type"),
|
||||
"message": obj.get("message")
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel
|
||||
from petstore_api.models.tag import Tag
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class ArrayOfArrayOfModel(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class ArrayOfArrayOfModel(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> ArrayOfArrayOfModel:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of ArrayOfArrayOfModel from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -67,15 +72,15 @@ class ArrayOfArrayOfModel(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> ArrayOfArrayOfModel:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of ArrayOfArrayOfModel from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return ArrayOfArrayOfModel.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = ArrayOfArrayOfModel.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"another_property": [
|
||||
[Tag.from_dict(_inner_item) for _inner_item in _item]
|
||||
for _item in obj.get("another_property")
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class ArrayOfArrayOfNumberOnly(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class ArrayOfArrayOfNumberOnly(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> ArrayOfArrayOfNumberOnly:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of ArrayOfArrayOfNumberOnly from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class ArrayOfArrayOfNumberOnly(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> ArrayOfArrayOfNumberOnly:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of ArrayOfArrayOfNumberOnly from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return ArrayOfArrayOfNumberOnly.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = ArrayOfArrayOfNumberOnly.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"ArrayArrayNumber": obj.get("ArrayArrayNumber")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class ArrayOfNumberOnly(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class ArrayOfNumberOnly(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> ArrayOfNumberOnly:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of ArrayOfNumberOnly from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class ArrayOfNumberOnly(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> ArrayOfNumberOnly:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of ArrayOfNumberOnly from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return ArrayOfNumberOnly.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = ArrayOfNumberOnly.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"ArrayNumber": obj.get("ArrayNumber")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -23,6 +23,11 @@ from pydantic import BaseModel, StrictInt, StrictStr
|
||||
from pydantic import Field
|
||||
from typing_extensions import Annotated
|
||||
from petstore_api.models.read_only_first import ReadOnlyFirst
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class ArrayTest(BaseModel):
|
||||
"""
|
||||
@@ -49,7 +54,7 @@ class ArrayTest(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> ArrayTest:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of ArrayTest from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -71,15 +76,15 @@ class ArrayTest(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> ArrayTest:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of ArrayTest from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return ArrayTest.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = ArrayTest.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"array_of_string": obj.get("array_of_string"),
|
||||
"array_array_of_integer": obj.get("array_array_of_integer"),
|
||||
"array_array_of_model": [
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class BasquePig(BaseModel):
|
||||
"""
|
||||
@@ -46,7 +51,7 @@ class BasquePig(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> BasquePig:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of BasquePig from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -59,15 +64,15 @@ class BasquePig(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> BasquePig:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of BasquePig from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return BasquePig.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = BasquePig.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"className": obj.get("className"),
|
||||
"color": obj.get("color")
|
||||
})
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Capitalization(BaseModel):
|
||||
"""
|
||||
@@ -50,7 +55,7 @@ class Capitalization(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Capitalization:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of Capitalization from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -63,15 +68,15 @@ class Capitalization(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Capitalization:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of Capitalization from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Capitalization.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = Capitalization.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"smallCamel": obj.get("smallCamel"),
|
||||
"CapitalCamel": obj.get("CapitalCamel"),
|
||||
"small_Snake": obj.get("small_Snake"),
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import StrictBool
|
||||
from petstore_api.models.animal import Animal
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Cat(Animal):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class Cat(Animal):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Cat:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of Cat from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class Cat(Animal):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Cat:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of Cat from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Cat.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = Cat.model_validate({
|
||||
_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")
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Category(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class Category(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Category:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of Category from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class Category(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Category:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of Category from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Category.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = Category.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"id": obj.get("id"),
|
||||
"name": obj.get("name") if obj.get("name") is not None else 'default-name'
|
||||
})
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class CircularReferenceModel(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class CircularReferenceModel(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> CircularReferenceModel:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of CircularReferenceModel from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -61,15 +66,15 @@ class CircularReferenceModel(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> CircularReferenceModel:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of CircularReferenceModel from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return CircularReferenceModel.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = CircularReferenceModel.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"size": obj.get("size"),
|
||||
"nested": FirstRef.from_dict(obj.get("nested")) if obj.get("nested") is not None else None
|
||||
})
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class ClassModel(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class ClassModel(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> ClassModel:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of ClassModel from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class ClassModel(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> ClassModel:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of ClassModel from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return ClassModel.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = ClassModel.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"_class": obj.get("_class")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Client(BaseModel):
|
||||
"""
|
||||
@@ -44,7 +49,7 @@ class Client(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Client:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of Client from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -57,15 +62,15 @@ class Client(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Client:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of Client from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Client.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = Client.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"client": obj.get("client")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -25,6 +25,10 @@ from typing_extensions import Annotated
|
||||
from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict
|
||||
from typing_extensions import Literal
|
||||
from pydantic import StrictStr, Field
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
COLOR_ONE_OF_SCHEMAS = ["List[int]", "str"]
|
||||
|
||||
@@ -92,13 +96,13 @@ class Color(BaseModel):
|
||||
return v
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Color:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
return cls.from_json(json.dumps(obj))
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Color:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Returns the object represented by the json string"""
|
||||
instance = Color.model_construct()
|
||||
instance = cls.model_construct()
|
||||
if json_str is None:
|
||||
return instance
|
||||
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from petstore_api.models.creature_info import CreatureInfo
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Creature(BaseModel):
|
||||
"""
|
||||
@@ -46,7 +51,7 @@ class Creature(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Creature:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of Creature from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -62,15 +67,15 @@ class Creature(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Creature:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of Creature from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Creature.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = Creature.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"info": CreatureInfo.from_dict(obj.get("info")) if obj.get("info") is not None else None,
|
||||
"type": obj.get("type")
|
||||
})
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class CreatureInfo(BaseModel):
|
||||
"""
|
||||
@@ -44,7 +49,7 @@ class CreatureInfo(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> CreatureInfo:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of CreatureInfo from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -57,15 +62,15 @@ class CreatureInfo(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> CreatureInfo:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of CreatureInfo from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return CreatureInfo.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = CreatureInfo.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"name": obj.get("name")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
|
||||
from pydantic import BaseModel, StrictInt, StrictStr
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class DanishPig(BaseModel):
|
||||
"""
|
||||
@@ -46,7 +51,7 @@ class DanishPig(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> DanishPig:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of DanishPig from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -59,15 +64,15 @@ class DanishPig(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> DanishPig:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of DanishPig from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return DanishPig.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = DanishPig.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"className": obj.get("className"),
|
||||
"size": obj.get("size")
|
||||
})
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class DeprecatedObject(BaseModel):
|
||||
"""
|
||||
@@ -44,7 +49,7 @@ class DeprecatedObject(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> DeprecatedObject:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of DeprecatedObject from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -57,15 +62,15 @@ class DeprecatedObject(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> DeprecatedObject:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of DeprecatedObject from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return DeprecatedObject.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = DeprecatedObject.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"name": obj.get("name")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import StrictStr
|
||||
from petstore_api.models.animal import Animal
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Dog(Animal):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class Dog(Animal):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Dog:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of Dog from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class Dog(Animal):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Dog:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of Dog from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Dog.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = Dog.model_validate({
|
||||
_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")
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class DummyModel(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class DummyModel(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> DummyModel:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of DummyModel from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -61,15 +66,15 @@ class DummyModel(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> DummyModel:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of DummyModel from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return DummyModel.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = DummyModel.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"category": obj.get("category"),
|
||||
"self_ref": SelfReferenceModel.from_dict(obj.get("self_ref")) if obj.get("self_ref") is not None else None
|
||||
})
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel, StrictStr, field_validator
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class EnumArrays(BaseModel):
|
||||
"""
|
||||
@@ -66,7 +71,7 @@ class EnumArrays(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> EnumArrays:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of EnumArrays from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -79,15 +84,15 @@ class EnumArrays(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> EnumArrays:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of EnumArrays from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return EnumArrays.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = EnumArrays.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"just_symbol": obj.get("just_symbol"),
|
||||
"array_enum": obj.get("array_enum")
|
||||
})
|
||||
|
||||
@@ -20,6 +20,10 @@ from enum import Enum
|
||||
|
||||
|
||||
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
class EnumClass(str, Enum):
|
||||
@@ -35,8 +39,8 @@ class EnumClass(str, Enum):
|
||||
LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS = '(xyz)'
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> EnumClass:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of EnumClass from a JSON string"""
|
||||
return EnumClass(json.loads(json_str))
|
||||
return cls(json.loads(json_str))
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ from enum import Enum
|
||||
|
||||
|
||||
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
class EnumString1(str, Enum):
|
||||
@@ -34,8 +38,8 @@ class EnumString1(str, Enum):
|
||||
B = 'b'
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> EnumString1:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of EnumString1 from a JSON string"""
|
||||
return EnumString1(json.loads(json_str))
|
||||
return cls(json.loads(json_str))
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ from enum import Enum
|
||||
|
||||
|
||||
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
class EnumString2(str, Enum):
|
||||
@@ -34,8 +38,8 @@ class EnumString2(str, Enum):
|
||||
D = 'd'
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> EnumString2:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of EnumString2 from a JSON string"""
|
||||
return EnumString2(json.loads(json_str))
|
||||
return cls(json.loads(json_str))
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,11 @@ from petstore_api.models.outer_enum import OuterEnum
|
||||
from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue
|
||||
from petstore_api.models.outer_enum_integer import OuterEnumInteger
|
||||
from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntegerDefaultValue
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class EnumTest(BaseModel):
|
||||
"""
|
||||
@@ -104,7 +109,7 @@ class EnumTest(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> EnumTest:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of EnumTest from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -122,15 +127,15 @@ class EnumTest(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> EnumTest:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of EnumTest from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return EnumTest.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = EnumTest.model_validate({
|
||||
_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,
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class File(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class File(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> File:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of File from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class File(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> File:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of File from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return File.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = File.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"sourceURI": obj.get("sourceURI")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel
|
||||
from petstore_api.models.file import File
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class FileSchemaTestClass(BaseModel):
|
||||
"""
|
||||
@@ -46,7 +51,7 @@ class FileSchemaTestClass(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> FileSchemaTestClass:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of FileSchemaTestClass from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -69,15 +74,15 @@ class FileSchemaTestClass(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> FileSchemaTestClass:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of FileSchemaTestClass from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return FileSchemaTestClass.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = FileSchemaTestClass.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"file": File.from_dict(obj.get("file")) if obj.get("file") is not None else None,
|
||||
"files": [File.from_dict(_item) for _item in obj.get("files")] if obj.get("files") is not None else None
|
||||
})
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class FirstRef(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class FirstRef(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> FirstRef:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of FirstRef from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -61,15 +66,15 @@ class FirstRef(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> FirstRef:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of FirstRef from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return FirstRef.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = FirstRef.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"category": obj.get("category"),
|
||||
"self_ref": SecondRef.from_dict(obj.get("self_ref")) if obj.get("self_ref") is not None else None
|
||||
})
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Foo(BaseModel):
|
||||
"""
|
||||
@@ -44,7 +49,7 @@ class Foo(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Foo:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of Foo from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -57,15 +62,15 @@ class Foo(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Foo:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of Foo from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Foo.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = Foo.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"bar": obj.get("bar") if obj.get("bar") is not None else 'bar'
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
from petstore_api.models.foo import Foo
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class FooGetDefaultResponse(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class FooGetDefaultResponse(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> FooGetDefaultResponse:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of FooGetDefaultResponse from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -61,15 +66,15 @@ class FooGetDefaultResponse(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> FooGetDefaultResponse:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of FooGetDefaultResponse from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return FooGetDefaultResponse.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = FooGetDefaultResponse.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"string": Foo.from_dict(obj.get("string")) if obj.get("string") is not None else None
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -23,6 +23,11 @@ from pydantic import BaseModel, StrictBytes, StrictInt, StrictStr, field_validat
|
||||
from decimal import Decimal
|
||||
from pydantic import Field
|
||||
from typing_extensions import Annotated
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class FormatTest(BaseModel):
|
||||
"""
|
||||
@@ -103,7 +108,7 @@ class FormatTest(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> FormatTest:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of FormatTest from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -116,15 +121,15 @@ class FormatTest(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> FormatTest:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of FormatTest from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return FormatTest.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = FormatTest.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"integer": obj.get("integer"),
|
||||
"int32": obj.get("int32"),
|
||||
"int64": obj.get("int64"),
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class HasOnlyReadOnly(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class HasOnlyReadOnly(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> HasOnlyReadOnly:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of HasOnlyReadOnly from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -60,15 +65,15 @@ class HasOnlyReadOnly(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> HasOnlyReadOnly:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of HasOnlyReadOnly from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return HasOnlyReadOnly.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = HasOnlyReadOnly.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"bar": obj.get("bar"),
|
||||
"foo": obj.get("foo")
|
||||
})
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class HealthCheckResult(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class HealthCheckResult(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> HealthCheckResult:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of HealthCheckResult from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -63,15 +68,15 @@ class HealthCheckResult(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> HealthCheckResult:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of HealthCheckResult from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return HealthCheckResult.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = HealthCheckResult.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"NullableMessage": obj.get("NullableMessage")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Any, Dict, Optional, Union
|
||||
from pydantic import BaseModel
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class InnerDictWithProperty(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class InnerDictWithProperty(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> InnerDictWithProperty:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of InnerDictWithProperty from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class InnerDictWithProperty(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> InnerDictWithProperty:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of InnerDictWithProperty from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return InnerDictWithProperty.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = InnerDictWithProperty.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"aProperty": obj.get("aProperty")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -25,6 +25,10 @@ from typing_extensions import Annotated
|
||||
from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict
|
||||
from typing_extensions import Literal
|
||||
from pydantic import StrictStr, Field
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
INTORSTRING_ONE_OF_SCHEMAS = ["int", "str"]
|
||||
|
||||
@@ -81,13 +85,13 @@ class IntOrString(BaseModel):
|
||||
return v
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> IntOrString:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
return cls.from_json(json.dumps(obj))
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> IntOrString:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Returns the object represented by the json string"""
|
||||
instance = IntOrString.model_construct()
|
||||
instance = cls.model_construct()
|
||||
error_messages = []
|
||||
match = 0
|
||||
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class List(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class List(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> List:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of List from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class List(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> List:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of List from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return List.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = List.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"123-list": obj.get("123-list")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class ListClass(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class ListClass(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> ListClass:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of ListClass from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class ListClass(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> ListClass:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of ListClass from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return ListClass.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = ListClass.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"123-list": obj.get("123-list")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -22,6 +22,11 @@ from typing import Dict, List, Optional
|
||||
from pydantic import BaseModel
|
||||
from pydantic import Field
|
||||
from petstore_api.models.tag import Tag
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class MapOfArrayOfModel(BaseModel):
|
||||
"""
|
||||
@@ -46,7 +51,7 @@ class MapOfArrayOfModel(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> MapOfArrayOfModel:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of MapOfArrayOfModel from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -68,15 +73,15 @@ class MapOfArrayOfModel(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> MapOfArrayOfModel:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of MapOfArrayOfModel from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return MapOfArrayOfModel.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = MapOfArrayOfModel.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"shopIdToOrgOnlineLipMap": dict(
|
||||
(_k,
|
||||
[Tag.from_dict(_item) for _item in _v]
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Dict, Optional
|
||||
from pydantic import BaseModel, StrictBool, StrictStr, field_validator
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class MapTest(BaseModel):
|
||||
"""
|
||||
@@ -57,7 +62,7 @@ class MapTest(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> MapTest:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of MapTest from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -70,15 +75,15 @@ class MapTest(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> MapTest:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of MapTest from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return MapTest.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = MapTest.model_validate({
|
||||
_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"),
|
||||
|
||||
@@ -22,6 +22,11 @@ from typing import Dict, Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from pydantic import Field
|
||||
from petstore_api.models.animal import Animal
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class MixedPropertiesAndAdditionalPropertiesClass(BaseModel):
|
||||
"""
|
||||
@@ -48,7 +53,7 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> MixedPropertiesAndAdditionalPropertiesClass:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of MixedPropertiesAndAdditionalPropertiesClass from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -68,15 +73,15 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> MixedPropertiesAndAdditionalPropertiesClass:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of MixedPropertiesAndAdditionalPropertiesClass from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return MixedPropertiesAndAdditionalPropertiesClass.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = MixedPropertiesAndAdditionalPropertiesClass.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"uuid": obj.get("uuid"),
|
||||
"dateTime": obj.get("dateTime"),
|
||||
"map": dict(
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt, StrictStr
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Model200Response(BaseModel):
|
||||
"""
|
||||
@@ -46,7 +51,7 @@ class Model200Response(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Model200Response:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of Model200Response from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -59,15 +64,15 @@ class Model200Response(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Model200Response:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of Model200Response from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Model200Response.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = Model200Response.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"name": obj.get("name"),
|
||||
"class": obj.get("class")
|
||||
})
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class ModelReturn(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class ModelReturn(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> ModelReturn:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of ModelReturn from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class ModelReturn(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> ModelReturn:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of ModelReturn from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return ModelReturn.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = ModelReturn.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"return": obj.get("return")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt, StrictStr
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Name(BaseModel):
|
||||
"""
|
||||
@@ -48,7 +53,7 @@ class Name(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Name:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of Name from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -63,15 +68,15 @@ class Name(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Name:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of Name from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Name.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = Name.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"name": obj.get("name"),
|
||||
"snake_case": obj.get("snake_case"),
|
||||
"property": obj.get("property"),
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
from datetime import date, datetime
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
from pydantic import BaseModel, StrictBool, StrictInt, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class NullableClass(BaseModel):
|
||||
"""
|
||||
@@ -57,7 +62,7 @@ class NullableClass(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> NullableClass:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of NullableClass from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -131,15 +136,15 @@ class NullableClass(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> NullableClass:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of NullableClass from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return NullableClass.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = NullableClass.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"required_integer_prop": obj.get("required_integer_prop"),
|
||||
"integer_prop": obj.get("integer_prop"),
|
||||
"number_prop": obj.get("number_prop"),
|
||||
|
||||
@@ -22,6 +22,11 @@ from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt, field_validator
|
||||
from pydantic import Field
|
||||
from typing_extensions import Annotated
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class NullableProperty(BaseModel):
|
||||
"""
|
||||
@@ -57,7 +62,7 @@ class NullableProperty(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> NullableProperty:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of NullableProperty from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -75,15 +80,15 @@ class NullableProperty(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> NullableProperty:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of NullableProperty from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return NullableProperty.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = NullableProperty.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"id": obj.get("id"),
|
||||
"name": obj.get("name")
|
||||
})
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class NumberOnly(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class NumberOnly(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> NumberOnly:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of NumberOnly from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class NumberOnly(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> NumberOnly:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of NumberOnly from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return NumberOnly.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = NumberOnly.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"JustNumber": obj.get("JustNumber")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictBool
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class ObjectToTestAdditionalProperties(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class ObjectToTestAdditionalProperties(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> ObjectToTestAdditionalProperties:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of ObjectToTestAdditionalProperties from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class ObjectToTestAdditionalProperties(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> ObjectToTestAdditionalProperties:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of ObjectToTestAdditionalProperties from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return ObjectToTestAdditionalProperties.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = ObjectToTestAdditionalProperties.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"property": obj.get("property") if obj.get("property") is not None else False
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -22,6 +22,11 @@ from typing import List, Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from pydantic import Field
|
||||
from petstore_api.models.deprecated_object import DeprecatedObject
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class ObjectWithDeprecatedFields(BaseModel):
|
||||
"""
|
||||
@@ -49,7 +54,7 @@ class ObjectWithDeprecatedFields(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> ObjectWithDeprecatedFields:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of ObjectWithDeprecatedFields from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -65,15 +70,15 @@ class ObjectWithDeprecatedFields(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> ObjectWithDeprecatedFields:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of ObjectWithDeprecatedFields from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return ObjectWithDeprecatedFields.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = ObjectWithDeprecatedFields.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"uuid": obj.get("uuid"),
|
||||
"id": obj.get("id"),
|
||||
"deprecatedRef": DeprecatedObject.from_dict(obj.get("deprecatedRef")) if obj.get("deprecatedRef") is not None else None,
|
||||
|
||||
@@ -25,6 +25,10 @@ from petstore_api.models.enum_string2 import EnumString2
|
||||
from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict
|
||||
from typing_extensions import Literal
|
||||
from pydantic import StrictStr, Field
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
ONEOFENUMSTRING_ONE_OF_SCHEMAS = ["EnumString1", "EnumString2"]
|
||||
|
||||
@@ -79,13 +83,13 @@ class OneOfEnumString(BaseModel):
|
||||
return v
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> OneOfEnumString:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
return cls.from_json(json.dumps(obj))
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> OneOfEnumString:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Returns the object represented by the json string"""
|
||||
instance = OneOfEnumString.model_construct()
|
||||
instance = cls.model_construct()
|
||||
error_messages = []
|
||||
match = 0
|
||||
|
||||
|
||||
@@ -21,6 +21,11 @@ from datetime import datetime
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictBool, StrictInt, StrictStr, field_validator
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Order(BaseModel):
|
||||
"""
|
||||
@@ -60,7 +65,7 @@ class Order(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Order:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of Order from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -73,15 +78,15 @@ class Order(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Order:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of Order from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Order.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = Order.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"id": obj.get("id"),
|
||||
"petId": obj.get("petId"),
|
||||
"quantity": obj.get("quantity"),
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictBool, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class OuterComposite(BaseModel):
|
||||
"""
|
||||
@@ -46,7 +51,7 @@ class OuterComposite(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> OuterComposite:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of OuterComposite from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -59,15 +64,15 @@ class OuterComposite(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> OuterComposite:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of OuterComposite from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return OuterComposite.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = OuterComposite.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"my_number": obj.get("my_number"),
|
||||
"my_string": obj.get("my_string"),
|
||||
"my_boolean": obj.get("my_boolean")
|
||||
|
||||
@@ -20,6 +20,10 @@ from enum import Enum
|
||||
|
||||
|
||||
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
class OuterEnum(str, Enum):
|
||||
@@ -35,8 +39,8 @@ class OuterEnum(str, Enum):
|
||||
DELIVERED = 'delivered'
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> OuterEnum:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of OuterEnum from a JSON string"""
|
||||
return OuterEnum(json.loads(json_str))
|
||||
return cls(json.loads(json_str))
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ from enum import Enum
|
||||
|
||||
|
||||
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
class OuterEnumDefaultValue(str, Enum):
|
||||
@@ -35,8 +39,8 @@ class OuterEnumDefaultValue(str, Enum):
|
||||
DELIVERED = 'delivered'
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> OuterEnumDefaultValue:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of OuterEnumDefaultValue from a JSON string"""
|
||||
return OuterEnumDefaultValue(json.loads(json_str))
|
||||
return cls(json.loads(json_str))
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ from enum import Enum
|
||||
|
||||
|
||||
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
class OuterEnumInteger(int, Enum):
|
||||
@@ -35,8 +39,8 @@ class OuterEnumInteger(int, Enum):
|
||||
NUMBER_2 = 2
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> OuterEnumInteger:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of OuterEnumInteger from a JSON string"""
|
||||
return OuterEnumInteger(json.loads(json_str))
|
||||
return cls(json.loads(json_str))
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ from enum import Enum
|
||||
|
||||
|
||||
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
class OuterEnumIntegerDefaultValue(int, Enum):
|
||||
@@ -36,8 +40,8 @@ class OuterEnumIntegerDefaultValue(int, Enum):
|
||||
NUMBER_2 = 2
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> OuterEnumIntegerDefaultValue:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of OuterEnumIntegerDefaultValue from a JSON string"""
|
||||
return OuterEnumIntegerDefaultValue(json.loads(json_str))
|
||||
return cls(json.loads(json_str))
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,11 @@ from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
from petstore_api.models.outer_enum import OuterEnum
|
||||
from petstore_api.models.outer_enum_integer import OuterEnumInteger
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class OuterObjectWithEnumProperty(BaseModel):
|
||||
"""
|
||||
@@ -47,7 +52,7 @@ class OuterObjectWithEnumProperty(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> OuterObjectWithEnumProperty:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of OuterObjectWithEnumProperty from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -65,15 +70,15 @@ class OuterObjectWithEnumProperty(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> OuterObjectWithEnumProperty:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of OuterObjectWithEnumProperty from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return OuterObjectWithEnumProperty.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = OuterObjectWithEnumProperty.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"str_value": obj.get("str_value"),
|
||||
"value": obj.get("value")
|
||||
})
|
||||
|
||||
@@ -22,6 +22,11 @@ from typing import Dict, Optional
|
||||
from pydantic import BaseModel
|
||||
from pydantic import Field
|
||||
from petstore_api.models.inner_dict_with_property import InnerDictWithProperty
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Parent(BaseModel):
|
||||
"""
|
||||
@@ -46,7 +51,7 @@ class Parent(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Parent:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of Parent from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -66,15 +71,15 @@ class Parent(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Parent:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of Parent from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Parent.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = Parent.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"optionalDict": dict(
|
||||
(_k, InnerDictWithProperty.from_dict(_v))
|
||||
for _k, _v in obj.get("optionalDict").items()
|
||||
|
||||
@@ -22,6 +22,11 @@ from typing import Dict, Optional
|
||||
from pydantic import BaseModel
|
||||
from pydantic import Field
|
||||
from petstore_api.models.inner_dict_with_property import InnerDictWithProperty
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class ParentWithOptionalDict(BaseModel):
|
||||
"""
|
||||
@@ -46,7 +51,7 @@ class ParentWithOptionalDict(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> ParentWithOptionalDict:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of ParentWithOptionalDict from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -66,15 +71,15 @@ class ParentWithOptionalDict(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> ParentWithOptionalDict:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of ParentWithOptionalDict from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return ParentWithOptionalDict.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = ParentWithOptionalDict.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"optionalDict": dict(
|
||||
(_k, InnerDictWithProperty.from_dict(_v))
|
||||
for _k, _v in obj.get("optionalDict").items()
|
||||
|
||||
@@ -24,6 +24,11 @@ from pydantic import Field
|
||||
from typing_extensions import Annotated
|
||||
from petstore_api.models.category import Category
|
||||
from petstore_api.models.tag import Tag
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Pet(BaseModel):
|
||||
"""
|
||||
@@ -63,7 +68,7 @@ class Pet(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Pet:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of Pet from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -86,15 +91,15 @@ class Pet(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Pet:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of Pet from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Pet.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = Pet.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"id": obj.get("id"),
|
||||
"category": Category.from_dict(obj.get("category")) if obj.get("category") is not None else None,
|
||||
"name": obj.get("name"),
|
||||
|
||||
@@ -25,6 +25,10 @@ from petstore_api.models.danish_pig import DanishPig
|
||||
from typing import Union, Any, List, TYPE_CHECKING, Optional, Dict
|
||||
from typing_extensions import Literal
|
||||
from pydantic import StrictStr, Field
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
PIG_ONE_OF_SCHEMAS = ["BasquePig", "DanishPig"]
|
||||
|
||||
@@ -82,13 +86,13 @@ class Pig(BaseModel):
|
||||
return v
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Pig:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
return cls.from_json(json.dumps(obj))
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Pig:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Returns the object represented by the json string"""
|
||||
instance = Pig.model_construct()
|
||||
instance = cls.model_construct()
|
||||
error_messages = []
|
||||
match = 0
|
||||
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class PropertyNameCollision(BaseModel):
|
||||
"""
|
||||
@@ -47,7 +52,7 @@ class PropertyNameCollision(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> PropertyNameCollision:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of PropertyNameCollision from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -60,15 +65,15 @@ class PropertyNameCollision(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> PropertyNameCollision:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of PropertyNameCollision from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return PropertyNameCollision.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = PropertyNameCollision.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"_type": obj.get("_type"),
|
||||
"type": obj.get("type"),
|
||||
"type_": obj.get("type_")
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class ReadOnlyFirst(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class ReadOnlyFirst(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> ReadOnlyFirst:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of ReadOnlyFirst from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -59,15 +64,15 @@ class ReadOnlyFirst(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> ReadOnlyFirst:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of ReadOnlyFirst from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return ReadOnlyFirst.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = ReadOnlyFirst.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"bar": obj.get("bar"),
|
||||
"baz": obj.get("baz")
|
||||
})
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class SecondRef(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class SecondRef(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> SecondRef:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of SecondRef from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -61,15 +66,15 @@ class SecondRef(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> SecondRef:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of SecondRef from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return SecondRef.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = SecondRef.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"category": obj.get("category"),
|
||||
"circular_ref": CircularReferenceModel.from_dict(obj.get("circular_ref")) if obj.get("circular_ref") is not None else None
|
||||
})
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class SelfReferenceModel(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class SelfReferenceModel(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> SelfReferenceModel:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of SelfReferenceModel from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -61,15 +66,15 @@ class SelfReferenceModel(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> SelfReferenceModel:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of SelfReferenceModel from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return SelfReferenceModel.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = SelfReferenceModel.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"size": obj.get("size"),
|
||||
"nested": DummyModel.from_dict(obj.get("nested")) if obj.get("nested") is not None else None
|
||||
})
|
||||
|
||||
@@ -20,6 +20,10 @@ from enum import Enum
|
||||
|
||||
|
||||
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
class SingleRefType(str, Enum):
|
||||
@@ -34,8 +38,8 @@ class SingleRefType(str, Enum):
|
||||
USER = 'user'
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> SingleRefType:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of SingleRefType from a JSON string"""
|
||||
return SingleRefType(json.loads(json_str))
|
||||
return cls(json.loads(json_str))
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ from enum import Enum
|
||||
|
||||
|
||||
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
class SpecialCharacterEnum(str, Enum):
|
||||
@@ -42,8 +46,8 @@ class SpecialCharacterEnum(str, Enum):
|
||||
HELLO_WORLD = ' hello world '
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> SpecialCharacterEnum:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of SpecialCharacterEnum from a JSON string"""
|
||||
return SpecialCharacterEnum(json.loads(json_str))
|
||||
return cls(json.loads(json_str))
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class SpecialModelName(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class SpecialModelName(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> SpecialModelName:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of SpecialModelName from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class SpecialModelName(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> SpecialModelName:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of SpecialModelName from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return SpecialModelName.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = SpecialModelName.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"$special[property.name]": obj.get("$special[property.name]")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -22,6 +22,11 @@ from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt, StrictStr, field_validator
|
||||
from pydantic import Field
|
||||
from petstore_api.models.category import Category
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class SpecialName(BaseModel):
|
||||
"""
|
||||
@@ -58,7 +63,7 @@ class SpecialName(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> SpecialName:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of SpecialName from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -74,15 +79,15 @@ class SpecialName(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> SpecialName:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of SpecialName from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return SpecialName.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = SpecialName.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"property": obj.get("property"),
|
||||
"async": Category.from_dict(obj.get("async")) if obj.get("async") is not None else None,
|
||||
"schema": obj.get("schema")
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Tag(BaseModel):
|
||||
"""
|
||||
@@ -45,7 +50,7 @@ class Tag(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Tag:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of Tag from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -58,15 +63,15 @@ class Tag(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Tag:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of Tag from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Tag.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = Tag.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"id": obj.get("id"),
|
||||
"name": obj.get("name")
|
||||
})
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class TestInlineFreeformAdditionalPropertiesRequest(BaseModel):
|
||||
"""
|
||||
@@ -46,7 +51,7 @@ class TestInlineFreeformAdditionalPropertiesRequest(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> TestInlineFreeformAdditionalPropertiesRequest:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of TestInlineFreeformAdditionalPropertiesRequest from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -65,15 +70,15 @@ class TestInlineFreeformAdditionalPropertiesRequest(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> TestInlineFreeformAdditionalPropertiesRequest:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of TestInlineFreeformAdditionalPropertiesRequest from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return TestInlineFreeformAdditionalPropertiesRequest.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = TestInlineFreeformAdditionalPropertiesRequest.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"someProperty": obj.get("someProperty")
|
||||
})
|
||||
# store additional fields in additional_properties
|
||||
|
||||
@@ -20,6 +20,11 @@ import json
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictStr
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class Tiger(BaseModel):
|
||||
"""
|
||||
@@ -44,7 +49,7 @@ class Tiger(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> Tiger:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of Tiger from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -57,15 +62,15 @@ class Tiger(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> Tiger:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of Tiger from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return Tiger.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = Tiger.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"skill": obj.get("skill")
|
||||
})
|
||||
return _obj
|
||||
|
||||
@@ -21,6 +21,11 @@ import json
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt, StrictStr
|
||||
from pydantic import Field
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class User(BaseModel):
|
||||
"""
|
||||
@@ -52,7 +57,7 @@ class User(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> User:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of User from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -65,15 +70,15 @@ class User(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> User:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of User from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return User.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = User.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"id": obj.get("id"),
|
||||
"username": obj.get("username"),
|
||||
"firstName": obj.get("firstName"),
|
||||
|
||||
@@ -22,6 +22,11 @@ from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt
|
||||
from petstore_api.models.one_of_enum_string import OneOfEnumString
|
||||
from petstore_api.models.pig import Pig
|
||||
from typing import Dict, Any
|
||||
try:
|
||||
from typing import Self
|
||||
except ImportError:
|
||||
from typing_extensions import Self
|
||||
|
||||
class WithNestedOneOf(BaseModel):
|
||||
"""
|
||||
@@ -48,7 +53,7 @@ class WithNestedOneOf(BaseModel):
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_str: str) -> WithNestedOneOf:
|
||||
def from_json(cls, json_str: str) -> Self:
|
||||
"""Create an instance of WithNestedOneOf from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
@@ -67,15 +72,15 @@ class WithNestedOneOf(BaseModel):
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> WithNestedOneOf:
|
||||
def from_dict(cls, obj: dict) -> Self:
|
||||
"""Create an instance of WithNestedOneOf from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return WithNestedOneOf.model_validate(obj)
|
||||
return cls.model_validate(obj)
|
||||
|
||||
_obj = WithNestedOneOf.model_validate({
|
||||
_obj = cls.model_validate({
|
||||
"size": obj.get("size"),
|
||||
"nested_pig": Pig.from_dict(obj.get("nested_pig")) if obj.get("nested_pig") is not None else None,
|
||||
"nested_oneof_enum_string": OneOfEnumString.from_dict(obj.get("nested_oneof_enum_string")) if obj.get("nested_oneof_enum_string") is not None else None
|
||||
|
||||
Reference in New Issue
Block a user