1
0
Fork 1
mirror of https://github.com/thatmattlove/hyperglass.git synced 2026-01-17 00:38:06 +00:00

Fixed API docs rendering

The use of `strip_whitespace` in `Field` for the query validation model caused the automatic generation of the API docs to fail with `ValueError: `schema_extra` declares key `strip_whitespace` which does not exist in `Schema` object`. By switching from `Field` to `Annotated` with `StringConstraints`, this avoids this issue allowing API docs to be correctly rendered.

Signed-off-by: Mattie Nickson <mnickson@sidingsmedia.com>
This commit is contained in:
Mattie Nickson 2025-06-06 10:08:59 +01:00
parent f49ff54fce
commit b7e268bf18
No known key found for this signature in database

View file

@ -7,7 +7,8 @@ import secrets
from datetime import datetime from datetime import datetime
# Third Party # Third Party
from pydantic import Field, BaseModel, ConfigDict, field_validator from pydantic import BaseModel, ConfigDict, field_validator, StringConstraints
from typing_extensions import Annotated
# Project # Project
from hyperglass.log import log from hyperglass.log import log
@ -21,6 +22,11 @@ from hyperglass.exceptions.private import InputValidationError
from ..config.devices import Device from ..config.devices import Device
QueryLocation = Annotated[str, StringConstraints(strict=True, min_length=1, strip_whitespace=True)]
QueryTarget = Annotated[str, StringConstraints(min_length=1, strip_whitespace=True)]
QueryType = Annotated[str, StringConstraints(strict=True, min_length=1, strip_whitespace=True)]
class SimpleQuery(BaseModel): class SimpleQuery(BaseModel):
"""A simple representation of a post-validated query.""" """A simple representation of a post-validated query."""
@ -39,12 +45,12 @@ class Query(BaseModel):
model_config = ConfigDict(extra="allow", alias_generator=snake_to_camel, populate_by_name=True) model_config = ConfigDict(extra="allow", alias_generator=snake_to_camel, populate_by_name=True)
# Device `name` field # Device `name` field
query_location: str = Field(strict=True, min_length=1, strip_whitespace=True) query_location: QueryLocation
query_target: t.Union[t.List[str], str] = Field(min_length=1, strip_whitespace=True) query_target: t.Union[t.List[QueryTarget], QueryTarget]
# Directive `id` field # Directive `id` field
query_type: str = Field(strict=True, min_length=1, strip_whitespace=True) query_type: QueryType
_kwargs: t.Dict[str, t.Any] _kwargs: t.Dict[str, t.Any]
def __init__(self, **data) -> None: def __init__(self, **data) -> None: