starlette_jsonapi.schema module

class starlette_jsonapi.schema.JSONAPISchema(*args, **kwargs)

Bases: marshmallow_jsonapi.schema.Schema

Extends marshmallow_jsonapi.Schema to offer Starlette support.

For extended information on what fields are required, or how to configure each field in a schema, you should consult the docs for:

When specifying related objects, the starlette_jsonapi.fields.JSONAPIRelationship field should be used, to support generating URLs from Starlette routes.

Example definition:

from marshmallow_jsonapi import fields

# example model
class User:
    id: int
    name: str

# example schema
class UserSchema(JSONAPISchema):
    class Meta:
        type_ = 'users'

    id = fields.Str()  # Exposed as a string, according to the json:api spec
    name = fields.Str()

alias of starlette_jsonapi.schema.BaseSchemaOpts

class Meta

Bases: object

Options object that takes the same options as marshmallow-jsonapi.Schema, but instead of self_url, self_url_kwargs and self_url_many has the following options to resolve the URLs from Starlette route names:

  • self_route - Route name to resolve the self URL link from.

  • self_route_kwargs - Replacement fields for self_route.

    String attributes enclosed in < > will be interpreted as attributes of the serialized object.

  • self_route_many - Route name to resolve the self URL link when a

    collection of resources is returned.

self_url = None
self_url_kwargs = None
self_url_many = None
__init__(*args, **kwargs)
generate_url(link, **kwargs)

Overriding base implementation to support serialization as a related resource.

Override the marshmallow-jsonapi implementation to check for None links.

classmethod get_fields()
Return type

Dict[str, marshmallow.fields.Field]

opts = <starlette_jsonapi.schema.BaseSchemaOpts object>