Extractor¶
You can extract swagger spec from flask’s view function using
flask_swag.extractor. And you can also customize it.
Extractor¶
This is base class & implementation of extractor.
extract_paths() method excutes extraction,
and returns list of path items.
Fields¶
Basic implementation of extractor extracts following fields from view functions.
description
Extracts description from docstring & normalizes indentations from.
extract_description()summary
Extracts summary from first line of description from
extract_summary(). It will be truncated if first line is longer than 120 chars.parameters
Extracts parameter info from path. Basically, it converts werkzeug converters to swagger type from
convert_werkzeug_converter(), and fallback to function parameter’s annotation usingconvert_annotation().responses
Since responses is required field, it makes empty default reponse from
extract_responses().
Filtering¶
You can filter endpoints by using endpoint & exclude_endpoint parameters, and also can filter blueprints by using blueprint & exclude_blueprint parameters.
Note
Since flask can have non-blueprint endpoints like
@app.route('/non-blueprint')
def non_blueprint():
pass
Endpoints with None blueprint means non-blueprint endpoints.
So, you can collect non-blueprint only endpoints by
extractor.extract_paths(app, blueprint=None)
Customization¶
You can customize extractor by subclassing Extractor.
extract_others() will be best point to override.
flask_swag.extractor.mark.MarkExtractor is simple example for customization.
MarkExtractor¶
Mark extractor extracts extra swagger specs from view functions.
This is the default extractor of flask_swag.Swag.
This will be useful when you want to write parameter info to view functions.