Skip to content

Commit

Permalink
Use enum schema for type in info endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Apr 25, 2022
1 parent 2f6ef1e commit 2160d04
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions optimade/models/optimade_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class Warnings(OptimadeError):
"""

type: Literal["warning"] = StrictField(
"warning",
description='Warnings must be of type "warning"',
)

Expand Down
8 changes: 3 additions & 5 deletions optimade/server/routers/index_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def get_info(request: Request) -> IndexInfoResponse:
return IndexInfoResponse(
meta=meta_values(request.url, 1, 1, more_data_available=False),
data=IndexInfoResource(
id=IndexInfoResource.schema()["properties"]["id"]["const"],
type=IndexInfoResource.schema()["properties"]["type"]["const"],
id=IndexInfoResource.schema()["properties"]["id"]["enum"][0],
type=IndexInfoResource.schema()["properties"]["type"]["enum"][0],
attributes=IndexInfoAttributes(
api_version=f"{__api_version__}",
available_api_versions=[
Expand All @@ -45,9 +45,7 @@ def get_info(request: Request) -> IndexInfoResponse:
relationships={
"default": IndexRelationship(
data={
"type": RelatedLinksResource.schema()["properties"]["type"][
"const"
],
"type": RelatedLinksResource.schema()["properties"]["type"]["enum"][0],
"id": CONFIG.default_db,
}
)
Expand Down
4 changes: 2 additions & 2 deletions optimade/server/routers/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def get_info(request: Request) -> InfoResponse:
return InfoResponse(
meta=meta_values(request.url, 1, 1, more_data_available=False),
data=BaseInfoResource(
id=BaseInfoResource.schema()["properties"]["id"]["const"],
type=BaseInfoResource.schema()["properties"]["type"]["const"],
id=BaseInfoResource.schema()["properties"]["id"]["enum"][0],
type=BaseInfoResource.schema()["properties"]["type"]["enum"][0],
attributes=BaseInfoAttributes(
api_version=__api_version__,
available_api_versions=[
Expand Down
4 changes: 2 additions & 2 deletions optimade/server/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def retrieve_queryable_properties(
else:
properties[name] = {"description": value.get("description", "")}
# Update schema with extension keys provided they are not None
for key in [_ for _ in ("unit", "queryable", "support") if _ in value]:
properties[name][key] = value[key]
for key in [_ for _ in ("x-optimade-unit", "x-optimade-queryable", "x-optimade-support") if _ in value]:
properties[name][key.strip("x-optimade-")] = value[key]
# All properties are sortable with the MongoDB backend.
# While the result for sorting lists may not be as expected, they are still sorted.
properties[name]["sortable"] = value.get("sortable", True)
Expand Down

0 comments on commit 2160d04

Please sign in to comment.