flask_combo_jsonapi package¶
flask_combo_jsonapi.data_layers.filtering.alchemy module¶
Helper to create sqlalchemy filters according to filter querystring parameter
- class flask_combo_jsonapi.data_layers.filtering.alchemy.Node(model, filter_, resource, schema)¶
Bases:
objectHelper to recursively create filters with sqlalchemy according to filter querystring parameter
- property column¶
Get the column object
- create_filter(marshmallow_field, model_column, operator, value)¶
Create sqlalchemy filter :param marshmallow_field: :param model_column: column sqlalchemy :param operator: :param value: :return:
- property name¶
Return the name of the node or raise a BadRequest exception
- Return str
the name of the field to filter on
- property op¶
Return the operator of the node
- Return str
the operator to use in the filter
- property operator¶
Get the function operator from his name
- Return callable
a callable to make operation on a column
Get the related model of a relationship field
- Return DeclarativeMeta
the related model
Get the related schema of a relationship field
- Return Schema
the related schema
- resolve() Tuple[BinaryExpression, List[List[Any]]]¶
Create filter for a particular node of the filter tree
- property value¶
Get the value to filter on
- Returns
the value to filter on
flask_combo_jsonapi.data_layers.base module¶
Helper to create sqlalchemy filters according to filter querystring parameter
- class flask_combo_jsonapi.data_layers.filtering.alchemy.Node(model, filter_, resource, schema)¶
Bases:
objectHelper to recursively create filters with sqlalchemy according to filter querystring parameter
- property column¶
Get the column object
- create_filter(marshmallow_field, model_column, operator, value)¶
Create sqlalchemy filter :param marshmallow_field: :param model_column: column sqlalchemy :param operator: :param value: :return:
- property name¶
Return the name of the node or raise a BadRequest exception
- Return str
the name of the field to filter on
- property op¶
Return the operator of the node
- Return str
the operator to use in the filter
- property operator¶
Get the function operator from his name
- Return callable
a callable to make operation on a column
- property related_model¶
Get the related model of a relationship field
- Return DeclarativeMeta
the related model
- property related_schema¶
Get the related schema of a relationship field
- Return Schema
the related schema
- resolve() Tuple[BinaryExpression, List[List[Any]]]¶
Create filter for a particular node of the filter tree
- property value¶
Get the value to filter on
- Returns
the value to filter on
flask_combo_jsonapi.data_layers.alchemy module¶
This module is a CRUD interface between resource managers and the sqlalchemy ORM
- class flask_combo_jsonapi.data_layers.alchemy.SqlalchemyDataLayer(kwargs)¶
Bases:
BaseDataLayerSqlalchemy data layer
- after_create_object(obj, data, view_kwargs)¶
Provide additional data after object creation
- Parameters
obj – an object from data layer
data (dict) – the data validated by marshmallow
view_kwargs (dict) – kwargs from the resource view
- after_create_relationship(obj, updated, json_data, relationship_field, related_id_field, view_kwargs)¶
Make work after to create a relationship
- Parameters
obj – an object from data layer
updated (bool) – True if object was updated else False
json_data (dict) – the request params
relationship_field (str) – the model attribute used for relationship
related_id_field (str) – the identifier field of the related model
view_kwargs (dict) – kwargs from the resource view
- Return boolean
True if relationship have changed else False
- after_delete_object(obj, view_kwargs)¶
Make work after delete object
- Parameters
obj – an object from data layer
view_kwargs (dict) – kwargs from the resource view
- after_delete_relationship(obj, updated, json_data, relationship_field, related_id_field, view_kwargs)¶
Make work after to delete a relationship
- Parameters
obj – an object from data layer
updated (bool) – True if object was updated else False
json_data (dict) – the request params
relationship_field (str) – the model attribute used for relationship
related_id_field (str) – the identifier field of the related model
view_kwargs (dict) – kwargs from the resource view
- after_get_collection(collection, qs, view_kwargs)¶
Make work after to retrieve a collection of objects
- Parameters
collection (iterable) – the collection of objects
qs (QueryStringManager) – a querystring manager to retrieve information from url
view_kwargs (dict) – kwargs from the resource view
- after_get_object(obj, view_kwargs)¶
Make work after to retrieve an object
- Parameters
obj – an object from data layer
view_kwargs (dict) – kwargs from the resource view
- after_get_relationship(obj, related_objects, relationship_field, related_type_, related_id_field, view_kwargs)¶
Make work after to get information about a relationship
- Parameters
obj – an object from data layer
related_objects (iterable) – related objects of the object
relationship_field (str) – the model attribute used for relationship
related_type (str) – the related resource type
related_id_field (str) – the identifier field of the related model
view_kwargs (dict) – kwargs from the resource view
- Return tuple
the object and related object(s)
- after_update_object(obj, data, view_kwargs)¶
Make work after update object
- Parameters
obj – an object from data layer
data (dict) – the data validated by marshmallow
view_kwargs (dict) – kwargs from the resource view
- after_update_relationship(obj, updated, json_data, relationship_field, related_id_field, view_kwargs)¶
Make work after to update a relationship
- Parameters
obj – an object from data layer
updated (bool) – True if object was updated else False
json_data (dict) – the request params
relationship_field (str) – the model attribute used for relationship
related_id_field (str) – the identifier field of the related model
view_kwargs (dict) – kwargs from the resource view
- Return boolean
True if relationship have changed else False
- apply_nested_fields(data, obj)¶
- apply_relationships(data, obj)¶
Apply relationship provided by data to obj
- Parameters
data (dict) – data provided by the client
obj (DeclarativeMeta) – the sqlalchemy object to plug relationships to
- Return boolean
True if relationship have changed else False
- before_create_object(data, view_kwargs)¶
Provide additional data before object creation
- Parameters
data (dict) – the data validated by marshmallow
view_kwargs (dict) – kwargs from the resource view
- before_create_relationship(json_data, relationship_field, related_id_field, view_kwargs)¶
Make work before to create a relationship
- Parameters
json_data (dict) – the request params
relationship_field (str) – the model attribute used for relationship
related_id_field (str) – the identifier field of the related model
view_kwargs (dict) – kwargs from the resource view
- Return boolean
True if relationship have changed else False
- before_delete_object(obj, view_kwargs)¶
Make checks before delete object
- Parameters
obj – an object from data layer
view_kwargs (dict) – kwargs from the resource view
- before_delete_relationship(json_data, relationship_field, related_id_field, view_kwargs)¶
Make work before to delete a relationship
- Parameters
json_data (dict) – the request params
relationship_field (str) – the model attribute used for relationship
related_id_field (str) – the identifier field of the related model
view_kwargs (dict) – kwargs from the resource view
- before_get_collection(qs, view_kwargs)¶
Make work before to retrieve a collection of objects
- Parameters
qs (QueryStringManager) – a querystring manager to retrieve information from url
view_kwargs (dict) – kwargs from the resource view
- before_get_object(view_kwargs)¶
Make work before to retrieve an object
- Parameters
view_kwargs (dict) – kwargs from the resource view
- before_get_relationship(relationship_field, related_type_, related_id_field, view_kwargs)¶
Make work before to get information about a relationship
- Parameters
relationship_field (str) – the model attribute used for relationship
related_type (str) – the related resource type
related_id_field (str) – the identifier field of the related model
view_kwargs (dict) – kwargs from the resource view
- Return tuple
the object and related object(s)
- before_update_object(obj, data, view_kwargs)¶
Make checks or provide additional data before update object
- Parameters
obj – an object from data layer
data (dict) – the data validated by marshmallow
view_kwargs (dict) – kwargs from the resource view
- before_update_relationship(json_data, relationship_field, related_id_field, view_kwargs)¶
Make work before to update a relationship
- Parameters
json_data (dict) – the request params
relationship_field (str) – the model attribute used for relationship
related_id_field (str) – the identifier field of the related model
view_kwargs (dict) – kwargs from the resource view
- Return boolean
True if relationship have changed else False
- create_object(data, view_kwargs)¶
Create an object through sqlalchemy
- Parameters
data (dict) – the data validated by marshmallow
view_kwargs (dict) – kwargs from the resource view
- Return DeclarativeMeta
an object from sqlalchemy
- create_relationship(json_data, relationship_field, related_id_field, view_kwargs)¶
Create a relationship
- Parameters
json_data (dict) – the request params
relationship_field (str) – the model attribute used for relationship
related_id_field (str) – the identifier field of the related model
view_kwargs (dict) – kwargs from the resource view
- Return boolean
True if relationship have changed else False
- delete_object(obj, view_kwargs)¶
Delete an object through sqlalchemy
- Parameters
item (DeclarativeMeta) – an item from sqlalchemy
view_kwargs (dict) – kwargs from the resource view
- delete_relationship(json_data, relationship_field, related_id_field, view_kwargs)¶
Delete a relationship
- Parameters
json_data (dict) – the request params
relationship_field (str) – the model attribute used for relationship
related_id_field (str) – the identifier field of the related model
view_kwargs (dict) – kwargs from the resource view
- eagerload_includes(query, qs)¶
Use eagerload feature of sqlalchemy to optimize data retrieval for include querystring parameter
- Parameters
query (Query) – sqlalchemy queryset
qs (QueryStringManager) – a querystring manager to retrieve information from url
- Return Query
the query with includes eagerloaded
- filter_query(query, filter_info, model)¶
Filter query according to jsonapi 1.0
- Parameters
query (Query) – sqlalchemy query to sort
filter_info (dict or None) – filter information
model (DeclarativeMeta) – an sqlalchemy model
- Return Query
the sorted query
- get_collection(qs, view_kwargs)¶
Retrieve a collection of objects through sqlalchemy
- Parameters
qs (QueryStringManager) – a querystring manager to retrieve information from url
view_kwargs (dict) – kwargs from the resource view
- Return tuple
the number of object and the list of objects
- get_collection_count(query, qs, view_kwargs) int¶
- Parameters
query – SQLAlchemy query
qs – QueryString
view_kwargs – view kwargs
- Returns
- get_object(view_kwargs, qs=None)¶
Retrieve an object through sqlalchemy
- Params dict view_kwargs
kwargs from the resource view
- Return DeclarativeMeta
an object from sqlalchemy
Get a related object
- Parameters
related_model (Model) – an sqlalchemy model
related_id_field (str) – the identifier field of the related model
obj (DeclarativeMeta) – the sqlalchemy object to retrieve related objects from
- Return DeclarativeMeta
a related object
- get_relationship(relationship_field, related_type_, related_id_field, view_kwargs)¶
Get a relationship
- Parameters
relationship_field (str) – the model attribute used for relationship
related_type (str) – the related resource type
related_id_field (str) – the identifier field of the related model
view_kwargs (dict) – kwargs from the resource view
- Return tuple
the object and related object(s)
- paginate_query(query, paginate_info)¶
Paginate query according to jsonapi 1.0
- Parameters
query (Query) – sqlalchemy queryset
paginate_info (dict) – pagination information
- Return Query
the paginated query
- post_init()¶
Checking some props here :return:
- query(view_kwargs)¶
Construct the base query to retrieve wanted data
- Parameters
view_kwargs (dict) – kwargs from the resource view
- retrieve_object_query(view_kwargs, filter_field, filter_value)¶
Build query to retrieve object
- Parameters
view_kwargs (dict) – kwargs from the resource view
- Params sqlalchemy_field filter_field
the field to filter on
- Params filter_value
the value to filter with
- Return sqlalchemy query
a query from sqlalchemy
- sort_query(query, sort_info)¶
Sort query according to jsonapi 1.0
- Parameters
query (Query) – sqlalchemy query to sort
sort_info (list) – sort information
- Return Query
the sorted query
- update_object(obj, data, view_kwargs)¶
Update an object through sqlalchemy
- Parameters
obj (DeclarativeMeta) – an object from sqlalchemy
data (dict) – the data validated by marshmallow
view_kwargs (dict) – kwargs from the resource view
- Return boolean
True if object have changed else False
- update_relationship(json_data, relationship_field, related_id_field, view_kwargs)¶
Update a relationship
- Parameters
json_data (dict) – the request params
relationship_field (str) – the model attribute used for relationship
related_id_field (str) – the identifier field of the related model
view_kwargs (dict) – kwargs from the resource view
- Return boolean
True if relationship have changed else False
flask_combo_jsonapi.api module¶
This module contains the main class of the Api to initialize the Api, plug default decorators for each resources methods, speficy which blueprint to use, define the Api routes and plug additional oauth manager and permission manager
- class flask_combo_jsonapi.api.Api(app=None, blueprint=None, decorators=None, plugins=None, qs_manager_class=None)¶
Bases:
objectThe main class of the Api
- static build_scope(resource, method)¶
Compute the name of the scope for oauth
- Parameters
resource (Resource) – the resource manager
method (str) – an http method
- Return str
the name of the scope
- static check_permissions(view, view_args, view_kwargs, *args, **kwargs)¶
The function use to check permissions
- Parameters
view (callable) – the view
view_args (list) – view args
view_kwargs (dict) – view kwargs
args (list) – decorator args
kwargs (dict) – decorator kwargs
- has_permission(*args, **kwargs)¶
Decorator used to check permissions before to call resource manager method
- init_app(app=None, blueprint=None, additional_blueprints=None)¶
Update flask application with our api
- Parameters
app (Application) – a flask application
blueprint –
additional_blueprints –
- oauth_manager(oauth_manager)¶
Use the oauth manager to enable oauth for API
- Parameters
oauth_manager – the oauth manager
- permission_manager(permission_manager, with_decorators=True)¶
Use permission manager to enable permission for API
- Parameters
permission_manager (callable) – the permission manager
flask_combo_jsonapi.constants module¶
flask_combo_jsonapi.decorators module¶
Decorators to check headers and method requirements for each Api calls
- flask_combo_jsonapi.decorators.check_headers(func)¶
Check headers according to jsonapi reference
- Parameters
func (callable) – the function to decorate
- Return callable
the wrapped function
- flask_combo_jsonapi.decorators.check_method_requirements(func)¶
Check methods requirements
- Parameters
func (callable) – the function to decorate
- Return callable
the wrapped function
- flask_combo_jsonapi.decorators.jsonapi_exception_formatter(func)¶
flask_combo_jsonapi.errors module¶
Helper to format Api errors according to jsonapi specification
- flask_combo_jsonapi.errors.format_http_exception(ex)¶
try to format http exception to jsonapi 1.0 Warning! It only works for errors with status code less than 500 :param ex: http exception :return:
- flask_combo_jsonapi.errors.jsonapi_errors(jsonapi_errors)¶
Construct api error according to jsonapi 1.0
- Parameters
jsonapi_errors (iterable) – an iterable of jsonapi error
- Return dict
a dict of errors according to jsonapi 1.0
flask_combo_jsonapi.exceptions module¶
Collection of useful http error for the Api
- exception flask_combo_jsonapi.exceptions.AccessDenied(detail, source=None, title=None, status=None, code=None, id_=None, links=None, meta=None)¶
Bases:
JsonApiExceptionThrow this error when requested resource owner doesn’t match the user of the ticket
- status = '403'¶
- title = 'Access denied'¶
- exception flask_combo_jsonapi.exceptions.BadRequest(detail, source=None, title=None, status=None, code=None, id_=None, links=None, meta=None)¶
Bases:
JsonApiExceptionBadRequest error
- status = '400'¶
- title = 'Bad request'¶
- exception flask_combo_jsonapi.exceptions.InvalidField(detail, source=None, title=None, status=None, code=None, id_=None, links=None, meta=None)¶
Bases:
BadRequestError to warn that a field specified in fields querystring is not in the requested resource schema
- source = {'parameter': 'fields'}¶
- title = 'Invalid fields querystring parameter.'¶
- exception flask_combo_jsonapi.exceptions.InvalidFilters(detail, source=None, title=None, status=None, code=None, id_=None, links=None, meta=None)¶
Bases:
BadRequestError to warn that a specified filters in querystring parameter contains errors
- source = {'parameter': 'filters'}¶
- title = 'Invalid filters querystring parameter.'¶
- exception flask_combo_jsonapi.exceptions.InvalidInclude(detail, source=None, title=None, status=None, code=None, id_=None, links=None, meta=None)¶
Bases:
BadRequestError to warn that a field specified in include querystring parameter is not a relationship of the requested resource schema
- source = {'parameter': 'include'}¶
- title = 'Invalid include querystring parameter.'¶
- exception flask_combo_jsonapi.exceptions.InvalidSort(detail, source=None, title=None, status=None, code=None, id_=None, links=None, meta=None)¶
Bases:
BadRequestError to warn that a field specified in sort querystring parameter is not in the requested resource schema
- source = {'parameter': 'sort'}¶
- title = 'Invalid sort querystring parameter.'¶
- exception flask_combo_jsonapi.exceptions.InvalidType(detail, source=None, title=None, status=None, code=None, id_=None, links=None, meta=None)¶
Bases:
JsonApiExceptionError to warn that there is a conflit between resource types
- status = '409'¶
- title = 'Invalid type'¶
- exception flask_combo_jsonapi.exceptions.JsonApiException(detail, source=None, title=None, status=None, code=None, id_=None, links=None, meta=None)¶
Bases:
ExceptionBase exception class for unknown errors
- source = None¶
- status = '500'¶
- title = 'Unknown error'¶
- to_dict()¶
Return values of each fields of an jsonapi error
- exception flask_combo_jsonapi.exceptions.JsonApiPluginException¶
Bases:
ExceptionBase class for all JsonApi in plugin-related errors.
- exception flask_combo_jsonapi.exceptions.ObjectNotFound(detail, source=None, title=None, status=None, code=None, id_=None, links=None, meta=None)¶
Bases:
JsonApiExceptionError to warn that an object is not found in a database
- status = '404'¶
- title = 'Object not found'¶
- exception flask_combo_jsonapi.exceptions.PluginMethodNotImplementedError¶
Bases:
JsonApiPluginException,NotImplementedErrorRaised when calling an unimplemented helper method in a plugin
- exception flask_combo_jsonapi.exceptions.RelatedObjectNotFound(detail, source=None, title=None, status=None, code=None, id_=None, links=None, meta=None)¶
Bases:
ObjectNotFoundError to warn that a related object is not found
- title = 'Related object not found'¶
- exception flask_combo_jsonapi.exceptions.RelationNotFound(detail, source=None, title=None, status=None, code=None, id_=None, links=None, meta=None)¶
Bases:
JsonApiExceptionError to warn that a relationship is not found on a model
- title = 'Relation not found'¶
- exception flask_combo_jsonapi.exceptions.Unauthorized(detail, source=None, title=None, status=None, code=None, id_=None, links=None, meta=None)¶
Bases:
JsonApiExceptionThrow this error if the user is not authorized
- status = '401'¶
- title = 'Unauthorized'¶
flask_combo_jsonapi.pagination module¶
Helper to create pagination links according to jsonapi specification
- flask_combo_jsonapi.pagination.add_pagination_links(data, object_count, querystring, base_url)¶
Add pagination links to result
- Parameters
data (dict) – the result of the view
object_count (int) – number of objects in result
querystring (QueryStringManager) – the managed querystring fields and values
base_url (str) – the base url for pagination
flask_combo_jsonapi.querystring module¶
Helper to deal with querystring parameters according to jsonapi specification
- class flask_combo_jsonapi.querystring.QueryStringManager(querystring, schema)¶
Bases:
objectQuerystring parser according to jsonapi reference
- MANAGED_KEYS = ('filter', 'page', 'fields', 'sort', 'include', 'q')¶
- property fields¶
Return fields wanted by client.
- Return dict
a dict of sparse fieldsets information
Return value will be a dict containing all fields by resource, for example:
{ "user": ['name', 'email'], }
- property filters¶
Return filters from query string.
- Return list
filter information
- property include¶
Return fields to include
- Return list
a list of include information
- property pagination¶
Return parameters page[size] and page[number) as a dict. If missing parmeter size then default parameter PAGE_SIZE is used.
- Return dict
a dict of pagination information
Example with number strategy:
>>> query_string = {'page[number]': '25', 'page[size]': '10'} >>> parsed_query.pagination {'number': 25, 'size': 10}
- property querystring¶
Return original querystring but containing only managed keys
- Return dict
dict of managed querystring parameter
- property sorting¶
Return fields to sort by including sort name for SQLAlchemy and row sort parameter for other ORMs
- Return list
a list of sorting information
Example of return value:
[ {'field': 'created_at', 'order': 'desc'}, ]
flask_combo_jsonapi.resource module¶
This module contains the logic of resource management
- class flask_combo_jsonapi.resource.Resource¶
Bases:
MethodViewBase resource class
- dispatch_request(*args, **kwargs)¶
Logic of how to handle a request
- qs_manager_class¶
alias of
QueryStringManager
- class flask_combo_jsonapi.resource.ResourceDetail¶
Bases:
ResourceBase class of a resource detail manager
- after_delete(result)¶
Hook to make custom work after delete method
- after_get(result)¶
Hook to make custom work after get method
- after_patch(result)¶
Hook to make custom work after patch method
- before_delete(args, kwargs)¶
Hook to make custom work before delete method
- before_get(args, kwargs)¶
Hook to make custom work before get method
- before_marshmallow(args, kwargs)¶
- before_patch(args, kwargs, data=None)¶
Hook to make custom work before patch method
- delete(*args, **kwargs)¶
Delete an object
- delete_object(kwargs)¶
- get(*args, **kwargs)¶
Get object details
- get_object(kwargs, qs)¶
- methods: ClassVar[Optional[Collection[str]]] = {'DELETE', 'GET', 'PATCH'}¶
The methods this view is registered for. Uses the same default (
["GET", "HEAD", "OPTIONS"]) asrouteandadd_url_ruleby default.
- patch(*args, **kwargs)¶
Update an object
- update_object(data, qs, kwargs)¶
- class flask_combo_jsonapi.resource.ResourceList¶
Bases:
ResourceBase class of a resource list manager
- after_get(result)¶
Hook to make custom work after get method
- after_post(result)¶
Hook to make custom work after post method
- before_get(args, kwargs)¶
Hook to make custom work before get method
- before_marshmallow(args, kwargs)¶
- before_post(args, kwargs, data=None)¶
Hook to make custom work before post method
- create_object(data, kwargs)¶
- get(*args, **kwargs)¶
Retrieve a collection of objects
- get_collection(qs, kwargs)¶
- methods: ClassVar[Optional[Collection[str]]] = {'GET', 'POST'}¶
The methods this view is registered for. Uses the same default (
["GET", "HEAD", "OPTIONS"]) asrouteandadd_url_ruleby default.
- post(*args, **kwargs)¶
Create an object
- class flask_combo_jsonapi.resource.ResourceRelationship¶
Bases:
ResourceBase class of a resource relationship manager
- after_delete(result, status_code)¶
Hook to make custom work after delete method
- after_get(result)¶
Hook to make custom work after get method
- after_patch(result, status_code)¶
Hook to make custom work after patch method
- after_post(result, status_code)¶
Hook to make custom work after post method
- before_delete(args, kwargs, json_data=None)¶
Hook to make custom work before delete method
- before_get(args, kwargs)¶
Hook to make custom work before get method
- before_patch(args, kwargs, json_data=None)¶
Hook to make custom work before patch method
- before_post(args, kwargs, json_data=None)¶
Hook to make custom work before post method
- delete(*args, **kwargs)¶
Delete relationship(s)
- get(*args, **kwargs)¶
Get a relationship details
- methods: ClassVar[Optional[Collection[str]]] = {'DELETE', 'GET', 'PATCH', 'POST'}¶
The methods this view is registered for. Uses the same default (
["GET", "HEAD", "OPTIONS"]) asrouteandadd_url_ruleby default.
- patch(*args, **kwargs)¶
Update a relationship
# https://jsonapi.org/format/#crud-updating-relationship-responses-200
> If a server accepts an update but also changes the targeted relationship(s) > in other ways than those specified by the request, > it MUST return a 200 OK response. > The response document MUST include a representation > of the updated relationship(s).
> A server MUST return a 200 OK status code if an update is successful, > the client’s current data remain up to date, > and the server responds only with top-level meta data. > In this case the server MUST NOT include a representation > of the updated relationship(s).
- post(*args, **kwargs)¶
Add / create relationship(s)
https://jsonapi.org/format/#crud-updating-to-many-relationships
flask_combo_jsonapi.schema module¶
Helpers to deal with marshmallow schemas
- flask_combo_jsonapi.schema.compute_schema(schema_cls, default_kwargs, qs, include)¶
Compute a schema around compound documents and sparse fieldsets
- Parameters
schema_cls (Schema) – the schema class
default_kwargs (dict) – the schema default kwargs
qs (QueryStringManager) – qs
include (list) – the relation field to include data from
- Return Schema schema
the schema computed
- flask_combo_jsonapi.schema.get_model_field(schema, field)¶
Get the model field of a schema field
- Parameters
schema (Schema) – a marshmallow schema
field (str) – the name of the schema field
- Return str
the name of the field in the model
- flask_combo_jsonapi.schema.get_nested_fields(schema, model_field=False)¶
Return nested fields of a schema to support a join
- Parameters
schema (Schema) – a marshmallow schema
model_field (boolean) – whether to extract the model field for the nested fields
- Return list
list of nested fields of the schema
Retrieve the related schema of a relationship field
- Parameters
schema (Schema) – the schema to retrieve le relationship field from
field – the relationship field
- Return Schema
the related schema
- flask_combo_jsonapi.schema.get_relationships(schema, model_field=False)¶
Return relationship fields of a schema
- Parameters
schema (Schema) – a marshmallow schema
list – list of relationship fields of a schema
- flask_combo_jsonapi.schema.get_schema_field(schema, field)¶
Get the schema field of a model field
- Parameters
schema (Schema) – a marshmallow schema
field (str) – the name of the model field
- Return str
the name of the field in the schema
- flask_combo_jsonapi.schema.get_schema_from_type(resource_type)¶
Retrieve a schema from the registry by his type
- Parameters
type (str) – the type of the resource
- Return Schema
the schema class