rest_framework_json_api.schemas.openapi module

class rest_framework_json_api.schemas.openapi.AutoSchema(tags=None, operation_id_base=None, component_name=None)

Bases: AutoSchema

Extend DRF’s openapi.AutoSchema for JSON:API serialization.

content_types = ['application/vnd.api+json']
get_operation(path, method)

JSON:API adds some standard fields to the API response that are not in upstream DRF: - some that only apply to GET/HEAD methods. - collections - special handling for POST, PATCH, DELETE

get_operation_id(path, method)

The upstream DRF version creates non-unique operationIDs, because the same view is used for the main path as well as such as related and relationships. This concatenates the (mapped) method name and path as the spec allows most any

get_request_body(path, method)

A request body is required by JSON:API for POST, PATCH, and DELETE methods.

map_serializer(serializer)

Custom map_serializer that serializes the schema using the JSON:API spec.

Non-attributes like related and identity fields, are moved to ‘relationships’ and ‘links’.

class rest_framework_json_api.schemas.openapi.SchemaGenerator(title=None, url=None, description=None, patterns=None, urlconf=None, version=None)

Bases: SchemaGenerator

Extend DRF’s SchemaGenerator to implement JSON:API flavored generateschema command.

get_schema(request=None, public=False)

Generate a JSON:API OpenAPI schema. Overrides upstream DRF’s get_schema.

jsonapi_components = {'parameters': {'fields': {'description': '[sparse fieldsets](https://jsonapi.org/format/#fetching-sparse-fieldsets).\nUse fields[\\<typename\\>]=field1,field2,...,fieldN', 'explode': True, 'in': 'query', 'name': 'fields', 'required': False, 'schema': {'type': 'object'}, 'style': 'deepObject'}, 'include': {'description': '[list of included related resources](https://jsonapi.org/format/#fetching-includes)', 'in': 'query', 'name': 'include', 'required': False, 'schema': {'type': 'string'}, 'style': 'form'}}, 'schemas': {'ResourceIdentifierObject': {'oneOf': [{'$ref': '#/components/schemas/relationshipToOne'}, {'$ref': '#/components/schemas/relationshipToMany'}]}, 'datum': {'description': 'singular item', 'properties': {'data': {'$ref': '#/components/schemas/resource'}}}, 'error': {'additionalProperties': False, 'properties': {'code': {'type': 'string'}, 'detail': {'type': 'string'}, 'id': {'type': 'string'}, 'links': {'$ref': '#/components/schemas/links'}, 'source': {'properties': {'meta': {'$ref': '#/components/schemas/meta'}, 'parameter': {'description': 'A string indicating which query parameter caused the error.', 'type': 'string'}, 'pointer': {'description': 'A [JSON Pointer](https://tools.ietf.org/html/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.', 'type': 'string'}}, 'type': 'object'}, 'status': {'type': 'string'}, 'title': {'type': 'string'}}, 'type': 'object'}, 'errors': {'items': {'$ref': '#/components/schemas/error'}, 'type': 'array', 'uniqueItems': True}, 'failure': {'properties': {'errors': {'$ref': '#/components/schemas/errors'}, 'jsonapi': {'$ref': '#/components/schemas/jsonapi'}, 'links': {'$ref': '#/components/schemas/links'}, 'meta': {'$ref': '#/components/schemas/meta'}}, 'required': ['errors'], 'type': 'object'}, 'id': {'description': 'Each resource object’s type and id pair MUST [identify](https://jsonapi.org/format/#document-resource-object-identification) a single, unique resource.', 'type': 'string'}, 'include': {'additionalProperties': False, 'properties': {'attributes': {'additionalProperties': True, 'type': 'object'}, 'id': {'$ref': '#/components/schemas/id'}, 'links': {'$ref': '#/components/schemas/links'}, 'meta': {'$ref': '#/components/schemas/meta'}, 'relationships': {'additionalProperties': True, 'type': 'object'}, 'type': {'$ref': '#/components/schemas/type'}}, 'required': ['type', 'id'], 'type': 'object'}, 'jsonapi': {'additionalProperties': False, 'description': "The server's implementation", 'properties': {'meta': {'$ref': '#/components/schemas/meta'}, 'version': {'type': 'string'}}, 'type': 'object'}, 'link': {'oneOf': [{'description': "a string containing the link's URL", 'format': 'uri-reference', 'type': 'string'}, {'properties': {'href': {'description': "a string containing the link's URL", 'format': 'uri-reference', 'type': 'string'}, 'meta': {'$ref': '#/components/schemas/meta'}}, 'required': ['href'], 'type': 'object'}]}, 'linkage': {'description': "the 'type' and 'id'", 'properties': {'id': {'$ref': '#/components/schemas/id'}, 'meta': {'$ref': '#/components/schemas/meta'}, 'type': {'$ref': '#/components/schemas/type'}}, 'required': ['type', 'id'], 'type': 'object'}, 'links': {'additionalProperties': {'$ref': '#/components/schemas/link'}, 'type': 'object'}, 'meta': {'additionalProperties': True, 'type': 'object'}, 'nulltype': {'default': None, 'nullable': True, 'type': 'object'}, 'onlymeta': {'additionalProperties': False, 'properties': {'meta': {'$ref': '#/components/schemas/meta'}}}, 'pageref': {'oneOf': [{'format': 'uri-reference', 'type': 'string'}, {'$ref': '#/components/schemas/nulltype'}]}, 'pagination': {'properties': {'first': {'$ref': '#/components/schemas/pageref'}, 'last': {'$ref': '#/components/schemas/pageref'}, 'next': {'$ref': '#/components/schemas/pageref'}, 'prev': {'$ref': '#/components/schemas/pageref'}}, 'type': 'object'}, 'relationshipLinks': {'additionalProperties': True, 'description': 'optional references to other resource objects', 'properties': {'related': {'$ref': '#/components/schemas/link'}, 'self': {'$ref': '#/components/schemas/link'}}, 'type': 'object'}, 'relationshipToMany': {'description': "An array of objects each containing the 'type' and 'id' for to-many relationships", 'items': {'$ref': '#/components/schemas/linkage'}, 'type': 'array', 'uniqueItems': True}, 'relationshipToOne': {'anyOf': [{'$ref': '#/components/schemas/nulltype'}, {'$ref': '#/components/schemas/linkage'}], 'description': 'reference to other resource in a to-one relationship'}, 'reltomany': {'description': "a multiple 'to-many' relationship", 'properties': {'data': {'$ref': '#/components/schemas/relationshipToMany'}, 'links': {'$ref': '#/components/schemas/relationshipLinks'}, 'meta': {'$ref': '#/components/schemas/meta'}}, 'type': 'object'}, 'reltoone': {'description': "a singular 'to-one' relationship", 'properties': {'data': {'$ref': '#/components/schemas/relationshipToOne'}, 'links': {'$ref': '#/components/schemas/relationshipLinks'}, 'meta': {'$ref': '#/components/schemas/meta'}}, 'type': 'object'}, 'resource': {'additionalProperties': False, 'properties': {'attributes': {'type': 'object'}, 'id': {'$ref': '#/components/schemas/id'}, 'links': {'$ref': '#/components/schemas/links'}, 'meta': {'$ref': '#/components/schemas/meta'}, 'relationships': {'type': 'object'}, 'type': {'$ref': '#/components/schemas/type'}}, 'required': ['type', 'id'], 'type': 'object'}, 'type': {'description': 'The [type](https://jsonapi.org/format/#document-resource-object-identification) member is used to describe resource objects that share common attributes and relationships.', 'type': 'string'}}}