Giter Club home page Giter Club logo

apispec-webframeworks's Introduction

apispec-webframeworks

PyPI version Build status marshmallow 2/3 compatible code style: black

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 in all supported Python versions in their own virtual environments (must have each interpreter installed):

$ tox

License

MIT licensed. See the bundled LICENSE file for more details.

apispec-webframeworks's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar elfjes avatar ergo avatar felixonmars avatar lafrech avatar sloria avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.