feat: fixes error on validation of IPAddresses by Upgrading Pydantic min version to v2.12.4, fixes internal tests implementation and fixes minor logic errors
This commit is contained in:
@@ -52,7 +52,7 @@ class GenericTypeParser(ABC, Generic[T]):
|
||||
"Default value is not valid", invalid_field=name
|
||||
)
|
||||
|
||||
if not self._validate_default(parsed_type, parsed_properties):
|
||||
if not self._validate_examples(parsed_type, parsed_properties):
|
||||
raise InvalidSchemaException(
|
||||
"Examples values are not valid", invalid_field=name
|
||||
)
|
||||
@@ -126,6 +126,25 @@ class GenericTypeParser(ABC, Generic[T]):
|
||||
if value is None:
|
||||
return True
|
||||
|
||||
return GenericTypeParser._is_valid_value(field_type, field_prop, value)
|
||||
|
||||
@staticmethod
|
||||
def _validate_examples(field_type: T, field_prop: dict) -> bool:
|
||||
examples = field_prop.get("examples")
|
||||
|
||||
if examples is None:
|
||||
return True
|
||||
|
||||
if not isinstance(examples, list):
|
||||
return False
|
||||
|
||||
return all(
|
||||
GenericTypeParser._is_valid_value(field_type, field_prop, e)
|
||||
for e in examples
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _is_valid_value(field_type: T, field_prop: dict, value: Any) -> bool:
|
||||
try:
|
||||
field = Annotated[field_type, Field(**field_prop)] # type: ignore
|
||||
TypeAdapter(field).validate_python(value)
|
||||
@@ -133,22 +152,3 @@ class GenericTypeParser(ABC, Generic[T]):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def _validate_examples(field_type: T, field_prop: dict) -> bool:
|
||||
values = field_prop.get("examples")
|
||||
|
||||
if values is None:
|
||||
return True
|
||||
|
||||
if not isinstance(values, list):
|
||||
return False
|
||||
|
||||
try:
|
||||
field = Annotated[field_type, Field(**field_prop)] # type: ignore
|
||||
for value in values:
|
||||
TypeAdapter(field).validate_python(value)
|
||||
except Exception as _:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@@ -65,7 +65,7 @@ class StringTypeParser(GenericTypeParser):
|
||||
|
||||
if "examples" in mapped_properties:
|
||||
mapped_properties["examples"] = [
|
||||
self.__parse_example(example, format_type, mapped_type)
|
||||
self._parse_example(example, format_type, mapped_type)
|
||||
for example in mapped_properties["examples"]
|
||||
]
|
||||
|
||||
@@ -75,7 +75,7 @@ class StringTypeParser(GenericTypeParser):
|
||||
|
||||
return mapped_type, mapped_properties
|
||||
|
||||
def __parse_example(
|
||||
def _parse_example(
|
||||
self, example: Any, format_type: str, mapped_type: type[Any]
|
||||
) -> Any:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user