Resource Class

class quart_openapi.Resource

Bases: quart.views.MethodView

Inherit from this to create RESTful routes with openapi docs

A Resource subclass needs only to implement async functions corresponding to the HTTP verbs you want to handle. Utilizing the decorators from Pint you can set the route, params, responses, and so on that will show up in the openapi documentation.

An example is,

app = Pint('sample')
@app.route('/<id>')
class SimpleRoute(Resource):
  async def get(self, id):
    return f"ID is {id}"

That will enable a route ‘/<id>’ which will return the string “ID is <id>” when called by a GET request. If using Pint.expect() to define the expected request body, it will perform validation unless validate is set to false.

dispatch_request(*args, **kwargs)[source]

Can be overridden instead of creating verb functions

This will be called with the request view_args, i.e. any url parameters

Return type:Union[Forwardref, Forwardref, AnyStr, Dict[str, Any], Asyncgenerator[AnyStr, None], Generator[AnyStr, None, None], Tuple[Union[Forwardref, Forwardref, AnyStr, Dict[str, Any], Asyncgenerator[AnyStr, None], Generator[AnyStr, None, None]], Union[Forwardref, Dict[str, Union[str, List[str], Tuple[str, …]]], List[Tuple[str, Union[str, List[str], Tuple[str, …]]]]]], Tuple[Union[Forwardref, Forwardref, AnyStr, Dict[str, Any], Asyncgenerator[AnyStr, None], Generator[AnyStr, None, None]], int], Tuple[Union[Forwardref, Forwardref, AnyStr, Dict[str, Any], Asyncgenerator[AnyStr, None], Generator[AnyStr, None, None]], int, Union[Forwardref, Dict[str, Union[str, List[str], Tuple[str, …]]], List[Tuple[str, Union[str, List[str], Tuple[str, …]]]]]]]
validate_payload(func)[source]

This will perform validation

Will check the api docs of the class as set by using the decorators in Pint and if an expect was present without validate set to False or None, it will attempt to validate any request against the schema if json, or ensure the content_type matches at least.

Return type:bool

Generated from version 1.7.2