OpenQuizz
Une application de gestion des contenus pédagogiques
SchemaResolver Class Reference

Public Member Functions

def __init__ (self, openapi_version, converter)
 
def resolve_operations (self, operations, **kwargs)
 
def resolve_callback (self, callbacks)
 
def resolve_parameters (self, parameters)
 
def resolve_response (self, response)
 
def resolve_schema (self, data)
 
def resolve_schema_dict (self, schema)
 

Data Fields

 openapi_version
 
 converter
 

Detailed Description

Resolve marshmallow Schemas in OpenAPI components and translate to OpenAPI
`schema objects
<https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schema-object>`_,
`parameter objects
<https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#parameter-object>`_
or `reference objects
<https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#reference-object>`_.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  openapi_version,
  converter 
)

Member Function Documentation

◆ resolve_callback()

def resolve_callback (   self,
  callbacks 
)
Resolve marshmallow Schemas in a dict mapping callback name to OpenApi `Callback Object
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#callbackObject`_.

This is done recursively, so it is possible to define callbacks in your callbacks.

Example: ::

    #Input
    {
"userEvent": {
    "https://my.example/user-callback": {
        "post": {
            "requestBody": {
                "content": {
                    "application/json": {
                        "schema": UserSchema
                    }
                }
            }
        },
    }
}
    }

    #Output
    {
"userEvent": {
    "https://my.example/user-callback": {
        "post": {
            "requestBody": {
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/User"
                        }
                    }
                }
            }
        },
    }
}
    }

◆ resolve_operations()

def resolve_operations (   self,
  operations,
**  kwargs 
)
Resolve marshmallow Schemas in a dict mapping operation to OpenApi `Operation Object
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#operationObject`_

◆ resolve_parameters()

def resolve_parameters (   self,
  parameters 
)
Resolve marshmallow Schemas in a list of OpenAPI `Parameter Objects
<https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#parameter-object>`_.
Each parameter object that contains a Schema will be translated into
one or more Parameter Objects.

If the value of a `schema` key is marshmallow Schema class, instance or
a string that resolves to a Schema Class each field in the Schema will
be expanded as a separate Parameter Object.

Example: ::

    #Input
    class UserSchema(Schema):
name = fields.String()
id = fields.Int()

    [
{"in": "query", "schema": "UserSchema"}
    ]

    #Output
    [
{"in": "query", "name": "id", "required": False, "schema": {"type": "integer"}},
{"in": "query", "name": "name", "required": False, "schema": {"type": "string"}}
    ]

If the Parameter Object contains a `content` key a single Parameter
Object is returned with the Schema translated into a Schema Object or
Reference Object.

Example: ::

    #Input
    [{"in": "query", "name": "pet", "content":{"application/json": {"schema": "PetSchema"}} }]

    #Output
    [
{
    "in": "query",
    "name": "pet",
    "content": {
        "application/json": {
            "schema": {"$ref": "#/components/schemas/Pet"}
        }
    }
}
    ]


:param list parameters: the list of OpenAPI parameter objects to resolve.

◆ resolve_response()

def resolve_response (   self,
  response 
)
Resolve marshmallow Schemas in OpenAPI `Response Objects
<https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#responseObject>`_.
Schemas may appear in either a Media Type Object or a Header Object.

Example: ::

    #Input
    {
"content": {"application/json": {"schema": "PetSchema"}},
"description": "successful operation",
"headers": {"PetHeader": {"schema": "PetHeaderSchema"}},
    }

    #Output
    {
"content": {
    "application/json":{"schema": {"$ref": "#/components/schemas/Pet"}}
},
"description": "successful operation",
"headers": {
    "PetHeader": {"schema": {"$ref": "#/components/schemas/PetHeader"}}
},
    }

:param dict response: the response object to resolve.

◆ resolve_schema()

def resolve_schema (   self,
  data 
)
Resolve marshmallow Schemas in an OpenAPI component or header -
modifies the input dictionary to translate marshmallow Schemas to OpenAPI
Schema Objects or Reference Objects.

OpenAPIv3 Components: ::

    #Input
    {
"description": "user to add to the system",
"content": {
    "application/json": {
        "schema": "UserSchema"
    }
}
    }

    #Output
    {
"description": "user to add to the system",
"content": {
    "application/json": {
        "schema": {
            "$ref": "#/components/schemas/User"
        }
    }
}
    }

:param dict|str data: either a parameter or response dictionary that may
    contain a schema, or a reference provided as string

◆ resolve_schema_dict()

def resolve_schema_dict (   self,
  schema 
)
Resolve a marshmallow Schema class, object, or a string that resolves
to a Schema class or a schema reference or an OpenAPI Schema Object
containing one of the above to an OpenAPI Schema Object or Reference Object.

If the input is a marshmallow Schema class, object or a string that resolves
to a Schema class the Schema will be translated to an OpenAPI Schema Object
or Reference Object.

Example: ::

    #Input
    "PetSchema"

    #Output
    {"$ref": "#/components/schemas/Pet"}

If the input is a dictionary representation of an OpenAPI Schema Object
recursively search for a marshmallow Schemas to resolve. For `"type": "array"`,
marshmallow Schemas may appear as the value of the `items` key. For
`"type": "object"` Marshmalow Schemas may appear as values in the `properties`
dictionary.

Examples: ::

    #Input
    {"type": "array", "items": "PetSchema"}

    #Output
    {"type": "array", "items": {"$ref": "#/components/schemas/Pet"}}

    #Input
    {"type": "object", "properties": {"pet": "PetSchcema", "user": "UserSchema"}}

    #Output
    {
"type": "object",
"properties": {
    "pet": {"$ref": "#/components/schemas/Pet"},
    "user": {"$ref": "#/components/schemas/User"}
}
    }

:param string|Schema|dict schema: the schema to resolve.

Field Documentation

◆ converter

converter

◆ openapi_version

openapi_version

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