(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:
@@ -51,6 +51,9 @@ class OneOfTypeParser(GenericTypeParser):
|
||||
def _build_type_one_of_with_discriminator(
|
||||
subfield_types: list[Annotated], discriminator_prop: dict
|
||||
) -> Annotated:
|
||||
"""
|
||||
Build a type with a discriminator.
|
||||
"""
|
||||
if not isinstance(discriminator_prop, dict):
|
||||
raise ValueError("Discriminator must be a dictionary")
|
||||
|
||||
@@ -63,8 +66,7 @@ class OneOfTypeParser(GenericTypeParser):
|
||||
@staticmethod
|
||||
def _build_type_one_of_with_func(subfield_types: list[Annotated]) -> Annotated:
|
||||
"""
|
||||
Build a validation function for the oneOf constraint.
|
||||
This function will validate that the value matches exactly one of the schemas.
|
||||
Build a type with a validation function for the oneOf constraint.
|
||||
"""
|
||||
|
||||
def validate_one_of(value: Any) -> Any:
|
||||
@@ -87,24 +89,3 @@ class OneOfTypeParser(GenericTypeParser):
|
||||
return value
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user