Swagger Class

class quart_openapi.Swagger(api)

Class for generating a openapi.json from the resources and information defined with Pint

__init__(api)[source]

Construct a Swagger object for generating the openapi Json

Parameters:api (Pint) – the main app interface for getting the base model and resources
Return type:None
as_dict()[source]

Return a dict which can be used with the json module to return valid json

Return type:Dict[str, Any]
static description_for(doc, method)[source]

Extract the description metadata and fallback on the whole docstring

Parameters:
  • doc (Dict[str, Any]) – a mapping from HTTP verb to the properties for serialization
  • method (str) – The HTTP Verb function for the route
Return type:

str

Returns:

The description as pulled from the docstring for the description property

expected_params(doc)[source]

Return the Media Type object for the expected request body.

Parameters:doc (Dict[str, Any]) – a mapping from HTTP verb to the properties for serialization
Return type:Dict[str, Any]
Returns:a dict containing the content type and schemas for the requestBody
static extract_resource_doc(resource, path)[source]

Return the doc mapping for this resource that we saved on it

Parameters:
Return type:

Dict[str, Any]

Returns:

a mapping from HTTP verb to the properties for serialization

This returns the object that is passed into the serialize_* functions that expect a doc parameter

operation_id_for(doc, method)[source]

Return the operation id to be used for openapi docs

Parameters:
  • doc (Dict[str, Any]) – a mapping from HTTP verb to the properties for serialization
  • method (str) – the HTTP Verb
Return type:

str

Returns:

The id str

parameters_for(doc)[source]

Get the list of param descriptions for output

Parameters:doc (Dict[str, Any]) – a mapping from HTTP verb to the properties for serialization
Return type:Iterable[Dict[str, Any]]
Returns:a list of dict objects containing params as described by the openapi 3.0 spec
static process_headers(response, doc, method=None, headers=None)[source]

Properly form the header parameter objects according to the openapi 3.0 spec

Parameters:
  • response (Dict[str, Any]) – Response object definition
  • doc (Dict[str, Any]) – a mapping from HTTP verb to the properties for serialization
  • method (Optional[str]) – the HTTP verb for specific requests or None for all in the resource
  • headers (Optional[Dict[str, Union[str, Dict[str, Any]]]]) – Header object dict to add to whatever is already in the resource and function decorators
Return type:

Dict[str, Any]

Returns:

The full set of headers for this particular route and request method joining the resource level, method level and any additional headers passed in

register_component(category, name, schema)[source]

Used for populating the components section of the openapi docs

Parameters:
  • category (str) – The category under the component section
  • name (str) – The name of the model for reference
  • schema (Dict[str, Any]) – the actual schema for this object
Return type:

None

responses_for(doc, method)[source]

Get the Response dictionary for a given route and HTTP verb

Parameters:
  • doc (Dict[str, Any]) – a mapping from HTTP verb to the properties for serialization
  • method (str) – the HTTP Verb to get the responses for
Return type:

Dict[HTTPStatus, Dict[str, Any]]

Returns:

A dict mapping status codes to object descriptions as per the openapi response object spec.

serialize_components()[source]

Generate the json for the components section

Return type:Mapping[str, Dict[str, Any]]
Returns:An OrderedDict of the components
serialize_operation(doc, method)[source]

Serialize a single operation on the resource corresponding to a single HTTP verb

Parameters:
  • doc (Mapping[str, Any]) – a mapping from HTTP verb to the properties for serialization
  • method (str) – The HTTP verb for this operation
Return type:

Dict[str, Any]

Returns:

The dict openapi representation to be converted to json for this operation

serialize_resource(resource, path, methods)[source]

Use the docstring and any decorated info to create the resource object

Parameters:
  • resource (Union[Resource, Callable]) – the Resource object or view function
  • path (str) – the route path for this resource
  • methods (Iterable[str]) – The list of available HTTP verbs for this route
Return type:

Dict[str, Any]

Returns:

The dict conforming to the openapi 3.0 spec for a path item object

serialize_schema(validator)[source]

Given a validator normalize the schema definition

Parameters:validator (Union[Type[int], Type[float], Type[str], Type[bool], str, Validator, Validator, Validator, Validator, Schema, Iterable[Forwardref]]) – either the name of a validator, a Draft4Validator instance, or the actual type of the value. Passing a list or tuple will create a schema for an array of that type
Return type:Dict[str, Any]
Returns:The schema as defined by the openapi 3.0 spec as a dict
static tags_for(doc)[source]

Get the list of tags for output

Parameters:doc (List[str]) – a mapping from HTTP verb to the properties for serialization
Return type:Iterable[List[str]]
Returns:a list of string containing tags as described by the openapi 3.0 spec

Generated from version 1.7.2