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>`_.
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.
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.
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.