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[BaseModelSubclassType] | None, json: Type[BaseModelSubclassType] | None, form: Type[BaseModelSubclassType] | None, headers: Type[BaseModelSubclassType] | None, cookies: Type[BaseModelSubclassType] | None, resp: Response | None, before: Callable, after: Callable, validation_error_status: int, skip_validation: 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: list, json: list, form: list, headers: dict, cookies: dict)

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

cookies: dict

Alias for field number 4

form: list

Alias for field number 2

headers: dict

Alias for field number 3

json: list

Alias for field number 1

query: list

Alias for field number 0

class spectree.plugins.base.RawResponsePayload[source]

RawResponsePayload(payload: Union[NoneType, int, str, bool, List[ForwardRef(‘JsonType’)], Dict[str, ForwardRef(‘JsonType’)], bytes])

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

ResponseValidationResult(payload: Any)

__init__(payload: Any) None
spectree.plugins.base.validate_response(validation_model: Type[BaseModelSubclassType] | None, response_payload: Any) ResponseValidationResult[source]

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

Parameters:
  • validation_model – Pydantic model 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.

class spectree.plugins.flask_plugin.FlaskPlugin[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)[source]
Parameters:

route – API routes

get the endpoint function from routes

parse_path(route: Mapping[str, str] | None, path_parameter_descriptions: Mapping[str, str] | None) Tuple[str, list][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

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[BaseModelSubclassType] | None, json: Type[BaseModelSubclassType] | None, form: Type[BaseModelSubclassType] | None, headers: Type[BaseModelSubclassType] | None, cookies: Type[BaseModelSubclassType] | None, resp: Response | None, before: Callable, after: Callable, validation_error_status: int, skip_validation: 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[BaseModelSubclassType] | None, json: Type[BaseModelSubclassType] | None, form: Type[BaseModelSubclassType] | None, headers: Type[BaseModelSubclassType] | None, cookies: Type[BaseModelSubclassType] | None, resp: Response | None, before: Callable, after: Callable, validation_error_status: int, skip_validation: 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[BaseModelSubclassType] | None, json: Type[BaseModelSubclassType] | None, form: Type[BaseModelSubclassType] | None, headers: Type[BaseModelSubclassType] | None, cookies: Type[BaseModelSubclassType] | None, resp: Response | None, before: Callable, after: Callable, validation_error_status: int, skip_validation: 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[BaseModelSubclassType] | None, json: Type[BaseModelSubclassType] | None, form: Type[BaseModelSubclassType] | None, headers: Type[BaseModelSubclassType] | None, cookies: Type[BaseModelSubclassType] | None, resp: Response | None, before: Callable, after: Callable, validation_error_status: int, skip_validation: bool, *args: Any, **kwargs: Any)[source]

validate the request and response