GithubHelp home page GithubHelp logo

dev-rijan / flask-classful-apispec Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 0.0 38 KB

Automatic api docs generation for flask classful based on apispec

License: MIT License

Python 100.00%
apispec flask-classful swagger-ui flask-classful-apispec

flask-classful-apispec's Introduction

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)
spec.paths(PetView)

print(json.dumps(spec.to_dict(), indent=2))

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

Generated OpenAPI Spec

{
  "paths": {
    "/pet/": {
      "get": {
        "description": "Get a list of pets",
        "responses": {
          "200": {
            "schema": {
              "$ref": "#/components/schemas/Pet"
            }
          }
        }
      }
    }
  },
  "info": {
    "title": "Swagger petstore",
    "version": "0.1.1"
  },
  "openapi": "3.0.2",
  "components": {
    "schemas": {
      "Pet": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "id": {
            "type": "integer"
          },
          "category": {
            "type": "string"
          }
        }
      }
    }
  }
}

Documentation

License

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

flask-classful-apispec's People

Contributors

dev-rijan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  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.