OpenQuizz
Une application de gestion des contenus pédagogiques
marshal_with Class Reference
Inheritance diagram for marshal_with:
Collaboration diagram for marshal_with:

Public Member Functions

def __init__ (self, fields, envelope=None, skip_none=False, mask=None, ordered=False)
 
def __call__ (self, f)
 

Data Fields

 fields
 
 envelope
 
 skip_none
 
 ordered
 
 mask
 

Detailed Description

A decorator that apply marshalling to the return values of your methods.

>>> from flask_restx import fields, marshal_with
>>> mfields = { 'a': fields.Raw }
>>> @marshal_with(mfields)
... def get():
...     return { 'a': 100, 'b': 'foo' }
...
...
>>> get()
OrderedDict([('a', 100)])

>>> @marshal_with(mfields, envelope='data')
... def get():
...     return { 'a': 100, 'b': 'foo' }
...
...
>>> get()
OrderedDict([('data', OrderedDict([('a', 100)]))])

>>> mfields = { 'a': fields.Raw, 'c': fields.Raw, 'd': fields.Raw }
>>> @marshal_with(mfields, skip_none=True)
... def get():
...     return { 'a': 100, 'b': 'foo', 'c': None }
...
...
>>> get()
OrderedDict([('a', 100)])

see :meth:`flask_restx.marshal`

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  fields,
  envelope = None,
  skip_none = False,
  mask = None,
  ordered = False 
)
:param fields: a dict of whose keys will make up the final
       serialized response output
:param envelope: optional key that will be used to envelop the serialized
         response

Member Function Documentation

◆ __call__()

def __call__ (   self,
  f 
)

Field Documentation

◆ envelope

envelope

◆ fields

fields

◆ mask

mask

◆ ordered

ordered

◆ skip_none

skip_none

The documentation for this class was generated from the following file: