#3029 - Add string-ip validator, improve validation, fix minor bugs in pulling schema data

This commit is contained in:
Marek Wolan
2025-01-31 12:18:52 +00:00
parent 09bfa7b700
commit 4fb54c9492
19 changed files with 116 additions and 76 deletions

View File

@@ -39,3 +39,12 @@ will automatically check and convert the input value to an instance of IPv4Addre
any Pydantic model uses it. This ensures that any field marked with this type is not just
an IPv4Address in form, but also valid according to the rules defined in ipv4_validator.
"""
def str_ip(value: Any) -> str:
"""Make sure it's a valid IP, but represent it as a string."""
# TODO: this is a bit of a hack, we should change RequestResponse to be able to handle IPV4Address objects
return str(IPV4Address(value))
StrIP: Final[Annotated] = Annotated[str, BeforeValidator(str_ip)]