Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ dependencies = [
"ldap3",
"orjson",
"pamela",
"pydantic",
"pydantic>2",
"pydantic-settings",
"python-jose",
"pyzmq",
"sqlalchemy",
"sqlalchemy>2",
"starlette",
"uvicorn",
]
Expand Down
2 changes: 1 addition & 1 deletion src/bluesky_httpserver/database/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import declarative_base

# Everything imports this so we put it in its own module to
# avoid circular imports.
Expand Down
14 changes: 8 additions & 6 deletions src/bluesky_httpserver/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ class Response(generic_model, Generic[DataT, LinksT, MetaT]):
links: LinksT | None = None
meta: MetaT | None = None

@pydantic.validator("error", always=True)
def check_consistency(cls, v, values):
if v is not None and values["data"] is not None:
@pydantic.field_validator("error", mode="after")
@classmethod
def check_consistency(cls, v, info):
values = info.data
if v is not None and values.get("data") is not None:
raise ValueError("must not provide both data and error")
if v is None and values.get("data") is None:
raise ValueError("must provide data or error")
Expand Down Expand Up @@ -310,7 +312,7 @@ class APIKeyRequestParams(pydantic.BaseModel):
# Provide an example for expires_in. Otherwise, OpenAPI suggests lifetime=0.
# If the user is not reading carefully, they will be frustrated when they
# try to use the instantly-expiring API key!
expires_in: int | None = pydantic.Field(..., example=600) # seconds
# scopes: Optional[List[str]] = pydantic.Field(..., example=["inherit"])
scopes: list[str] | None = pydantic.Field(default=["inherit"], example=["inherit"])
expires_in: int | None = pydantic.Field(..., json_schema_extra={"example": 600}) # seconds
# scopes: Optional[List[str]] = pydantic.Field(..., json_schema_extra={"example": ["inherit"]})
scopes: list[str] | None = pydantic.Field(default=["inherit"], json_schema_extra={"example": ["inherit"]})
note: str | None = None
Loading