flask_swag.extractor package

Submodules

flask_swag.extractor.base module

extractor.base

Base & default implmentation class of extractor.

class flask_swag.extractor.base.Extractor[source]

Bases: object

Base class that extract swagger spec from flask application.

You can extract path items from app by using extract_paths() and customize converting method by overriding them.

build_parameters(view, param_info, ctx: dict) → list[source]

Build parameters from path params and view params. path params have higher order.

collect_endpoints(app: flask.app.Flask, blueprint=<object object>, endpoint=None, exclude_blueprint=<object object>, exclude_endpoint=None) → dict[source]

Collect endpoints in rules.

Parameters:
  • blueprint – name of blueprints to be collected. None means non-blueprint endpoints. It cat either be list or string.
  • endpoint – endpoints to be collected. It cat either be list or string.
  • exclude_blueprint – blueprints not to be collected.
  • exclude_endpoint – endpoint not to be collected.
convert_annotation(name, annotation, ctx: dict)[source]

Convert function annotation to swagger parameter object.

convert_werkzeug_converter(name: str, converter: flask_swag.extractor.base.WerkzeugConverter, ctx: dict)[source]

Convert werkzeug converter to swagger parameter object.

default_path_param(name, ctx: dict)[source]
extract_description(view, ctx: dict) → str[source]

Extract description info from view function.

extract_others(view, ctx: dict)[source]

Extract other fields from view & context.

extract_param(view, name, ctx: dict)[source]

Extract path parameters info from view function.

extract_paths(app: flask.app.Flask, blueprint=<object object>, endpoint=None, exclude_blueprint=<object object>, exclude_endpoint=None)[source]

Extract path items from flask app.

Parameters:
  • blueprint – name of blueprints to be collected. None means non-blueprint endpoints. It cat either be list or string.
  • endpoint – endpoints to be collected. It cat either be list or string.
  • exclude_blueprint – blueprints not to be collected.
  • exclude_endpoint – endpoint not to be collected.
extract_responses(view, ctx: dict)[source]
extract_summary(view, ctx) → str[source]

Extract brief description from view function.

make_operation(view, params: dict, ctx: dict)[source]

Convert view to swagger opration object.

make_path_item(app: flask.app.Flask, rule: str, endpoints: dict, ctx: dict) → flask_swag.extractor.base.PathAndPathItem[source]

Make path item from rule and endpoints collected by HTTP methods.

parse_werkzeug_rule(rule: str, ctx: dict) → flask_swag.extractor.base.PathAndParams[source]

Convert werkzeug rule to swagger path format and extract parameter info.

class flask_swag.extractor.base.PathAndParams(path, params)

Bases: tuple

params

Alias for field number 1

path

Alias for field number 0

class flask_swag.extractor.base.PathAndPathItem(path, item)

Bases: tuple

item

Alias for field number 1

path

Alias for field number 0

class flask_swag.extractor.base.WerkzeugConverter(converter, args, kwargs)

Bases: tuple

args

Alias for field number 1

converter

Alias for field number 0

kwargs

Alias for field number 2

flask_swag.extractor.mark module

extractor.mark

Extractor that extracts swagger spec from marked view.

class flask_swag.extractor.mark.MarkExtractor[source]

Bases: flask_swag.extractor.base.Extractor

build_parameters(view, param_info, ctx: dict) → list[source]
extract_others(view, ctx: dict)[source]
extract_responses(view, ctx: dict)[source]
get_mark(view)[source]

Get mark object from view function.

Module contents

extractor

Extract path info from flask application.

class flask_swag.extractor.Extractor[source]

Bases: object

Base class that extract swagger spec from flask application.

You can extract path items from app by using extract_paths() and customize converting method by overriding them.

build_parameters(view, param_info, ctx: dict) → list[source]

Build parameters from path params and view params. path params have higher order.

collect_endpoints(app: flask.app.Flask, blueprint=<object object>, endpoint=None, exclude_blueprint=<object object>, exclude_endpoint=None) → dict[source]

Collect endpoints in rules.

Parameters:
  • blueprint – name of blueprints to be collected. None means non-blueprint endpoints. It cat either be list or string.
  • endpoint – endpoints to be collected. It cat either be list or string.
  • exclude_blueprint – blueprints not to be collected.
  • exclude_endpoint – endpoint not to be collected.
convert_annotation(name, annotation, ctx: dict)[source]

Convert function annotation to swagger parameter object.

convert_werkzeug_converter(name: str, converter: flask_swag.extractor.base.WerkzeugConverter, ctx: dict)[source]

Convert werkzeug converter to swagger parameter object.

default_path_param(name, ctx: dict)[source]
extract_description(view, ctx: dict) → str[source]

Extract description info from view function.

extract_others(view, ctx: dict)[source]

Extract other fields from view & context.

extract_param(view, name, ctx: dict)[source]

Extract path parameters info from view function.

extract_paths(app: flask.app.Flask, blueprint=<object object>, endpoint=None, exclude_blueprint=<object object>, exclude_endpoint=None)[source]

Extract path items from flask app.

Parameters:
  • blueprint – name of blueprints to be collected. None means non-blueprint endpoints. It cat either be list or string.
  • endpoint – endpoints to be collected. It cat either be list or string.
  • exclude_blueprint – blueprints not to be collected.
  • exclude_endpoint – endpoint not to be collected.
extract_responses(view, ctx: dict)[source]
extract_summary(view, ctx) → str[source]

Extract brief description from view function.

make_operation(view, params: dict, ctx: dict)[source]

Convert view to swagger opration object.

make_path_item(app: flask.app.Flask, rule: str, endpoints: dict, ctx: dict) → flask_swag.extractor.base.PathAndPathItem[source]

Make path item from rule and endpoints collected by HTTP methods.

parse_werkzeug_rule(rule: str, ctx: dict) → flask_swag.extractor.base.PathAndParams[source]

Convert werkzeug rule to swagger path format and extract parameter info.

class flask_swag.extractor.MarkExtractor[source]

Bases: flask_swag.extractor.base.Extractor

build_parameters(view, param_info, ctx: dict) → list[source]
extract_others(view, ctx: dict)[source]
extract_responses(view, ctx: dict)[source]
get_mark(view)[source]

Get mark object from view function.