diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java index a9bd72e390ac..437c28e0fc9a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java @@ -871,13 +871,13 @@ private ModelsMap postProcessModelsMap(ModelsMap objs) { pydanticImports.add("Field"); pydanticImports.add("StrictStr"); pydanticImports.add("ValidationError"); - pydanticImports.add("validator"); + pydanticImports.add(usePydanticV2 ? "field_validator" : "validator"); } else if (!model.anyOf.isEmpty()) { // anyOF codegenProperties = model.getComposedSchemas().getAnyOf(); pydanticImports.add("Field"); pydanticImports.add("StrictStr"); pydanticImports.add("ValidationError"); - pydanticImports.add("validator"); + pydanticImports.add(usePydanticV2 ? "field_validator" : "validator"); } else { // typical model codegenProperties = model.vars; @@ -1110,7 +1110,7 @@ private String getPydanticType(CodegenParameter cp, fieldCustomization.add("min_length=" + cp.getMinLength()); } if (cp.getPattern() != null) { - pydanticImports.add("validator"); + pydanticImports.add(usePydanticV2 ? "field_validator" : "validator"); // use validator instead as regex doesn't support flags, e.g. IGNORECASE //fieldCustomization.add(String.format(Locale.ROOT, "regex=r'%s'", cp.getPattern())); } @@ -1229,7 +1229,7 @@ private String getPydanticType(CodegenParameter cp, fieldCustomization.add("max_length=" + cp.getMaxLength()); } if (cp.getPattern() != null) { - pydanticImports.add("validator"); + pydanticImports.add(usePydanticV2 ? "field_validator" : "validator"); // use validator instead as regex doesn't support flags, e.g. IGNORECASE //fieldCustomization.add(Locale.ROOT, String.format(Locale.ROOT, "regex=r'%s'", cp.getPattern())); } @@ -1347,7 +1347,7 @@ private String getPydanticType(CodegenProperty cp, } if (cp.isEnum) { - pydanticImports.add("validator"); + pydanticImports.add(usePydanticV2 ? "field_validator" : "validator"); } /* comment out the following since Literal requires python 3.8 @@ -1397,7 +1397,7 @@ private String getPydanticType(CodegenProperty cp, fieldCustomization.add("min_length=" + cp.getMinLength()); } if (cp.getPattern() != null) { - pydanticImports.add("validator"); + pydanticImports.add(usePydanticV2 ? "field_validator" : "validator"); // use validator instead as regex doesn't support flags, e.g. IGNORECASE //fieldCustomization.add(Locale.ROOT, String.format(Locale.ROOT, "regex=r'%s'", cp.getPattern())); } @@ -1516,7 +1516,7 @@ private String getPydanticType(CodegenProperty cp, fieldCustomization.add("max_length=" + cp.getMaxLength()); } if (cp.getPattern() != null) { - pydanticImports.add("validator"); + pydanticImports.add(usePydanticV2 ? "field_validator" : "validator"); // use validator instead as regex doesn't support flags, e.g. IGNORECASE //fieldCustomization.add(Locale.ROOT, String.format(Locale.ROOT, "regex=r'%s'", cp.getPattern())); } diff --git a/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache b/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache index 15fbe332696a..b6fe413d1001 100644 --- a/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache +++ b/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache @@ -34,5 +34,8 @@ from pprint import pprint {{#vendorExtensions.x-py-postponed-example-imports}} {{{.}}} {{/vendorExtensions.x-py-postponed-example-imports}} -{{classname}}.update_forward_refs() +try: + {{classname}}.{{#usePydanticV2}}model_rebuild{{/usePydanticV2}}{{^usePydanticV2}}update_forward_refs{{/usePydanticV2}}() +except Exception: + pass {{/vendorExtensions.x-py-postponed-example-imports.size}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/python/model_anyof.mustache b/modules/openapi-generator/src/main/resources/python/model_anyof.mustache index ff0b3fcd7df5..ccf005ba3f55 100644 --- a/modules/openapi-generator/src/main/resources/python/model_anyof.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_anyof.mustache @@ -30,9 +30,9 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}} {{/composedSchemas.anyOf}} if TYPE_CHECKING: - actual_instance: Union[{{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}] + actual_instance: Union[{{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}{{#isNullable}}, None{{/isNullable}}] else: - actual_instance: Any + actual_instance: Any = None {{^usePydanticV2}} any_of_schemas: List[str] = Field({{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ANY_OF_SCHEMAS, const=True) {{/usePydanticV2}} @@ -50,14 +50,6 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} class Config: validate_assignment = True {{/usePydanticV2}} -{{#discriminator}} - - discriminator_value_class_map = { -{{#children}} - '{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}': '{{{classname}}}'{{^-last}},{{/-last}} -{{/children}} - } -{{/discriminator}} def __init__(self, *args, **kwargs) -> None: if args: @@ -66,17 +58,24 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) + {{#usePydanticV2}} + @field_validator('actual_instance') + {{/usePydanticV2}} + {{^usePydanticV2}} @validator('actual_instance') + {{/usePydanticV2}} def actual_instance_must_validate_anyof(cls, v): {{#isNullable}} if v is None: return v {{/isNullable}} - instance = {{{classname}}}.construct() + instance = {{{classname}}}.{{#usePydanticV2}}model_construct{{/usePydanticV2}}{{^usePydanticV2}}construct{{/usePydanticV2}}() error_messages = [] {{#composedSchemas.anyOf}} # validate data type: {{{dataType}}} @@ -88,20 +87,11 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} error_messages.append(str(e)) {{/isContainer}} {{^isContainer}} - {{#isPrimitiveType}} try: instance.{{vendorExtensions.x-py-name}} = v return v except (ValidationError, ValueError) as e: error_messages.append(str(e)) - {{/isPrimitiveType}} - {{^isPrimitiveType}} - if not isinstance(v, {{{dataType}}}): - error_messages.append(f"Error! Input type `{type(v)}` is not `{{{dataType}}}`") - else: - return v - - {{/isPrimitiveType}} {{/isContainer}} {{/composedSchemas.anyOf}} if error_messages: @@ -117,7 +107,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} @classmethod def from_json(cls, json_str: str) -> {{{classname}}}: """Returns the object represented by the json string""" - instance = {{{classname}}}.construct() + instance = {{{classname}}}.{{#usePydanticV2}}model_construct{{/usePydanticV2}}{{^usePydanticV2}}construct{{/usePydanticV2}}() {{#isNullable}} if json_str is None: return instance @@ -189,11 +179,14 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.{{#usePydanticV2}}model_dump{{/usePydanticV2}}{{^usePydanticV2}}dict{{/usePydanticV2}}()) {{#vendorExtensions.x-py-postponed-model-imports.size}} {{#vendorExtensions.x-py-postponed-model-imports}} {{{.}}} {{/vendorExtensions.x-py-postponed-model-imports}} -{{classname}}.update_forward_refs() +try: + {{classname}}.{{#usePydanticV2}}model_rebuild{{/usePydanticV2}}{{^usePydanticV2}}update_forward_refs{{/usePydanticV2}}() +except Exception: + pass {{/vendorExtensions.x-py-postponed-model-imports.size}} diff --git a/modules/openapi-generator/src/main/resources/python/model_generic.mustache b/modules/openapi-generator/src/main/resources/python/model_generic.mustache index 30072031c0c1..f6b10ebeeb31 100644 --- a/modules/openapi-generator/src/main/resources/python/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_generic.mustache @@ -20,11 +20,15 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{#isAdditionalPropertiesTrue}} additional_properties: Dict[str, Any] = {} {{/isAdditionalPropertiesTrue}} - __properties = [{{#allVars}}"{{baseName}}"{{^-last}}, {{/-last}}{{/allVars}}] {{#vars}} {{#vendorExtensions.x-regex}} + {{#usePydanticV2}} + @field_validator('{{{name}}}') + {{/usePydanticV2}} + {{^usePydanticV2}} @validator('{{{name}}}') + {{/usePydanticV2}} def {{{name}}}_validate_regular_expression(cls, value): """Validates the regular expression""" {{^required}} @@ -45,7 +49,12 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{/vendorExtensions.x-regex}} {{#isEnum}} + {{#usePydanticV2}} + @field_validator('{{{name}}}') + {{/usePydanticV2}} + {{^usePydanticV2}} @validator('{{{name}}}') + {{/usePydanticV2}} def {{{name}}}_validate_enum(cls, value): """Validates the enum""" {{^required}} @@ -89,33 +98,25 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{#hasChildren}} {{#discriminator}} # JSON field name that stores the object type - __discriminator_property_name = '{{discriminator.propertyBaseName}}' - - {{#mappedModels}} - {{#-first}} - # discriminator mappings - __discriminator_value_class_map = { - {{/-first}} - '{{{mappingName}}}': '{{{modelName}}}'{{^-last}},{{/-last}} - {{#-last}} - } @classmethod def get_discriminator_value(cls, obj: dict) -> str: """Returns the discriminator value (object type) of the data""" - discriminator_value = obj[cls.__discriminator_property_name] + discriminator_value = obj['{{discriminator.propertyBaseName}}'] + discriminator_value_class_map = { + {{#mappedModels}}'{{{mappingName}}}': '{{{modelName}}}'{{^-last}},{{/-last}}{{/mappedModels}} + } + if discriminator_value: - return cls.__discriminator_value_class_map.get(discriminator_value) + return discriminator_value_class_map.get(discriminator_value) else: return None - {{/-last}} - {{/mappedModels}} {{/discriminator}} {{/hasChildren}} def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.{{#usePydanticV2}}model_dump{{/usePydanticV2}}{{^usePydanticV2}}dict{{/usePydanticV2}}(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -128,7 +129,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.{{#usePydanticV2}}model_dump{{/usePydanticV2}}{{^usePydanticV2}}dict{{/usePydanticV2}}(by_alias=True, exclude={ {{#vendorExtensions.x-py-readonly}} "{{{.}}}", @@ -216,7 +217,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{#isNullable}} # set to None if {{{name}}} (nullable) is None # and __fields_set__ contains the field - if self.{{name}} is None and "{{{name}}}" in self.__fields_set__: + if self.{{name}} is None and "{{{name}}}" in self.{{#usePydanticV2}}model_fields_set{{/usePydanticV2}}{{^usePydanticV2}}__fields_set__{{/usePydanticV2}}: _dict['{{{baseName}}}'] = None {{/isNullable}} @@ -230,13 +231,16 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{#discriminator}} # look up the object type based on discriminator mapping object_type = cls.get_discriminator_value(obj) + discriminator_value_class_map = { + {{#mappedModels}}'{{{mappingName}}}': '{{{modelName}}}'{{^-last}},{{/-last}}{{/mappedModels}} + } if object_type: klass = globals()[object_type] return klass.from_dict(obj) else: raise ValueError("{{{classname}}} failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) + json.dumps(obj) + ". Discriminator property name: " + '{{discriminator.propertyBaseName}}' + + ", mapping: " + json.dumps(discriminator_value_class_map)) {{/discriminator}} {{/hasChildren}} {{^hasChildren}} @@ -244,18 +248,18 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} return None if not isinstance(obj, dict): - return {{{classname}}}.parse_obj(obj) + return {{{classname}}}.{{#usePydanticV2}}model_validate{{/usePydanticV2}}{{^usePydanticV2}}parse_obj{{/usePydanticV2}}(obj) {{#disallowAdditionalPropertiesIfNotPresent}} {{^isAdditionalPropertiesTrue}} # raise errors for additional fields in the input for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in [{{#allVars}}"{{{baseName}}}"{{^-last}}, {{/-last}}{{/allVars}}]: raise ValueError("Error due to additional fields (not defined in {{classname}}) in the input: " + obj) {{/isAdditionalPropertiesTrue}} {{/disallowAdditionalPropertiesIfNotPresent}} - _obj = {{{classname}}}.parse_obj({ + _obj = {{{classname}}}.{{#usePydanticV2}}model_validate{{/usePydanticV2}}{{^usePydanticV2}}parse_obj{{/usePydanticV2}}({ {{#allVars}} {{#isContainer}} {{#isArray}} @@ -354,7 +358,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{#isAdditionalPropertiesTrue}} # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in [{{#allVars}}"{{{baseName}}}"{{^-last}}, {{/-last}}{{/allVars}}]: _obj.additional_properties[_key] = obj.get(_key) {{/isAdditionalPropertiesTrue}} @@ -365,5 +369,8 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{#vendorExtensions.x-py-postponed-model-imports}} {{{.}}} {{/vendorExtensions.x-py-postponed-model-imports}} -{{classname}}.update_forward_refs() +try: + {{classname}}.{{#usePydanticV2}}model_rebuild{{/usePydanticV2}}{{^usePydanticV2}}update_forward_refs{{/usePydanticV2}}() +except Exception: + pass {{/vendorExtensions.x-py-postponed-model-imports.size}} diff --git a/modules/openapi-generator/src/main/resources/python/model_oneof.mustache b/modules/openapi-generator/src/main/resources/python/model_oneof.mustache index b2ff88833b54..40dd820edb6b 100644 --- a/modules/openapi-generator/src/main/resources/python/model_oneof.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_oneof.mustache @@ -29,9 +29,9 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{vendorExtensions.x-py-name}}: {{{vendorExtensions.x-py-typing}}} {{/composedSchemas.oneOf}} if TYPE_CHECKING: - actual_instance: Union[{{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}] + actual_instance: Union[{{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}{{#isNullable}}, None{{/isNullable}}] else: - actual_instance: Any + actual_instance: Any = None {{#usePydanticV2}} one_of_schemas: List[str] = Literal[{{#oneOf}}"{{.}}"{{^-last}}, {{/-last}}{{/oneOf}}] @@ -50,14 +50,6 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} class Config: validate_assignment = True {{/usePydanticV2}} -{{#discriminator}} - - discriminator_value_class_map = { -{{#children}} - '{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}': '{{{classname}}}'{{^-last}},{{/-last}} -{{/children}} - } -{{/discriminator}} def __init__(self, *args, **kwargs) -> None: if args: @@ -66,17 +58,24 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) + {{#usePydanticV2}} + @field_validator('actual_instance') + {{/usePydanticV2}} + {{^usePydanticV2}} @validator('actual_instance') + {{/usePydanticV2}} def actual_instance_must_validate_oneof(cls, v): {{#isNullable}} if v is None: return v {{/isNullable}} - instance = {{{classname}}}.construct() + instance = {{{classname}}}.{{#usePydanticV2}}model_construct{{/usePydanticV2}}{{^usePydanticV2}}construct{{/usePydanticV2}}() error_messages = [] match = 0 {{#composedSchemas.oneOf}} @@ -89,23 +88,17 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} error_messages.append(str(e)) {{/isContainer}} {{^isContainer}} - {{#isPrimitiveType}} try: instance.{{vendorExtensions.x-py-name}} = v match += 1 except (ValidationError, ValueError) as e: error_messages.append(str(e)) - {{/isPrimitiveType}} - {{^isPrimitiveType}} - if not isinstance(v, {{{dataType}}}): - error_messages.append(f"Error! Input type `{type(v)}` is not `{{{dataType}}}`") - else: - match += 1 - {{/isPrimitiveType}} {{/isContainer}} {{/composedSchemas.oneOf}} if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when setting `actual_instance` in {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -120,7 +113,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} @classmethod def from_json(cls, json_str: str) -> {{{classname}}}: """Returns the object represented by the json string""" - instance = {{{classname}}}.construct() + instance = {{{classname}}}.{{#usePydanticV2}}model_construct{{/usePydanticV2}}{{^usePydanticV2}}construct{{/usePydanticV2}}() {{#isNullable}} if json_str is None: return instance @@ -184,6 +177,8 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when deserializing the JSON string into {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -216,11 +211,14 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.{{#usePydanticV2}}model_dump{{/usePydanticV2}}{{^usePydanticV2}}dict{{/usePydanticV2}}()) {{#vendorExtensions.x-py-postponed-model-imports.size}} {{#vendorExtensions.x-py-postponed-model-imports}} {{{.}}} {{/vendorExtensions.x-py-postponed-model-imports}} -{{classname}}.update_forward_refs() +try: + {{classname}}.{{#usePydanticV2}}model_rebuild{{/usePydanticV2}}{{^usePydanticV2}}update_forward_refs{{/usePydanticV2}}() +except Exception: + pass {{/vendorExtensions.x-py-postponed-model-imports.size}} diff --git a/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-pydantic-v2.yaml b/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-pydantic-v2.yaml index 4fe96df00525..9a509f711008 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-pydantic-v2.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-pydantic-v2.yaml @@ -2197,27 +2197,27 @@ components: properties: optionalDict: $ref: "#/components/schemas/DictWithAdditionalProperties" - #Circular-Reference-Model: - # type: object - # properties: - # size: - # type: integer - # nested: - # $ref: '#/components/schemas/FirstRef' - #FirstRef: - # type: object - # properties: - # category: - # type: string - # self_ref: - # $ref: '#/components/schemas/SecondRef' - #SecondRef: - # type: object - # properties: - # category: - # type: string - # circular_ref: - # $ref: '#/components/schemas/Circular-Reference-Model' + Circular-Reference-Model: + type: object + properties: + size: + type: integer + nested: + $ref: '#/components/schemas/FirstRef' + FirstRef: + type: object + properties: + category: + type: string + self_ref: + $ref: '#/components/schemas/SecondRef' + SecondRef: + type: object + properties: + category: + type: string + circular_ref: + $ref: '#/components/schemas/Circular-Reference-Model' InnerDictWithAdditionalProperties: type: object additionalProperties: diff --git a/samples/client/echo_api/python/openapi_client/models/bird.py b/samples/client/echo_api/python/openapi_client/models/bird.py index 7afefcc9e596..eda5597d8da4 100644 --- a/samples/client/echo_api/python/openapi_client/models/bird.py +++ b/samples/client/echo_api/python/openapi_client/models/bird.py @@ -28,7 +28,6 @@ class Bird(BaseModel): """ size: Optional[StrictStr] = None color: Optional[StrictStr] = None - __properties = ["size", "color"] """Pydantic configuration""" class Config: diff --git a/samples/client/echo_api/python/openapi_client/models/category.py b/samples/client/echo_api/python/openapi_client/models/category.py index 4a9de5bdfb04..6e6e351e8ae3 100644 --- a/samples/client/echo_api/python/openapi_client/models/category.py +++ b/samples/client/echo_api/python/openapi_client/models/category.py @@ -28,7 +28,6 @@ class Category(BaseModel): """ id: Optional[StrictInt] = None name: Optional[StrictStr] = None - __properties = ["id", "name"] """Pydantic configuration""" class Config: diff --git a/samples/client/echo_api/python/openapi_client/models/data_query.py b/samples/client/echo_api/python/openapi_client/models/data_query.py index 6dc4e225ae91..c512f9e64fd2 100644 --- a/samples/client/echo_api/python/openapi_client/models/data_query.py +++ b/samples/client/echo_api/python/openapi_client/models/data_query.py @@ -30,7 +30,6 @@ class DataQuery(Query): suffix: Optional[StrictStr] = Field(None, description="test suffix") text: Optional[StrictStr] = Field(None, description="Some text containing white spaces") var_date: Optional[datetime] = Field(None, alias="date", description="A date") - __properties = ["id", "outcomes", "suffix", "text", "date"] """Pydantic configuration""" class Config: diff --git a/samples/client/echo_api/python/openapi_client/models/default_value.py b/samples/client/echo_api/python/openapi_client/models/default_value.py index 486612d7ce5a..b370912637a4 100644 --- a/samples/client/echo_api/python/openapi_client/models/default_value.py +++ b/samples/client/echo_api/python/openapi_client/models/default_value.py @@ -35,7 +35,6 @@ class DefaultValue(BaseModel): array_string_nullable: Optional[conlist(StrictStr)] = None array_string_extension_nullable: Optional[conlist(StrictStr)] = None string_nullable: Optional[StrictStr] = None - __properties = ["array_string_enum_ref_default", "array_string_enum_default", "array_string_default", "array_integer_default", "array_string", "array_string_nullable", "array_string_extension_nullable", "string_nullable"] @validator('array_string_enum_default') def array_string_enum_default_validate_enum(cls, value): diff --git a/samples/client/echo_api/python/openapi_client/models/number_properties_only.py b/samples/client/echo_api/python/openapi_client/models/number_properties_only.py index b8a367516306..0eae5e40ad76 100644 --- a/samples/client/echo_api/python/openapi_client/models/number_properties_only.py +++ b/samples/client/echo_api/python/openapi_client/models/number_properties_only.py @@ -29,7 +29,6 @@ class NumberPropertiesOnly(BaseModel): number: Optional[Union[StrictFloat, StrictInt]] = None float: Optional[Union[StrictFloat, StrictInt]] = None double: Optional[Union[confloat(le=50.2, ge=0.8, strict=True), conint(le=50, ge=1, strict=True)]] = None - __properties = ["number", "float", "double"] """Pydantic configuration""" class Config: diff --git a/samples/client/echo_api/python/openapi_client/models/pet.py b/samples/client/echo_api/python/openapi_client/models/pet.py index b758fbf5a0ff..bcf9933c2b0f 100644 --- a/samples/client/echo_api/python/openapi_client/models/pet.py +++ b/samples/client/echo_api/python/openapi_client/models/pet.py @@ -34,7 +34,6 @@ class Pet(BaseModel): photo_urls: conlist(StrictStr) = Field(..., alias="photoUrls") tags: Optional[conlist(Tag)] = None status: Optional[StrictStr] = Field(None, description="pet status in the store") - __properties = ["id", "name", "category", "photoUrls", "tags", "status"] @validator('status') def status_validate_enum(cls, value): diff --git a/samples/client/echo_api/python/openapi_client/models/query.py b/samples/client/echo_api/python/openapi_client/models/query.py index 9342db8bc355..5b2ee54dcea8 100644 --- a/samples/client/echo_api/python/openapi_client/models/query.py +++ b/samples/client/echo_api/python/openapi_client/models/query.py @@ -28,7 +28,6 @@ class Query(BaseModel): """ id: Optional[StrictInt] = Field(None, description="Query") outcomes: Optional[conlist(StrictStr)] = None - __properties = ["id", "outcomes"] @validator('outcomes') def outcomes_validate_enum(cls, value): diff --git a/samples/client/echo_api/python/openapi_client/models/tag.py b/samples/client/echo_api/python/openapi_client/models/tag.py index 28b06fa6bff9..a94fe4c1abd2 100644 --- a/samples/client/echo_api/python/openapi_client/models/tag.py +++ b/samples/client/echo_api/python/openapi_client/models/tag.py @@ -28,7 +28,6 @@ class Tag(BaseModel): """ id: Optional[StrictInt] = None name: Optional[StrictStr] = None - __properties = ["id", "name"] """Pydantic configuration""" class Config: diff --git a/samples/client/echo_api/python/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.py b/samples/client/echo_api/python/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.py index ef0865cb0fbf..a0ee6b36feb6 100644 --- a/samples/client/echo_api/python/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.py +++ b/samples/client/echo_api/python/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.py @@ -30,7 +30,6 @@ class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseMod color: Optional[StrictStr] = None id: Optional[StrictInt] = None name: Optional[StrictStr] = None - __properties = ["size", "color", "id", "name"] """Pydantic configuration""" class Config: diff --git a/samples/client/echo_api/python/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.py b/samples/client/echo_api/python/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.py index 78c5e72410de..fb8d197f7232 100644 --- a/samples/client/echo_api/python/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.py +++ b/samples/client/echo_api/python/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.py @@ -27,7 +27,6 @@ class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel): TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter """ values: Optional[conlist(StrictStr)] = None - __properties = ["values"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_any_type.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_any_type.py index c0d9294a9094..a29082ee88a9 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_any_type.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_any_type.py @@ -27,7 +27,6 @@ class AdditionalPropertiesAnyType(BaseModel): """ name: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["name"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> AdditionalPropertiesAnyType: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_class.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_class.py index ad1308c084a5..7deaad1e09b0 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_class.py @@ -27,7 +27,6 @@ class AdditionalPropertiesClass(BaseModel): """ map_property: Optional[Dict[str, StrictStr]] = None map_of_map_property: Optional[Dict[str, Dict[str, StrictStr]]] = None - __properties = ["map_property", "map_of_map_property"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_object.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_object.py index b3e50b40923b..89afb442762a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_object.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_object.py @@ -27,7 +27,6 @@ class AdditionalPropertiesObject(BaseModel): """ name: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["name"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> AdditionalPropertiesObject: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_with_description_only.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_with_description_only.py index feedf9a744a7..72156d9f1431 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_with_description_only.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/additional_properties_with_description_only.py @@ -27,7 +27,6 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel): """ name: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["name"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> AdditionalPropertiesWithDescriptionOnly: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_with_single_ref.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_with_single_ref.py index f624188049d7..802e1ac74905 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_with_single_ref.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/all_of_with_single_ref.py @@ -28,7 +28,6 @@ class AllOfWithSingleRef(BaseModel): """ username: Optional[StrictStr] = None single_ref_type: Optional[SingleRefType] = Field(None, alias="SingleRefType") - __properties = ["username", "SingleRefType"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/animal.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/animal.py index 82f6b724d70e..6f9878edc827 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/animal.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/animal.py @@ -27,7 +27,6 @@ class Animal(BaseModel): """ class_name: StrictStr = Field(..., alias="className") color: Optional[StrictStr] = 'red' - __properties = ["className", "color"] """Pydantic configuration""" class Config: @@ -35,20 +34,17 @@ class Config: validate_assignment = True # JSON field name that stores the object type - __discriminator_property_name = 'className' - - # discriminator mappings - __discriminator_value_class_map = { - 'Cat': 'Cat', - 'Dog': 'Dog' - } @classmethod def get_discriminator_value(cls, obj: dict) -> str: """Returns the discriminator value (object type) of the data""" - discriminator_value = obj[cls.__discriminator_property_name] + discriminator_value = obj['className'] + discriminator_value_class_map = { + 'Cat': 'Cat','Dog': 'Dog' + } + if discriminator_value: - return cls.__discriminator_value_class_map.get(discriminator_value) + return discriminator_value_class_map.get(discriminator_value) else: return None @@ -78,15 +74,21 @@ def from_dict(cls, obj: dict) -> Union(Cat, Dog): """Create an instance of Animal from a dict""" # look up the object type based on discriminator mapping object_type = cls.get_discriminator_value(obj) + discriminator_value_class_map = { + 'Cat': 'Cat','Dog': 'Dog' + } if object_type: klass = globals()[object_type] return klass.from_dict(obj) else: raise ValueError("Animal failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) + json.dumps(obj) + ". Discriminator property name: " + 'className' + + ", mapping: " + json.dumps(discriminator_value_class_map)) from petstore_api.models.cat import Cat from petstore_api.models.dog import Dog -Animal.update_forward_refs() +try: + Animal.update_forward_refs() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py index 79eece679cda..caea52cba72c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py @@ -38,7 +38,7 @@ class AnyOfColor(BaseModel): if TYPE_CHECKING: actual_instance: Union[List[int], str] else: - actual_instance: Any + actual_instance: Any = None any_of_schemas: List[str] = Field(ANYOFCOLOR_ANY_OF_SCHEMAS, const=True) """Pydantic configuration""" @@ -52,8 +52,10 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) @validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_pig.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_pig.py index 30274e51269a..4e9c82be45a0 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_pig.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_pig.py @@ -38,7 +38,7 @@ class AnyOfPig(BaseModel): if TYPE_CHECKING: actual_instance: Union[BasquePig, DanishPig] else: - actual_instance: Any + actual_instance: Any = None any_of_schemas: List[str] = Field(ANYOFPIG_ANY_OF_SCHEMAS, const=True) """Pydantic configuration""" @@ -52,25 +52,27 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) @validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): instance = AnyOfPig.construct() error_messages = [] # validate data type: BasquePig - if not isinstance(v, BasquePig): - error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`") - else: + try: + instance.anyof_schema_1_validator = v return v - + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) # validate data type: DanishPig - if not isinstance(v, DanishPig): - error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`") - else: + try: + instance.anyof_schema_2_validator = v return v - + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) if error_messages: # no match raise ValueError("No match found when setting the actual_instance in AnyOfPig with anyOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/api_response.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/api_response.py index 4f5cc095e3c2..06390e75553d 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/api_response.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/api_response.py @@ -28,7 +28,6 @@ class ApiResponse(BaseModel): code: Optional[StrictInt] = None type: Optional[StrictStr] = None message: Optional[StrictStr] = None - __properties = ["code", "type", "message"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_model.py index bd23f1c16cf1..41c59d217328 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_model.py @@ -27,7 +27,6 @@ class ArrayOfArrayOfModel(BaseModel): ArrayOfArrayOfModel """ another_property: Optional[conlist(conlist(Tag))] = None - __properties = ["another_property"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_number_only.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_number_only.py index eef48c4f0693..577adbce5977 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_number_only.py @@ -26,7 +26,6 @@ class ArrayOfArrayOfNumberOnly(BaseModel): ArrayOfArrayOfNumberOnly """ array_array_number: Optional[conlist(conlist(float))] = Field(None, alias="ArrayArrayNumber") - __properties = ["ArrayArrayNumber"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_number_only.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_number_only.py index 549faf416bd4..d6f875262a7a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_number_only.py @@ -26,7 +26,6 @@ class ArrayOfNumberOnly(BaseModel): ArrayOfNumberOnly """ array_number: Optional[conlist(float)] = Field(None, alias="ArrayNumber") - __properties = ["ArrayNumber"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_test.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_test.py index 24faffd03434..6d5fb16e27ec 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_test.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_test.py @@ -29,7 +29,6 @@ class ArrayTest(BaseModel): array_of_string: Optional[conlist(StrictStr, max_items=3, min_items=0)] = None array_array_of_integer: Optional[conlist(conlist(StrictInt))] = None array_array_of_model: Optional[conlist(conlist(ReadOnlyFirst))] = None - __properties = ["array_of_string", "array_array_of_integer", "array_array_of_model"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/basque_pig.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/basque_pig.py index c54cec9359da..eb77a0d1bf2f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/basque_pig.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/basque_pig.py @@ -27,7 +27,6 @@ class BasquePig(BaseModel): """ class_name: StrictStr = Field(..., alias="className") color: StrictStr = Field(...) - __properties = ["className", "color"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/capitalization.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/capitalization.py index 72c4d2e044e6..a11f804271f0 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/capitalization.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/capitalization.py @@ -31,7 +31,6 @@ class Capitalization(BaseModel): capital_snake: Optional[StrictStr] = Field(None, alias="Capital_Snake") sca_eth_flow_points: Optional[StrictStr] = Field(None, alias="SCA_ETH_Flow_Points") att_name: Optional[StrictStr] = Field(None, alias="ATT_NAME", description="Name of the pet ") - __properties = ["smallCamel", "CapitalCamel", "small_Snake", "Capital_Snake", "SCA_ETH_Flow_Points", "ATT_NAME"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/cat.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/cat.py index 096693b202e7..5a8fbfe3b7c9 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/cat.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/cat.py @@ -27,7 +27,6 @@ class Cat(Animal): Cat """ declawed: Optional[StrictBool] = None - __properties = ["className", "color", "declawed"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/category.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/category.py index 2fd4312fad55..1dada60fef2d 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/category.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/category.py @@ -27,7 +27,6 @@ class Category(BaseModel): """ id: Optional[StrictInt] = None name: StrictStr = Field(...) - __properties = ["id", "name"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_reference_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_reference_model.py index e427ea092423..756c7b4b75c8 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_reference_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_reference_model.py @@ -27,7 +27,6 @@ class CircularReferenceModel(BaseModel): """ size: Optional[StrictInt] = None nested: Optional[FirstRef] = None - __properties = ["size", "nested"] """Pydantic configuration""" class Config: @@ -74,5 +73,8 @@ def from_dict(cls, obj: dict) -> CircularReferenceModel: return _obj from petstore_api.models.first_ref import FirstRef -CircularReferenceModel.update_forward_refs() +try: + CircularReferenceModel.update_forward_refs() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/class_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/class_model.py index ab7646983d9e..09d78f1f57a6 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/class_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/class_model.py @@ -26,7 +26,6 @@ class ClassModel(BaseModel): Model for testing model with \"_class\" property # noqa: E501 """ var_class: Optional[StrictStr] = Field(None, alias="_class") - __properties = ["_class"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/client.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/client.py index dea9123d8623..ca12ada42718 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/client.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/client.py @@ -26,7 +26,6 @@ class Client(BaseModel): Client """ client: Optional[StrictStr] = None - __properties = ["client"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py index 574093092a01..51a35dba4d8f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py @@ -35,9 +35,9 @@ class Color(BaseModel): # data type: str oneof_schema_3_validator: Optional[constr(strict=True, max_length=7, min_length=7)] = Field(None, description="Hex color string, such as #00FF00.") if TYPE_CHECKING: - actual_instance: Union[List[int], str] + actual_instance: Union[List[int], str, None] else: - actual_instance: Any + actual_instance: Any = None one_of_schemas: List[str] = Field(COLOR_ONE_OF_SCHEMAS, const=True) @@ -52,8 +52,10 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) @validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): @@ -83,6 +85,8 @@ def actual_instance_must_validate_oneof(cls, v): error_messages.append(str(e)) if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when setting `actual_instance` in Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -134,6 +138,8 @@ def from_json(cls, json_str: str) -> Color: if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) elif match == 0: # no match diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature.py index 2567fa7565f9..c78ad2c7c6b3 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature.py @@ -28,7 +28,6 @@ class Creature(BaseModel): """ info: CreatureInfo = Field(...) type: StrictStr = Field(...) - __properties = ["info", "type"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature_info.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature_info.py index f287fb975013..b1912ef4b349 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature_info.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature_info.py @@ -26,7 +26,6 @@ class CreatureInfo(BaseModel): CreatureInfo """ name: StrictStr = Field(...) - __properties = ["name"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/danish_pig.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/danish_pig.py index 47321e4adb15..1d47bd5743bd 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/danish_pig.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/danish_pig.py @@ -27,7 +27,6 @@ class DanishPig(BaseModel): """ class_name: StrictStr = Field(..., alias="className") size: StrictInt = Field(...) - __properties = ["className", "size"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/deprecated_object.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/deprecated_object.py index 0615eb18e66a..8b353fd78315 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/deprecated_object.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/deprecated_object.py @@ -26,7 +26,6 @@ class DeprecatedObject(BaseModel): DeprecatedObject """ name: Optional[StrictStr] = None - __properties = ["name"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dog.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dog.py index 2b35e739c1a0..cdff19ea158c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dog.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dog.py @@ -27,7 +27,6 @@ class Dog(Animal): Dog """ breed: Optional[StrictStr] = None - __properties = ["className", "color", "breed"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dummy_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dummy_model.py index 8b0242b6cf16..4606066ae8db 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dummy_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/dummy_model.py @@ -27,7 +27,6 @@ class DummyModel(BaseModel): """ category: Optional[StrictStr] = None self_ref: Optional[SelfReferenceModel] = None - __properties = ["category", "self_ref"] """Pydantic configuration""" class Config: @@ -74,5 +73,8 @@ def from_dict(cls, obj: dict) -> DummyModel: return _obj from petstore_api.models.self_reference_model import SelfReferenceModel -DummyModel.update_forward_refs() +try: + DummyModel.update_forward_refs() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_arrays.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_arrays.py index 445292b697e4..74ad7ea852aa 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_arrays.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_arrays.py @@ -27,7 +27,6 @@ class EnumArrays(BaseModel): """ just_symbol: Optional[StrictStr] = None array_enum: Optional[conlist(StrictStr)] = None - __properties = ["just_symbol", "array_enum"] @validator('just_symbol') def just_symbol_validate_enum(cls, value): diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py index c8caa42c35de..51594616b428 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py @@ -38,7 +38,6 @@ class EnumTest(BaseModel): outer_enum_integer: Optional[OuterEnumInteger] = Field(None, alias="outerEnumInteger") outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(None, alias="outerEnumDefaultValue") outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(None, alias="outerEnumIntegerDefaultValue") - __properties = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] @validator('enum_string') def enum_string_validate_enum(cls, value): diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file.py index 8e7dd176489e..090919169161 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file.py @@ -26,7 +26,6 @@ class File(BaseModel): Must be named `File` for test. # noqa: E501 """ source_uri: Optional[StrictStr] = Field(None, alias="sourceURI", description="Test capitalization") - __properties = ["sourceURI"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file_schema_test_class.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file_schema_test_class.py index a4d41a8cd7d6..71b070ba2d93 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file_schema_test_class.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file_schema_test_class.py @@ -28,7 +28,6 @@ class FileSchemaTestClass(BaseModel): """ file: Optional[File] = None files: Optional[conlist(File)] = None - __properties = ["file", "files"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/first_ref.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/first_ref.py index 80663edce859..3051d7a2ab36 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/first_ref.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/first_ref.py @@ -27,7 +27,6 @@ class FirstRef(BaseModel): """ category: Optional[StrictStr] = None self_ref: Optional[SecondRef] = None - __properties = ["category", "self_ref"] """Pydantic configuration""" class Config: @@ -74,5 +73,8 @@ def from_dict(cls, obj: dict) -> FirstRef: return _obj from petstore_api.models.second_ref import SecondRef -FirstRef.update_forward_refs() +try: + FirstRef.update_forward_refs() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo.py index 44d47be8e6ef..ce6292936a41 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo.py @@ -26,7 +26,6 @@ class Foo(BaseModel): Foo """ bar: Optional[StrictStr] = 'bar' - __properties = ["bar"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo_get_default_response.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo_get_default_response.py index 67548a902f31..119ec5bcc79d 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo_get_default_response.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/foo_get_default_response.py @@ -27,7 +27,6 @@ class FooGetDefaultResponse(BaseModel): FooGetDefaultResponse """ string: Optional[Foo] = None - __properties = ["string"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/format_test.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/format_test.py index 139dbeeed32b..9f9a69d28848 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/format_test.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/format_test.py @@ -42,7 +42,6 @@ class FormatTest(BaseModel): password: constr(strict=True, max_length=64, min_length=10) = Field(...) pattern_with_digits: Optional[constr(strict=True)] = Field(None, description="A string that is a 10 digit number. Can have leading zeros.") pattern_with_digits_and_delimiter: Optional[constr(strict=True)] = Field(None, description="A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01.") - __properties = ["integer", "int32", "int64", "number", "float", "double", "decimal", "string", "string_with_double_quote_pattern", "byte", "binary", "date", "dateTime", "uuid", "password", "pattern_with_digits", "pattern_with_digits_and_delimiter"] @validator('string') def string_validate_regular_expression(cls, value): diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/has_only_read_only.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/has_only_read_only.py index cfacff0a12ab..cc452361cf24 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/has_only_read_only.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/has_only_read_only.py @@ -27,7 +27,6 @@ class HasOnlyReadOnly(BaseModel): """ bar: Optional[StrictStr] = None foo: Optional[StrictStr] = None - __properties = ["bar", "foo"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/health_check_result.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/health_check_result.py index 4fadb6f6caa6..5a43814a8f0e 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/health_check_result.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/health_check_result.py @@ -26,7 +26,6 @@ class HealthCheckResult(BaseModel): Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. # noqa: E501 """ nullable_message: Optional[StrictStr] = Field(None, alias="NullableMessage") - __properties = ["NullableMessage"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/inner_dict_with_property.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/inner_dict_with_property.py index 3576f85dde55..8803c2a8c3ae 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/inner_dict_with_property.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/inner_dict_with_property.py @@ -26,7 +26,6 @@ class InnerDictWithProperty(BaseModel): InnerDictWithProperty """ a_property: Optional[Dict[str, Any]] = Field(None, alias="aProperty") - __properties = ["aProperty"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/int_or_string.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/int_or_string.py index 574c73549525..3af97701905d 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/int_or_string.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/int_or_string.py @@ -35,7 +35,7 @@ class IntOrString(BaseModel): if TYPE_CHECKING: actual_instance: Union[int, str] else: - actual_instance: Any + actual_instance: Any = None one_of_schemas: List[str] = Field(INTORSTRING_ONE_OF_SCHEMAS, const=True) @@ -50,8 +50,10 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) @validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): @@ -72,6 +74,8 @@ def actual_instance_must_validate_oneof(cls, v): error_messages.append(str(e)) if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when setting `actual_instance` in IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -111,6 +115,8 @@ def from_json(cls, json_str: str) -> IntOrString: if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when deserializing the JSON string into IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) elif match == 0: # no match diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/list.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/list.py index e77c678ec09e..c716e9c2ec83 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/list.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/list.py @@ -26,7 +26,6 @@ class List(BaseModel): List """ var_123_list: Optional[StrictStr] = Field(None, alias="123-list") - __properties = ["123-list"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py index 4ca8b1aadd04..23fd1ab8a604 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py @@ -27,7 +27,6 @@ class MapOfArrayOfModel(BaseModel): MapOfArrayOfModel """ shop_id_to_org_online_lip_map: Optional[Dict[str, conlist(Tag)]] = Field(None, alias="shopIdToOrgOnlineLipMap") - __properties = ["shopIdToOrgOnlineLipMap"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_test.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_test.py index c11ef8376458..d8da08ff112e 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_test.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_test.py @@ -29,7 +29,6 @@ class MapTest(BaseModel): map_of_enum_string: Optional[Dict[str, StrictStr]] = None direct_map: Optional[Dict[str, StrictBool]] = None indirect_map: Optional[Dict[str, StrictBool]] = None - __properties = ["map_map_of_string", "map_of_enum_string", "direct_map", "indirect_map"] @validator('map_of_enum_string') def map_of_enum_string_validate_enum(cls, value): diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py index 92d55f68bbe7..bcab08dd6dc4 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -29,7 +29,6 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): uuid: Optional[StrictStr] = None date_time: Optional[datetime] = Field(None, alias="dateTime") map: Optional[Dict[str, Animal]] = None - __properties = ["uuid", "dateTime", "map"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model200_response.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model200_response.py index 581bfcd15fe0..6207031536dc 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model200_response.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model200_response.py @@ -27,7 +27,6 @@ class Model200Response(BaseModel): """ name: Optional[StrictInt] = None var_class: Optional[StrictStr] = Field(None, alias="class") - __properties = ["name", "class"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_return.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_return.py index cc9d76d869e6..3053e8058985 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_return.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_return.py @@ -26,7 +26,6 @@ class ModelReturn(BaseModel): Model for testing reserved words # noqa: E501 """ var_return: Optional[StrictInt] = Field(None, alias="return") - __properties = ["return"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/name.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/name.py index f0c88a09eee2..42d90a40429f 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/name.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/name.py @@ -29,7 +29,6 @@ class Name(BaseModel): snake_case: Optional[StrictInt] = None var_property: Optional[StrictStr] = Field(None, alias="property") var_123_number: Optional[StrictInt] = Field(None, alias="123Number") - __properties = ["name", "snake_case", "property", "123Number"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_class.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_class.py index f960d26b6611..f33eca4dd301 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_class.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_class.py @@ -39,7 +39,6 @@ class NullableClass(BaseModel): object_and_items_nullable_prop: Optional[Dict[str, Dict[str, Any]]] = None object_items_nullable: Optional[Dict[str, Dict[str, Any]]] = None additional_properties: Dict[str, Any] = {} - __properties = ["required_integer_prop", "integer_prop", "number_prop", "boolean_prop", "string_prop", "date_prop", "datetime_prop", "array_nullable_prop", "array_and_items_nullable_prop", "array_items_nullable", "object_nullable_prop", "object_and_items_nullable_prop", "object_items_nullable"] """Pydantic configuration""" class Config: @@ -154,7 +153,7 @@ def from_dict(cls, obj: dict) -> NullableClass: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["required_integer_prop", "integer_prop", "number_prop", "boolean_prop", "string_prop", "date_prop", "datetime_prop", "array_nullable_prop", "array_and_items_nullable_prop", "array_items_nullable", "object_nullable_prop", "object_and_items_nullable_prop", "object_items_nullable"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_property.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_property.py index 616e4002fafa..2016915e288c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_property.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/nullable_property.py @@ -27,7 +27,6 @@ class NullableProperty(BaseModel): """ id: StrictInt = Field(...) name: Optional[constr(strict=True)] = Field(...) - __properties = ["id", "name"] @validator('name') def name_validate_regular_expression(cls, value): diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/number_only.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/number_only.py index 3092648bbca2..d509fdc7eee5 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/number_only.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/number_only.py @@ -26,7 +26,6 @@ class NumberOnly(BaseModel): NumberOnly """ just_number: Optional[float] = Field(None, alias="JustNumber") - __properties = ["JustNumber"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_to_test_additional_properties.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_to_test_additional_properties.py index 55fa9ad5da1c..98ef3c80b86c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_to_test_additional_properties.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_to_test_additional_properties.py @@ -26,7 +26,6 @@ class ObjectToTestAdditionalProperties(BaseModel): Minimal object # noqa: E501 """ var_property: Optional[StrictBool] = Field(False, alias="property", description="Property") - __properties = ["property"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_with_deprecated_fields.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_with_deprecated_fields.py index 653e292cf06a..492393b9cb4e 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_with_deprecated_fields.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/object_with_deprecated_fields.py @@ -30,7 +30,6 @@ class ObjectWithDeprecatedFields(BaseModel): id: Optional[float] = None deprecated_ref: Optional[DeprecatedObject] = Field(None, alias="deprecatedRef") bars: Optional[conlist(StrictStr)] = None - __properties = ["uuid", "id", "deprecatedRef", "bars"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/one_of_enum_string.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/one_of_enum_string.py index f4b18189e6f9..a781e3febe0a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/one_of_enum_string.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/one_of_enum_string.py @@ -37,7 +37,7 @@ class OneOfEnumString(BaseModel): if TYPE_CHECKING: actual_instance: Union[EnumString1, EnumString2] else: - actual_instance: Any + actual_instance: Any = None one_of_schemas: List[str] = Field(ONEOFENUMSTRING_ONE_OF_SCHEMAS, const=True) @@ -52,8 +52,10 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) @validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): @@ -61,17 +63,21 @@ def actual_instance_must_validate_oneof(cls, v): error_messages = [] match = 0 # validate data type: EnumString1 - if not isinstance(v, EnumString1): - error_messages.append(f"Error! Input type `{type(v)}` is not `EnumString1`") - else: + try: + instance.oneof_schema_1_validator = v match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) # validate data type: EnumString2 - if not isinstance(v, EnumString2): - error_messages.append(f"Error! Input type `{type(v)}` is not `EnumString2`") - else: + try: + instance.oneof_schema_2_validator = v match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when setting `actual_instance` in OneOfEnumString with oneOf schemas: EnumString1, EnumString2. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -105,6 +111,8 @@ def from_json(cls, json_str: str) -> OneOfEnumString: if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when deserializing the JSON string into OneOfEnumString with oneOf schemas: EnumString1, EnumString2. Details: " + ", ".join(error_messages)) elif match == 0: # no match diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/order.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/order.py index 510d0eac306a..d0e9f89d3379 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/order.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/order.py @@ -31,7 +31,6 @@ class Order(BaseModel): ship_date: Optional[datetime] = Field(None, alias="shipDate") status: Optional[StrictStr] = Field(None, description="Order Status") complete: Optional[StrictBool] = False - __properties = ["id", "petId", "quantity", "shipDate", "status", "complete"] @validator('status') def status_validate_enum(cls, value): diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_composite.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_composite.py index 1b6f4f5cb35d..6da5e274f77d 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_composite.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_composite.py @@ -28,7 +28,6 @@ class OuterComposite(BaseModel): my_number: Optional[float] = None my_string: Optional[StrictStr] = None my_boolean: Optional[StrictBool] = None - __properties = ["my_number", "my_string", "my_boolean"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_object_with_enum_property.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_object_with_enum_property.py index 58959f5b17bb..bc4d1e167346 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_object_with_enum_property.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/outer_object_with_enum_property.py @@ -29,7 +29,6 @@ class OuterObjectWithEnumProperty(BaseModel): """ str_value: Optional[OuterEnum] = None value: OuterEnumInteger = Field(...) - __properties = ["str_value", "value"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent.py index cc52de56a3c0..7ba4aab407e8 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent.py @@ -27,7 +27,6 @@ class Parent(BaseModel): Parent """ optional_dict: Optional[Dict[str, InnerDictWithProperty]] = Field(None, alias="optionalDict") - __properties = ["optionalDict"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent_with_optional_dict.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent_with_optional_dict.py index b910f83b8eae..999440310049 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent_with_optional_dict.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent_with_optional_dict.py @@ -27,7 +27,6 @@ class ParentWithOptionalDict(BaseModel): ParentWithOptionalDict """ optional_dict: Optional[Dict[str, InnerDictWithProperty]] = Field(None, alias="optionalDict") - __properties = ["optionalDict"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pet.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pet.py index 06e8bc38ccc4..c483bc8941a8 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pet.py @@ -33,7 +33,6 @@ class Pet(BaseModel): photo_urls: conlist(StrictStr, min_items=0, unique_items=True) = Field(..., alias="photoUrls") tags: Optional[conlist(Tag)] = None status: Optional[StrictStr] = Field(None, description="pet status in the store") - __properties = ["id", "category", "name", "photoUrls", "tags", "status"] @validator('status') def status_validate_enum(cls, value): diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pig.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pig.py index 8d6478cb2cc5..42a3b40ccff3 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pig.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pig.py @@ -37,7 +37,7 @@ class Pig(BaseModel): if TYPE_CHECKING: actual_instance: Union[BasquePig, DanishPig] else: - actual_instance: Any + actual_instance: Any = None one_of_schemas: List[str] = Field(PIG_ONE_OF_SCHEMAS, const=True) @@ -45,9 +45,6 @@ class Pig(BaseModel): class Config: validate_assignment = True - discriminator_value_class_map = { - } - def __init__(self, *args, **kwargs) -> None: if args: if len(args) > 1: @@ -55,8 +52,10 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) @validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): @@ -64,17 +63,21 @@ def actual_instance_must_validate_oneof(cls, v): error_messages = [] match = 0 # validate data type: BasquePig - if not isinstance(v, BasquePig): - error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`") - else: + try: + instance.oneof_schema_1_validator = v match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) # validate data type: DanishPig - if not isinstance(v, DanishPig): - error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`") - else: + try: + instance.oneof_schema_2_validator = v match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when setting `actual_instance` in Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -108,6 +111,8 @@ def from_json(cls, json_str: str) -> Pig: if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when deserializing the JSON string into Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) elif match == 0: # no match diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_name_collision.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_name_collision.py index c6118a2fabd9..2c1bfa49906a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_name_collision.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_name_collision.py @@ -28,7 +28,6 @@ class PropertyNameCollision(BaseModel): type: Optional[StrictStr] = Field(None, alias="_type") type: Optional[StrictStr] = None type_: Optional[StrictStr] = None - __properties = ["_type", "type", "type_"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/read_only_first.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/read_only_first.py index 892f302f304e..d9ee0ffd4f38 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/read_only_first.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/read_only_first.py @@ -27,7 +27,6 @@ class ReadOnlyFirst(BaseModel): """ bar: Optional[StrictStr] = None baz: Optional[StrictStr] = None - __properties = ["bar", "baz"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_ref.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_ref.py index 51d6b5980c0b..dbba9dabdf9c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_ref.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_ref.py @@ -27,7 +27,6 @@ class SecondRef(BaseModel): """ category: Optional[StrictStr] = None circular_ref: Optional[CircularReferenceModel] = None - __properties = ["category", "circular_ref"] """Pydantic configuration""" class Config: @@ -74,5 +73,8 @@ def from_dict(cls, obj: dict) -> SecondRef: return _obj from petstore_api.models.circular_reference_model import CircularReferenceModel -SecondRef.update_forward_refs() +try: + SecondRef.update_forward_refs() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/self_reference_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/self_reference_model.py index c1a61f7ea998..a837177d235c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/self_reference_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/self_reference_model.py @@ -27,7 +27,6 @@ class SelfReferenceModel(BaseModel): """ size: Optional[StrictInt] = None nested: Optional[DummyModel] = None - __properties = ["size", "nested"] """Pydantic configuration""" class Config: @@ -74,5 +73,8 @@ def from_dict(cls, obj: dict) -> SelfReferenceModel: return _obj from petstore_api.models.dummy_model import DummyModel -SelfReferenceModel.update_forward_refs() +try: + SelfReferenceModel.update_forward_refs() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_model_name.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_model_name.py index d847e05341bd..bf89e1de2bd3 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_model_name.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_model_name.py @@ -26,7 +26,6 @@ class SpecialModelName(BaseModel): SpecialModelName """ special_property_name: Optional[StrictInt] = Field(None, alias="$special[property.name]") - __properties = ["$special[property.name]"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_name.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_name.py index 886252dde6ff..861203d85248 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_name.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/special_name.py @@ -29,7 +29,6 @@ class SpecialName(BaseModel): var_property: Optional[StrictInt] = Field(None, alias="property") var_async: Optional[Category] = Field(None, alias="async") var_schema: Optional[StrictStr] = Field(None, alias="schema", description="pet status in the store") - __properties = ["property", "async", "schema"] @validator('var_schema') def var_schema_validate_enum(cls, value): diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tag.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tag.py index a593806f058c..fabeeabfb98b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tag.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tag.py @@ -27,7 +27,6 @@ class Tag(BaseModel): """ id: Optional[StrictInt] = None name: Optional[StrictStr] = None - __properties = ["id", "name"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tiger.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tiger.py index bf1111c222bc..aad2230b6d15 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tiger.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/tiger.py @@ -26,7 +26,6 @@ class Tiger(BaseModel): Tiger """ skill: Optional[StrictStr] = None - __properties = ["skill"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/user.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/user.py index 3f04a229ede9..e424b4199ceb 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/user.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/user.py @@ -33,7 +33,6 @@ class User(BaseModel): password: Optional[StrictStr] = None phone: Optional[StrictStr] = None user_status: Optional[StrictInt] = Field(None, alias="userStatus", description="User Status") - __properties = ["id", "username", "firstName", "lastName", "email", "password", "phone", "userStatus"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/with_nested_one_of.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/with_nested_one_of.py index 9af30656878d..f25eb079ff67 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/with_nested_one_of.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/with_nested_one_of.py @@ -30,7 +30,6 @@ class WithNestedOneOf(BaseModel): size: Optional[StrictInt] = None nested_pig: Optional[Pig] = None nested_oneof_enum_string: Optional[OneOfEnumString] = None - __properties = ["size", "nested_pig", "nested_oneof_enum_string"] """Pydantic configuration""" class Config: diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-pydantic-v2/.openapi-generator/FILES index 6aacf0a81498..ed3c7e10e796 100755 --- a/samples/openapi3/client/petstore/python-pydantic-v2/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-pydantic-v2/.openapi-generator/FILES @@ -21,6 +21,7 @@ docs/BasquePig.md docs/Capitalization.md docs/Cat.md docs/Category.md +docs/CircularReferenceModel.md docs/ClassModel.md docs/Client.md docs/Color.md @@ -40,6 +41,7 @@ docs/FakeApi.md docs/FakeClassnameTags123Api.md docs/File.md docs/FileSchemaTestClass.md +docs/FirstRef.md docs/Foo.md docs/FooGetDefaultResponse.md docs/FormatTest.md @@ -74,6 +76,7 @@ docs/PetApi.md docs/Pig.md docs/PropertyNameCollision.md docs/ReadOnlyFirst.md +docs/SecondRef.md docs/SelfReferenceModel.md docs/SingleRefType.md docs/SpecialCharacterEnum.md @@ -117,6 +120,7 @@ petstore_api/models/basque_pig.py petstore_api/models/capitalization.py petstore_api/models/cat.py petstore_api/models/category.py +petstore_api/models/circular_reference_model.py petstore_api/models/class_model.py petstore_api/models/client.py petstore_api/models/color.py @@ -133,6 +137,7 @@ petstore_api/models/enum_string2.py petstore_api/models/enum_test.py petstore_api/models/file.py petstore_api/models/file_schema_test_class.py +petstore_api/models/first_ref.py petstore_api/models/foo.py petstore_api/models/foo_get_default_response.py petstore_api/models/format_test.py @@ -166,6 +171,7 @@ petstore_api/models/pet.py petstore_api/models/pig.py petstore_api/models/property_name_collision.py petstore_api/models/read_only_first.py +petstore_api/models/second_ref.py petstore_api/models/self_reference_model.py petstore_api/models/single_ref_type.py petstore_api/models/special_character_enum.py @@ -184,3 +190,6 @@ setup.cfg setup.py test-requirements.txt test/__init__.py +test/test_circular_reference_model.py +test/test_first_ref.py +test/test_second_ref.py diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/README.md b/samples/openapi3/client/petstore/python-pydantic-v2/README.md index 044c74065b1c..7882186348d2 100755 --- a/samples/openapi3/client/petstore/python-pydantic-v2/README.md +++ b/samples/openapi3/client/petstore/python-pydantic-v2/README.md @@ -151,6 +151,7 @@ Class | Method | HTTP request | Description - [Capitalization](docs/Capitalization.md) - [Cat](docs/Cat.md) - [Category](docs/Category.md) + - [CircularReferenceModel](docs/CircularReferenceModel.md) - [ClassModel](docs/ClassModel.md) - [Client](docs/Client.md) - [Color](docs/Color.md) @@ -167,6 +168,7 @@ Class | Method | HTTP request | Description - [EnumTest](docs/EnumTest.md) - [File](docs/File.md) - [FileSchemaTestClass](docs/FileSchemaTestClass.md) + - [FirstRef](docs/FirstRef.md) - [Foo](docs/Foo.md) - [FooGetDefaultResponse](docs/FooGetDefaultResponse.md) - [FormatTest](docs/FormatTest.md) @@ -200,6 +202,7 @@ Class | Method | HTTP request | Description - [Pig](docs/Pig.md) - [PropertyNameCollision](docs/PropertyNameCollision.md) - [ReadOnlyFirst](docs/ReadOnlyFirst.md) + - [SecondRef](docs/SecondRef.md) - [SelfReferenceModel](docs/SelfReferenceModel.md) - [SingleRefType](docs/SingleRefType.md) - [SpecialCharacterEnum](docs/SpecialCharacterEnum.md) diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/__init__.py index 2fb3745aeaa2..9803f5297120 100755 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/__init__.py @@ -55,6 +55,7 @@ from petstore_api.models.capitalization import Capitalization from petstore_api.models.cat import Cat from petstore_api.models.category import Category +from petstore_api.models.circular_reference_model import CircularReferenceModel from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client from petstore_api.models.color import Color @@ -71,6 +72,7 @@ from petstore_api.models.enum_test import EnumTest from petstore_api.models.file import File from petstore_api.models.file_schema_test_class import FileSchemaTestClass +from petstore_api.models.first_ref import FirstRef from petstore_api.models.foo import Foo from petstore_api.models.foo_get_default_response import FooGetDefaultResponse from petstore_api.models.format_test import FormatTest @@ -104,6 +106,7 @@ from petstore_api.models.pig import Pig from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst +from petstore_api.models.second_ref import SecondRef from petstore_api.models.self_reference_model import SelfReferenceModel from petstore_api.models.single_ref_type import SingleRefType from petstore_api.models.special_character_enum import SpecialCharacterEnum diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/api/fake_api.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/api/fake_api.py index 71ce52841e8d..7d93f9879e83 100755 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/api/fake_api.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/api/fake_api.py @@ -22,7 +22,7 @@ from typing_extensions import Annotated from datetime import date, datetime -from pydantic import Field, StrictBool, StrictBytes, StrictFloat, StrictInt, StrictStr, conbytes, confloat, conint, conlist, constr, validator +from pydantic import Field, StrictBool, StrictBytes, StrictFloat, StrictInt, StrictStr, conbytes, confloat, conint, conlist, constr, field_validator from typing import Any, Dict, List, Optional, Union diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/api/pet_api.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/api/pet_api.py index 979aaa65a244..af7737f4e7be 100755 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/api/pet_api.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/api/pet_api.py @@ -20,7 +20,7 @@ from typing_extensions import Annotated from typing_extensions import Annotated -from pydantic import Field, StrictBytes, StrictInt, StrictStr, conlist, validator +from pydantic import Field, StrictBytes, StrictInt, StrictStr, conlist, field_validator from typing import List, Optional, Union diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/__init__.py index b3a4d362afc6..5e4468e4b56f 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/__init__.py @@ -31,6 +31,7 @@ from petstore_api.models.capitalization import Capitalization from petstore_api.models.cat import Cat from petstore_api.models.category import Category +from petstore_api.models.circular_reference_model import CircularReferenceModel from petstore_api.models.class_model import ClassModel from petstore_api.models.client import Client from petstore_api.models.color import Color @@ -47,6 +48,7 @@ from petstore_api.models.enum_test import EnumTest from petstore_api.models.file import File from petstore_api.models.file_schema_test_class import FileSchemaTestClass +from petstore_api.models.first_ref import FirstRef from petstore_api.models.foo import Foo from petstore_api.models.foo_get_default_response import FooGetDefaultResponse from petstore_api.models.format_test import FormatTest @@ -80,6 +82,7 @@ from petstore_api.models.pig import Pig from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst +from petstore_api.models.second_ref import SecondRef from petstore_api.models.self_reference_model import SelfReferenceModel from petstore_api.models.single_ref_type import SingleRefType from petstore_api.models.special_character_enum import SpecialCharacterEnum diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_any_type.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_any_type.py index 22dda9cd1174..eaef63eba2c5 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_any_type.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_any_type.py @@ -27,7 +27,6 @@ class AdditionalPropertiesAnyType(BaseModel): """ name: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["name"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class AdditionalPropertiesAnyType(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> AdditionalPropertiesAnyType: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> AdditionalPropertiesAnyType: return None if not isinstance(obj, dict): - return AdditionalPropertiesAnyType.parse_obj(obj) + return AdditionalPropertiesAnyType.model_validate(obj) - _obj = AdditionalPropertiesAnyType.parse_obj({ + _obj = AdditionalPropertiesAnyType.model_validate({ "name": obj.get("name") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_class.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_class.py index 77a275f8dd31..fc66331a3d53 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_class.py @@ -28,7 +28,6 @@ class AdditionalPropertiesClass(BaseModel): map_property: Optional[Dict[str, StrictStr]] = None map_of_map_property: Optional[Dict[str, Dict[str, StrictStr]]] = None additional_properties: Dict[str, Any] = {} - __properties = ["map_property", "map_of_map_property"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class AdditionalPropertiesClass(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> AdditionalPropertiesClass: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -70,15 +69,15 @@ def from_dict(cls, obj: dict) -> AdditionalPropertiesClass: return None if not isinstance(obj, dict): - return AdditionalPropertiesClass.parse_obj(obj) + return AdditionalPropertiesClass.model_validate(obj) - _obj = AdditionalPropertiesClass.parse_obj({ + _obj = AdditionalPropertiesClass.model_validate({ "map_property": obj.get("map_property"), "map_of_map_property": obj.get("map_of_map_property") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["map_property", "map_of_map_property"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_object.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_object.py index 7254315fc50e..ffd84283a415 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_object.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_object.py @@ -27,7 +27,6 @@ class AdditionalPropertiesObject(BaseModel): """ name: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["name"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class AdditionalPropertiesObject(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> AdditionalPropertiesObject: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> AdditionalPropertiesObject: return None if not isinstance(obj, dict): - return AdditionalPropertiesObject.parse_obj(obj) + return AdditionalPropertiesObject.model_validate(obj) - _obj = AdditionalPropertiesObject.parse_obj({ + _obj = AdditionalPropertiesObject.model_validate({ "name": obj.get("name") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_with_description_only.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_with_description_only.py index 59219a93c349..bb3ab9abc249 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_with_description_only.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/additional_properties_with_description_only.py @@ -27,7 +27,6 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel): """ name: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["name"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> AdditionalPropertiesWithDescriptionOnly: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> AdditionalPropertiesWithDescriptionOnly: return None if not isinstance(obj, dict): - return AdditionalPropertiesWithDescriptionOnly.parse_obj(obj) + return AdditionalPropertiesWithDescriptionOnly.model_validate(obj) - _obj = AdditionalPropertiesWithDescriptionOnly.parse_obj({ + _obj = AdditionalPropertiesWithDescriptionOnly.model_validate({ "name": obj.get("name") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/all_of_with_single_ref.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/all_of_with_single_ref.py index 34eada9a625f..875eb7bf8237 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/all_of_with_single_ref.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/all_of_with_single_ref.py @@ -29,7 +29,6 @@ class AllOfWithSingleRef(BaseModel): username: Optional[StrictStr] = None single_ref_type: Optional[SingleRefType] = Field(None, alias="SingleRefType") additional_properties: Dict[str, Any] = {} - __properties = ["username", "SingleRefType"] """Pydantic configuration""" model_config = { @@ -39,7 +38,7 @@ class AllOfWithSingleRef(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -52,7 +51,7 @@ def from_json(cls, json_str: str) -> AllOfWithSingleRef: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -71,15 +70,15 @@ def from_dict(cls, obj: dict) -> AllOfWithSingleRef: return None if not isinstance(obj, dict): - return AllOfWithSingleRef.parse_obj(obj) + return AllOfWithSingleRef.model_validate(obj) - _obj = AllOfWithSingleRef.parse_obj({ + _obj = AllOfWithSingleRef.model_validate({ "username": obj.get("username"), "single_ref_type": obj.get("SingleRefType") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["username", "SingleRefType"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/animal.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/animal.py index 678dfe222968..fb469490a14c 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/animal.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/animal.py @@ -28,7 +28,6 @@ class Animal(BaseModel): class_name: StrictStr = Field(..., alias="className") color: Optional[StrictStr] = 'red' additional_properties: Dict[str, Any] = {} - __properties = ["className", "color"] """Pydantic configuration""" model_config = { @@ -37,26 +36,23 @@ class Animal(BaseModel): } # JSON field name that stores the object type - __discriminator_property_name = 'className' - - # discriminator mappings - __discriminator_value_class_map = { - 'Cat': 'Cat', - 'Dog': 'Dog' - } @classmethod def get_discriminator_value(cls, obj: dict) -> str: """Returns the discriminator value (object type) of the data""" - discriminator_value = obj[cls.__discriminator_property_name] + discriminator_value = obj['className'] + discriminator_value_class_map = { + 'Cat': 'Cat','Dog': 'Dog' + } + if discriminator_value: - return cls.__discriminator_value_class_map.get(discriminator_value) + return discriminator_value_class_map.get(discriminator_value) else: return None def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -69,7 +65,7 @@ def from_json(cls, json_str: str) -> Union(Cat, Dog): def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -86,15 +82,21 @@ def from_dict(cls, obj: dict) -> Union(Cat, Dog): """Create an instance of Animal from a dict""" # look up the object type based on discriminator mapping object_type = cls.get_discriminator_value(obj) + discriminator_value_class_map = { + 'Cat': 'Cat','Dog': 'Dog' + } if object_type: klass = globals()[object_type] return klass.from_dict(obj) else: raise ValueError("Animal failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) + json.dumps(obj) + ". Discriminator property name: " + 'className' + + ", mapping: " + json.dumps(discriminator_value_class_map)) from petstore_api.models.cat import Cat from petstore_api.models.dog import Dog -Animal.update_forward_refs() +try: + Animal.model_rebuild() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/any_of_color.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/any_of_color.py index e178a110e51a..476ff07df79b 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/any_of_color.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/any_of_color.py @@ -19,7 +19,7 @@ import re # noqa: F401 from typing import List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, conlist, constr, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, conlist, constr, field_validator from typing import Union, Any, List, TYPE_CHECKING try: from typing import Literal @@ -43,7 +43,7 @@ class AnyOfColor(BaseModel): if TYPE_CHECKING: actual_instance: Union[List[int], str] else: - actual_instance: Any + actual_instance: Any = None any_of_schemas: List[str] = Literal["List[int]", "str"] """Pydantic configuration""" @@ -58,12 +58,14 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): - instance = AnyOfColor.construct() + instance = AnyOfColor.model_construct() error_messages = [] # validate data type: List[int] try: @@ -96,7 +98,7 @@ def from_dict(cls, obj: dict) -> AnyOfColor: @classmethod def from_json(cls, json_str: str) -> AnyOfColor: """Returns the object represented by the json string""" - instance = AnyOfColor.construct() + instance = AnyOfColor.model_construct() error_messages = [] # deserialize data into List[int] try: @@ -156,6 +158,6 @@ def to_dict(self) -> dict: def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/any_of_pig.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/any_of_pig.py index 1f5c819e7dfd..4a033002e45f 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/any_of_pig.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/any_of_pig.py @@ -19,7 +19,7 @@ import re # noqa: F401 from typing import Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig from typing import Union, Any, List, TYPE_CHECKING @@ -43,7 +43,7 @@ class AnyOfPig(BaseModel): if TYPE_CHECKING: actual_instance: Union[BasquePig, DanishPig] else: - actual_instance: Any + actual_instance: Any = None any_of_schemas: List[str] = Literal["BasquePig", "DanishPig"] """Pydantic configuration""" @@ -58,25 +58,27 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): - instance = AnyOfPig.construct() + instance = AnyOfPig.model_construct() error_messages = [] # validate data type: BasquePig - if not isinstance(v, BasquePig): - error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`") - else: + try: + instance.anyof_schema_1_validator = v return v - + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) # validate data type: DanishPig - if not isinstance(v, DanishPig): - error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`") - else: + try: + instance.anyof_schema_2_validator = v return v - + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) if error_messages: # no match raise ValueError("No match found when setting the actual_instance in AnyOfPig with anyOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) @@ -90,7 +92,7 @@ def from_dict(cls, obj: dict) -> AnyOfPig: @classmethod def from_json(cls, json_str: str) -> AnyOfPig: """Returns the object represented by the json string""" - instance = AnyOfPig.construct() + instance = AnyOfPig.model_construct() error_messages = [] # anyof_schema_1_validator: Optional[BasquePig] = None try: @@ -135,6 +137,6 @@ def to_dict(self) -> dict: def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/api_response.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/api_response.py index 3c176c73e294..db939f2eac85 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/api_response.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/api_response.py @@ -29,7 +29,6 @@ class ApiResponse(BaseModel): type: Optional[StrictStr] = None message: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["code", "type", "message"] """Pydantic configuration""" model_config = { @@ -39,7 +38,7 @@ class ApiResponse(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -52,7 +51,7 @@ def from_json(cls, json_str: str) -> ApiResponse: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -71,16 +70,16 @@ def from_dict(cls, obj: dict) -> ApiResponse: return None if not isinstance(obj, dict): - return ApiResponse.parse_obj(obj) + return ApiResponse.model_validate(obj) - _obj = ApiResponse.parse_obj({ + _obj = ApiResponse.model_validate({ "code": obj.get("code"), "type": obj.get("type"), "message": obj.get("message") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["code", "type", "message"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_of_array_of_model.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_of_array_of_model.py index 1b6c9a6e1338..2bf2d4906c5b 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_of_array_of_model.py @@ -28,7 +28,6 @@ class ArrayOfArrayOfModel(BaseModel): """ another_property: Optional[conlist(conlist(Tag))] = None additional_properties: Dict[str, Any] = {} - __properties = ["another_property"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class ArrayOfArrayOfModel(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> ArrayOfArrayOfModel: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -79,9 +78,9 @@ def from_dict(cls, obj: dict) -> ArrayOfArrayOfModel: return None if not isinstance(obj, dict): - return ArrayOfArrayOfModel.parse_obj(obj) + return ArrayOfArrayOfModel.model_validate(obj) - _obj = ArrayOfArrayOfModel.parse_obj({ + _obj = ArrayOfArrayOfModel.model_validate({ "another_property": [ [Tag.from_dict(_inner_item) for _inner_item in _item] for _item in obj.get("another_property") @@ -89,7 +88,7 @@ def from_dict(cls, obj: dict) -> ArrayOfArrayOfModel: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["another_property"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_of_array_of_number_only.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_of_array_of_number_only.py index 8e908b531f5c..4441738f78e3 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_of_array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_of_array_of_number_only.py @@ -27,7 +27,6 @@ class ArrayOfArrayOfNumberOnly(BaseModel): """ array_array_number: Optional[conlist(conlist(StrictFloat))] = Field(None, alias="ArrayArrayNumber") additional_properties: Dict[str, Any] = {} - __properties = ["ArrayArrayNumber"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class ArrayOfArrayOfNumberOnly(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> ArrayOfArrayOfNumberOnly: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> ArrayOfArrayOfNumberOnly: return None if not isinstance(obj, dict): - return ArrayOfArrayOfNumberOnly.parse_obj(obj) + return ArrayOfArrayOfNumberOnly.model_validate(obj) - _obj = ArrayOfArrayOfNumberOnly.parse_obj({ + _obj = ArrayOfArrayOfNumberOnly.model_validate({ "array_array_number": obj.get("ArrayArrayNumber") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["ArrayArrayNumber"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_of_number_only.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_of_number_only.py index cf4fa2f1039e..63dd35643d8d 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_of_number_only.py @@ -27,7 +27,6 @@ class ArrayOfNumberOnly(BaseModel): """ array_number: Optional[conlist(StrictFloat)] = Field(None, alias="ArrayNumber") additional_properties: Dict[str, Any] = {} - __properties = ["ArrayNumber"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class ArrayOfNumberOnly(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> ArrayOfNumberOnly: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> ArrayOfNumberOnly: return None if not isinstance(obj, dict): - return ArrayOfNumberOnly.parse_obj(obj) + return ArrayOfNumberOnly.model_validate(obj) - _obj = ArrayOfNumberOnly.parse_obj({ + _obj = ArrayOfNumberOnly.model_validate({ "array_number": obj.get("ArrayNumber") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["ArrayNumber"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_test.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_test.py index ba695c59d32a..0157b7a3db87 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_test.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/array_test.py @@ -30,7 +30,6 @@ class ArrayTest(BaseModel): array_array_of_integer: Optional[conlist(conlist(StrictInt))] = None array_array_of_model: Optional[conlist(conlist(ReadOnlyFirst))] = None additional_properties: Dict[str, Any] = {} - __properties = ["array_of_string", "array_array_of_integer", "array_array_of_model"] """Pydantic configuration""" model_config = { @@ -40,7 +39,7 @@ class ArrayTest(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -53,7 +52,7 @@ def from_json(cls, json_str: str) -> ArrayTest: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -81,9 +80,9 @@ def from_dict(cls, obj: dict) -> ArrayTest: return None if not isinstance(obj, dict): - return ArrayTest.parse_obj(obj) + return ArrayTest.model_validate(obj) - _obj = ArrayTest.parse_obj({ + _obj = ArrayTest.model_validate({ "array_of_string": obj.get("array_of_string"), "array_array_of_integer": obj.get("array_array_of_integer"), "array_array_of_model": [ @@ -93,7 +92,7 @@ def from_dict(cls, obj: dict) -> ArrayTest: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["array_of_string", "array_array_of_integer", "array_array_of_model"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/basque_pig.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/basque_pig.py index 4738611803df..42a34809caa7 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/basque_pig.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/basque_pig.py @@ -28,7 +28,6 @@ class BasquePig(BaseModel): class_name: StrictStr = Field(..., alias="className") color: StrictStr = Field(...) additional_properties: Dict[str, Any] = {} - __properties = ["className", "color"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class BasquePig(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> BasquePig: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -70,15 +69,15 @@ def from_dict(cls, obj: dict) -> BasquePig: return None if not isinstance(obj, dict): - return BasquePig.parse_obj(obj) + return BasquePig.model_validate(obj) - _obj = BasquePig.parse_obj({ + _obj = BasquePig.model_validate({ "class_name": obj.get("className"), "color": obj.get("color") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["className", "color"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/capitalization.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/capitalization.py index 0b5393374277..acc6b50d1c88 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/capitalization.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/capitalization.py @@ -32,7 +32,6 @@ class Capitalization(BaseModel): sca_eth_flow_points: Optional[StrictStr] = Field(None, alias="SCA_ETH_Flow_Points") att_name: Optional[StrictStr] = Field(None, alias="ATT_NAME", description="Name of the pet ") additional_properties: Dict[str, Any] = {} - __properties = ["smallCamel", "CapitalCamel", "small_Snake", "Capital_Snake", "SCA_ETH_Flow_Points", "ATT_NAME"] """Pydantic configuration""" model_config = { @@ -42,7 +41,7 @@ class Capitalization(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -55,7 +54,7 @@ def from_json(cls, json_str: str) -> Capitalization: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -74,9 +73,9 @@ def from_dict(cls, obj: dict) -> Capitalization: return None if not isinstance(obj, dict): - return Capitalization.parse_obj(obj) + return Capitalization.model_validate(obj) - _obj = Capitalization.parse_obj({ + _obj = Capitalization.model_validate({ "small_camel": obj.get("smallCamel"), "capital_camel": obj.get("CapitalCamel"), "small_snake": obj.get("small_Snake"), @@ -86,7 +85,7 @@ def from_dict(cls, obj: dict) -> Capitalization: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["smallCamel", "CapitalCamel", "small_Snake", "Capital_Snake", "SCA_ETH_Flow_Points", "ATT_NAME"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/cat.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/cat.py index 01bf3dea821b..b02ebf9d6eec 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/cat.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/cat.py @@ -28,7 +28,6 @@ class Cat(Animal): """ declawed: Optional[StrictBool] = None additional_properties: Dict[str, Any] = {} - __properties = ["className", "color", "declawed"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class Cat(Animal): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> Cat: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -70,16 +69,16 @@ def from_dict(cls, obj: dict) -> Cat: return None if not isinstance(obj, dict): - return Cat.parse_obj(obj) + return Cat.model_validate(obj) - _obj = Cat.parse_obj({ + _obj = Cat.model_validate({ "class_name": obj.get("className"), "color": obj.get("color") if obj.get("color") is not None else 'red', "declawed": obj.get("declawed") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["className", "color", "declawed"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/category.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/category.py index a8f297a19c64..f3dfc7607a09 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/category.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/category.py @@ -28,7 +28,6 @@ class Category(BaseModel): id: Optional[StrictInt] = None name: StrictStr = Field(...) additional_properties: Dict[str, Any] = {} - __properties = ["id", "name"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class Category(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> Category: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -70,15 +69,15 @@ def from_dict(cls, obj: dict) -> Category: return None if not isinstance(obj, dict): - return Category.parse_obj(obj) + return Category.model_validate(obj) - _obj = Category.parse_obj({ + _obj = Category.model_validate({ "id": obj.get("id"), "name": obj.get("name") if obj.get("name") is not None else 'default-name' }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["id", "name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/circular_reference_model.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/circular_reference_model.py index 9a3c62cfbe72..87bae3fc1de9 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/circular_reference_model.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/circular_reference_model.py @@ -28,7 +28,6 @@ class CircularReferenceModel(BaseModel): size: Optional[StrictInt] = None nested: Optional[FirstRef] = None additional_properties: Dict[str, Any] = {} - __properties = ["size", "nested"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class CircularReferenceModel(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> CircularReferenceModel: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -73,19 +72,22 @@ def from_dict(cls, obj: dict) -> CircularReferenceModel: return None if not isinstance(obj, dict): - return CircularReferenceModel.parse_obj(obj) + return CircularReferenceModel.model_validate(obj) - _obj = CircularReferenceModel.parse_obj({ + _obj = CircularReferenceModel.model_validate({ "size": obj.get("size"), "nested": FirstRef.from_dict(obj.get("nested")) if obj.get("nested") is not None else None }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["size", "nested"]: _obj.additional_properties[_key] = obj.get(_key) return _obj from petstore_api.models.first_ref import FirstRef -CircularReferenceModel.update_forward_refs() +try: + CircularReferenceModel.model_rebuild() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/class_model.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/class_model.py index 34e526e1641b..06bb096e0d49 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/class_model.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/class_model.py @@ -27,7 +27,6 @@ class ClassModel(BaseModel): """ var_class: Optional[StrictStr] = Field(None, alias="_class") additional_properties: Dict[str, Any] = {} - __properties = ["_class"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class ClassModel(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> ClassModel: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> ClassModel: return None if not isinstance(obj, dict): - return ClassModel.parse_obj(obj) + return ClassModel.model_validate(obj) - _obj = ClassModel.parse_obj({ + _obj = ClassModel.model_validate({ "var_class": obj.get("_class") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["_class"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/client.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/client.py index dfc21947aa42..cf59980ff0da 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/client.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/client.py @@ -27,7 +27,6 @@ class Client(BaseModel): """ client: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["client"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class Client(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> Client: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> Client: return None if not isinstance(obj, dict): - return Client.parse_obj(obj) + return Client.model_validate(obj) - _obj = Client.parse_obj({ + _obj = Client.model_validate({ "client": obj.get("client") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["client"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/color.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/color.py index a05243df89ee..544a790b85e9 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/color.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/color.py @@ -19,7 +19,7 @@ import re # noqa: F401 from typing import Any, List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, conlist, constr, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, conlist, constr, field_validator from typing import Union, Any, List, TYPE_CHECKING try: from typing import Literal @@ -40,9 +40,9 @@ class Color(BaseModel): # data type: str oneof_schema_3_validator: Optional[constr(strict=True, max_length=7, min_length=7)] = Field(None, description="Hex color string, such as #00FF00.") if TYPE_CHECKING: - actual_instance: Union[List[int], str] + actual_instance: Union[List[int], str, None] else: - actual_instance: Any + actual_instance: Any = None one_of_schemas: List[str] = Literal["List[int]", "str"] @@ -58,15 +58,17 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): if v is None: return v - instance = Color.construct() + instance = Color.model_construct() error_messages = [] match = 0 # validate data type: List[int] @@ -89,6 +91,8 @@ def actual_instance_must_validate_oneof(cls, v): error_messages.append(str(e)) if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when setting `actual_instance` in Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -103,7 +107,7 @@ def from_dict(cls, obj: dict) -> Color: @classmethod def from_json(cls, json_str: str) -> Color: """Returns the object represented by the json string""" - instance = Color.construct() + instance = Color.model_construct() if json_str is None: return instance @@ -140,6 +144,8 @@ def from_json(cls, json_str: str) -> Color: if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -172,6 +178,6 @@ def to_dict(self) -> dict: def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/creature.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/creature.py index 89f8d3a162c8..5704ddb105cb 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/creature.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/creature.py @@ -29,7 +29,6 @@ class Creature(BaseModel): info: CreatureInfo = Field(...) type: StrictStr = Field(...) additional_properties: Dict[str, Any] = {} - __properties = ["info", "type"] """Pydantic configuration""" model_config = { @@ -39,7 +38,7 @@ class Creature(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -52,7 +51,7 @@ def from_json(cls, json_str: str) -> Creature: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -74,15 +73,15 @@ def from_dict(cls, obj: dict) -> Creature: return None if not isinstance(obj, dict): - return Creature.parse_obj(obj) + return Creature.model_validate(obj) - _obj = Creature.parse_obj({ + _obj = Creature.model_validate({ "info": CreatureInfo.from_dict(obj.get("info")) if obj.get("info") is not None else None, "type": obj.get("type") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["info", "type"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/creature_info.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/creature_info.py index 1ff7145528d6..be89fa13e084 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/creature_info.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/creature_info.py @@ -27,7 +27,6 @@ class CreatureInfo(BaseModel): """ name: StrictStr = Field(...) additional_properties: Dict[str, Any] = {} - __properties = ["name"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class CreatureInfo(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> CreatureInfo: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> CreatureInfo: return None if not isinstance(obj, dict): - return CreatureInfo.parse_obj(obj) + return CreatureInfo.model_validate(obj) - _obj = CreatureInfo.parse_obj({ + _obj = CreatureInfo.model_validate({ "name": obj.get("name") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/danish_pig.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/danish_pig.py index 4fec4f6fb8a2..b98ac4cef0b2 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/danish_pig.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/danish_pig.py @@ -28,7 +28,6 @@ class DanishPig(BaseModel): class_name: StrictStr = Field(..., alias="className") size: StrictInt = Field(...) additional_properties: Dict[str, Any] = {} - __properties = ["className", "size"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class DanishPig(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> DanishPig: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -70,15 +69,15 @@ def from_dict(cls, obj: dict) -> DanishPig: return None if not isinstance(obj, dict): - return DanishPig.parse_obj(obj) + return DanishPig.model_validate(obj) - _obj = DanishPig.parse_obj({ + _obj = DanishPig.model_validate({ "class_name": obj.get("className"), "size": obj.get("size") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["className", "size"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/deprecated_object.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/deprecated_object.py index ea1d52b15ccd..07c697272e37 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/deprecated_object.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/deprecated_object.py @@ -27,7 +27,6 @@ class DeprecatedObject(BaseModel): """ name: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["name"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class DeprecatedObject(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> DeprecatedObject: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> DeprecatedObject: return None if not isinstance(obj, dict): - return DeprecatedObject.parse_obj(obj) + return DeprecatedObject.model_validate(obj) - _obj = DeprecatedObject.parse_obj({ + _obj = DeprecatedObject.model_validate({ "name": obj.get("name") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/dog.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/dog.py index 28bab5868275..85434bdf0c29 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/dog.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/dog.py @@ -28,7 +28,6 @@ class Dog(Animal): """ breed: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["className", "color", "breed"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class Dog(Animal): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> Dog: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -70,16 +69,16 @@ def from_dict(cls, obj: dict) -> Dog: return None if not isinstance(obj, dict): - return Dog.parse_obj(obj) + return Dog.model_validate(obj) - _obj = Dog.parse_obj({ + _obj = Dog.model_validate({ "class_name": obj.get("className"), "color": obj.get("color") if obj.get("color") is not None else 'red', "breed": obj.get("breed") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["className", "color", "breed"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/dummy_model.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/dummy_model.py index 6085e77308fa..24ae7c25080d 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/dummy_model.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/dummy_model.py @@ -28,7 +28,6 @@ class DummyModel(BaseModel): category: Optional[StrictStr] = None self_ref: Optional[SelfReferenceModel] = None additional_properties: Dict[str, Any] = {} - __properties = ["category", "self_ref"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class DummyModel(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> DummyModel: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -73,19 +72,22 @@ def from_dict(cls, obj: dict) -> DummyModel: return None if not isinstance(obj, dict): - return DummyModel.parse_obj(obj) + return DummyModel.model_validate(obj) - _obj = DummyModel.parse_obj({ + _obj = DummyModel.model_validate({ "category": obj.get("category"), "self_ref": SelfReferenceModel.from_dict(obj.get("self_ref")) if obj.get("self_ref") is not None else None }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["category", "self_ref"]: _obj.additional_properties[_key] = obj.get(_key) return _obj from petstore_api.models.self_reference_model import SelfReferenceModel -DummyModel.update_forward_refs() +try: + DummyModel.model_rebuild() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/enum_arrays.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/enum_arrays.py index cae2015f7777..a66eef8b042e 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/enum_arrays.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/enum_arrays.py @@ -19,7 +19,7 @@ from typing import Any, Dict, List, Optional -from pydantic import BaseModel, StrictStr, conlist, validator +from pydantic import BaseModel, StrictStr, conlist, field_validator class EnumArrays(BaseModel): """ @@ -28,9 +28,8 @@ class EnumArrays(BaseModel): just_symbol: Optional[StrictStr] = None array_enum: Optional[conlist(StrictStr)] = None additional_properties: Dict[str, Any] = {} - __properties = ["just_symbol", "array_enum"] - @validator('just_symbol') + @field_validator('just_symbol') def just_symbol_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -40,7 +39,7 @@ def just_symbol_validate_enum(cls, value): raise ValueError("must be one of enum values ('>=', '$')") return value - @validator('array_enum') + @field_validator('array_enum') def array_enum_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -59,7 +58,7 @@ def array_enum_validate_enum(cls, value): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -72,7 +71,7 @@ def from_json(cls, json_str: str) -> EnumArrays: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -91,15 +90,15 @@ def from_dict(cls, obj: dict) -> EnumArrays: return None if not isinstance(obj, dict): - return EnumArrays.parse_obj(obj) + return EnumArrays.model_validate(obj) - _obj = EnumArrays.parse_obj({ + _obj = EnumArrays.model_validate({ "just_symbol": obj.get("just_symbol"), "array_enum": obj.get("array_enum") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["just_symbol", "array_enum"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/enum_test.py index a0226d95eed3..88a5ad903244 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/enum_test.py @@ -19,7 +19,7 @@ from typing import Any, Dict, Optional -from pydantic import BaseModel, Field, StrictFloat, StrictInt, StrictStr, validator +from pydantic import BaseModel, Field, StrictFloat, StrictInt, StrictStr, field_validator 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 @@ -39,9 +39,8 @@ class EnumTest(BaseModel): outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(None, alias="outerEnumDefaultValue") outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(None, alias="outerEnumIntegerDefaultValue") additional_properties: Dict[str, Any] = {} - __properties = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] - @validator('enum_string') + @field_validator('enum_string') def enum_string_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -51,14 +50,14 @@ def enum_string_validate_enum(cls, value): raise ValueError("must be one of enum values ('UPPER', 'lower', '')") return value - @validator('enum_string_required') + @field_validator('enum_string_required') def enum_string_required_validate_enum(cls, value): """Validates the enum""" if value not in ('UPPER', 'lower', ''): raise ValueError("must be one of enum values ('UPPER', 'lower', '')") return value - @validator('enum_integer_default') + @field_validator('enum_integer_default') def enum_integer_default_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -68,7 +67,7 @@ def enum_integer_default_validate_enum(cls, value): raise ValueError("must be one of enum values (1, 5, 14)") return value - @validator('enum_integer') + @field_validator('enum_integer') def enum_integer_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -78,7 +77,7 @@ def enum_integer_validate_enum(cls, value): raise ValueError("must be one of enum values (1, -1)") return value - @validator('enum_number') + @field_validator('enum_number') def enum_number_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -96,7 +95,7 @@ def enum_number_validate_enum(cls, value): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -109,7 +108,7 @@ def from_json(cls, json_str: str) -> EnumTest: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -121,7 +120,7 @@ def to_dict(self): # set to None if outer_enum (nullable) is None # and __fields_set__ contains the field - if self.outer_enum is None and "outer_enum" in self.__fields_set__: + if self.outer_enum is None and "outer_enum" in self.model_fields_set: _dict['outerEnum'] = None return _dict @@ -133,9 +132,9 @@ def from_dict(cls, obj: dict) -> EnumTest: return None if not isinstance(obj, dict): - return EnumTest.parse_obj(obj) + return EnumTest.model_validate(obj) - _obj = EnumTest.parse_obj({ + _obj = EnumTest.model_validate({ "enum_string": obj.get("enum_string"), "enum_string_required": obj.get("enum_string_required"), "enum_integer_default": obj.get("enum_integer_default") if obj.get("enum_integer_default") is not None else 5, @@ -148,7 +147,7 @@ def from_dict(cls, obj: dict) -> EnumTest: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/file.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/file.py index 6702d83e6209..22a3e2a5ee58 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/file.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/file.py @@ -27,7 +27,6 @@ class File(BaseModel): """ source_uri: Optional[StrictStr] = Field(None, alias="sourceURI", description="Test capitalization") additional_properties: Dict[str, Any] = {} - __properties = ["sourceURI"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class File(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> File: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> File: return None if not isinstance(obj, dict): - return File.parse_obj(obj) + return File.model_validate(obj) - _obj = File.parse_obj({ + _obj = File.model_validate({ "source_uri": obj.get("sourceURI") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["sourceURI"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/file_schema_test_class.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/file_schema_test_class.py index 86f565ac5e5f..63faa8a8890f 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/file_schema_test_class.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/file_schema_test_class.py @@ -29,7 +29,6 @@ class FileSchemaTestClass(BaseModel): file: Optional[File] = None files: Optional[conlist(File)] = None additional_properties: Dict[str, Any] = {} - __properties = ["file", "files"] """Pydantic configuration""" model_config = { @@ -39,7 +38,7 @@ class FileSchemaTestClass(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -52,7 +51,7 @@ def from_json(cls, json_str: str) -> FileSchemaTestClass: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -81,15 +80,15 @@ def from_dict(cls, obj: dict) -> FileSchemaTestClass: return None if not isinstance(obj, dict): - return FileSchemaTestClass.parse_obj(obj) + return FileSchemaTestClass.model_validate(obj) - _obj = FileSchemaTestClass.parse_obj({ + _obj = FileSchemaTestClass.model_validate({ "file": File.from_dict(obj.get("file")) if obj.get("file") is not None else None, "files": [File.from_dict(_item) for _item in obj.get("files")] if obj.get("files") is not None else None }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["file", "files"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/first_ref.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/first_ref.py index 3edf4c14bfaf..3317534222ae 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/first_ref.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/first_ref.py @@ -28,7 +28,6 @@ class FirstRef(BaseModel): category: Optional[StrictStr] = None self_ref: Optional[SecondRef] = None additional_properties: Dict[str, Any] = {} - __properties = ["category", "self_ref"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class FirstRef(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> FirstRef: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -73,19 +72,22 @@ def from_dict(cls, obj: dict) -> FirstRef: return None if not isinstance(obj, dict): - return FirstRef.parse_obj(obj) + return FirstRef.model_validate(obj) - _obj = FirstRef.parse_obj({ + _obj = FirstRef.model_validate({ "category": obj.get("category"), "self_ref": SecondRef.from_dict(obj.get("self_ref")) if obj.get("self_ref") is not None else None }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["category", "self_ref"]: _obj.additional_properties[_key] = obj.get(_key) return _obj from petstore_api.models.second_ref import SecondRef -FirstRef.update_forward_refs() +try: + FirstRef.model_rebuild() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/foo.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/foo.py index b607b20b493a..e96f9e89d212 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/foo.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/foo.py @@ -27,7 +27,6 @@ class Foo(BaseModel): """ bar: Optional[StrictStr] = 'bar' additional_properties: Dict[str, Any] = {} - __properties = ["bar"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class Foo(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> Foo: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> Foo: return None if not isinstance(obj, dict): - return Foo.parse_obj(obj) + return Foo.model_validate(obj) - _obj = Foo.parse_obj({ + _obj = Foo.model_validate({ "bar": obj.get("bar") if obj.get("bar") is not None else 'bar' }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["bar"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/foo_get_default_response.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/foo_get_default_response.py index 4814aa51bad5..43d8b4eb1f90 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/foo_get_default_response.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/foo_get_default_response.py @@ -28,7 +28,6 @@ class FooGetDefaultResponse(BaseModel): """ string: Optional[Foo] = None additional_properties: Dict[str, Any] = {} - __properties = ["string"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class FooGetDefaultResponse(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> FooGetDefaultResponse: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -73,14 +72,14 @@ def from_dict(cls, obj: dict) -> FooGetDefaultResponse: return None if not isinstance(obj, dict): - return FooGetDefaultResponse.parse_obj(obj) + return FooGetDefaultResponse.model_validate(obj) - _obj = FooGetDefaultResponse.parse_obj({ + _obj = FooGetDefaultResponse.model_validate({ "string": Foo.from_dict(obj.get("string")) if obj.get("string") is not None else None }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["string"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/format_test.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/format_test.py index a456b64abc7e..1488b291eb6b 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/format_test.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/format_test.py @@ -19,7 +19,7 @@ from datetime import date, datetime from typing import Any, Dict, Optional, Union -from pydantic import BaseModel, Field, StrictBytes, StrictInt, StrictStr, condecimal, confloat, conint, constr, validator +from pydantic import BaseModel, Field, StrictBytes, StrictInt, StrictStr, condecimal, confloat, conint, constr, field_validator class FormatTest(BaseModel): """ @@ -43,9 +43,8 @@ class FormatTest(BaseModel): pattern_with_digits: Optional[constr(strict=True)] = Field(None, description="A string that is a 10 digit number. Can have leading zeros.") pattern_with_digits_and_delimiter: Optional[constr(strict=True)] = Field(None, description="A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01.") additional_properties: Dict[str, Any] = {} - __properties = ["integer", "int32", "int64", "number", "float", "double", "decimal", "string", "string_with_double_quote_pattern", "byte", "binary", "date", "dateTime", "uuid", "password", "pattern_with_digits", "pattern_with_digits_and_delimiter"] - @validator('string') + @field_validator('string') def string_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -55,7 +54,7 @@ def string_validate_regular_expression(cls, value): raise ValueError(r"must validate the regular expression /[a-z]/i") return value - @validator('string_with_double_quote_pattern') + @field_validator('string_with_double_quote_pattern') def string_with_double_quote_pattern_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -65,7 +64,7 @@ def string_with_double_quote_pattern_validate_regular_expression(cls, value): raise ValueError(r"must validate the regular expression /this is \"something\"/") return value - @validator('pattern_with_digits') + @field_validator('pattern_with_digits') def pattern_with_digits_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -75,7 +74,7 @@ def pattern_with_digits_validate_regular_expression(cls, value): raise ValueError(r"must validate the regular expression /^\d{10}$/") return value - @validator('pattern_with_digits_and_delimiter') + @field_validator('pattern_with_digits_and_delimiter') def pattern_with_digits_and_delimiter_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -93,7 +92,7 @@ def pattern_with_digits_and_delimiter_validate_regular_expression(cls, value): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -106,7 +105,7 @@ def from_json(cls, json_str: str) -> FormatTest: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -125,9 +124,9 @@ def from_dict(cls, obj: dict) -> FormatTest: return None if not isinstance(obj, dict): - return FormatTest.parse_obj(obj) + return FormatTest.model_validate(obj) - _obj = FormatTest.parse_obj({ + _obj = FormatTest.model_validate({ "integer": obj.get("integer"), "int32": obj.get("int32"), "int64": obj.get("int64"), @@ -148,7 +147,7 @@ def from_dict(cls, obj: dict) -> FormatTest: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["integer", "int32", "int64", "number", "float", "double", "decimal", "string", "string_with_double_quote_pattern", "byte", "binary", "date", "dateTime", "uuid", "password", "pattern_with_digits", "pattern_with_digits_and_delimiter"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/has_only_read_only.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/has_only_read_only.py index 1b0116b2bbb5..e6ece3087b15 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/has_only_read_only.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/has_only_read_only.py @@ -28,7 +28,6 @@ class HasOnlyReadOnly(BaseModel): bar: Optional[StrictStr] = None foo: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["bar", "foo"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class HasOnlyReadOnly(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> HasOnlyReadOnly: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "bar", "foo", @@ -72,15 +71,15 @@ def from_dict(cls, obj: dict) -> HasOnlyReadOnly: return None if not isinstance(obj, dict): - return HasOnlyReadOnly.parse_obj(obj) + return HasOnlyReadOnly.model_validate(obj) - _obj = HasOnlyReadOnly.parse_obj({ + _obj = HasOnlyReadOnly.model_validate({ "bar": obj.get("bar"), "foo": obj.get("foo") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["bar", "foo"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/health_check_result.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/health_check_result.py index 0beb041f523a..5e695fe58b3b 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/health_check_result.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/health_check_result.py @@ -27,7 +27,6 @@ class HealthCheckResult(BaseModel): """ nullable_message: Optional[StrictStr] = Field(None, alias="NullableMessage") additional_properties: Dict[str, Any] = {} - __properties = ["NullableMessage"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class HealthCheckResult(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> HealthCheckResult: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -62,7 +61,7 @@ def to_dict(self): # set to None if nullable_message (nullable) is None # and __fields_set__ contains the field - if self.nullable_message is None and "nullable_message" in self.__fields_set__: + if self.nullable_message is None and "nullable_message" in self.model_fields_set: _dict['NullableMessage'] = None return _dict @@ -74,14 +73,14 @@ def from_dict(cls, obj: dict) -> HealthCheckResult: return None if not isinstance(obj, dict): - return HealthCheckResult.parse_obj(obj) + return HealthCheckResult.model_validate(obj) - _obj = HealthCheckResult.parse_obj({ + _obj = HealthCheckResult.model_validate({ "nullable_message": obj.get("NullableMessage") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["NullableMessage"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/inner_dict_with_property.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/inner_dict_with_property.py index 053eb4c2a5da..0906e856e578 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/inner_dict_with_property.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/inner_dict_with_property.py @@ -27,7 +27,6 @@ class InnerDictWithProperty(BaseModel): """ a_property: Optional[Dict[str, Any]] = Field(None, alias="aProperty") additional_properties: Dict[str, Any] = {} - __properties = ["aProperty"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class InnerDictWithProperty(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> InnerDictWithProperty: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> InnerDictWithProperty: return None if not isinstance(obj, dict): - return InnerDictWithProperty.parse_obj(obj) + return InnerDictWithProperty.model_validate(obj) - _obj = InnerDictWithProperty.parse_obj({ + _obj = InnerDictWithProperty.model_validate({ "a_property": obj.get("aProperty") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["aProperty"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/int_or_string.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/int_or_string.py index e3420c4ae071..782abc0c10ac 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/int_or_string.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/int_or_string.py @@ -19,7 +19,7 @@ import re # noqa: F401 from typing import Any, List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, conint, field_validator from typing import Union, Any, List, TYPE_CHECKING try: from typing import Literal @@ -40,7 +40,7 @@ class IntOrString(BaseModel): if TYPE_CHECKING: actual_instance: Union[int, str] else: - actual_instance: Any + actual_instance: Any = None one_of_schemas: List[str] = Literal["int", "str"] @@ -56,12 +56,14 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): - instance = IntOrString.construct() + instance = IntOrString.model_construct() error_messages = [] match = 0 # validate data type: int @@ -78,6 +80,8 @@ def actual_instance_must_validate_oneof(cls, v): error_messages.append(str(e)) if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when setting `actual_instance` in IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -92,7 +96,7 @@ def from_dict(cls, obj: dict) -> IntOrString: @classmethod def from_json(cls, json_str: str) -> IntOrString: """Returns the object represented by the json string""" - instance = IntOrString.construct() + instance = IntOrString.model_construct() error_messages = [] match = 0 @@ -117,6 +121,8 @@ def from_json(cls, json_str: str) -> IntOrString: if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when deserializing the JSON string into IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -149,6 +155,6 @@ def to_dict(self) -> dict: def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/list.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/list.py index 4ca9ce45ae57..19fa0d1a8110 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/list.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/list.py @@ -27,7 +27,6 @@ class List(BaseModel): """ var_123_list: Optional[StrictStr] = Field(None, alias="123-list") additional_properties: Dict[str, Any] = {} - __properties = ["123-list"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class List(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> List: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> List: return None if not isinstance(obj, dict): - return List.parse_obj(obj) + return List.model_validate(obj) - _obj = List.parse_obj({ + _obj = List.model_validate({ "var_123_list": obj.get("123-list") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["123-list"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/map_of_array_of_model.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/map_of_array_of_model.py index cdcbc232f988..01462673ee3c 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/map_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/map_of_array_of_model.py @@ -28,7 +28,6 @@ class MapOfArrayOfModel(BaseModel): """ shop_id_to_org_online_lip_map: Optional[Dict[str, conlist(Tag)]] = Field(None, alias="shopIdToOrgOnlineLipMap") additional_properties: Dict[str, Any] = {} - __properties = ["shopIdToOrgOnlineLipMap"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class MapOfArrayOfModel(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> MapOfArrayOfModel: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -79,9 +78,9 @@ def from_dict(cls, obj: dict) -> MapOfArrayOfModel: return None if not isinstance(obj, dict): - return MapOfArrayOfModel.parse_obj(obj) + return MapOfArrayOfModel.model_validate(obj) - _obj = MapOfArrayOfModel.parse_obj({ + _obj = MapOfArrayOfModel.model_validate({ "shop_id_to_org_online_lip_map": dict( (_k, [Tag.from_dict(_item) for _item in _v] @@ -93,7 +92,7 @@ def from_dict(cls, obj: dict) -> MapOfArrayOfModel: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["shopIdToOrgOnlineLipMap"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/map_test.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/map_test.py index c2d729e9c9fd..947494a20cc4 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/map_test.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/map_test.py @@ -19,7 +19,7 @@ from typing import Any, Dict, Optional -from pydantic import BaseModel, StrictBool, StrictStr, validator +from pydantic import BaseModel, StrictBool, StrictStr, field_validator class MapTest(BaseModel): """ @@ -30,9 +30,8 @@ class MapTest(BaseModel): direct_map: Optional[Dict[str, StrictBool]] = None indirect_map: Optional[Dict[str, StrictBool]] = None additional_properties: Dict[str, Any] = {} - __properties = ["map_map_of_string", "map_of_enum_string", "direct_map", "indirect_map"] - @validator('map_of_enum_string') + @field_validator('map_of_enum_string') def map_of_enum_string_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -50,7 +49,7 @@ def map_of_enum_string_validate_enum(cls, value): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -63,7 +62,7 @@ def from_json(cls, json_str: str) -> MapTest: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -82,9 +81,9 @@ def from_dict(cls, obj: dict) -> MapTest: return None if not isinstance(obj, dict): - return MapTest.parse_obj(obj) + return MapTest.model_validate(obj) - _obj = MapTest.parse_obj({ + _obj = MapTest.model_validate({ "map_map_of_string": obj.get("map_map_of_string"), "map_of_enum_string": obj.get("map_of_enum_string"), "direct_map": obj.get("direct_map"), @@ -92,7 +91,7 @@ def from_dict(cls, obj: dict) -> MapTest: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["map_map_of_string", "map_of_enum_string", "direct_map", "indirect_map"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/mixed_properties_and_additional_properties_class.py index 257f9a737395..52c283a595e6 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -30,7 +30,6 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): date_time: Optional[datetime] = Field(None, alias="dateTime") map: Optional[Dict[str, Animal]] = None additional_properties: Dict[str, Any] = {} - __properties = ["uuid", "dateTime", "map"] """Pydantic configuration""" model_config = { @@ -40,7 +39,7 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -53,7 +52,7 @@ def from_json(cls, json_str: str) -> MixedPropertiesAndAdditionalPropertiesClass def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -79,9 +78,9 @@ def from_dict(cls, obj: dict) -> MixedPropertiesAndAdditionalPropertiesClass: return None if not isinstance(obj, dict): - return MixedPropertiesAndAdditionalPropertiesClass.parse_obj(obj) + return MixedPropertiesAndAdditionalPropertiesClass.model_validate(obj) - _obj = MixedPropertiesAndAdditionalPropertiesClass.parse_obj({ + _obj = MixedPropertiesAndAdditionalPropertiesClass.model_validate({ "uuid": obj.get("uuid"), "date_time": obj.get("dateTime"), "map": dict( @@ -93,7 +92,7 @@ def from_dict(cls, obj: dict) -> MixedPropertiesAndAdditionalPropertiesClass: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["uuid", "dateTime", "map"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/model200_response.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/model200_response.py index d10d3e913b02..523d9af1a26a 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/model200_response.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/model200_response.py @@ -28,7 +28,6 @@ class Model200Response(BaseModel): name: Optional[StrictInt] = None var_class: Optional[StrictStr] = Field(None, alias="class") additional_properties: Dict[str, Any] = {} - __properties = ["name", "class"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class Model200Response(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> Model200Response: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -70,15 +69,15 @@ def from_dict(cls, obj: dict) -> Model200Response: return None if not isinstance(obj, dict): - return Model200Response.parse_obj(obj) + return Model200Response.model_validate(obj) - _obj = Model200Response.parse_obj({ + _obj = Model200Response.model_validate({ "name": obj.get("name"), "var_class": obj.get("class") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name", "class"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/model_return.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/model_return.py index c7f18b149034..f7c5e2aa6a0b 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/model_return.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/model_return.py @@ -27,7 +27,6 @@ class ModelReturn(BaseModel): """ var_return: Optional[StrictInt] = Field(None, alias="return") additional_properties: Dict[str, Any] = {} - __properties = ["return"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class ModelReturn(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> ModelReturn: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> ModelReturn: return None if not isinstance(obj, dict): - return ModelReturn.parse_obj(obj) + return ModelReturn.model_validate(obj) - _obj = ModelReturn.parse_obj({ + _obj = ModelReturn.model_validate({ "var_return": obj.get("return") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["return"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/name.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/name.py index 483f75e148d6..bc6f56764765 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/name.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/name.py @@ -30,7 +30,6 @@ class Name(BaseModel): var_property: Optional[StrictStr] = Field(None, alias="property") var_123_number: Optional[StrictInt] = Field(None, alias="123Number") additional_properties: Dict[str, Any] = {} - __properties = ["name", "snake_case", "property", "123Number"] """Pydantic configuration""" model_config = { @@ -40,7 +39,7 @@ class Name(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -53,7 +52,7 @@ def from_json(cls, json_str: str) -> Name: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "snake_case", "var_123_number", @@ -74,9 +73,9 @@ def from_dict(cls, obj: dict) -> Name: return None if not isinstance(obj, dict): - return Name.parse_obj(obj) + return Name.model_validate(obj) - _obj = Name.parse_obj({ + _obj = Name.model_validate({ "name": obj.get("name"), "snake_case": obj.get("snake_case"), "var_property": obj.get("property"), @@ -84,7 +83,7 @@ def from_dict(cls, obj: dict) -> Name: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name", "snake_case", "property", "123Number"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/nullable_class.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/nullable_class.py index 52f9ad12be36..999da9f55082 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/nullable_class.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/nullable_class.py @@ -39,7 +39,6 @@ class NullableClass(BaseModel): object_and_items_nullable_prop: Optional[Dict[str, Dict[str, Any]]] = None object_items_nullable: Optional[Dict[str, Dict[str, Any]]] = None additional_properties: Dict[str, Any] = {} - __properties = ["required_integer_prop", "integer_prop", "number_prop", "boolean_prop", "string_prop", "date_prop", "datetime_prop", "array_nullable_prop", "array_and_items_nullable_prop", "array_items_nullable", "object_nullable_prop", "object_and_items_nullable_prop", "object_items_nullable"] """Pydantic configuration""" model_config = { @@ -49,7 +48,7 @@ class NullableClass(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -62,7 +61,7 @@ def from_json(cls, json_str: str) -> NullableClass: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -74,57 +73,57 @@ def to_dict(self): # set to None if required_integer_prop (nullable) is None # and __fields_set__ contains the field - if self.required_integer_prop is None and "required_integer_prop" in self.__fields_set__: + if self.required_integer_prop is None and "required_integer_prop" in self.model_fields_set: _dict['required_integer_prop'] = None # set to None if integer_prop (nullable) is None # and __fields_set__ contains the field - if self.integer_prop is None and "integer_prop" in self.__fields_set__: + if self.integer_prop is None and "integer_prop" in self.model_fields_set: _dict['integer_prop'] = None # set to None if number_prop (nullable) is None # and __fields_set__ contains the field - if self.number_prop is None and "number_prop" in self.__fields_set__: + if self.number_prop is None and "number_prop" in self.model_fields_set: _dict['number_prop'] = None # set to None if boolean_prop (nullable) is None # and __fields_set__ contains the field - if self.boolean_prop is None and "boolean_prop" in self.__fields_set__: + if self.boolean_prop is None and "boolean_prop" in self.model_fields_set: _dict['boolean_prop'] = None # set to None if string_prop (nullable) is None # and __fields_set__ contains the field - if self.string_prop is None and "string_prop" in self.__fields_set__: + if self.string_prop is None and "string_prop" in self.model_fields_set: _dict['string_prop'] = None # set to None if date_prop (nullable) is None # and __fields_set__ contains the field - if self.date_prop is None and "date_prop" in self.__fields_set__: + if self.date_prop is None and "date_prop" in self.model_fields_set: _dict['date_prop'] = None # set to None if datetime_prop (nullable) is None # and __fields_set__ contains the field - if self.datetime_prop is None and "datetime_prop" in self.__fields_set__: + if self.datetime_prop is None and "datetime_prop" in self.model_fields_set: _dict['datetime_prop'] = None # set to None if array_nullable_prop (nullable) is None # and __fields_set__ contains the field - if self.array_nullable_prop is None and "array_nullable_prop" in self.__fields_set__: + if self.array_nullable_prop is None and "array_nullable_prop" in self.model_fields_set: _dict['array_nullable_prop'] = None # set to None if array_and_items_nullable_prop (nullable) is None # and __fields_set__ contains the field - if self.array_and_items_nullable_prop is None and "array_and_items_nullable_prop" in self.__fields_set__: + if self.array_and_items_nullable_prop is None and "array_and_items_nullable_prop" in self.model_fields_set: _dict['array_and_items_nullable_prop'] = None # set to None if object_nullable_prop (nullable) is None # and __fields_set__ contains the field - if self.object_nullable_prop is None and "object_nullable_prop" in self.__fields_set__: + if self.object_nullable_prop is None and "object_nullable_prop" in self.model_fields_set: _dict['object_nullable_prop'] = None # set to None if object_and_items_nullable_prop (nullable) is None # and __fields_set__ contains the field - if self.object_and_items_nullable_prop is None and "object_and_items_nullable_prop" in self.__fields_set__: + if self.object_and_items_nullable_prop is None and "object_and_items_nullable_prop" in self.model_fields_set: _dict['object_and_items_nullable_prop'] = None return _dict @@ -136,9 +135,9 @@ def from_dict(cls, obj: dict) -> NullableClass: return None if not isinstance(obj, dict): - return NullableClass.parse_obj(obj) + return NullableClass.model_validate(obj) - _obj = NullableClass.parse_obj({ + _obj = NullableClass.model_validate({ "required_integer_prop": obj.get("required_integer_prop"), "integer_prop": obj.get("integer_prop"), "number_prop": obj.get("number_prop"), @@ -155,7 +154,7 @@ def from_dict(cls, obj: dict) -> NullableClass: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["required_integer_prop", "integer_prop", "number_prop", "boolean_prop", "string_prop", "date_prop", "datetime_prop", "array_nullable_prop", "array_and_items_nullable_prop", "array_items_nullable", "object_nullable_prop", "object_and_items_nullable_prop", "object_items_nullable"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/nullable_property.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/nullable_property.py index 3cbde9fd5406..41013b164b59 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/nullable_property.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/nullable_property.py @@ -19,7 +19,7 @@ from typing import Any, Dict, Optional -from pydantic import BaseModel, Field, StrictInt, constr, validator +from pydantic import BaseModel, Field, StrictInt, constr, field_validator class NullableProperty(BaseModel): """ @@ -28,9 +28,8 @@ class NullableProperty(BaseModel): id: StrictInt = Field(...) name: Optional[constr(strict=True)] = Field(...) additional_properties: Dict[str, Any] = {} - __properties = ["id", "name"] - @validator('name') + @field_validator('name') def name_validate_regular_expression(cls, value): """Validates the regular expression""" if value is None: @@ -48,7 +47,7 @@ def name_validate_regular_expression(cls, value): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -61,7 +60,7 @@ def from_json(cls, json_str: str) -> NullableProperty: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -73,7 +72,7 @@ def to_dict(self): # set to None if name (nullable) is None # and __fields_set__ contains the field - if self.name is None and "name" in self.__fields_set__: + if self.name is None and "name" in self.model_fields_set: _dict['name'] = None return _dict @@ -85,15 +84,15 @@ def from_dict(cls, obj: dict) -> NullableProperty: return None if not isinstance(obj, dict): - return NullableProperty.parse_obj(obj) + return NullableProperty.model_validate(obj) - _obj = NullableProperty.parse_obj({ + _obj = NullableProperty.model_validate({ "id": obj.get("id"), "name": obj.get("name") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["id", "name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/number_only.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/number_only.py index 9d9f9ed9df08..159c41a9e5af 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/number_only.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/number_only.py @@ -27,7 +27,6 @@ class NumberOnly(BaseModel): """ just_number: Optional[StrictFloat] = Field(None, alias="JustNumber") additional_properties: Dict[str, Any] = {} - __properties = ["JustNumber"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class NumberOnly(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> NumberOnly: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> NumberOnly: return None if not isinstance(obj, dict): - return NumberOnly.parse_obj(obj) + return NumberOnly.model_validate(obj) - _obj = NumberOnly.parse_obj({ + _obj = NumberOnly.model_validate({ "just_number": obj.get("JustNumber") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["JustNumber"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/object_to_test_additional_properties.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/object_to_test_additional_properties.py index ff8f56fa9d6e..d7dda3c9442f 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/object_to_test_additional_properties.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/object_to_test_additional_properties.py @@ -27,7 +27,6 @@ class ObjectToTestAdditionalProperties(BaseModel): """ var_property: Optional[StrictBool] = Field(False, alias="property", description="Property") additional_properties: Dict[str, Any] = {} - __properties = ["property"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class ObjectToTestAdditionalProperties(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> ObjectToTestAdditionalProperties: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> ObjectToTestAdditionalProperties: return None if not isinstance(obj, dict): - return ObjectToTestAdditionalProperties.parse_obj(obj) + return ObjectToTestAdditionalProperties.model_validate(obj) - _obj = ObjectToTestAdditionalProperties.parse_obj({ + _obj = ObjectToTestAdditionalProperties.model_validate({ "var_property": obj.get("property") if obj.get("property") is not None else False }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["property"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/object_with_deprecated_fields.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/object_with_deprecated_fields.py index c2236b329861..03c00f0af7f9 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/object_with_deprecated_fields.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/object_with_deprecated_fields.py @@ -31,7 +31,6 @@ class ObjectWithDeprecatedFields(BaseModel): deprecated_ref: Optional[DeprecatedObject] = Field(None, alias="deprecatedRef") bars: Optional[conlist(StrictStr)] = None additional_properties: Dict[str, Any] = {} - __properties = ["uuid", "id", "deprecatedRef", "bars"] """Pydantic configuration""" model_config = { @@ -41,7 +40,7 @@ class ObjectWithDeprecatedFields(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -54,7 +53,7 @@ def from_json(cls, json_str: str) -> ObjectWithDeprecatedFields: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -76,9 +75,9 @@ def from_dict(cls, obj: dict) -> ObjectWithDeprecatedFields: return None if not isinstance(obj, dict): - return ObjectWithDeprecatedFields.parse_obj(obj) + return ObjectWithDeprecatedFields.model_validate(obj) - _obj = ObjectWithDeprecatedFields.parse_obj({ + _obj = ObjectWithDeprecatedFields.model_validate({ "uuid": obj.get("uuid"), "id": obj.get("id"), "deprecated_ref": DeprecatedObject.from_dict(obj.get("deprecatedRef")) if obj.get("deprecatedRef") is not None else None, @@ -86,7 +85,7 @@ def from_dict(cls, obj: dict) -> ObjectWithDeprecatedFields: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["uuid", "id", "deprecatedRef", "bars"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/one_of_enum_string.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/one_of_enum_string.py index ab6c7a72586a..7e3fc3da5f89 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/one_of_enum_string.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/one_of_enum_string.py @@ -19,7 +19,7 @@ import re # noqa: F401 from typing import Any, List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from petstore_api.models.enum_string1 import EnumString1 from petstore_api.models.enum_string2 import EnumString2 from typing import Union, Any, List, TYPE_CHECKING @@ -42,7 +42,7 @@ class OneOfEnumString(BaseModel): if TYPE_CHECKING: actual_instance: Union[EnumString1, EnumString2] else: - actual_instance: Any + actual_instance: Any = None one_of_schemas: List[str] = Literal["EnumString1", "EnumString2"] @@ -58,26 +58,32 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): - instance = OneOfEnumString.construct() + instance = OneOfEnumString.model_construct() error_messages = [] match = 0 # validate data type: EnumString1 - if not isinstance(v, EnumString1): - error_messages.append(f"Error! Input type `{type(v)}` is not `EnumString1`") - else: + try: + instance.oneof_schema_1_validator = v match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) # validate data type: EnumString2 - if not isinstance(v, EnumString2): - error_messages.append(f"Error! Input type `{type(v)}` is not `EnumString2`") - else: + try: + instance.oneof_schema_2_validator = v match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when setting `actual_instance` in OneOfEnumString with oneOf schemas: EnumString1, EnumString2. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -92,7 +98,7 @@ def from_dict(cls, obj: dict) -> OneOfEnumString: @classmethod def from_json(cls, json_str: str) -> OneOfEnumString: """Returns the object represented by the json string""" - instance = OneOfEnumString.construct() + instance = OneOfEnumString.model_construct() error_messages = [] match = 0 @@ -111,6 +117,8 @@ def from_json(cls, json_str: str) -> OneOfEnumString: if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when deserializing the JSON string into OneOfEnumString with oneOf schemas: EnumString1, EnumString2. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -143,6 +151,6 @@ def to_dict(self) -> dict: def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/order.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/order.py index 8e6b41dfbc18..6d3e4d669036 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/order.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/order.py @@ -19,7 +19,7 @@ from datetime import datetime from typing import Any, Dict, Optional -from pydantic import BaseModel, Field, StrictBool, StrictInt, StrictStr, validator +from pydantic import BaseModel, Field, StrictBool, StrictInt, StrictStr, field_validator class Order(BaseModel): """ @@ -32,9 +32,8 @@ class Order(BaseModel): status: Optional[StrictStr] = Field(None, description="Order Status") complete: Optional[StrictBool] = False additional_properties: Dict[str, Any] = {} - __properties = ["id", "petId", "quantity", "shipDate", "status", "complete"] - @validator('status') + @field_validator('status') def status_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -52,7 +51,7 @@ def status_validate_enum(cls, value): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -65,7 +64,7 @@ def from_json(cls, json_str: str) -> Order: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -84,9 +83,9 @@ def from_dict(cls, obj: dict) -> Order: return None if not isinstance(obj, dict): - return Order.parse_obj(obj) + return Order.model_validate(obj) - _obj = Order.parse_obj({ + _obj = Order.model_validate({ "id": obj.get("id"), "pet_id": obj.get("petId"), "quantity": obj.get("quantity"), @@ -96,7 +95,7 @@ def from_dict(cls, obj: dict) -> Order: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["id", "petId", "quantity", "shipDate", "status", "complete"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/outer_composite.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/outer_composite.py index 478c1b53622b..d90223f6acf4 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/outer_composite.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/outer_composite.py @@ -29,7 +29,6 @@ class OuterComposite(BaseModel): my_string: Optional[StrictStr] = None my_boolean: Optional[StrictBool] = None additional_properties: Dict[str, Any] = {} - __properties = ["my_number", "my_string", "my_boolean"] """Pydantic configuration""" model_config = { @@ -39,7 +38,7 @@ class OuterComposite(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -52,7 +51,7 @@ def from_json(cls, json_str: str) -> OuterComposite: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -71,16 +70,16 @@ def from_dict(cls, obj: dict) -> OuterComposite: return None if not isinstance(obj, dict): - return OuterComposite.parse_obj(obj) + return OuterComposite.model_validate(obj) - _obj = OuterComposite.parse_obj({ + _obj = OuterComposite.model_validate({ "my_number": obj.get("my_number"), "my_string": obj.get("my_string"), "my_boolean": obj.get("my_boolean") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["my_number", "my_string", "my_boolean"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/outer_object_with_enum_property.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/outer_object_with_enum_property.py index 8d7ad9f5c6d2..3d83ba884784 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/outer_object_with_enum_property.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/outer_object_with_enum_property.py @@ -30,7 +30,6 @@ class OuterObjectWithEnumProperty(BaseModel): str_value: Optional[OuterEnum] = None value: OuterEnumInteger = Field(...) additional_properties: Dict[str, Any] = {} - __properties = ["str_value", "value"] """Pydantic configuration""" model_config = { @@ -40,7 +39,7 @@ class OuterObjectWithEnumProperty(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -53,7 +52,7 @@ def from_json(cls, json_str: str) -> OuterObjectWithEnumProperty: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -65,7 +64,7 @@ def to_dict(self): # set to None if str_value (nullable) is None # and __fields_set__ contains the field - if self.str_value is None and "str_value" in self.__fields_set__: + if self.str_value is None and "str_value" in self.model_fields_set: _dict['str_value'] = None return _dict @@ -77,15 +76,15 @@ def from_dict(cls, obj: dict) -> OuterObjectWithEnumProperty: return None if not isinstance(obj, dict): - return OuterObjectWithEnumProperty.parse_obj(obj) + return OuterObjectWithEnumProperty.model_validate(obj) - _obj = OuterObjectWithEnumProperty.parse_obj({ + _obj = OuterObjectWithEnumProperty.model_validate({ "str_value": obj.get("str_value"), "value": obj.get("value") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["str_value", "value"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/parent.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/parent.py index f06c8c6f94e4..181958dc1140 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/parent.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/parent.py @@ -28,7 +28,6 @@ class Parent(BaseModel): """ optional_dict: Optional[Dict[str, InnerDictWithProperty]] = Field(None, alias="optionalDict") additional_properties: Dict[str, Any] = {} - __properties = ["optionalDict"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class Parent(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> Parent: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -77,9 +76,9 @@ def from_dict(cls, obj: dict) -> Parent: return None if not isinstance(obj, dict): - return Parent.parse_obj(obj) + return Parent.model_validate(obj) - _obj = Parent.parse_obj({ + _obj = Parent.model_validate({ "optional_dict": dict( (_k, InnerDictWithProperty.from_dict(_v)) for _k, _v in obj.get("optionalDict").items() @@ -89,7 +88,7 @@ def from_dict(cls, obj: dict) -> Parent: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["optionalDict"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/parent_with_optional_dict.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/parent_with_optional_dict.py index 229a0b5f6e23..dde2bcd774a0 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/parent_with_optional_dict.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/parent_with_optional_dict.py @@ -28,7 +28,6 @@ class ParentWithOptionalDict(BaseModel): """ optional_dict: Optional[Dict[str, InnerDictWithProperty]] = Field(None, alias="optionalDict") additional_properties: Dict[str, Any] = {} - __properties = ["optionalDict"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class ParentWithOptionalDict(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> ParentWithOptionalDict: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -77,9 +76,9 @@ def from_dict(cls, obj: dict) -> ParentWithOptionalDict: return None if not isinstance(obj, dict): - return ParentWithOptionalDict.parse_obj(obj) + return ParentWithOptionalDict.model_validate(obj) - _obj = ParentWithOptionalDict.parse_obj({ + _obj = ParentWithOptionalDict.model_validate({ "optional_dict": dict( (_k, InnerDictWithProperty.from_dict(_v)) for _k, _v in obj.get("optionalDict").items() @@ -89,7 +88,7 @@ def from_dict(cls, obj: dict) -> ParentWithOptionalDict: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["optionalDict"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/pet.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/pet.py index dee18eb28c9c..f5ebae825c7c 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/pet.py @@ -19,7 +19,7 @@ from typing import Any, Dict, List, Optional -from pydantic import BaseModel, Field, StrictInt, StrictStr, conlist, validator +from pydantic import BaseModel, Field, StrictInt, StrictStr, conlist, field_validator from petstore_api.models.category import Category from petstore_api.models.tag import Tag @@ -34,9 +34,8 @@ class Pet(BaseModel): tags: Optional[conlist(Tag)] = None status: Optional[StrictStr] = Field(None, description="pet status in the store") additional_properties: Dict[str, Any] = {} - __properties = ["id", "category", "name", "photoUrls", "tags", "status"] - @validator('status') + @field_validator('status') def status_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -54,7 +53,7 @@ def status_validate_enum(cls, value): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -67,7 +66,7 @@ def from_json(cls, json_str: str) -> Pet: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -96,9 +95,9 @@ def from_dict(cls, obj: dict) -> Pet: return None if not isinstance(obj, dict): - return Pet.parse_obj(obj) + return Pet.model_validate(obj) - _obj = Pet.parse_obj({ + _obj = Pet.model_validate({ "id": obj.get("id"), "category": Category.from_dict(obj.get("category")) if obj.get("category") is not None else None, "name": obj.get("name"), @@ -108,7 +107,7 @@ def from_dict(cls, obj: dict) -> Pet: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["id", "category", "name", "photoUrls", "tags", "status"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/pig.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/pig.py index 7ceaec51ee85..81335b164e87 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/pig.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/pig.py @@ -19,7 +19,7 @@ import re # noqa: F401 from typing import Any, List, Optional -from pydantic import BaseModel, Field, StrictStr, ValidationError, validator +from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator from petstore_api.models.basque_pig import BasquePig from petstore_api.models.danish_pig import DanishPig from typing import Union, Any, List, TYPE_CHECKING @@ -42,7 +42,7 @@ class Pig(BaseModel): if TYPE_CHECKING: actual_instance: Union[BasquePig, DanishPig] else: - actual_instance: Any + actual_instance: Any = None one_of_schemas: List[str] = Literal["BasquePig", "DanishPig"] @@ -51,9 +51,6 @@ class Pig(BaseModel): "validate_assignment": True, } - discriminator_value_class_map = { - } - def __init__(self, *args, **kwargs) -> None: if args: if len(args) > 1: @@ -61,26 +58,32 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) - @validator('actual_instance') + @field_validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): - instance = Pig.construct() + instance = Pig.model_construct() error_messages = [] match = 0 # validate data type: BasquePig - if not isinstance(v, BasquePig): - error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`") - else: + try: + instance.oneof_schema_1_validator = v match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) # validate data type: DanishPig - if not isinstance(v, DanishPig): - error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`") - else: + try: + instance.oneof_schema_2_validator = v match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when setting `actual_instance` in Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -95,7 +98,7 @@ def from_dict(cls, obj: dict) -> Pig: @classmethod def from_json(cls, json_str: str) -> Pig: """Returns the object represented by the json string""" - instance = Pig.construct() + instance = Pig.model_construct() error_messages = [] match = 0 @@ -129,6 +132,8 @@ def from_json(cls, json_str: str) -> Pig: if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when deserializing the JSON string into Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -161,6 +166,6 @@ def to_dict(self) -> dict: def to_str(self) -> str: """Returns the string representation of the actual instance""" - return pprint.pformat(self.dict()) + return pprint.pformat(self.model_dump()) diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/property_name_collision.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/property_name_collision.py index 0bc34c0540c2..63554d1d89f4 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/property_name_collision.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/property_name_collision.py @@ -29,7 +29,6 @@ class PropertyNameCollision(BaseModel): type: Optional[StrictStr] = None type_with_underscore: Optional[StrictStr] = Field(None, alias="type_") additional_properties: Dict[str, Any] = {} - __properties = ["_type", "type", "type_"] """Pydantic configuration""" model_config = { @@ -39,7 +38,7 @@ class PropertyNameCollision(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -52,7 +51,7 @@ def from_json(cls, json_str: str) -> PropertyNameCollision: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -71,16 +70,16 @@ def from_dict(cls, obj: dict) -> PropertyNameCollision: return None if not isinstance(obj, dict): - return PropertyNameCollision.parse_obj(obj) + return PropertyNameCollision.model_validate(obj) - _obj = PropertyNameCollision.parse_obj({ + _obj = PropertyNameCollision.model_validate({ "underscore_type": obj.get("_type"), "type": obj.get("type"), "type_with_underscore": obj.get("type_") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["_type", "type", "type_"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/read_only_first.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/read_only_first.py index b158341ff4c8..fba35533e476 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/read_only_first.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/read_only_first.py @@ -28,7 +28,6 @@ class ReadOnlyFirst(BaseModel): bar: Optional[StrictStr] = None baz: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["bar", "baz"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class ReadOnlyFirst(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> ReadOnlyFirst: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "bar", "additional_properties" @@ -71,15 +70,15 @@ def from_dict(cls, obj: dict) -> ReadOnlyFirst: return None if not isinstance(obj, dict): - return ReadOnlyFirst.parse_obj(obj) + return ReadOnlyFirst.model_validate(obj) - _obj = ReadOnlyFirst.parse_obj({ + _obj = ReadOnlyFirst.model_validate({ "bar": obj.get("bar"), "baz": obj.get("baz") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["bar", "baz"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/second_ref.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/second_ref.py index f4583d5fd584..219b6ebfbba3 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/second_ref.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/second_ref.py @@ -28,7 +28,6 @@ class SecondRef(BaseModel): category: Optional[StrictStr] = None circular_ref: Optional[CircularReferenceModel] = None additional_properties: Dict[str, Any] = {} - __properties = ["category", "circular_ref"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class SecondRef(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> SecondRef: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -73,19 +72,22 @@ def from_dict(cls, obj: dict) -> SecondRef: return None if not isinstance(obj, dict): - return SecondRef.parse_obj(obj) + return SecondRef.model_validate(obj) - _obj = SecondRef.parse_obj({ + _obj = SecondRef.model_validate({ "category": obj.get("category"), "circular_ref": CircularReferenceModel.from_dict(obj.get("circular_ref")) if obj.get("circular_ref") is not None else None }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["category", "circular_ref"]: _obj.additional_properties[_key] = obj.get(_key) return _obj from petstore_api.models.circular_reference_model import CircularReferenceModel -SecondRef.update_forward_refs() +try: + SecondRef.model_rebuild() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/self_reference_model.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/self_reference_model.py index fb6699d8ca33..ecad3b7a2357 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/self_reference_model.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/self_reference_model.py @@ -28,7 +28,6 @@ class SelfReferenceModel(BaseModel): size: Optional[StrictInt] = None nested: Optional[DummyModel] = None additional_properties: Dict[str, Any] = {} - __properties = ["size", "nested"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class SelfReferenceModel(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> SelfReferenceModel: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -73,19 +72,22 @@ def from_dict(cls, obj: dict) -> SelfReferenceModel: return None if not isinstance(obj, dict): - return SelfReferenceModel.parse_obj(obj) + return SelfReferenceModel.model_validate(obj) - _obj = SelfReferenceModel.parse_obj({ + _obj = SelfReferenceModel.model_validate({ "size": obj.get("size"), "nested": DummyModel.from_dict(obj.get("nested")) if obj.get("nested") is not None else None }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["size", "nested"]: _obj.additional_properties[_key] = obj.get(_key) return _obj from petstore_api.models.dummy_model import DummyModel -SelfReferenceModel.update_forward_refs() +try: + SelfReferenceModel.model_rebuild() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/special_model_name.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/special_model_name.py index 9d4671a535e8..eaeba63d4c56 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/special_model_name.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/special_model_name.py @@ -27,7 +27,6 @@ class SpecialModelName(BaseModel): """ special_property_name: Optional[StrictInt] = Field(None, alias="$special[property.name]") additional_properties: Dict[str, Any] = {} - __properties = ["$special[property.name]"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class SpecialModelName(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> SpecialModelName: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> SpecialModelName: return None if not isinstance(obj, dict): - return SpecialModelName.parse_obj(obj) + return SpecialModelName.model_validate(obj) - _obj = SpecialModelName.parse_obj({ + _obj = SpecialModelName.model_validate({ "special_property_name": obj.get("$special[property.name]") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["$special[property.name]"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/special_name.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/special_name.py index 0c1db5f7d2ec..2dfa625e8188 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/special_name.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/special_name.py @@ -19,7 +19,7 @@ from typing import Any, Dict, Optional -from pydantic import BaseModel, Field, StrictInt, StrictStr, validator +from pydantic import BaseModel, Field, StrictInt, StrictStr, field_validator from petstore_api.models.category import Category class SpecialName(BaseModel): @@ -30,9 +30,8 @@ class SpecialName(BaseModel): var_async: Optional[Category] = Field(None, alias="async") var_schema: Optional[StrictStr] = Field(None, alias="schema", description="pet status in the store") additional_properties: Dict[str, Any] = {} - __properties = ["property", "async", "schema"] - @validator('var_schema') + @field_validator('var_schema') def var_schema_validate_enum(cls, value): """Validates the enum""" if value is None: @@ -50,7 +49,7 @@ def var_schema_validate_enum(cls, value): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -63,7 +62,7 @@ def from_json(cls, json_str: str) -> SpecialName: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -85,16 +84,16 @@ def from_dict(cls, obj: dict) -> SpecialName: return None if not isinstance(obj, dict): - return SpecialName.parse_obj(obj) + return SpecialName.model_validate(obj) - _obj = SpecialName.parse_obj({ + _obj = SpecialName.model_validate({ "var_property": obj.get("property"), "var_async": Category.from_dict(obj.get("async")) if obj.get("async") is not None else None, "var_schema": obj.get("schema") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["property", "async", "schema"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/tag.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/tag.py index 76347c44fe18..b128fee5e740 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/tag.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/tag.py @@ -28,7 +28,6 @@ class Tag(BaseModel): id: Optional[StrictInt] = None name: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["id", "name"] """Pydantic configuration""" model_config = { @@ -38,7 +37,7 @@ class Tag(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -51,7 +50,7 @@ def from_json(cls, json_str: str) -> Tag: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -70,15 +69,15 @@ def from_dict(cls, obj: dict) -> Tag: return None if not isinstance(obj, dict): - return Tag.parse_obj(obj) + return Tag.model_validate(obj) - _obj = Tag.parse_obj({ + _obj = Tag.model_validate({ "id": obj.get("id"), "name": obj.get("name") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["id", "name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/tiger.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/tiger.py index 7c1c35949194..1236029d81f9 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/tiger.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/tiger.py @@ -27,7 +27,6 @@ class Tiger(BaseModel): """ skill: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["skill"] """Pydantic configuration""" model_config = { @@ -37,7 +36,7 @@ class Tiger(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -50,7 +49,7 @@ def from_json(cls, json_str: str) -> Tiger: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -69,14 +68,14 @@ def from_dict(cls, obj: dict) -> Tiger: return None if not isinstance(obj, dict): - return Tiger.parse_obj(obj) + return Tiger.model_validate(obj) - _obj = Tiger.parse_obj({ + _obj = Tiger.model_validate({ "skill": obj.get("skill") }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["skill"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/user.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/user.py index c4791674d1b1..3b77e98fb1b7 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/user.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/user.py @@ -34,7 +34,6 @@ class User(BaseModel): phone: Optional[StrictStr] = None user_status: Optional[StrictInt] = Field(None, alias="userStatus", description="User Status") additional_properties: Dict[str, Any] = {} - __properties = ["id", "username", "firstName", "lastName", "email", "password", "phone", "userStatus"] """Pydantic configuration""" model_config = { @@ -44,7 +43,7 @@ class User(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -57,7 +56,7 @@ def from_json(cls, json_str: str) -> User: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -76,9 +75,9 @@ def from_dict(cls, obj: dict) -> User: return None if not isinstance(obj, dict): - return User.parse_obj(obj) + return User.model_validate(obj) - _obj = User.parse_obj({ + _obj = User.model_validate({ "id": obj.get("id"), "username": obj.get("username"), "first_name": obj.get("firstName"), @@ -90,7 +89,7 @@ def from_dict(cls, obj: dict) -> User: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["id", "username", "firstName", "lastName", "email", "password", "phone", "userStatus"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/with_nested_one_of.py b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/with_nested_one_of.py index 3dc7c65504c6..b0d7c6fabf97 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/with_nested_one_of.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/with_nested_one_of.py @@ -31,7 +31,6 @@ class WithNestedOneOf(BaseModel): nested_pig: Optional[Pig] = None nested_oneof_enum_string: Optional[OneOfEnumString] = None additional_properties: Dict[str, Any] = {} - __properties = ["size", "nested_pig", "nested_oneof_enum_string"] """Pydantic configuration""" model_config = { @@ -41,7 +40,7 @@ class WithNestedOneOf(BaseModel): def to_str(self) -> str: """Returns the string representation of the model using alias""" - return pprint.pformat(self.dict(by_alias=True)) + return pprint.pformat(self.model_dump(by_alias=True)) def to_json(self) -> str: """Returns the JSON representation of the model using alias""" @@ -54,7 +53,7 @@ def from_json(cls, json_str: str) -> WithNestedOneOf: def to_dict(self): """Returns the dictionary representation of the model using alias""" - _dict = self.dict(by_alias=True, + _dict = self.model_dump(by_alias=True, exclude={ "additional_properties" }, @@ -79,16 +78,16 @@ def from_dict(cls, obj: dict) -> WithNestedOneOf: return None if not isinstance(obj, dict): - return WithNestedOneOf.parse_obj(obj) + return WithNestedOneOf.model_validate(obj) - _obj = WithNestedOneOf.parse_obj({ + _obj = WithNestedOneOf.model_validate({ "size": obj.get("size"), "nested_pig": Pig.from_dict(obj.get("nested_pig")) if obj.get("nested_pig") is not None else None, "nested_oneof_enum_string": OneOfEnumString.from_dict(obj.get("nested_oneof_enum_string")) if obj.get("nested_oneof_enum_string") is not None else None }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["size", "nested_pig", "nested_oneof_enum_string"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/test/test_circular_reference_model.py b/samples/openapi3/client/petstore/python-pydantic-v2/test/test_circular_reference_model.py new file mode 100644 index 000000000000..f23f02000225 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v2/test/test_circular_reference_model.py @@ -0,0 +1,60 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.circular_reference_model import CircularReferenceModel # noqa: E501 + +class TestCircularReferenceModel(unittest.TestCase): + """CircularReferenceModel unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> CircularReferenceModel: + """Test CircularReferenceModel + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `CircularReferenceModel` + """ + model = CircularReferenceModel() # noqa: E501 + if include_optional: + return CircularReferenceModel( + size = 56, + nested = petstore_api.models.first_ref.FirstRef( + category = '', + self_ref = petstore_api.models.second_ref.SecondRef( + category = '', + circular_ref = petstore_api.models.circular_reference_model.Circular-Reference-Model( + size = 56, + nested = petstore_api.models.first_ref.FirstRef( + category = '', ), ), ), ) + ) + else: + return CircularReferenceModel( + ) + """ + + def testCircularReferenceModel(self): + """Test CircularReferenceModel""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/test/test_first_ref.py b/samples/openapi3/client/petstore/python-pydantic-v2/test/test_first_ref.py new file mode 100644 index 000000000000..a99fc7cfc796 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v2/test/test_first_ref.py @@ -0,0 +1,58 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.first_ref import FirstRef # noqa: E501 + +class TestFirstRef(unittest.TestCase): + """FirstRef unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> FirstRef: + """Test FirstRef + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `FirstRef` + """ + model = FirstRef() # noqa: E501 + if include_optional: + return FirstRef( + category = '', + self_ref = petstore_api.models.second_ref.SecondRef( + category = '', + circular_ref = petstore_api.models.circular_reference_model.Circular-Reference-Model( + size = 56, + nested = petstore_api.models.first_ref.FirstRef( + category = '', ), ), ) + ) + else: + return FirstRef( + ) + """ + + def testFirstRef(self): + """Test FirstRef""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/test/test_second_ref.py b/samples/openapi3/client/petstore/python-pydantic-v2/test/test_second_ref.py new file mode 100644 index 000000000000..44194f94544f --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v2/test/test_second_ref.py @@ -0,0 +1,58 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.second_ref import SecondRef # noqa: E501 + +class TestSecondRef(unittest.TestCase): + """SecondRef unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> SecondRef: + """Test SecondRef + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `SecondRef` + """ + model = SecondRef() # noqa: E501 + if include_optional: + return SecondRef( + category = '', + circular_ref = petstore_api.models.circular_reference_model.Circular-Reference-Model( + size = 56, + nested = petstore_api.models.first_ref.FirstRef( + category = '', + self_ref = petstore_api.models.second_ref.SecondRef( + category = '', ), ), ) + ) + else: + return SecondRef( + ) + """ + + def testSecondRef(self): + """Test SecondRef""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/tests/test_api_validation.py b/samples/openapi3/client/petstore/python-pydantic-v2/tests/test_api_validation.py index dc7da96329c0..c14d5b572af6 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/tests/test_api_validation.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/tests/test_api_validation.py @@ -51,23 +51,25 @@ def test_required_param_validation(self): try: self.pet_api.get_pet_by_id() except ValidationError as e: - self.assertEqual(str(e), "1 validation error for GetPetById\n" + self.assertEqual(str(e), "1 validation error for get_pet_by_id\n" "pet_id\n" - " field required (type=value_error.missing)") + " Missing required argument [type=missing_argument, input_value=ArgsKwargs(()), input_type=ArgsKwargs]\n" + " For further information visit https://errors.pydantic.dev/2.3/v/missing_argument") def test_integer_validation(self): try: self.pet_api.get_pet_by_id("123") except ValidationError as e: - self.assertEqual(str(e), "1 validation error for GetPetById\n" - "pet_id\n" - " value is not a valid integer (type=type_error.integer)") + self.assertEqual(str(e), "1 validation error for get_pet_by_id\n" + "0\n" + " Input should be a valid integer [type=int_type, input_value='123', input_type=str]\n"+ + " For further information visit https://errors.pydantic.dev/2.3/v/int_type") def test_string_enum_validation(self): try: self.pet_api.find_pets_by_status(["Cat"]) except ValidationError as e: - self.assertEqual(str(e), "1 validation error for FindPetsByStatus\n" + self.assertEqual(str(e), "1 validation error for find_pets_by_status\n" "status -> 0\n" " unexpected value; permitted: 'available', 'pending', 'sold' (" "type=value_error.const; given=Cat; permitted=('available', 'pending', 'sold'))") diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/tests/test_model.py b/samples/openapi3/client/petstore/python-pydantic-v2/tests/test_model.py index 01d5d001fab8..fb62780a254f 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v2/tests/test_model.py +++ b/samples/openapi3/client/petstore/python-pydantic-v2/tests/test_model.py @@ -93,12 +93,12 @@ def test_oneOf_array_of_integers(self): try: new_color.oneof_schema_1_validator = array_of_integers except ValueError as e: - self.assertTrue("ensure this value is less than or equal to 255" in str(e)) + self.assertTrue("1 validation error for Color" in str(e)) try: new_color.actual_instance = array_of_integers except ValueError as e: - self.assertTrue("ensure this value is less than or equal to 255" in str(e)) + self.assertTrue("1 validation error for Color" in str(e)) # test from_josn json_str = '[12,34,56]' @@ -108,7 +108,7 @@ def test_oneOf_array_of_integers(self): try: p = petstore_api.Color.from_json('[2342112,0,0,0]') except ValueError as e: - self.assertTrue("ensure this value is less than or equal to 255" in str(e)) + self.assertTrue("1 validation error for Color" in str(e)) # test to_json, to_dict method json_str = '[12,34,56]' @@ -170,12 +170,12 @@ def test_anyOf_array_of_integers(self): try: new_color.anyof_schema_1_validator = array_of_integers except ValueError as e: - self.assertTrue("ensure this value is less than or equal to 255" in str(e)) + self.assertTrue("1 validation error for AnyOfColor" in str(e)) try: new_color.actual_instance = array_of_integers except ValueError as e: - self.assertTrue("ensure this value is less than or equal to 255" in str(e)) + self.assertTrue("1 validation error for AnyOfColor" in str(e)) # test from_josn json_str = '[12,34,56]' @@ -185,7 +185,7 @@ def test_anyOf_array_of_integers(self): try: p = petstore_api.AnyOfColor.from_json('[2342112,0,0,0]') except ValueError as e: - self.assertTrue("ensure this value is less than or equal to 255" in str(e)) + self.assertTrue("1 validation error for AnyOfColor" in str(e)) def test_oneOf(self): # test new Pig @@ -291,13 +291,14 @@ def test_anyOf(self): p2 = petstore_api.AnyOfPig.from_json("1") self.assertTrue(False) # this line shouldn't execute except ValueError as e: + self.maxDiff = None error_message = ( "No match found when deserializing the JSON string into AnyOfPig with anyOf schemas: BasquePig, " "DanishPig. Details: 1 validation error for BasquePig\n" - "__root__\n" - " BasquePig expected dict not int (type=type_error), 1 validation error for DanishPig\n" - "__root__\n" - " DanishPig expected dict not int (type=type_error)") + " Input should be a valid dictionary or instance of BasquePig [type=model_type, input_value=1, input_type=int]\n" + " For further information visit https://errors.pydantic.dev/2.3/v/model_type, 1 validation error for DanishPig\n" + " Input should be a valid dictionary or instance of DanishPig [type=model_type, input_value=1, input_type=int]\n" + " For further information visit https://errors.pydantic.dev/2.3/v/model_type") self.assertEqual(str(e), error_message) # test to_json @@ -321,9 +322,10 @@ def test_list(self): except ValueError as e: #error_message = ( # "1 validation error for List\n" - # "123-list\n" - # " str type expected (type=type_error.str)\n") - self.assertTrue("str type expected" in str(e)) + # "var_123_list\n" + # " Input should be a valid string [type=string_type, input_value=123, input_type=int]\n" + # " For further information visit https://errors.pydantic.dev/2.3/v/string_type + self.assertTrue("Input should be a valid string" in str(e)) l = petstore_api.List(var_123_list="bulldog") self.assertEqual(l.to_json(), '{"123-list": "bulldog"}') @@ -348,9 +350,9 @@ def test_enum_ref_property(self): d4 = petstore_api.OuterObjectWithEnumProperty(value=petstore_api.OuterEnumInteger.NUMBER_1, str_value=None) self.assertEqual(d4.to_json(), '{"value": 1, "str_value": null}') d5 = petstore_api.OuterObjectWithEnumProperty(value=petstore_api.OuterEnumInteger.NUMBER_1) - self.assertEqual(d5.__fields_set__, {'value'}) + self.assertEqual(d5.model_fields_set, {'value'}) d5.str_value = None # set None explicitly - self.assertEqual(d5.__fields_set__, {'value', 'str_value'}) + self.assertEqual(d5.model_fields_set, {'value', 'str_value'}) self.assertEqual(d5.to_json(), '{"value": 1, "str_value": null}') def test_valdiator(self): @@ -482,7 +484,7 @@ def test_int_or_string_oneof(self): try: a = petstore_api.IntOrString(1) except ValueError as e: - self.assertTrue("ensure this value is greater than or equal to 10" in str(e)) + self.assertTrue("1 validation error for IntOrString" in str(e)) def test_map_of_array_of_model(self): a = petstore_api.MapOfArrayOfModel() diff --git a/samples/openapi3/client/petstore/python-pydantic-v2/tox.ini b/samples/openapi3/client/petstore/python-pydantic-v2/tox.ini index 49d3f9352a6c..8989fc3c4d96 100755 --- a/samples/openapi3/client/petstore/python-pydantic-v2/tox.ini +++ b/samples/openapi3/client/petstore/python-pydantic-v2/tox.ini @@ -6,4 +6,4 @@ deps=-r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt commands= - pytest --cov=petstore_api test/test_model.py + pytest --cov=petstore_api diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_any_type.py b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_any_type.py index eba260e84f41..89f2b10fc197 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_any_type.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_any_type.py @@ -27,7 +27,6 @@ class AdditionalPropertiesAnyType(BaseModel): """ name: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["name"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> AdditionalPropertiesAnyType: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_class.py index f7c4f8663e89..532c78772af3 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_class.py @@ -28,7 +28,6 @@ class AdditionalPropertiesClass(BaseModel): map_property: Optional[Dict[str, StrictStr]] = None map_of_map_property: Optional[Dict[str, Dict[str, StrictStr]]] = None additional_properties: Dict[str, Any] = {} - __properties = ["map_property", "map_of_map_property"] """Pydantic configuration""" class Config: @@ -77,7 +76,7 @@ def from_dict(cls, obj: dict) -> AdditionalPropertiesClass: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["map_property", "map_of_map_property"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_object.py b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_object.py index 14707fa99697..f30640a9b562 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_object.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_object.py @@ -27,7 +27,6 @@ class AdditionalPropertiesObject(BaseModel): """ name: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["name"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> AdditionalPropertiesObject: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_with_description_only.py b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_with_description_only.py index 3c64a8134d65..c6c38c9eb3ec 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_with_description_only.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_with_description_only.py @@ -27,7 +27,6 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel): """ name: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["name"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> AdditionalPropertiesWithDescriptionOnly: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/all_of_with_single_ref.py b/samples/openapi3/client/petstore/python/petstore_api/models/all_of_with_single_ref.py index b28814c3a4ca..325491e077fb 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/all_of_with_single_ref.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/all_of_with_single_ref.py @@ -29,7 +29,6 @@ class AllOfWithSingleRef(BaseModel): username: Optional[StrictStr] = None single_ref_type: Optional[SingleRefType] = Field(None, alias="SingleRefType") additional_properties: Dict[str, Any] = {} - __properties = ["username", "SingleRefType"] """Pydantic configuration""" class Config: @@ -78,7 +77,7 @@ def from_dict(cls, obj: dict) -> AllOfWithSingleRef: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["username", "SingleRefType"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/animal.py b/samples/openapi3/client/petstore/python/petstore_api/models/animal.py index a4a2f85ec7ff..9fbf48c7183f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/animal.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/animal.py @@ -28,7 +28,6 @@ class Animal(BaseModel): class_name: StrictStr = Field(..., alias="className") color: Optional[StrictStr] = 'red' additional_properties: Dict[str, Any] = {} - __properties = ["className", "color"] """Pydantic configuration""" class Config: @@ -36,20 +35,17 @@ class Config: validate_assignment = True # JSON field name that stores the object type - __discriminator_property_name = 'className' - - # discriminator mappings - __discriminator_value_class_map = { - 'Cat': 'Cat', - 'Dog': 'Dog' - } @classmethod def get_discriminator_value(cls, obj: dict) -> str: """Returns the discriminator value (object type) of the data""" - discriminator_value = obj[cls.__discriminator_property_name] + discriminator_value = obj['className'] + discriminator_value_class_map = { + 'Cat': 'Cat','Dog': 'Dog' + } + if discriminator_value: - return cls.__discriminator_value_class_map.get(discriminator_value) + return discriminator_value_class_map.get(discriminator_value) else: return None @@ -85,15 +81,21 @@ def from_dict(cls, obj: dict) -> Union(Cat, Dog): """Create an instance of Animal from a dict""" # look up the object type based on discriminator mapping object_type = cls.get_discriminator_value(obj) + discriminator_value_class_map = { + 'Cat': 'Cat','Dog': 'Dog' + } if object_type: klass = globals()[object_type] return klass.from_dict(obj) else: raise ValueError("Animal failed to lookup discriminator value from " + - json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + - ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) + json.dumps(obj) + ". Discriminator property name: " + 'className' + + ", mapping: " + json.dumps(discriminator_value_class_map)) from petstore_api.models.cat import Cat from petstore_api.models.dog import Dog -Animal.update_forward_refs() +try: + Animal.update_forward_refs() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py b/samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py index 79eece679cda..caea52cba72c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/any_of_color.py @@ -38,7 +38,7 @@ class AnyOfColor(BaseModel): if TYPE_CHECKING: actual_instance: Union[List[int], str] else: - actual_instance: Any + actual_instance: Any = None any_of_schemas: List[str] = Field(ANYOFCOLOR_ANY_OF_SCHEMAS, const=True) """Pydantic configuration""" @@ -52,8 +52,10 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) @validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/any_of_pig.py b/samples/openapi3/client/petstore/python/petstore_api/models/any_of_pig.py index 30274e51269a..4e9c82be45a0 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/any_of_pig.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/any_of_pig.py @@ -38,7 +38,7 @@ class AnyOfPig(BaseModel): if TYPE_CHECKING: actual_instance: Union[BasquePig, DanishPig] else: - actual_instance: Any + actual_instance: Any = None any_of_schemas: List[str] = Field(ANYOFPIG_ANY_OF_SCHEMAS, const=True) """Pydantic configuration""" @@ -52,25 +52,27 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) @validator('actual_instance') def actual_instance_must_validate_anyof(cls, v): instance = AnyOfPig.construct() error_messages = [] # validate data type: BasquePig - if not isinstance(v, BasquePig): - error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`") - else: + try: + instance.anyof_schema_1_validator = v return v - + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) # validate data type: DanishPig - if not isinstance(v, DanishPig): - error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`") - else: + try: + instance.anyof_schema_2_validator = v return v - + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) if error_messages: # no match raise ValueError("No match found when setting the actual_instance in AnyOfPig with anyOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/api_response.py b/samples/openapi3/client/petstore/python/petstore_api/models/api_response.py index 56e7928f07be..112dbba70820 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/api_response.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/api_response.py @@ -29,7 +29,6 @@ class ApiResponse(BaseModel): type: Optional[StrictStr] = None message: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["code", "type", "message"] """Pydantic configuration""" class Config: @@ -79,7 +78,7 @@ def from_dict(cls, obj: dict) -> ApiResponse: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["code", "type", "message"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_model.py index 293c13902dbe..9a3773162d43 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_model.py @@ -28,7 +28,6 @@ class ArrayOfArrayOfModel(BaseModel): """ another_property: Optional[conlist(conlist(Tag))] = None additional_properties: Dict[str, Any] = {} - __properties = ["another_property"] """Pydantic configuration""" class Config: @@ -88,7 +87,7 @@ def from_dict(cls, obj: dict) -> ArrayOfArrayOfModel: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["another_property"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py index 2a52c2936ba1..9caaf1133cd9 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py @@ -27,7 +27,6 @@ class ArrayOfArrayOfNumberOnly(BaseModel): """ array_array_number: Optional[conlist(conlist(StrictFloat))] = Field(None, alias="ArrayArrayNumber") additional_properties: Dict[str, Any] = {} - __properties = ["ArrayArrayNumber"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> ArrayOfArrayOfNumberOnly: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["ArrayArrayNumber"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_number_only.py b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_number_only.py index 10dd656729ce..590eb855e911 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_number_only.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_number_only.py @@ -27,7 +27,6 @@ class ArrayOfNumberOnly(BaseModel): """ array_number: Optional[conlist(StrictFloat)] = Field(None, alias="ArrayNumber") additional_properties: Dict[str, Any] = {} - __properties = ["ArrayNumber"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> ArrayOfNumberOnly: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["ArrayNumber"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py index 8fcc378f6d48..83e43f0590a5 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py @@ -30,7 +30,6 @@ class ArrayTest(BaseModel): array_array_of_integer: Optional[conlist(conlist(StrictInt))] = None array_array_of_model: Optional[conlist(conlist(ReadOnlyFirst))] = None additional_properties: Dict[str, Any] = {} - __properties = ["array_of_string", "array_array_of_integer", "array_array_of_model"] """Pydantic configuration""" class Config: @@ -92,7 +91,7 @@ def from_dict(cls, obj: dict) -> ArrayTest: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["array_of_string", "array_array_of_integer", "array_array_of_model"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/basque_pig.py b/samples/openapi3/client/petstore/python/petstore_api/models/basque_pig.py index e1455ef6aac3..53bfd2b137f2 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/basque_pig.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/basque_pig.py @@ -28,7 +28,6 @@ class BasquePig(BaseModel): class_name: StrictStr = Field(..., alias="className") color: StrictStr = Field(...) additional_properties: Dict[str, Any] = {} - __properties = ["className", "color"] """Pydantic configuration""" class Config: @@ -77,7 +76,7 @@ def from_dict(cls, obj: dict) -> BasquePig: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["className", "color"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py b/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py index b5b6be2e7b1f..530f8ee7b343 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py @@ -32,7 +32,6 @@ class Capitalization(BaseModel): sca_eth_flow_points: Optional[StrictStr] = Field(None, alias="SCA_ETH_Flow_Points") att_name: Optional[StrictStr] = Field(None, alias="ATT_NAME", description="Name of the pet ") additional_properties: Dict[str, Any] = {} - __properties = ["smallCamel", "CapitalCamel", "small_Snake", "Capital_Snake", "SCA_ETH_Flow_Points", "ATT_NAME"] """Pydantic configuration""" class Config: @@ -85,7 +84,7 @@ def from_dict(cls, obj: dict) -> Capitalization: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["smallCamel", "CapitalCamel", "small_Snake", "Capital_Snake", "SCA_ETH_Flow_Points", "ATT_NAME"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/cat.py b/samples/openapi3/client/petstore/python/petstore_api/models/cat.py index a0767dcda8db..85b3f6cd5438 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/cat.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/cat.py @@ -28,7 +28,6 @@ class Cat(Animal): """ declawed: Optional[StrictBool] = None additional_properties: Dict[str, Any] = {} - __properties = ["className", "color", "declawed"] """Pydantic configuration""" class Config: @@ -78,7 +77,7 @@ def from_dict(cls, obj: dict) -> Cat: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["className", "color", "declawed"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/category.py b/samples/openapi3/client/petstore/python/petstore_api/models/category.py index e741639d3d26..a4777afedcd1 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/category.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/category.py @@ -28,7 +28,6 @@ class Category(BaseModel): id: Optional[StrictInt] = None name: StrictStr = Field(...) additional_properties: Dict[str, Any] = {} - __properties = ["id", "name"] """Pydantic configuration""" class Config: @@ -77,7 +76,7 @@ def from_dict(cls, obj: dict) -> Category: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["id", "name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/circular_reference_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/circular_reference_model.py index 4c65c3e7e9df..3bc5fd8666e4 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/circular_reference_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/circular_reference_model.py @@ -28,7 +28,6 @@ class CircularReferenceModel(BaseModel): size: Optional[StrictInt] = None nested: Optional[FirstRef] = None additional_properties: Dict[str, Any] = {} - __properties = ["size", "nested"] """Pydantic configuration""" class Config: @@ -80,11 +79,14 @@ def from_dict(cls, obj: dict) -> CircularReferenceModel: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["size", "nested"]: _obj.additional_properties[_key] = obj.get(_key) return _obj from petstore_api.models.first_ref import FirstRef -CircularReferenceModel.update_forward_refs() +try: + CircularReferenceModel.update_forward_refs() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/class_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/class_model.py index 8dbe440495f4..b07086e5fb0f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/class_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/class_model.py @@ -27,7 +27,6 @@ class ClassModel(BaseModel): """ var_class: Optional[StrictStr] = Field(None, alias="_class") additional_properties: Dict[str, Any] = {} - __properties = ["_class"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> ClassModel: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["_class"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/client.py b/samples/openapi3/client/petstore/python/petstore_api/models/client.py index d33089c7acf2..438d32b0ad58 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/client.py @@ -27,7 +27,6 @@ class Client(BaseModel): """ client: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["client"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> Client: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["client"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/color.py b/samples/openapi3/client/petstore/python/petstore_api/models/color.py index 574093092a01..51a35dba4d8f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/color.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/color.py @@ -35,9 +35,9 @@ class Color(BaseModel): # data type: str oneof_schema_3_validator: Optional[constr(strict=True, max_length=7, min_length=7)] = Field(None, description="Hex color string, such as #00FF00.") if TYPE_CHECKING: - actual_instance: Union[List[int], str] + actual_instance: Union[List[int], str, None] else: - actual_instance: Any + actual_instance: Any = None one_of_schemas: List[str] = Field(COLOR_ONE_OF_SCHEMAS, const=True) @@ -52,8 +52,10 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) @validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): @@ -83,6 +85,8 @@ def actual_instance_must_validate_oneof(cls, v): error_messages.append(str(e)) if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when setting `actual_instance` in Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -134,6 +138,8 @@ def from_json(cls, json_str: str) -> Color: if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when deserializing the JSON string into Color with oneOf schemas: List[int], str. Details: " + ", ".join(error_messages)) elif match == 0: # no match diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/creature.py b/samples/openapi3/client/petstore/python/petstore_api/models/creature.py index b825d112ffde..dc04d6cabefb 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/creature.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/creature.py @@ -29,7 +29,6 @@ class Creature(BaseModel): info: CreatureInfo = Field(...) type: StrictStr = Field(...) additional_properties: Dict[str, Any] = {} - __properties = ["info", "type"] """Pydantic configuration""" class Config: @@ -81,7 +80,7 @@ def from_dict(cls, obj: dict) -> Creature: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["info", "type"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/creature_info.py b/samples/openapi3/client/petstore/python/petstore_api/models/creature_info.py index 1e3f89ba59bc..db671f32ca63 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/creature_info.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/creature_info.py @@ -27,7 +27,6 @@ class CreatureInfo(BaseModel): """ name: StrictStr = Field(...) additional_properties: Dict[str, Any] = {} - __properties = ["name"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> CreatureInfo: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/danish_pig.py b/samples/openapi3/client/petstore/python/petstore_api/models/danish_pig.py index 63ac5adc7c93..be678472d38d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/danish_pig.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/danish_pig.py @@ -28,7 +28,6 @@ class DanishPig(BaseModel): class_name: StrictStr = Field(..., alias="className") size: StrictInt = Field(...) additional_properties: Dict[str, Any] = {} - __properties = ["className", "size"] """Pydantic configuration""" class Config: @@ -77,7 +76,7 @@ def from_dict(cls, obj: dict) -> DanishPig: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["className", "size"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/deprecated_object.py b/samples/openapi3/client/petstore/python/petstore_api/models/deprecated_object.py index 072a70136f7d..b6245ab754ef 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/deprecated_object.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/deprecated_object.py @@ -27,7 +27,6 @@ class DeprecatedObject(BaseModel): """ name: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["name"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> DeprecatedObject: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/dog.py b/samples/openapi3/client/petstore/python/petstore_api/models/dog.py index 8c64d451b9ed..c8fa1f3b7b97 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/dog.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/dog.py @@ -28,7 +28,6 @@ class Dog(Animal): """ breed: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["className", "color", "breed"] """Pydantic configuration""" class Config: @@ -78,7 +77,7 @@ def from_dict(cls, obj: dict) -> Dog: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["className", "color", "breed"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/dummy_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/dummy_model.py index fd5e54166033..41dd3be90cb2 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/dummy_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/dummy_model.py @@ -28,7 +28,6 @@ class DummyModel(BaseModel): category: Optional[StrictStr] = None self_ref: Optional[SelfReferenceModel] = None additional_properties: Dict[str, Any] = {} - __properties = ["category", "self_ref"] """Pydantic configuration""" class Config: @@ -80,11 +79,14 @@ def from_dict(cls, obj: dict) -> DummyModel: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["category", "self_ref"]: _obj.additional_properties[_key] = obj.get(_key) return _obj from petstore_api.models.self_reference_model import SelfReferenceModel -DummyModel.update_forward_refs() +try: + DummyModel.update_forward_refs() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_arrays.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_arrays.py index af6d88417552..ff1ffdd738bf 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_arrays.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_arrays.py @@ -28,7 +28,6 @@ class EnumArrays(BaseModel): just_symbol: Optional[StrictStr] = None array_enum: Optional[conlist(StrictStr)] = None additional_properties: Dict[str, Any] = {} - __properties = ["just_symbol", "array_enum"] @validator('just_symbol') def just_symbol_validate_enum(cls, value): @@ -98,7 +97,7 @@ def from_dict(cls, obj: dict) -> EnumArrays: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["just_symbol", "array_enum"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py index 0bae41973e41..d4bbd50c3994 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py @@ -39,7 +39,6 @@ class EnumTest(BaseModel): outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(None, alias="outerEnumDefaultValue") outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(None, alias="outerEnumIntegerDefaultValue") additional_properties: Dict[str, Any] = {} - __properties = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] @validator('enum_string') def enum_string_validate_enum(cls, value): @@ -147,7 +146,7 @@ def from_dict(cls, obj: dict) -> EnumTest: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/file.py b/samples/openapi3/client/petstore/python/petstore_api/models/file.py index 38c1c6628984..aecaa35c00f8 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/file.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/file.py @@ -27,7 +27,6 @@ class File(BaseModel): """ source_uri: Optional[StrictStr] = Field(None, alias="sourceURI", description="Test capitalization") additional_properties: Dict[str, Any] = {} - __properties = ["sourceURI"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> File: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["sourceURI"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py index 65561c5e061d..e921e8293814 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py @@ -29,7 +29,6 @@ class FileSchemaTestClass(BaseModel): file: Optional[File] = None files: Optional[conlist(File)] = None additional_properties: Dict[str, Any] = {} - __properties = ["file", "files"] """Pydantic configuration""" class Config: @@ -88,7 +87,7 @@ def from_dict(cls, obj: dict) -> FileSchemaTestClass: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["file", "files"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/first_ref.py b/samples/openapi3/client/petstore/python/petstore_api/models/first_ref.py index ee6cf8a9ca00..883cea6ac861 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/first_ref.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/first_ref.py @@ -28,7 +28,6 @@ class FirstRef(BaseModel): category: Optional[StrictStr] = None self_ref: Optional[SecondRef] = None additional_properties: Dict[str, Any] = {} - __properties = ["category", "self_ref"] """Pydantic configuration""" class Config: @@ -80,11 +79,14 @@ def from_dict(cls, obj: dict) -> FirstRef: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["category", "self_ref"]: _obj.additional_properties[_key] = obj.get(_key) return _obj from petstore_api.models.second_ref import SecondRef -FirstRef.update_forward_refs() +try: + FirstRef.update_forward_refs() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/foo.py b/samples/openapi3/client/petstore/python/petstore_api/models/foo.py index 72cb376c34b0..266f5826db56 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/foo.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/foo.py @@ -27,7 +27,6 @@ class Foo(BaseModel): """ bar: Optional[StrictStr] = 'bar' additional_properties: Dict[str, Any] = {} - __properties = ["bar"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> Foo: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["bar"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/foo_get_default_response.py b/samples/openapi3/client/petstore/python/petstore_api/models/foo_get_default_response.py index 5a0b5e662a6f..9eddc861bcf0 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/foo_get_default_response.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/foo_get_default_response.py @@ -28,7 +28,6 @@ class FooGetDefaultResponse(BaseModel): """ string: Optional[Foo] = None additional_properties: Dict[str, Any] = {} - __properties = ["string"] """Pydantic configuration""" class Config: @@ -79,7 +78,7 @@ def from_dict(cls, obj: dict) -> FooGetDefaultResponse: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["string"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/format_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/format_test.py index 9593187ab837..ef3b19f22a16 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/format_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/format_test.py @@ -43,7 +43,6 @@ class FormatTest(BaseModel): pattern_with_digits: Optional[constr(strict=True)] = Field(None, description="A string that is a 10 digit number. Can have leading zeros.") pattern_with_digits_and_delimiter: Optional[constr(strict=True)] = Field(None, description="A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01.") additional_properties: Dict[str, Any] = {} - __properties = ["integer", "int32", "int64", "number", "float", "double", "decimal", "string", "string_with_double_quote_pattern", "byte", "binary", "date", "dateTime", "uuid", "password", "pattern_with_digits", "pattern_with_digits_and_delimiter"] @validator('string') def string_validate_regular_expression(cls, value): @@ -147,7 +146,7 @@ def from_dict(cls, obj: dict) -> FormatTest: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["integer", "int32", "int64", "number", "float", "double", "decimal", "string", "string_with_double_quote_pattern", "byte", "binary", "date", "dateTime", "uuid", "password", "pattern_with_digits", "pattern_with_digits_and_delimiter"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/has_only_read_only.py b/samples/openapi3/client/petstore/python/petstore_api/models/has_only_read_only.py index d1325c9ff63c..2058a418a7ea 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/has_only_read_only.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/has_only_read_only.py @@ -28,7 +28,6 @@ class HasOnlyReadOnly(BaseModel): bar: Optional[StrictStr] = None foo: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["bar", "foo"] """Pydantic configuration""" class Config: @@ -79,7 +78,7 @@ def from_dict(cls, obj: dict) -> HasOnlyReadOnly: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["bar", "foo"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/health_check_result.py b/samples/openapi3/client/petstore/python/petstore_api/models/health_check_result.py index b3f08f79162d..662420fb8841 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/health_check_result.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/health_check_result.py @@ -27,7 +27,6 @@ class HealthCheckResult(BaseModel): """ nullable_message: Optional[StrictStr] = Field(None, alias="NullableMessage") additional_properties: Dict[str, Any] = {} - __properties = ["NullableMessage"] """Pydantic configuration""" class Config: @@ -80,7 +79,7 @@ def from_dict(cls, obj: dict) -> HealthCheckResult: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["NullableMessage"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/inner_dict_with_property.py b/samples/openapi3/client/petstore/python/petstore_api/models/inner_dict_with_property.py index 97c87383862b..4c47dd933fae 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/inner_dict_with_property.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/inner_dict_with_property.py @@ -27,7 +27,6 @@ class InnerDictWithProperty(BaseModel): """ a_property: Optional[Dict[str, Any]] = Field(None, alias="aProperty") additional_properties: Dict[str, Any] = {} - __properties = ["aProperty"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> InnerDictWithProperty: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["aProperty"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/int_or_string.py b/samples/openapi3/client/petstore/python/petstore_api/models/int_or_string.py index 574c73549525..3af97701905d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/int_or_string.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/int_or_string.py @@ -35,7 +35,7 @@ class IntOrString(BaseModel): if TYPE_CHECKING: actual_instance: Union[int, str] else: - actual_instance: Any + actual_instance: Any = None one_of_schemas: List[str] = Field(INTORSTRING_ONE_OF_SCHEMAS, const=True) @@ -50,8 +50,10 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) @validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): @@ -72,6 +74,8 @@ def actual_instance_must_validate_oneof(cls, v): error_messages.append(str(e)) if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when setting `actual_instance` in IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -111,6 +115,8 @@ def from_json(cls, json_str: str) -> IntOrString: if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when deserializing the JSON string into IntOrString with oneOf schemas: int, str. Details: " + ", ".join(error_messages)) elif match == 0: # no match diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/list.py b/samples/openapi3/client/petstore/python/petstore_api/models/list.py index c1e80a8bf1d6..dc1900090a36 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/list.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/list.py @@ -27,7 +27,6 @@ class List(BaseModel): """ var_123_list: Optional[StrictStr] = Field(None, alias="123-list") additional_properties: Dict[str, Any] = {} - __properties = ["123-list"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> List: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["123-list"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py index 5339b05fb0ae..90cb32bcc888 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py @@ -28,7 +28,6 @@ class MapOfArrayOfModel(BaseModel): """ shop_id_to_org_online_lip_map: Optional[Dict[str, conlist(Tag)]] = Field(None, alias="shopIdToOrgOnlineLipMap") additional_properties: Dict[str, Any] = {} - __properties = ["shopIdToOrgOnlineLipMap"] """Pydantic configuration""" class Config: @@ -92,7 +91,7 @@ def from_dict(cls, obj: dict) -> MapOfArrayOfModel: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["shopIdToOrgOnlineLipMap"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py index d9a35e2e76c4..14fb340672ea 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py @@ -30,7 +30,6 @@ class MapTest(BaseModel): direct_map: Optional[Dict[str, StrictBool]] = None indirect_map: Optional[Dict[str, StrictBool]] = None additional_properties: Dict[str, Any] = {} - __properties = ["map_map_of_string", "map_of_enum_string", "direct_map", "indirect_map"] @validator('map_of_enum_string') def map_of_enum_string_validate_enum(cls, value): @@ -91,7 +90,7 @@ def from_dict(cls, obj: dict) -> MapTest: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["map_map_of_string", "map_of_enum_string", "direct_map", "indirect_map"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py index 656a0c70c329..39a44af60b9a 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -30,7 +30,6 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): date_time: Optional[datetime] = Field(None, alias="dateTime") map: Optional[Dict[str, Animal]] = None additional_properties: Dict[str, Any] = {} - __properties = ["uuid", "dateTime", "map"] """Pydantic configuration""" class Config: @@ -92,7 +91,7 @@ def from_dict(cls, obj: dict) -> MixedPropertiesAndAdditionalPropertiesClass: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["uuid", "dateTime", "map"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/model200_response.py b/samples/openapi3/client/petstore/python/petstore_api/models/model200_response.py index a3955bcb9632..1fed6c711e01 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/model200_response.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/model200_response.py @@ -28,7 +28,6 @@ class Model200Response(BaseModel): name: Optional[StrictInt] = None var_class: Optional[StrictStr] = Field(None, alias="class") additional_properties: Dict[str, Any] = {} - __properties = ["name", "class"] """Pydantic configuration""" class Config: @@ -77,7 +76,7 @@ def from_dict(cls, obj: dict) -> Model200Response: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name", "class"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/model_return.py b/samples/openapi3/client/petstore/python/petstore_api/models/model_return.py index 5d73d5ff459c..6a304ea51107 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/model_return.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/model_return.py @@ -27,7 +27,6 @@ class ModelReturn(BaseModel): """ var_return: Optional[StrictInt] = Field(None, alias="return") additional_properties: Dict[str, Any] = {} - __properties = ["return"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> ModelReturn: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["return"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/name.py b/samples/openapi3/client/petstore/python/petstore_api/models/name.py index 78691119c80d..b53c0848a129 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/name.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/name.py @@ -30,7 +30,6 @@ class Name(BaseModel): var_property: Optional[StrictStr] = Field(None, alias="property") var_123_number: Optional[StrictInt] = Field(None, alias="123Number") additional_properties: Dict[str, Any] = {} - __properties = ["name", "snake_case", "property", "123Number"] """Pydantic configuration""" class Config: @@ -83,7 +82,7 @@ def from_dict(cls, obj: dict) -> Name: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["name", "snake_case", "property", "123Number"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py index f9f75200a479..3393c1a6c0f0 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py @@ -39,7 +39,6 @@ class NullableClass(BaseModel): object_and_items_nullable_prop: Optional[Dict[str, Dict[str, Any]]] = None object_items_nullable: Optional[Dict[str, Dict[str, Any]]] = None additional_properties: Dict[str, Any] = {} - __properties = ["required_integer_prop", "integer_prop", "number_prop", "boolean_prop", "string_prop", "date_prop", "datetime_prop", "array_nullable_prop", "array_and_items_nullable_prop", "array_items_nullable", "object_nullable_prop", "object_and_items_nullable_prop", "object_items_nullable"] """Pydantic configuration""" class Config: @@ -154,7 +153,7 @@ def from_dict(cls, obj: dict) -> NullableClass: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["required_integer_prop", "integer_prop", "number_prop", "boolean_prop", "string_prop", "date_prop", "datetime_prop", "array_nullable_prop", "array_and_items_nullable_prop", "array_items_nullable", "object_nullable_prop", "object_and_items_nullable_prop", "object_items_nullable"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/nullable_property.py b/samples/openapi3/client/petstore/python/petstore_api/models/nullable_property.py index f9852c6d4c50..d200563a69ba 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/nullable_property.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/nullable_property.py @@ -28,7 +28,6 @@ class NullableProperty(BaseModel): id: StrictInt = Field(...) name: Optional[constr(strict=True)] = Field(...) additional_properties: Dict[str, Any] = {} - __properties = ["id", "name"] @validator('name') def name_validate_regular_expression(cls, value): @@ -92,7 +91,7 @@ def from_dict(cls, obj: dict) -> NullableProperty: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["id", "name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/number_only.py b/samples/openapi3/client/petstore/python/petstore_api/models/number_only.py index b615444e8cb4..ce73a0df547c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/number_only.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/number_only.py @@ -27,7 +27,6 @@ class NumberOnly(BaseModel): """ just_number: Optional[StrictFloat] = Field(None, alias="JustNumber") additional_properties: Dict[str, Any] = {} - __properties = ["JustNumber"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> NumberOnly: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["JustNumber"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/object_to_test_additional_properties.py b/samples/openapi3/client/petstore/python/petstore_api/models/object_to_test_additional_properties.py index 69889866bbad..568f4e5cf296 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/object_to_test_additional_properties.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/object_to_test_additional_properties.py @@ -27,7 +27,6 @@ class ObjectToTestAdditionalProperties(BaseModel): """ var_property: Optional[StrictBool] = Field(False, alias="property", description="Property") additional_properties: Dict[str, Any] = {} - __properties = ["property"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> ObjectToTestAdditionalProperties: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["property"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/object_with_deprecated_fields.py b/samples/openapi3/client/petstore/python/petstore_api/models/object_with_deprecated_fields.py index 1b23fea5022e..71cb09c56a83 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/object_with_deprecated_fields.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/object_with_deprecated_fields.py @@ -31,7 +31,6 @@ class ObjectWithDeprecatedFields(BaseModel): deprecated_ref: Optional[DeprecatedObject] = Field(None, alias="deprecatedRef") bars: Optional[conlist(StrictStr)] = None additional_properties: Dict[str, Any] = {} - __properties = ["uuid", "id", "deprecatedRef", "bars"] """Pydantic configuration""" class Config: @@ -85,7 +84,7 @@ def from_dict(cls, obj: dict) -> ObjectWithDeprecatedFields: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["uuid", "id", "deprecatedRef", "bars"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/one_of_enum_string.py b/samples/openapi3/client/petstore/python/petstore_api/models/one_of_enum_string.py index f4b18189e6f9..a781e3febe0a 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/one_of_enum_string.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/one_of_enum_string.py @@ -37,7 +37,7 @@ class OneOfEnumString(BaseModel): if TYPE_CHECKING: actual_instance: Union[EnumString1, EnumString2] else: - actual_instance: Any + actual_instance: Any = None one_of_schemas: List[str] = Field(ONEOFENUMSTRING_ONE_OF_SCHEMAS, const=True) @@ -52,8 +52,10 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) @validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): @@ -61,17 +63,21 @@ def actual_instance_must_validate_oneof(cls, v): error_messages = [] match = 0 # validate data type: EnumString1 - if not isinstance(v, EnumString1): - error_messages.append(f"Error! Input type `{type(v)}` is not `EnumString1`") - else: + try: + instance.oneof_schema_1_validator = v match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) # validate data type: EnumString2 - if not isinstance(v, EnumString2): - error_messages.append(f"Error! Input type `{type(v)}` is not `EnumString2`") - else: + try: + instance.oneof_schema_2_validator = v match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when setting `actual_instance` in OneOfEnumString with oneOf schemas: EnumString1, EnumString2. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -105,6 +111,8 @@ def from_json(cls, json_str: str) -> OneOfEnumString: if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when deserializing the JSON string into OneOfEnumString with oneOf schemas: EnumString1, EnumString2. Details: " + ", ".join(error_messages)) elif match == 0: # no match diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/order.py b/samples/openapi3/client/petstore/python/petstore_api/models/order.py index 46744c6d899c..c372d10443a7 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/order.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/order.py @@ -32,7 +32,6 @@ class Order(BaseModel): status: Optional[StrictStr] = Field(None, description="Order Status") complete: Optional[StrictBool] = False additional_properties: Dict[str, Any] = {} - __properties = ["id", "petId", "quantity", "shipDate", "status", "complete"] @validator('status') def status_validate_enum(cls, value): @@ -95,7 +94,7 @@ def from_dict(cls, obj: dict) -> Order: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["id", "petId", "quantity", "shipDate", "status", "complete"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_composite.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_composite.py index ab19c5478cab..5dbc893d2ac2 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_composite.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_composite.py @@ -29,7 +29,6 @@ class OuterComposite(BaseModel): my_string: Optional[StrictStr] = None my_boolean: Optional[StrictBool] = None additional_properties: Dict[str, Any] = {} - __properties = ["my_number", "my_string", "my_boolean"] """Pydantic configuration""" class Config: @@ -79,7 +78,7 @@ def from_dict(cls, obj: dict) -> OuterComposite: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["my_number", "my_string", "my_boolean"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_object_with_enum_property.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_object_with_enum_property.py index f925d15226d0..1d0c83ee1eae 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_object_with_enum_property.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_object_with_enum_property.py @@ -30,7 +30,6 @@ class OuterObjectWithEnumProperty(BaseModel): str_value: Optional[OuterEnum] = None value: OuterEnumInteger = Field(...) additional_properties: Dict[str, Any] = {} - __properties = ["str_value", "value"] """Pydantic configuration""" class Config: @@ -84,7 +83,7 @@ def from_dict(cls, obj: dict) -> OuterObjectWithEnumProperty: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["str_value", "value"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/parent.py b/samples/openapi3/client/petstore/python/petstore_api/models/parent.py index ffd387db12e9..1c87d16db279 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/parent.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/parent.py @@ -28,7 +28,6 @@ class Parent(BaseModel): """ optional_dict: Optional[Dict[str, InnerDictWithProperty]] = Field(None, alias="optionalDict") additional_properties: Dict[str, Any] = {} - __properties = ["optionalDict"] """Pydantic configuration""" class Config: @@ -88,7 +87,7 @@ def from_dict(cls, obj: dict) -> Parent: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["optionalDict"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/parent_with_optional_dict.py b/samples/openapi3/client/petstore/python/petstore_api/models/parent_with_optional_dict.py index a7832616daed..4c4b39bd7273 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/parent_with_optional_dict.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/parent_with_optional_dict.py @@ -28,7 +28,6 @@ class ParentWithOptionalDict(BaseModel): """ optional_dict: Optional[Dict[str, InnerDictWithProperty]] = Field(None, alias="optionalDict") additional_properties: Dict[str, Any] = {} - __properties = ["optionalDict"] """Pydantic configuration""" class Config: @@ -88,7 +87,7 @@ def from_dict(cls, obj: dict) -> ParentWithOptionalDict: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["optionalDict"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/pet.py b/samples/openapi3/client/petstore/python/petstore_api/models/pet.py index 2f68cf79f205..e7aa0f53e650 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/pet.py @@ -34,7 +34,6 @@ class Pet(BaseModel): tags: Optional[conlist(Tag)] = None status: Optional[StrictStr] = Field(None, description="pet status in the store") additional_properties: Dict[str, Any] = {} - __properties = ["id", "category", "name", "photoUrls", "tags", "status"] @validator('status') def status_validate_enum(cls, value): @@ -107,7 +106,7 @@ def from_dict(cls, obj: dict) -> Pet: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["id", "category", "name", "photoUrls", "tags", "status"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/pig.py b/samples/openapi3/client/petstore/python/petstore_api/models/pig.py index 0f96725a08b9..0647ef1208ca 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/pig.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/pig.py @@ -37,7 +37,7 @@ class Pig(BaseModel): if TYPE_CHECKING: actual_instance: Union[BasquePig, DanishPig] else: - actual_instance: Any + actual_instance: Any = None one_of_schemas: List[str] = Field(PIG_ONE_OF_SCHEMAS, const=True) @@ -45,9 +45,6 @@ class Pig(BaseModel): class Config: validate_assignment = True - discriminator_value_class_map = { - } - def __init__(self, *args, **kwargs) -> None: if args: if len(args) > 1: @@ -55,8 +52,10 @@ def __init__(self, *args, **kwargs) -> None: if kwargs: raise ValueError("If a position argument is used, keyword arguments cannot be used.") super().__init__(actual_instance=args[0]) - else: + elif kwargs: super().__init__(**kwargs) + else: + super().__init__(actual_instance=None) @validator('actual_instance') def actual_instance_must_validate_oneof(cls, v): @@ -64,17 +63,21 @@ def actual_instance_must_validate_oneof(cls, v): error_messages = [] match = 0 # validate data type: BasquePig - if not isinstance(v, BasquePig): - error_messages.append(f"Error! Input type `{type(v)}` is not `BasquePig`") - else: + try: + instance.oneof_schema_1_validator = v match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) # validate data type: DanishPig - if not isinstance(v, DanishPig): - error_messages.append(f"Error! Input type `{type(v)}` is not `DanishPig`") - else: + try: + instance.oneof_schema_2_validator = v match += 1 + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when setting `actual_instance` in Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) elif match == 0: # no match @@ -123,6 +126,8 @@ def from_json(cls, json_str: str) -> Pig: if match > 1: # more than 1 match + if v is None: + return v raise ValueError("Multiple matches found when deserializing the JSON string into Pig with oneOf schemas: BasquePig, DanishPig. Details: " + ", ".join(error_messages)) elif match == 0: # no match diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/property_name_collision.py b/samples/openapi3/client/petstore/python/petstore_api/models/property_name_collision.py index 10a53fc54ddd..f74682800ccd 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/property_name_collision.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/property_name_collision.py @@ -29,7 +29,6 @@ class PropertyNameCollision(BaseModel): type: Optional[StrictStr] = None type_with_underscore: Optional[StrictStr] = Field(None, alias="type_") additional_properties: Dict[str, Any] = {} - __properties = ["_type", "type", "type_"] """Pydantic configuration""" class Config: @@ -79,7 +78,7 @@ def from_dict(cls, obj: dict) -> PropertyNameCollision: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["_type", "type", "type_"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/read_only_first.py b/samples/openapi3/client/petstore/python/petstore_api/models/read_only_first.py index 00fccbdf1a48..4a2fd25376c1 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/read_only_first.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/read_only_first.py @@ -28,7 +28,6 @@ class ReadOnlyFirst(BaseModel): bar: Optional[StrictStr] = None baz: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["bar", "baz"] """Pydantic configuration""" class Config: @@ -78,7 +77,7 @@ def from_dict(cls, obj: dict) -> ReadOnlyFirst: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["bar", "baz"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/second_ref.py b/samples/openapi3/client/petstore/python/petstore_api/models/second_ref.py index 8fc160607612..82490f7c7d36 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/second_ref.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/second_ref.py @@ -28,7 +28,6 @@ class SecondRef(BaseModel): category: Optional[StrictStr] = None circular_ref: Optional[CircularReferenceModel] = None additional_properties: Dict[str, Any] = {} - __properties = ["category", "circular_ref"] """Pydantic configuration""" class Config: @@ -80,11 +79,14 @@ def from_dict(cls, obj: dict) -> SecondRef: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["category", "circular_ref"]: _obj.additional_properties[_key] = obj.get(_key) return _obj from petstore_api.models.circular_reference_model import CircularReferenceModel -SecondRef.update_forward_refs() +try: + SecondRef.update_forward_refs() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/self_reference_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/self_reference_model.py index 6176d7327d7f..ef185b1056a2 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/self_reference_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/self_reference_model.py @@ -28,7 +28,6 @@ class SelfReferenceModel(BaseModel): size: Optional[StrictInt] = None nested: Optional[DummyModel] = None additional_properties: Dict[str, Any] = {} - __properties = ["size", "nested"] """Pydantic configuration""" class Config: @@ -80,11 +79,14 @@ def from_dict(cls, obj: dict) -> SelfReferenceModel: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["size", "nested"]: _obj.additional_properties[_key] = obj.get(_key) return _obj from petstore_api.models.dummy_model import DummyModel -SelfReferenceModel.update_forward_refs() +try: + SelfReferenceModel.update_forward_refs() +except Exception: + pass diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/special_model_name.py b/samples/openapi3/client/petstore/python/petstore_api/models/special_model_name.py index 373b1209fe04..2d603f0cdcba 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/special_model_name.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/special_model_name.py @@ -27,7 +27,6 @@ class SpecialModelName(BaseModel): """ special_property_name: Optional[StrictInt] = Field(None, alias="$special[property.name]") additional_properties: Dict[str, Any] = {} - __properties = ["$special[property.name]"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> SpecialModelName: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["$special[property.name]"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/special_name.py b/samples/openapi3/client/petstore/python/petstore_api/models/special_name.py index 01075364c1b2..d9892515330f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/special_name.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/special_name.py @@ -30,7 +30,6 @@ class SpecialName(BaseModel): var_async: Optional[Category] = Field(None, alias="async") var_schema: Optional[StrictStr] = Field(None, alias="schema", description="pet status in the store") additional_properties: Dict[str, Any] = {} - __properties = ["property", "async", "schema"] @validator('var_schema') def var_schema_validate_enum(cls, value): @@ -93,7 +92,7 @@ def from_dict(cls, obj: dict) -> SpecialName: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["property", "async", "schema"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/tag.py b/samples/openapi3/client/petstore/python/petstore_api/models/tag.py index 28766eda136a..a67b9a99d074 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/tag.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/tag.py @@ -28,7 +28,6 @@ class Tag(BaseModel): id: Optional[StrictInt] = None name: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["id", "name"] """Pydantic configuration""" class Config: @@ -77,7 +76,7 @@ def from_dict(cls, obj: dict) -> Tag: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["id", "name"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/tiger.py b/samples/openapi3/client/petstore/python/petstore_api/models/tiger.py index 26c12744c636..56103e75a314 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/tiger.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/tiger.py @@ -27,7 +27,6 @@ class Tiger(BaseModel): """ skill: Optional[StrictStr] = None additional_properties: Dict[str, Any] = {} - __properties = ["skill"] """Pydantic configuration""" class Config: @@ -75,7 +74,7 @@ def from_dict(cls, obj: dict) -> Tiger: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["skill"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/user.py b/samples/openapi3/client/petstore/python/petstore_api/models/user.py index 2c1e32c81ce7..0795e68aa576 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/user.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/user.py @@ -34,7 +34,6 @@ class User(BaseModel): phone: Optional[StrictStr] = None user_status: Optional[StrictInt] = Field(None, alias="userStatus", description="User Status") additional_properties: Dict[str, Any] = {} - __properties = ["id", "username", "firstName", "lastName", "email", "password", "phone", "userStatus"] """Pydantic configuration""" class Config: @@ -89,7 +88,7 @@ def from_dict(cls, obj: dict) -> User: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["id", "username", "firstName", "lastName", "email", "password", "phone", "userStatus"]: _obj.additional_properties[_key] = obj.get(_key) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/with_nested_one_of.py b/samples/openapi3/client/petstore/python/petstore_api/models/with_nested_one_of.py index 8bf965cd87e7..df210096d07f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/with_nested_one_of.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/with_nested_one_of.py @@ -31,7 +31,6 @@ class WithNestedOneOf(BaseModel): nested_pig: Optional[Pig] = None nested_oneof_enum_string: Optional[OneOfEnumString] = None additional_properties: Dict[str, Any] = {} - __properties = ["size", "nested_pig", "nested_oneof_enum_string"] """Pydantic configuration""" class Config: @@ -87,7 +86,7 @@ def from_dict(cls, obj: dict) -> WithNestedOneOf: }) # store additional fields in additional_properties for _key in obj.keys(): - if _key not in cls.__properties: + if _key not in ["size", "nested_pig", "nested_oneof_enum_string"]: _obj.additional_properties[_key] = obj.get(_key) return _obj