Plugins#

class spectree.plugins.base.BasePlugin[source]#

Base plugin for SpecTree plugin classes.

Parameters:

spectreespectree.SpecTree instance

__init__(spectree: SpecTree)[source]#
bypass(func: Callable, method: str) bool[source]#
Parameters:
  • func – route function (endpoint)

  • method – HTTP method for this route function

bypass some routes that shouldn’t be shown in document

find_routes() BackendRoute[source]#

find the routes from application

get_func_operation_id(func: Callable, path: str, method: str)[source]#
Parameters:
  • func – route function (endpoint)

  • method – URI path for this route function

  • method – HTTP method for this route function

get the operation_id value for the endpoint

parse_func(route: BackendRoute)[source]#
Parameters:

route – API routes

get the endpoint function from routes

parse_path(route: Any, path_parameter_descriptions: Mapping[str, str] | None)[source]#
Parameters:
  • route – API routes

  • path_parameter_descriptions – A dictionary of path parameter names and their description.

parse URI path to get the variables in path

register_route(app: Any)[source]#
Parameters:

app – backend framework application

register document API routes to application

validate(func: Callable, query: type[Any] | None, json: type[Any] | None, form: type[Any] | None, headers: type[Any] | None, cookies: type[Any] | None, resp: Response | None, before: Callable[[Any, Any, Exception | None, Any, ModelAdapter[Any, Exception, Any]], Any], after: Callable[[Any, Any, Exception | None, Any, ModelAdapter[Any, Exception, Any]], Any], validation_error_status: int, skip_validation: bool, force_resp_serialize: bool, *args: Any, **kwargs: Any)[source]#

validate the request and response

class spectree.plugins.base.Context[source]#

Context(query, json, form, headers, cookies)

static __new__(_cls, query: Any | None, json: Any | None, form: Any | None, headers: Any | None, cookies: Any | None)#

Create new instance of Context(query, json, form, headers, cookies)

cookies: Any | None#

Alias for field number 4

form: Any | None#

Alias for field number 2

headers: Any | None#

Alias for field number 3

json: Any | None#

Alias for field number 1

query: Any | None#

Alias for field number 0

class spectree.plugins.base.RawResponsePayload[source]#

RawResponsePayload(payload: Union[int, str, bool, list[‘JsonType’], dict[str, ‘JsonType’], NoneType, bytes])

__init__(payload: int | str | bool | list[int | str | bool | list[JsonType] | dict[str, JsonType] | None] | dict[str, int | str | bool | list[JsonType] | dict[str, JsonType] | None] | None | bytes) None#
class spectree.plugins.base.ResponseValidationResult[source]#

ResponseValidationResult(payload: Any)

__init__(payload: Any) None#
spectree.plugins.base.validate_response(model_adapter: ModelAdapter[Any, Exception, Any], validation_model: type[Any] | None, response_payload: Any, force_serialize: bool = False) ResponseValidationResult[source]#

Validate a given response_payload against a validation_model. This does nothing if validation_model is None.

Parameters:
  • validation_model – model class used to validate the provided response_payload.

  • response_payload – Validated response payload. A RawResponsePayload should be provided when the plugin view function returned an already JSON-serialized response payload.

  • force_serialize – Always serialize the validation model instance.

class spectree.plugins.flask_plugin.FlaskPlugin[source]#
request_validation(request, query, json, form, headers, cookies)[source]#

req_query: werkzeug.datastructures.ImmutableMultiDict req_json: dict req_headers: werkzeug.datastructures.EnvironHeaders req_cookies: werkzeug.datastructures.ImmutableMultiDict

validate(func: Callable, query: type[Any] | None, json: type[Any] | None, form: type[Any] | None, headers: type[Any] | None, cookies: type[Any] | None, resp: Response | None, before: Callable[[Any, Any, Exception | None, Any, ModelAdapter[Any, Exception, Any]], Any], after: Callable[[Any, Any, Exception | None, Any, ModelAdapter[Any, Exception, Any]], Any], validation_error_status: int, skip_validation: bool, force_resp_serialize: bool, *args: Any, **kwargs: Any)[source]#

validate the request and response

class spectree.plugins.falcon_plugin.FalconAsgiPlugin[source]#

Light wrapper around default Falcon plug-in to support Falcon 3.0 ASGI apps

async validate(func: Callable, query: type[Any] | None, json: type[Any] | None, form: type[Any] | None, headers: type[Any] | None, cookies: type[Any] | None, resp: Response | None, before: Callable[[Any, Any, Exception | None, Any, ModelAdapter[Any, Exception, Any]], Any], after: Callable[[Any, Any, Exception | None, Any, ModelAdapter[Any, Exception, Any]], Any], validation_error_status: int, skip_validation: bool, force_resp_serialize: bool, *args: Any, **kwargs: Any)[source]#

validate the request and response

class spectree.plugins.falcon_plugin.FalconPlugin[source]#
__init__(spectree)[source]#
bypass(func, method)[source]#
Parameters:
  • func – route function (endpoint)

  • method – HTTP method for this route function

bypass some routes that shouldn’t be shown in document

find_routes()[source]#

find the routes from application

parse_func(route: Any) dict[str, Any][source]#
Parameters:

route – API routes

get the endpoint function from routes

parse_path(route, path_parameter_descriptions)[source]#
Parameters:
  • route – API routes

  • path_parameter_descriptions – A dictionary of path parameter names and their description.

parse URI path to get the variables in path

register_route(app: Any)[source]#
Parameters:

app – backend framework application

register document API routes to application

validate(func: Callable, query: type[Any] | None, json: type[Any] | None, form: type[Any] | None, headers: type[Any] | None, cookies: type[Any] | None, resp: Response | None, before: Callable[[Any, Any, Exception | None, Any, ModelAdapter[Any, Exception, Any]], Any], after: Callable[[Any, Any, Exception | None, Any, ModelAdapter[Any, Exception, Any]], Any], validation_error_status: int, skip_validation: bool, force_resp_serialize: bool, *args: Any, **kwargs: Any)[source]#

validate the request and response

class spectree.plugins.starlette_plugin.Route#

Route(path, methods, func)

static __new__(_cls, path, methods, func)#

Create new instance of Route(path, methods, func)

func#

Alias for field number 2

methods#

Alias for field number 1

path#

Alias for field number 0

class spectree.plugins.starlette_plugin.StarlettePlugin[source]#
__init__(spectree)[source]#
bypass(func, method)[source]#
Parameters:
  • func – route function (endpoint)

  • method – HTTP method for this route function

bypass some routes that shouldn’t be shown in document

find_routes()[source]#

find the routes from application

parse_func(route)[source]#
Parameters:

route – API routes

get the endpoint function from routes

parse_path(route, path_parameter_descriptions)[source]#
Parameters:
  • route – API routes

  • path_parameter_descriptions – A dictionary of path parameter names and their description.

parse URI path to get the variables in path

register_route(app)[source]#
Parameters:

app – backend framework application

register document API routes to application

async validate(func: Callable, query: type[Any] | None, json: type[Any] | None, form: type[Any] | None, headers: type[Any] | None, cookies: type[Any] | None, resp: Response | None, before: Callable[[Any, Any, Exception | None, Any, ModelAdapter[Any, Exception, Any]], Any], after: Callable[[Any, Any, Exception | None, Any, ModelAdapter[Any, Exception, Any]], Any], validation_error_status: int, skip_validation: bool, force_resp_serialize: bool, *args: Any, **kwargs: Any)[source]#

validate the request and response