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 jsonReturn type: Dict
[str
,Any
]
-
static
description_for
(doc, method)[source]¶ Extract the description metadata and fallback on the whole docstring
Parameters: Return type: 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 serializationReturn 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: 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: Return type: 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 serializationReturn 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: 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
- response (
-
register_component
(category, name, schema)[source]¶ Used for populating the components section of the openapi docs
Parameters: Return type: None
-
responses_for
(doc, method)[source]¶ Get the Response dictionary for a given route and HTTP verb
Parameters: 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: Return type: 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: Return type: 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, aDraft4Validator
instance, or the actual type of the value. Passing a list or tuple will create a schema for an array of that typeReturn type: Dict
[str
,Any
]Returns: The schema as defined by the openapi 3.0 spec as a dict
-
Generated from version 1.7.2