jsonapi¶
This module should reproduce JSON API v1.0 https://jsonapi.org/format/1.0/
Attributes
¶
Members of the attributes object ("attributes") represent information about the resource object in which it's defined.
The keys for Attributes MUST NOT be
relationships links id type
Source code in optimade/models/jsonapi.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
|
Config
¶
Source code in optimade/models/jsonapi.py
287 288 |
|
extra = 'allow'
class-attribute
¶
check_illegal_attributes_fields(values)
¶
Source code in optimade/models/jsonapi.py
290 291 292 293 294 295 296 297 298 |
|
BaseResource
¶
Minimum requirements to represent a Resource
Source code in optimade/models/jsonapi.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
id: str = StrictField(Ellipsis, description='Resource ID')
class-attribute
¶
type: str = StrictField(Ellipsis, description='Resource type')
class-attribute
¶
Config
¶
Source code in optimade/models/jsonapi.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
schema_extra(schema, model)
staticmethod
¶
Ensure id
and type
are the first two entries in the list required properties.
Note
This requires that id
and type
are the first model fields defined
for all sub-models of BaseResource
.
Source code in optimade/models/jsonapi.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
Error
¶
An error response
Source code in optimade/models/jsonapi.py
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 |
|
code: Optional[str] = StrictField(None, description='an application-specific error code, expressed as a string value.')
class-attribute
¶
detail: Optional[str] = StrictField(None, description='A human-readable explanation specific to this occurrence of the problem.')
class-attribute
¶
id: Optional[str] = StrictField(None, description='A unique identifier for this particular occurrence of the problem.')
class-attribute
¶
links: Optional[ErrorLinks] = StrictField(None, description='A links object storing about')
class-attribute
¶
meta: Optional[Meta] = StrictField(None, description='a meta object containing non-standard meta-information about the error.')
class-attribute
¶
source: Optional[ErrorSource] = StrictField(None, description='An object containing references to the source of the error')
class-attribute
¶
status: Optional[str] = StrictField(None, description='the HTTP status code applicable to this problem, expressed as a string value.')
class-attribute
¶
title: Optional[str] = StrictField(None, description='A short, human-readable summary of the problem. It **SHOULD NOT** change from occurrence to occurrence of the problem, except for purposes of localization.')
class-attribute
¶
__hash__()
¶
Source code in optimade/models/jsonapi.py
158 159 |
|
ErrorLinks
¶
A Links object specific to Error objects
Source code in optimade/models/jsonapi.py
100 101 102 103 104 105 106 |
|
about: Optional[Union[AnyUrl, Link]] = StrictField(None, description='A link that leads to further details about this particular occurrence of the problem.')
class-attribute
¶
ErrorSource
¶
an object containing references to the source of the error
Source code in optimade/models/jsonapi.py
109 110 111 112 113 114 115 116 117 118 119 120 |
|
parameter: Optional[str] = StrictField(None, description='a string indicating which URI query parameter caused the error.')
class-attribute
¶
pointer: Optional[str] = StrictField(None, description='a JSON Pointer [RFC6901] to the associated entity in the request document [e.g. "/data" for a primary data object, or "/data/attributes/title" for a specific attribute].')
class-attribute
¶
JsonApi
¶
An object describing the server's implementation
Source code in optimade/models/jsonapi.py
49 50 51 52 53 54 55 56 57 |
|
Link
¶
A link MUST be represented as either: a string containing the link's URL or a link object.
Source code in optimade/models/jsonapi.py
39 40 41 42 43 44 45 46 |
|
Meta
¶
Non-standard meta-information that can not be represented as an attribute or relationship.
Source code in optimade/models/jsonapi.py
32 33 34 35 36 |
|
Relationship
¶
Representation references from the resource object in which it’s defined to other resource objects.
Source code in optimade/models/jsonapi.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
data: Optional[Union[BaseResource, List[BaseResource]]] = StrictField(None, description='Resource linkage')
class-attribute
¶
links: Optional[RelationshipLinks] = StrictField(None, description='a links object containing at least one of the following: self, related')
class-attribute
¶
meta: Optional[Meta] = StrictField(None, description='a meta object that contains non-standard meta-information about the relationship.')
class-attribute
¶
at_least_one_relationship_key_must_be_set(values)
¶
Source code in optimade/models/jsonapi.py
237 238 239 240 241 242 243 244 245 246 |
|
RelationshipLinks
¶
A resource object MAY contain references to other resource objects ("relationships"). Relationships may be to-one or to-many. Relationships can be specified by including a member in a resource's links object.
Source code in optimade/models/jsonapi.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
related: Optional[Union[AnyUrl, Link]] = StrictField(None, description='A [related resource link](https://jsonapi.org/format/1.0/#document-resource-object-related-resource-links).')
class-attribute
¶
self: Optional[Union[AnyUrl, Link]] = StrictField(None, description="A link for the relationship itself (a 'relationship link').\nThis link allows the client to directly manipulate the relationship.\nWhen fetched successfully, this link returns the [linkage](https://jsonapi.org/format/1.0/#document-resource-object-linkage) for the related resources as its primary data.\n(See [Fetching Relationships](https://jsonapi.org/format/1.0/#fetching-relationships).)")
class-attribute
¶
either_self_or_related_must_be_specified(values)
¶
Source code in optimade/models/jsonapi.py
210 211 212 213 214 215 216 217 218 219 |
|
Relationships
¶
Members of the relationships object ("relationships") represent references from the resource object in which it's defined to other resource objects.
Keys MUST NOT be
type id
Source code in optimade/models/jsonapi.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
check_illegal_relationships_fields(values)
¶
Source code in optimade/models/jsonapi.py
257 258 259 260 261 262 263 264 265 |
|
Resource
¶
Resource objects appear in a JSON API document to represent resources.
Source code in optimade/models/jsonapi.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
|
attributes: Optional[Attributes] = StrictField(None, description='an attributes object representing some of the resource’s data.')
class-attribute
¶
links: Optional[ResourceLinks] = StrictField(None, description='a links object containing links related to the resource.')
class-attribute
¶
meta: Optional[Meta] = StrictField(None, description='a meta object containing non-standard meta-information about a resource that can not be represented as an attribute or relationship.')
class-attribute
¶
relationships: Optional[Relationships] = StrictField(None, description='[Relationships object](https://jsonapi.org/format/1.0/#document-resource-object-relationships)\ndescribing relationships between the resource and other JSON API resources.')
class-attribute
¶
ResourceLinks
¶
A Resource Links object
Source code in optimade/models/jsonapi.py
268 269 270 271 272 273 274 |
|
self: Optional[Union[AnyUrl, Link]] = StrictField(None, description='A link that identifies the resource represented by the resource object.')
class-attribute
¶
Response
¶
A top-level response
Source code in optimade/models/jsonapi.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
|
data: Optional[Union[None, Resource, List[Resource]]] = StrictField(None, description='Outputted Data', uniqueItems=True)
class-attribute
¶
errors: Optional[List[Error]] = StrictField(None, description='A list of unique errors', uniqueItems=True)
class-attribute
¶
included: Optional[List[Resource]] = StrictField(None, description='A list of unique included resources', uniqueItems=True)
class-attribute
¶
jsonapi: Optional[JsonApi] = StrictField(None, description='Information about the JSON API used')
class-attribute
¶
links: Optional[ToplevelLinks] = StrictField(None, description='Links associated with the primary data or errors')
class-attribute
¶
meta: Optional[Meta] = StrictField(None, description='A meta object containing non-standard information related to the Success')
class-attribute
¶
Config
¶
The specification mandates that datetimes must be encoded following RFC3339, which does not support fractional seconds, thus they must be stripped in the response. This can cause issues when the underlying database contains fields that do include microseconds, as filters may return unexpected results.
Source code in optimade/models/jsonapi.py
356 357 358 359 360 361 362 363 364 365 366 367 368 |
|
json_encoders = {datetime: lambda v: v.astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')}
class-attribute
¶
either_data_meta_or_errors_must_be_set(values)
¶
Source code in optimade/models/jsonapi.py
345 346 347 348 349 350 351 352 353 354 |
|
ToplevelLinks
¶
A set of Links objects, possibly including pagination
Source code in optimade/models/jsonapi.py
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 |
|
first: Optional[Union[AnyUrl, Link]] = StrictField(None, description='The first page of data')
class-attribute
¶
last: Optional[Union[AnyUrl, Link]] = StrictField(None, description='The last page of data')
class-attribute
¶
next: Optional[Union[AnyUrl, Link]] = StrictField(None, description='The next page of data')
class-attribute
¶
prev: Optional[Union[AnyUrl, Link]] = StrictField(None, description='The previous page of data')
class-attribute
¶
related: Optional[Union[AnyUrl, Link]] = StrictField(None, description='A related resource link')
class-attribute
¶
self: Optional[Union[AnyUrl, Link]] = StrictField(None, description='A link to itself')
class-attribute
¶
Config
¶
Source code in optimade/models/jsonapi.py
96 97 |
|
extra = 'allow'
class-attribute
¶
check_additional_keys_are_links(values)
¶
The ToplevelLinks
class allows any additional keys, as long as
they are also Links or Urls themselves.
Source code in optimade/models/jsonapi.py
84 85 86 87 88 89 90 91 92 93 94 |
|