API Reference
v1.1¶
Content Type¶
AcceptHeaderError
¶
ContentNegotiation
¶
Class to handle content negotiation according to the JSON:API specification.
Source code in pyjas/v1_1/content_negotiation.py
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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
__init__(supported_extensions=None)
¶
Initialize with the list of supported extension URIs.
generate_vary_header()
¶
validate_accept_header(accept_header)
¶
Validate the Accept header of a request.
Raises:
Type | Description |
---|---|
AcceptHeaderError
|
If the Accept header is invalid or not acceptable. |
Source code in pyjas/v1_1/content_negotiation.py
validate_content_type_header(content_type_str)
¶
Validate the Content-Type header of a request.
Raises:
Type | Description |
---|---|
ContentTypeError
|
If the Content-Type header is invalid. |
Source code in pyjas/v1_1/content_negotiation.py
ContentType
¶
Source code in pyjas/v1_1/content_negotiation.py
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 |
|
extensions: list[str]
property
¶
Return the list of extension URIs.
profiles: list[str]
property
¶
Return the list of profile URIs.
create(extensions=None, profiles=None)
classmethod
¶
Create a ContentType instance with the given extensions and profiles.
Source code in pyjas/v1_1/content_negotiation.py
parse(content_type_str)
classmethod
¶
Parse a content type string and return a ContentType instance.
Source code in pyjas/v1_1/content_negotiation.py
to_string()
¶
Serialize the ContentType back to a string.
Source code in pyjas/v1_1/content_negotiation.py
validate()
¶
Validate the media type and parameters according to the JSON:API spec.
Source code in pyjas/v1_1/content_negotiation.py
JSON API Reference¶
LinkValue = Union[str, LinkObject, None]
module-attribute
¶
LinkValue: a union type for link values in JSON:API documents.
Refer to https://jsonapi.org/format/#document-links for more information.
LinkValue can be one of the following types: - str: a string whose value is a URI-reference [RFC3986 Section 4.1] pointing to the link's target, - LinkObject: a LinkObject instance. - None: a null value if the link does not exist.
Document
¶
Bases: BaseModel
Source code in pyjas/v1_1/jsonapi_builder.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 |
|
validate_document()
¶
Validate the Document according to the JSON:API spec.
Source code in pyjas/v1_1/jsonapi_builder.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
|
JSONAPIObject
¶
Bases: BaseModel
JSONAPIObject enforces the JSON:API version in a JSON:API document.
Refer to https://jsonapi.org/format/#document-jsonapi-object for more information.
Required fields
version (str): The JSON:API version. Default is '1.1'.
Optional fields
meta (dict): a meta object containing non-standard meta-information about the JSON:API document.
Raises:
Type | Description |
---|---|
ValueError
|
ensure 'version' is one of the allowed JSON:API versions. |
Source code in pyjas/v1_1/jsonapi_builder.py
must_have_correct_version(v)
classmethod
¶
Validate the 'version' field according to the JSON:API spec.
Source code in pyjas/v1_1/jsonapi_builder.py
LinkObject
¶
Bases: BaseModel
LinkObject enforces a link in a JSON:API document.
Refer to https://jsonapi.org/format/#auto-id--link-objects for more information.
Required fields
href (HttpUrl): The URL of the link.
Optional fields
rel (str): a string indicating the link's relation type. The string MUST be a valid link relation type. describedby (HttpUrl): a link to a description document (e.g. OpenAPI or JSON Schema) for the link target. title (str): a string which serves as a label for the destination of a link such that it can be used as a human-readable identifier (e.g., a menu entry). type (str): a string indicating the media type of the link's target. hreflang (str | list[str]): a string or an array of strings indicating the language(s) of the link's target. An array of strings indicates that the link's target is available in multiple languages. Each string MUST be a valid language tag [RFC5646]. meta (dict): a meta object containing non-standard meta-information about the link.
Raises:
Type | Description |
---|---|
ValueError
|
href and describedby are invalid URIs. |
ValueError
|
each hreflang language tag is valid according to RFC 5646. |
ValueError
|
ensure type and rel fields are strings, if present. |
Source code in pyjas/v1_1/jsonapi_builder.py
validate_link_object()
¶
Validate the LinkObject according to the JSON:API spec.
Source code in pyjas/v1_1/jsonapi_builder.py
RelationshipObject
¶
Bases: BaseModel
RelationshipObject enforces a relationship in a JSON:API document.
Refer to https://jsonapi.org/format/#document-resource-object-relationships for more information.
Please note that extra members are allowed in the RelationshipObject.
Optional fields
links (dict): a links object containing links related to the resource. data (ResourceIdentifierObject | list[ResourceIdentifierObject]): resource linkage. meta (dict): a meta object containing non-standard meta-information about the relationship.
Raises:
Type | Description |
---|---|
ValueError
|
ensure at least one of 'links', 'data', or 'meta' is present. |
Source code in pyjas/v1_1/jsonapi_builder.py
validate_relationship()
¶
Validate the RelationshipObject according to the JSON:API spec.
Source code in pyjas/v1_1/jsonapi_builder.py
ResourceIdentifierObject
¶
Bases: BaseModel
ResourceIdentifierObject enforces a resource identifier in a JSON:API document.
Refer to https://jsonapi.org/format/#auto-id--link-objects for more information. Note that extra members are allowed in the ResourceIdentifierObject.
Required fields
type (NonEmptyStr): The type of the resource.
Optional fields
id (NonEmptyStr): The id of the resource. lid (NonEmptyStr): A locally unique identifier for the resource. meta (dict): a meta object containing non-standard meta-information about the resource.
Raises:
Type | Description |
---|---|
ValueError
|
ensure at least 'id' or 'lid' are present. |
ValueError
|
ensure 'type' is a string. |
ValueError
|
ensure 'id' and 'lid' are strings, if present. |
Source code in pyjas/v1_1/jsonapi_builder.py
validate_id_or_lid()
¶
Check that the ResourceIdentifierObject has either id or lid.
Source code in pyjas/v1_1/jsonapi_builder.py
ResourceObject
¶
Bases: BaseModel
ResourceObject enforces a resource object in a JSON:API document.
Refer to https://jsonapi.org/format/#document-resource-objects for more information. Note that extra members are not allowed in the ResourceObject.
Required fields
type (str): The type of the resource.
Optional fields
id (str): The id of the resource. lid (str): A locally unique identifier for the resource. attributes (dict): an attributes object representing some of the resource's data. relationships (dict): a relationships object describing relationships between the resource and other resources. links (dict): a links object containing links related to the resource. meta (dict): a meta object containing non-standard meta-information about the resource.
Raises:
Type | Description |
---|---|
ValueError
|
ensure 'type' is a string. |
ValueError
|
ensure either 'id' or 'lid' is present. |
ValueError
|
ensure 'id' or 'lid' are strings, if present. |
ValueError
|
ensure no field name conflicts between attributes and relationships. |
ValueError
|
ensure attribute keys do not include 'type', 'id', 'lid'. |
ValueError
|
ensure relationship keys do not include 'type', 'id', 'lid'. |
ValueError
|
ensure no foreign keys in attributes (e.g., 'author_id'). |
ValueError
|
ensure all included resources are reachable from primary data. |
ValueError
|
ensure all included resources are unique. |
ValueError
|
ensure all included resources are linked from primary data. |
ValueError
|
ensure links are valid URIs. |
ValueError
|
ensure links are valid LinkObjects. |
ValueError
|
ensure links are valid keys ('self', 'related', 'describedby', 'pagination'). |
ValueError
|
ensure 'lid' is unique within the document. |
Source code in pyjas/v1_1/jsonapi_builder.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 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 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
|
from_model(model, type_=None, id_=None, relationships=None, links=None, meta=None, lid_registry=None)
classmethod
¶
Create a ResourceObject from a Pydantic BaseModel instance.
Source code in pyjas/v1_1/jsonapi_builder.py
validate_resource_object()
¶
Validate the ResourceObject according to the JSON:API spec.
Source code in pyjas/v1_1/jsonapi_builder.py
validate_member_name(name)
¶
Validates a JSON:API member name according to the specification rules.
Refer to https://jsonapi.org/format/#document-member-names for more information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The member name to validate. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the member name does not comply with the rules. |