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.