API Reference¶
Annotations¶
-
flask_apispec.annotations.
doc
(inherit=None, **kwargs)[source]¶ Annotate the decorated view function or class with the specified Swagger attributes.
Usage:
@doc(tags=['pet'], description='a pet store') def get_pet(pet_id): return Pet.query.filter(Pet.id == pet_id).one()
Parameters: inherit – Inherit Swagger documentation from parent classes
-
flask_apispec.annotations.
marshal_with
(schema, code='default', description='', inherit=None, apply=None)[source]¶ Marshal the return value of the decorated view function using the specified schema.
Usage:
class PetSchema(Schema): class Meta: fields = ('name', 'category') @marshal_with(PetSchema) def get_pet(pet_id): return Pet.query.filter(Pet.id == pet_id).one()
Parameters:
-
flask_apispec.annotations.
use_kwargs
(args, locations=None, inherit=None, apply=None, **kwargs)[source]¶ Inject keyword arguments from the specified webargs arguments into the decorated view function.
Usage:
from marshmallow import fields @use_kwargs({'name': fields.Str(), 'category': fields.Str()}) def get_pets(**kwargs): return Pet.query.filter_by(**kwargs).all()
Parameters:
Extension¶
-
class
flask_apispec.extension.
FlaskApiSpec
(app=None)[source]¶ Flask-apispec extension.
Usage:
app = Flask(__name__) app.config.update({ 'APISPEC_SPEC': APISpec( title='pets', version='v1', plugins=[MarshmallowPlugin()], ), 'APISPEC_SWAGGER_URL': '/swagger/', }) docs = FlaskApiSpec(app) @app.route('/pet/<pet_id>') def get_pet(pet_id): return Pet.query.filter(Pet.id == pet_id).one() docs.register(get_pet)
Parameters: - app (Flask) – App associated with API documentation
- spec (APISpec) – apispec specification associated with API documentation
-
register
(target, endpoint=None, blueprint=None, resource_class_args=None, resource_class_kwargs=None)[source]¶ Register a view.
Parameters: - target – view function or view class.
- endpoint – (optional) endpoint name.
- blueprint – (optional) blueprint name.
- resource_class_args (tuple) – (optional) args to be forwarded to the view class constructor.
- resource_class_kwargs (dict) – (optional) kwargs to be forwarded to the view class constructor.