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

Public Member Functions

def init_attribute_functions (self)
 
def map_to_openapi_type (self, *args)
 
def add_attribute_function (self, func)
 
def field2property (self, field)
 
def field2type_and_format (self, field, **kwargs)
 
def field2default (self, field, **kwargs)
 
def field2choices (self, field, **kwargs)
 
def field2read_only (self, field, **kwargs)
 
def field2write_only (self, field, **kwargs)
 
def field2nullable (self, field, ret)
 
def field2range (self, field, ret)
 
def field2length (self, field, **kwargs)
 
def field2pattern (self, field, **kwargs)
 
def metadata2properties (self, field, **kwargs)
 
def nested2properties (self, field, ret)
 
def pluck2properties (self, field, **kwargs)
 
def list2properties (self, field, **kwargs)
 
def dict2properties (self, field, **kwargs)
 
def timedelta2properties (self, field, **kwargs)
 

Data Fields

 attribute_functions
 

Static Public Attributes

 field_mapping = DEFAULT_FIELD_MAPPING
 

Detailed Description

Adds methods for converting marshmallow fields to an OpenAPI properties.

Member Function Documentation

◆ add_attribute_function()

def add_attribute_function (   self,
  func 
)
Method to add an attribute function to the list of attribute functions
that will be called on a field to convert it from a field to an OpenAPI
property.

:param func func: the attribute function to add
    The attribute function will be bound to the
    `OpenAPIConverter <apispec.ext.marshmallow.openapi.OpenAPIConverter>`
    instance.
    It will be called for each field in a schema with
    `self <apispec.ext.marshmallow.openapi.OpenAPIConverter>` and a
    `field <marshmallow.fields.Field>` instance
    positional arguments and `ret <dict>` keyword argument.
    Must return a dictionary of OpenAPI properties that will be shallow
    merged with the return values of all other attribute functions called on the field.
    User added attribute functions will be called after all built-in attribute
    functions in the order they were added. The merged results of all
    previously called attribute functions are accessable via the `ret`
    argument.

◆ dict2properties()

def dict2properties (   self,
  field,
**  kwargs 
)
Return a dictionary of properties from :class:`Dict <marshmallow.fields.Dict>` fields.

Only applicable for Marshmallow versions greater than 3. Will provide an
`additionalProperties` property based on the field's `value_field` attribute

:param Field field: A marshmallow field.
:rtype: dict

◆ field2choices()

def field2choices (   self,
  field,
**  kwargs 
)
Return the dictionary of OpenAPI field attributes for valid choices definition.

:param Field field: A marshmallow field.
:rtype: dict

◆ field2default()

def field2default (   self,
  field,
**  kwargs 
)
Return the dictionary containing the field's default value.

Will first look for a `doc_default` key in the field's metadata and then
fall back on the field's `missing` parameter. A callable passed to the
field's missing parameter will be ignored.

:param Field field: A marshmallow field.
:rtype: dict

◆ field2length()

def field2length (   self,
  field,
**  kwargs 
)
Return the dictionary of OpenAPI field attributes for a set of
:class:`Length <marshmallow.validators.Length>` validators.

:param Field field: A marshmallow field.
:rtype: dict

◆ field2nullable()

def field2nullable (   self,
  field,
  ret 
)
Return the dictionary of OpenAPI field attributes for a nullable field.

:param Field field: A marshmallow field.
:rtype: dict

◆ field2pattern()

def field2pattern (   self,
  field,
**  kwargs 
)
Return the dictionary of OpenAPI field attributes for a
:class:`Regexp <marshmallow.validators.Regexp>` validator.

If there is more than one such validator, only the first
is used in the output spec.

:param Field field: A marshmallow field.
:rtype: dict

◆ field2property()

def field2property (   self,
  field 
)
Return the JSON Schema property definition given a marshmallow
:class:`Field <marshmallow.fields.Field>`.

Will include field metadata that are valid properties of OpenAPI schema objects
(e.g. "description", "enum", "example").

https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schemaObject

:param Field field: A marshmallow field.
:rtype: dict, a Property Object

◆ field2range()

def field2range (   self,
  field,
  ret 
)
Return the dictionary of OpenAPI field attributes for a set of
:class:`Range <marshmallow.validators.Range>` validators.

:param Field field: A marshmallow field.
:rtype: dict

◆ field2read_only()

def field2read_only (   self,
  field,
**  kwargs 
)
Return the dictionary of OpenAPI field attributes for a dump_only field.

:param Field field: A marshmallow field.
:rtype: dict

◆ field2type_and_format()

def field2type_and_format (   self,
  field,
**  kwargs 
)
Return the dictionary of OpenAPI type and format based on the field type.

:param Field field: A marshmallow field.
:rtype: dict

◆ field2write_only()

def field2write_only (   self,
  field,
**  kwargs 
)
Return the dictionary of OpenAPI field attributes for a load_only field.

:param Field field: A marshmallow field.
:rtype: dict

◆ init_attribute_functions()

def init_attribute_functions (   self)

◆ list2properties()

def list2properties (   self,
  field,
**  kwargs 
)
Return a dictionary of properties from :class:`List <marshmallow.fields.List>` fields.

Will provide an `items` property based on the field's `inner` attribute

:param Field field: A marshmallow field.
:rtype: dict

◆ map_to_openapi_type()

def map_to_openapi_type (   self,
args 
)
Decorator to set mapping for custom fields.

``*args`` can be:

- a pair of the form ``(type, format)``
- a core marshmallow field type (in which case we reuse that type's mapping)

◆ metadata2properties()

def metadata2properties (   self,
  field,
**  kwargs 
)
Return a dictionary of properties extracted from field metadata.

Will include field metadata that are valid properties of `OpenAPI schema
objects
<https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schemaObject>`_
(e.g. "description", "enum", "example").

In addition, `specification extensions
<https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#specification-extensions>`_
are supported.  Prefix `x_` to the desired extension when passing the
keyword argument to the field constructor. apispec will convert `x_` to
`x-` to comply with OpenAPI.

:param Field field: A marshmallow field.
:rtype: dict

◆ nested2properties()

def nested2properties (   self,
  field,
  ret 
)
Return a dictionary of properties from :class:`Nested <marshmallow.fields.Nested` fields.

Typically provides a reference object and will add the schema to the spec
if it is not already present
If a custom `schema_name_resolver` function returns `None` for the nested
schema a JSON schema object will be returned

:param Field field: A marshmallow field.
:rtype: dict

◆ pluck2properties()

def pluck2properties (   self,
  field,
**  kwargs 
)
Return a dictionary of properties from :class:`Pluck <marshmallow.fields.Pluck` fields.

Pluck effectively trans-includes a field from another schema into this,
possibly wrapped in an array (`many=True`).

:param Field field: A marshmallow field.
:rtype: dict

◆ timedelta2properties()

def timedelta2properties (   self,
  field,
**  kwargs 
)
Return a dictionary of properties from :class:`TimeDelta <marshmallow.fields.TimeDelta>` fields.

Adds a `x-unit` vendor property based on the field's `precision` attribute

:param Field field: A marshmallow field.
:rtype: dict

Field Documentation

◆ attribute_functions

attribute_functions

◆ field_mapping

field_mapping = DEFAULT_FIELD_MAPPING
static

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