starlette_jsonapi.schema module
- class starlette_jsonapi.schema.JSONAPISchema(*args, **kwargs)
Bases:
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()
- OPTIONS_CLASS
alias of
BaseSchemaOpts
- class Meta
Bases:
object
Options object that takes the same options as
marshmallow-jsonapi.Schema
, but instead ofself_url
,self_url_kwargs
andself_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 forself_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 acollection of resources is returned.
- self_url = None
- self_url_kwargs = None
- self_url_many = None
- __init__(*args, **kwargs)
- generate_url(link, **kwargs)
- get_top_level_links(data, many)
Overriding base implementation to support serialization as a related resource.
- get_resource_links(item)
Override the marshmallow-jsonapi implementation to check for None links.
- classmethod get_fields()
- Return type
Dict[str, Field]
- opts = <starlette_jsonapi.schema.BaseSchemaOpts object>