-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathresponses.py
More file actions
175 lines (144 loc) · 5.13 KB
/
responses.py
File metadata and controls
175 lines (144 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
from typing import Annotated, Any
from pydantic import model_validator
from optimade.models.baseinfo import BaseInfoResource
from optimade.models.entries import EntryInfoResource, EntryResource
from optimade.models.files import FileResource
from optimade.models.index_metadb import IndexInfoResource
from optimade.models.jsonapi import Response
from optimade.models.links import LinksResource
from optimade.models.optimade_json import OptimadeError, ResponseMeta, Success
from optimade.models.references import ReferenceResource
from optimade.models.structures import StructureResource
from optimade.models.utils import StrictField
__all__ = (
"ErrorResponse",
"EntryInfoResponse",
"IndexInfoResponse",
"InfoResponse",
"LinksResponse",
"EntryResponseOne",
"EntryResponseMany",
"StructureResponseOne",
"StructureResponseMany",
"FileResponseOne",
"FileResponseMany",
"ReferenceResponseOne",
"ReferenceResponseMany",
)
class ErrorResponse(Response):
"""errors MUST be present and data MUST be skipped"""
meta: Annotated[
ResponseMeta,
StrictField(description="A meta object containing non-standard information."),
]
errors: Annotated[
list[OptimadeError],
StrictField(
description="A list of OPTIMADE-specific JSON API error objects, where the field detail MUST be present.",
uniqueItems=True,
),
]
@model_validator(mode="after")
def data_must_be_skipped(self) -> "ErrorResponse":
if self.data or "data" in self.model_fields_set:
raise ValueError("data MUST be skipped for failures reporting errors.")
return self
class IndexInfoResponse(Success):
data: Annotated[
IndexInfoResource, StrictField(description="Index meta-database /info data.")
]
class EntryInfoResponse(Success):
data: Annotated[
EntryInfoResource,
StrictField(description="OPTIMADE information for an entry endpoint."),
]
class InfoResponse(Success):
data: Annotated[
BaseInfoResource, StrictField(description="The implementations /info data.")
]
class EntryResponseOne(Success):
data: Annotated[
EntryResource | dict[str, Any] | None,
StrictField(
description="The single entry resource returned by this query.",
union_mode="left_to_right",
),
] = None # type: ignore[assignment]
included: Annotated[
list[EntryResource] | list[dict[str, Any]] | None,
StrictField(
description="A list of unique included OPTIMADE entry resources.",
uniqueItems=True,
union_mode="left_to_right",
),
] = None # type: ignore[assignment]
class EntryResponseMany(Success):
data: Annotated[ # type: ignore[assignment]
list[EntryResource] | list[dict[str, Any]],
StrictField(
description="List of unique OPTIMADE entry resource objects.",
uniqueItems=True,
union_mode="left_to_right",
),
]
included: Annotated[
list[EntryResource] | list[dict[str, Any]] | None,
StrictField(
description="A list of unique included OPTIMADE entry resources.",
uniqueItems=True,
union_mode="left_to_right",
),
] = None # type: ignore[assignment]
class LinksResponse(EntryResponseMany):
data: Annotated[
list[LinksResource] | list[dict[str, Any]],
StrictField(
description="List of unique OPTIMADE links resource objects.",
uniqueItems=True,
union_mode="left_to_right",
),
]
class StructureResponseOne(EntryResponseOne):
data: Annotated[
StructureResource | dict[str, Any] | None,
StrictField(
description="A single structures entry resource.",
union_mode="left_to_right",
),
]
class StructureResponseMany(EntryResponseMany):
data: Annotated[
list[StructureResource] | list[dict[str, Any]],
StrictField(
description="List of unique OPTIMADE structures entry resource objects.",
uniqueItems=True,
union_mode="left_to_right",
),
]
class FileResponseOne(EntryResponseOne):
data: Union[FileResource, dict[str, Any], None] = StrictField(
..., description="A single files entry resource."
)
class FileResponseMany(EntryResponseMany):
data: Union[list[FileResource], list[dict[str, Any]]] = StrictField(
...,
description="List of unique OPTIMADE files entry resource objects.",
uniqueItems=True,
)
class ReferenceResponseOne(EntryResponseOne):
data: Annotated[
ReferenceResource | dict[str, Any] | None,
StrictField(
description="A single references entry resource.",
union_mode="left_to_right",
),
]
class ReferenceResponseMany(EntryResponseMany):
data: Annotated[
list[ReferenceResource] | list[dict[str, Any]],
StrictField(
description="List of unique OPTIMADE references entry resource objects.",
uniqueItems=True,
union_mode="left_to_right",
),
]