Skip to content

Dave4272-Office/flask-openapi3

Repository files navigation

flask-openapi3

GitHub Workflow Status PyPI PyPI - Downloads PyPI - Python Version

Generate RESTful API and OpenAPI document for your Flask project.

Requirements

Python 3.6+

flask-openapi3 be dependent on the following libraries:

Installation

$ pip install -U flask-openapi3

A Simple Example

Here's a simple example, further go to the docs

from pydantic import BaseModel

from flask_openapi3 import OpenAPI
from flask_openapi3.models import Info, Tag

info = Info(title='book API', version='1.0.0')
app = OpenAPI(__name__, info=info)

book_tag = Tag(name='book', description='Some Book')


class BookQuery(BaseModel):
    age: int
    author: str


@app.get('/book', tags=[book_tag])
def get_book(query: BookQuery):
    """get books
    get all books
    """
    return {
        "code": 0,
        "message": "ok",
        "data": [
            {"bid": 1, "age": query.age, "author": query.author},
            {"bid": 2, "age": query.age, "author": query.author}
        ]
    }


if __name__ == '__main__':
    app.run(debug=True)

API docs

Run the simple example, and go to http://127.0.0.1:5000/openapi.

You will see the document: Swagger UI and Redoc.

openapi openapi-swagger openapi-redoc

About

Generate REST API and OpenAPI documentation for your Flask project.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%