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

Public Member Functions

def __init__ (self, openapi_version, schema_name_resolver, spec)
 
def resolve_nested_schema (self, schema)
 
def schema2parameters (self, schema, *location, name="body", required=False, description=None)
 
def schema2jsonschema (self, schema)
 
def fields2jsonschema (self, fields, *ordered=False, partial=None)
 
def get_ref_dict (self, schema)
 
- Public Member Functions inherited from FieldConverterMixin
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

 openapi_version
 
 schema_name_resolver
 
 spec
 
 refs
 
- Data Fields inherited from FieldConverterMixin
 attribute_functions
 

Additional Inherited Members

- Static Public Attributes inherited from FieldConverterMixin
 field_mapping = DEFAULT_FIELD_MAPPING
 

Detailed Description

Adds methods for generating OpenAPI specification from marshmallow schemas and fields.

:param str|OpenAPIVersion openapi_version: The OpenAPI version to use.
    Should be in the form '2.x' or '3.x.x' to comply with the OpenAPI standard.
:param callable schema_name_resolver: Callable to generate the schema definition name.
    Receives the `Schema` class and returns the name to be used in refs within
    the generated spec. When working with circular referencing this function
    must must not return `None` for schemas in a circular reference chain.
:param APISpec spec: An initalied spec. Nested schemas will be added to the
    spec

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  openapi_version,
  schema_name_resolver,
  spec 
)

Member Function Documentation

◆ fields2jsonschema()

def fields2jsonschema (   self,
  fields,
ordered = False,
  partial = None 
)
Return the JSON Schema Object given a mapping between field names and
:class:`Field <marshmallow.Field>` objects.

:param dict fields: A dictionary of field name field object pairs
:param bool ordered: Whether to preserve the order in which fields were declared
:param bool|tuple partial: Whether to override a field's required flag.
    If `True` no fields will be set as required. If an iterable fields
    in the iterable will not be marked as required.
:rtype: dict, a JSON Schema Object

◆ get_ref_dict()

def get_ref_dict (   self,
  schema 
)
Method to create a dictionary containing a JSON reference to the
schema in the spec

◆ resolve_nested_schema()

def resolve_nested_schema (   self,
  schema 
)
Return the OpenAPI representation of a marshmallow Schema.

Adds the schema to the spec if it isn't already present.

Typically will return a dictionary with the reference to the schema's
path in the spec unless the `schema_name_resolver` returns `None`, in
which case the returned dictoinary will contain a JSON Schema Object
representation of the schema.

:param schema: schema to add to the spec

◆ schema2jsonschema()

def schema2jsonschema (   self,
  schema 
)
Return the JSON Schema Object for a given marshmallow
:class:`Schema <marshmallow.Schema>` instance. Schema may optionally
provide the ``title`` and ``description`` class Meta options.

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

:param Schema schema: A marshmallow Schema instance
:rtype: dict, a JSON Schema Object

◆ schema2parameters()

def schema2parameters (   self,
  schema,
location,
  name = "body",
  required = False,
  description = None 
)
Return an array of OpenAPI parameters given a given marshmallow
:class:`Schema <marshmallow.Schema>`. If `location` is "body", then return an array
of a single parameter; else return an array of a parameter for each included field in
the :class:`Schema <marshmallow.Schema>`.

In OpenAPI 3, only "query", "header", "path" or "cookie" are allowed for the location
of parameters. "requestBody" is used when fields are in the body.

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

Field Documentation

◆ openapi_version

openapi_version

◆ refs

refs

◆ schema_name_resolver

schema_name_resolver

◆ spec

spec

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