GithubHelp home page GithubHelp logo

drewisme / apispec-flask-restful Goto Github PK

View Code? Open in Web Editor NEW

This project forked from theirix/apispec-flask-restful

0.0 1.0 0.0 6 KB

Flask-RESTful plugin for apispec

License: MIT License

Python 100.00%

apispec-flask-restful's Introduction

apispec_flask_restful

Flask-RESTful plugin.

Includes a path helper that allows you to pass a Flask-RESTful resource object to add_path.

Inspired by AndrewPashkin/apispec_restful plugin.

Install

pip install apispec_flask_restful

Usage

Typical usage

from pprint import pprint

from flask_restful import Api, Resource
from flask import Flask
from apispec import APISpec

class HelloResource(Resource):
    def get(self, hello_id):
        '''A greeting endpoint.
               ---
               description: get a greeting
               responses:
                   200:
                       description: a pet to be returned
                       schema:
                           $ref: #/definitions/Pet
        '''
        pass

app = Flask(__name__)
api = Api(app)
spec = APISpec(title='Spec', version='1.0', plugins=['apispec_flask_restful'])

api.add_resource(HelloResource, '/hello')

spec.add_path(resource=HelloResource, api=api)
pprint(spec.to_dict()['paths'])

# OrderedDict([('/hello',
#          {'get': {'description': 'get a greeting',
#                   'responses': {200: {'description': 'a pet to be returned',
#                                       'schema': {'$ref': None}}}}})])

Without API

Method add_path can be invoked with a resource path in a path parameter instead of api parameter:

spec.add_path(resource=HelloResource, path='/hello')

With Blueprint

Flask blueprints are supported too by passing Flask app in app parameter:

spec.add_path(resource=HelloResource, api=api, app=app)

apispec-flask-restful's People

Contributors

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