Skip to main content

Auto docs generation from marshmallow schema for flask classfy

Project description

Flask classful apispec

A pluggable API specification generator generator for Flask classful based on apispec

Features

  • Utilities for parsing flask classful docstrings

  • Support for marshmallow

Installation

$ pip install flask-classful-apispec

Usage

import json
from flask import Flask
from flask_classful import FlaskView
from flask_classful_apispec import APISpec
from marshmallow import Schema, fields

app = Flask(__name__)

app.config["DOC_TITLE"] = "Swagger petstore"
app.config["DOC_VERSION"] = "0.1.1"
app.config["DOC_OPEN_API_VERSION"] = "3.0.2"

spec = APISpec(app)

pets = [
    {'id': 0, 'name': 'Kitty', 'category': 'cat'},
    {'id': 1, 'name': 'Coco', 'category': 'dog'}
]

class PetSchema(Schema):
    id = fields.Integer()
    name = fields.String()
    category = fields.String()

class PetView(FlaskView):
    def index(self):
        """A pet api endpoint.
        ---
        description: Get a list of pets
        responses:
          200:
            schema: PetSchema
        """
        return PetSchema(many=True).dumps(pets)

PetView.register(app)

with app.test_request_context():
spec.paths(PetView, app)
print(json.dumps(spec.to_dict(), indent=2))

if __name__ == "__main__":
    app.run()

Generated OpenAPI Spec

Documentation

License

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask-classful-apispec-0.1.8.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

flask_classful_apispec-0.1.8-py2.py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page