Spectastic API¶
Submodules¶
Errors¶
Operation¶
-
exception
spectastic.operation.
InvalidPath
[source]¶ Bases:
exceptions.Exception
Raised when a path does not match an operation’s route.
-
class
spectastic.operation.
Operation
(schema, route, method, local_schema)[source]¶ Bases:
object
Parameters: -
body_schema
()[source]¶ Returns a tuple of consisting of the body parameter and it’s corresponding body schema.
-
extract_path_args
(path)[source]¶ Matches a request path against this operation’s route, returning an intermediate dictionary of strings for each path parameter. The resulting dictionary is not validated nor are it’s types coerced.
Return dict: A dictionary of path arguments, with keys corresponding to the case sensitive name specified in the swagger schema.
-
header_schema
(header_name)[source]¶ Returns the schema for a header parameter of a given name. The parameter name is case-insensitive.
Raises: KeyError
If the header is not found.
-
iter_request_body_errors
(request_body)[source]¶ Validates a request body against the schema, yielding a
FieldError
for each failure.
-
iter_request_errors
(request)[source]¶ Validates an entire request, yielding a
FieldError
for each failure.Parameters: request (BasicRequest) – A request conforming to the structure outlined in BasicRequest
-
iter_request_header_errors
(request_headers)[source]¶ Validates individual request headers against the schema, yielding a
FieldError
for each failure.
-
iter_request_path_errors
(request_path)[source]¶ Validates a request path against the schema, yielding a
FieldError
for each failure.
-
iter_request_query_errors
(query_params)[source]¶ Validates a request query against the schema, yielding a
FieldError
for each failure.
-
path_schema
(path_param_name)[source]¶ Returns the schema for a path parameter of a given name. The parameter name is case-insensitive.
Raises: KeyError
If the query is not found.
-
query_schema
(query_param_name)[source]¶ Returns the schema for a query parameter of a given name. The parameter name is case-insensitive.
Raises: KeyError
If the query is not found.
-
validate_request
(request)[source]¶ Validates all components of a request.
Parameters: request – A request conforming to the structure outlined in BasicRequest
Raises: ValidationErrors
When validation fails.Return bool: True on success.
-
validate_request_body
(request_body)[source]¶ Validates a request body against the operation schema.
Raises: ValidationErrors
When validation fails.Return bool: True on success.
-
validate_request_headers
(headers)[source]¶ Validates headers against the operation.
Raises: ValidationErrors
When validation fails.Return bool: True on success.
-
validate_request_path
(path_arguments)[source]¶ Validates headers against the operation.
Raises: ValidationErrors
When validation fails.Return bool: True on success.
-
validate_request_query
(query_params)[source]¶ Validates the query parameters from a request.
Parameters: query_params (dict|werkzeug.datastructures.MultiDict) – A dictionary like object of query parameters. Raises: ValidationErrors
When validation fails.Return bool: True on success.
-
validator
¶
-
-
exception
spectastic.operation.
OperationNotFound
[source]¶ Bases:
exceptions.Exception
Raised when an operation cannot be found in a schema.
-
spectastic.operation.
coerce_param
(value, schema)[source]¶ Coerces a named parameter within a path, query, or headers to the type specified in the appropriate schema. If the string is not properly formated, raise a FieldError.
Parameters: Raises: FieldError
When the primitive type is not coercible.Returns: The value, coerced according to the parameter definition for the field named
name
located inlocation
.
-
spectastic.operation.
find_operation
(schema, operation_id)[source]¶ Returns a tuple of the route, method and schema for an operation.
Raises: OperationNotFound
When the operation_id does not exist anywhere in the sec.
Schema¶
-
class
spectastic.schema.
Schema
(schema_dict)[source]¶ Bases:
dict
Simple wrapper around Swagger / Open API schema’s. At some ‘semblance’ of type safety. Mostly used to resolve all references with the provided schema to make spectastic’s job easier.
Request¶
Flask Utilities¶
-
spectastic.contrib.flask_utils.
convert_request
(flask_request)[source]¶ Converts a flask
flask.Request
to aBasicRequest
Returns: BasicRequest
-
spectastic.contrib.flask_utils.
default_responder
(validation_errors)[source]¶ Generates a flask response from provided
validation_errors
.Parameters: validation_errors (ValidationErrors) – A instance containing an aggregate of all errors discovered during request parsing.