(feature): Removes _has_meaningful_constraints

Removes _has_meaningful_constraints since nowhere in the spec says that a subproperty should have a meaningful value other that its type
This commit is contained in:
2025-08-19 20:29:25 -03:00
parent 86894fa918
commit 79932bb595

View File

@@ -51,6 +51,9 @@ class OneOfTypeParser(GenericTypeParser):
def _build_type_one_of_with_discriminator( def _build_type_one_of_with_discriminator(
subfield_types: list[Annotated], discriminator_prop: dict subfield_types: list[Annotated], discriminator_prop: dict
) -> Annotated: ) -> Annotated:
"""
Build a type with a discriminator.
"""
if not isinstance(discriminator_prop, dict): if not isinstance(discriminator_prop, dict):
raise ValueError("Discriminator must be a dictionary") raise ValueError("Discriminator must be a dictionary")
@@ -63,8 +66,7 @@ class OneOfTypeParser(GenericTypeParser):
@staticmethod @staticmethod
def _build_type_one_of_with_func(subfield_types: list[Annotated]) -> Annotated: def _build_type_one_of_with_func(subfield_types: list[Annotated]) -> Annotated:
""" """
Build a validation function for the oneOf constraint. Build a type with a validation function for the oneOf constraint.
This function will validate that the value matches exactly one of the schemas.
""" """
def validate_one_of(value: Any) -> Any: def validate_one_of(value: Any) -> Any:
@@ -87,24 +89,3 @@ class OneOfTypeParser(GenericTypeParser):
return value return value
return Annotated[Union[(*subfield_types,)], BeforeValidator(validate_one_of)] return Annotated[Union[(*subfield_types,)], BeforeValidator(validate_one_of)]
@staticmethod
def _has_meaningful_constraints(field_props):
"""
Check if field properties contain meaningful constraints that require Field wrapping.
Returns False if:
- field_props is None or empty
- field_props only contains {'default': None}
Returns True if:
- field_props contains a non-None default value
- field_props contains other constraint properties (min_length, max_length, pattern, etc.)
"""
if not field_props:
return False
# If only default is set and it's None, no meaningful constraints
if field_props == {"default": None}:
return False
# If there are multiple properties or non-None default, that's meaningful
return True