Web framework plugins for apispec.
Project description
apispec plugins for integrating with various web frameworks.
These plugins used to be in apispec.ext but have since been moved to their own package.
Included plugins:
apispec_webframeworks.bottle
apispec_webframeworks.flask
apispec_webframeworks.tornado
Migration from apispec<1.0.0
To migrate from older versions of apispec, install this package with
pip install apispec-webframeworks
Change your imports, like so:
# apispec<1.0.0
from apispec.ext.flask import FlaskPlugin
# apispec>=1.0.0
from apispec_webframeworks.flask import FlaskPlugin
Example Usage
from flask import Flask
from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from apispec_webframeworks.flask import FlaskPlugin
from marshmallow import Schema, fields
spec = APISpec(
title='Gisty',
version='1.0.0',
info=dict(
description='A minimal gist API'
),
plugins=[
FlaskPlugin(),
MarshmallowPlugin(),
]
)
app = Flask(__name__)
class GistParameter(Schema):
gist_id = fields.Int()
class GistSchema(Schema):
id = fields.Int()
content = fields.Str()
@app.route('/gists/<gist_id>')
def gist_detail(gist_id):
"""Gist detail view.
---
get:
parameters:
- in: path
schema: GistParameter
responses:
200:
schema: GistSchema
"""
return 'details about gist {}'.format(gist_id)
# Since `path` inspects the view and its route,
# we need to be in a Flask request context
with app.test_request_context():
spec.path(view=gist_detail)
Documentation
For documentation for a specific plugin, see its module docstring.
Development
Clone and cd into this repo
Create and activate a virtual environment
Install this package (in editable mode) and the development dependencies
$ pip install '.[dev]'
Install pre-commit hooks
$ pre-commit install
Running tests
To run all tests:
$ pytest
To run syntax checks:
$ tox -e lint
(Optional) To run tests on Python 2.7, 3.5, 3.6, and 3.7 virtual environments (must have each interpreter installed):
$ tox
License
MIT licensed. See the bundled LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for apispec-webframeworks-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5957e05502a07a54750242f5252375ccdc1b32c5100713fcdeeb85757d6bf3ab |
|
MD5 | f9cb7aff85c70510bf58027e9eb9fcb2 |
|
BLAKE2b-256 | c278300fec9daa650c892a92d2b1d0ea791d112bb17c9c9e0e47248f5c37b1dd |
Hashes for apispec_webframeworks-0.3.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2788277c39bb537a9e64561e768876bc27e4579b6e2c4acaf3c2442230ba229e |
|
MD5 | f96c66ce8d21fb1ed60790ae1ec7e999 |
|
BLAKE2b-256 | 66679449e918d2b4a4a07d104f88783045a4dd63b21d3686f0b5e6d761012e5a |