Metadata-Version: 2.1
Name: flask-marshmallow-openapi
Version: 0.6.2
Summary: Flask + marshmallow + OpenAPI
Author-email: Tomislav Adamic <tomislav.adamic@gmail.com>
License: MIT
Project-URL: Source, https://github.com/tadams42/flask-marshmallow-openapi
Keywords: OpenAPI SwaggerUI ReDoc
Platform: any
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: apispec[marshmallow,yaml]
Requires-Dist: flask >=2.0.1
Requires-Dist: inflection
Requires-Dist: marshmallow >=3.18.0
Requires-Dist: pyyaml
Requires-Dist: requests
Requires-Dist: wrapt
Requires-Dist: openapi-pydantic-models >=1.0.1
Provides-Extra: dev
Requires-Dist: black >=22.1.0 ; extra == 'dev'
Requires-Dist: bump2version >=1.0.1 ; extra == 'dev'
Requires-Dist: check-manifest >=0.47 ; extra == 'dev'
Requires-Dist: flask-shell-ipython >=0.5.1 ; extra == 'dev'
Requires-Dist: ipython >=8.6.0 ; extra == 'dev'
Requires-Dist: isort >=5.10.1 ; extra == 'dev'
Requires-Dist: pip-tools >=6.5.1 ; extra == 'dev'
Provides-Extra: docs
Requires-Dist: furo ; extra == 'docs'
Requires-Dist: myst-parser ; extra == 'docs'
Requires-Dist: sphinx >5.2.0 ; extra == 'docs'
Requires-Dist: sphinx-rtd-theme ; extra == 'docs'
Requires-Dist: sphinx-copybutton ; extra == 'docs'
Provides-Extra: tests
Requires-Dist: coverage ; extra == 'tests'
Requires-Dist: factory-boy >=3.2.1 ; extra == 'tests'
Requires-Dist: faker >=12.3.0 ; extra == 'tests'
Requires-Dist: lorem >=0.1.1 ; extra == 'tests'
Requires-Dist: pytest >=7.0.1 ; extra == 'tests'
Requires-Dist: pytest-profiling >=1.7.0 ; extra == 'tests'
Requires-Dist: pytest-random-order >=1.0.4 ; extra == 'tests'
Requires-Dist: pytest-spec >=3.2.0 ; extra == 'tests'

# Overview

[![PyPI Status](https://badge.fury.io/py/flask-marshmallow-openapi.svg)](https://badge.fury.io/py/flask-marshmallow-openapi)
[![license](https://img.shields.io/pypi/l/flask-marshmallow-openapi.svg)](https://opensource.org/licenses/MIT)
[![python_versions](https://img.shields.io/pypi/pyversions/flask-marshmallow-openapi.svg)](https://pypi.org/project/flask-marshmallow-openapi/)
[![documentation](https://readthedocs.org/projects/flask-marshmallow-openapi/badge/?version=latest)](https://flask-marshmallow-openapi.readthedocs.io/en/latest/?badge=latest)


Provides OpenAPI documentation generated from code for
[Flask](https://flask.palletsprojects.com/en/latest/) APIs built around
[marshmallow](https://marshmallow.readthedocs.io/en/stable/) schemas.

This hackish and organically grown ™ package was created because no other similar
projects worked exactly the way I wanted them.

Similar projects:

- [flasgger](https://github.com/flasgger/flasgger)
- [flask-openapi3](https://github.com/luolingchun/flask-openapi3)

## Installation

~~~sh
pip install flask-marshmallow-openapi
~~~

## Documentation

[Read the Docs](https://flask-marshmallow-openapi.readthedocs.io/en/latest)

## What does it do?

Searches your codebase for [marshmallow](https://marshmallow.readthedocs.io/en/stable/)
schemas and 🎖️ decorated 🎖️ Flask routes.

It then produces `swagger.json` and injects it into self-hosted
[ReDoc](https://github.com/Redocly/redoc) and
[SwaggerUI](https://github.com/swagger-api/swagger-ui) documentation viewers.

```py
api = flask.Blueprint("my_api", __name__)


class BookSchema(ma.Schema):
    id = ma.fields.Integer(as_string=True)
    title = ma.fields.String(allow_none=False)
    publisher = ma.fields.String(allow_none=False)
    isbn = ma.fields.String(allow_none=False)


@open_api.get_list(BookSchema)
@api.route("/books", methods=["GET"])
def books_list():
    return "<p>Hello, World!</p>"


app = flask.Flask(__name__)
app.register_blueprint(api, url_prefix="/v1")


conf = OpenAPISettings(
    api_version="v1", api_name="My API", app_package_name="my_api", mounted_at="/v1"
)
docs = OpenAPI(config=conf)
docs.init_app(app)
```

New app routes:

```sh
$ flask routes

Endpoint               Methods  Rule
---------------------  -------  -------------------------------
# ...
open_api.re_doc        GET      /v1/docs/re_doc
open_api.static        GET      /v1/docs/static/<path:filename>
open_api.swagger_json  GET      /v1/docs/static/swagger.json
open_api.swagger_ui    GET      /v1/docs/swagger_ui
open_api.swagger_yaml  GET      /v1/docs/static/swagger.yaml
# ...
```
