Skip to content

Commit

Permalink
update snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Jun 24, 2024
1 parent 0ebcefe commit d9787bf
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions test/generators/python/presets/__snapshots__/Pydantic.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,37 @@ exports[`PYTHON_PYDANTIC_PRESET should render pydantic for class 1`] = `
line
description''', default=None)
additional_properties: Optional[dict[str, Any]] = Field(exclude=True, default=None, alias='''additionalProperties''')
@model_serializer(mode='wrap')
def custom_serializer(self, handler):
serialized_self = handler(self)
additional_properties = getattr(self, \\"additional_properties\\")
if additional_properties is not None:
for key, value in additional_properties.items():
# Never overwrite existing values, to avoid clashes
if not hasattr(serialized_self, key):
serialized_self[key] = value
return serialized_self
@model_validator(mode='before')
@classmethod
def unwrap_additional_properties(cls, data):
json_properties = list(data.keys())
known_object_properties = ['prop', 'additional_properties']
unknown_object_properties = [element for element in json_properties if element not in known_object_properties]
# Ignore attempts that validate regular models, only when unknown input is used we add unwrap extensions
if len(unknown_object_properties) == 0:
return data
known_json_properties = ['prop', 'additionalProperties']
additional_properties = {}
for obj_key in list(data.keys()):
if not known_json_properties.__contains__(obj_key):
additional_properties[obj_key] = data.pop(obj_key, None)
data['additionalProperties'] = additional_properties
return data
"
`;

Expand All @@ -15,14 +46,107 @@ Array [
"class UnionTest(BaseModel):
union_test: Optional[Union[Union1.Union1, Union2.Union2]] = Field(default=None, alias='''unionTest''')
additional_properties: Optional[dict[str, Any]] = Field(exclude=True, default=None, alias='''additionalProperties''')
@model_serializer(mode='wrap')
def custom_serializer(self, handler):
serialized_self = handler(self)
additional_properties = getattr(self, \\"additional_properties\\")
if additional_properties is not None:
for key, value in additional_properties.items():
# Never overwrite existing values, to avoid clashes
if not hasattr(serialized_self, key):
serialized_self[key] = value
return serialized_self
@model_validator(mode='before')
@classmethod
def unwrap_additional_properties(cls, data):
json_properties = list(data.keys())
known_object_properties = ['union_test', 'additional_properties']
unknown_object_properties = [element for element in json_properties if element not in known_object_properties]
# Ignore attempts that validate regular models, only when unknown input is used we add unwrap extensions
if len(unknown_object_properties) == 0:
return data
known_json_properties = ['unionTest', 'additionalProperties']
additional_properties = {}
for obj_key in list(data.keys()):
if not known_json_properties.__contains__(obj_key):
additional_properties[obj_key] = data.pop(obj_key, None)
data['additionalProperties'] = additional_properties
return data
",
"class Union1(BaseModel):
test_prop1: Optional[str] = Field(default=None, alias='''testProp1''')
additional_properties: Optional[dict[str, Any]] = Field(exclude=True, default=None, alias='''additionalProperties''')
@model_serializer(mode='wrap')
def custom_serializer(self, handler):
serialized_self = handler(self)
additional_properties = getattr(self, \\"additional_properties\\")
if additional_properties is not None:
for key, value in additional_properties.items():
# Never overwrite existing values, to avoid clashes
if not hasattr(serialized_self, key):
serialized_self[key] = value
return serialized_self
@model_validator(mode='before')
@classmethod
def unwrap_additional_properties(cls, data):
json_properties = list(data.keys())
known_object_properties = ['test_prop1', 'additional_properties']
unknown_object_properties = [element for element in json_properties if element not in known_object_properties]
# Ignore attempts that validate regular models, only when unknown input is used we add unwrap extensions
if len(unknown_object_properties) == 0:
return data
known_json_properties = ['testProp1', 'additionalProperties']
additional_properties = {}
for obj_key in list(data.keys()):
if not known_json_properties.__contains__(obj_key):
additional_properties[obj_key] = data.pop(obj_key, None)
data['additionalProperties'] = additional_properties
return data
",
"class Union2(BaseModel):
test_prop2: Optional[str] = Field(default=None, alias='''testProp2''')
additional_properties: Optional[dict[str, Any]] = Field(exclude=True, default=None, alias='''additionalProperties''')
@model_serializer(mode='wrap')
def custom_serializer(self, handler):
serialized_self = handler(self)
additional_properties = getattr(self, \\"additional_properties\\")
if additional_properties is not None:
for key, value in additional_properties.items():
# Never overwrite existing values, to avoid clashes
if not hasattr(serialized_self, key):
serialized_self[key] = value
return serialized_self
@model_validator(mode='before')
@classmethod
def unwrap_additional_properties(cls, data):
json_properties = list(data.keys())
known_object_properties = ['test_prop2', 'additional_properties']
unknown_object_properties = [element for element in json_properties if element not in known_object_properties]
# Ignore attempts that validate regular models, only when unknown input is used we add unwrap extensions
if len(unknown_object_properties) == 0:
return data
known_json_properties = ['testProp2', 'additionalProperties']
additional_properties = {}
for obj_key in list(data.keys()):
if not known_json_properties.__contains__(obj_key):
additional_properties[obj_key] = data.pop(obj_key, None)
data['additionalProperties'] = additional_properties
return data
",
]
`;

0 comments on commit d9787bf

Please sign in to comment.