Auto docs generation from marshmallow schema for flask classfy
Project description
Flask classful apispec
A pluggable API specification generator generator for Flask classful <https://flask-classful.teracy.org/>
_ based on apispec <https://apispec.readthedocs.io/en/latest/>
_
Features
- Utilities for parsing flask classful docstrings
- Support for
marshmallow <https://marshmallow.readthedocs.io/>
_
Installation
::
$ pip install flask-classful-apispec
Usage
.. code-block:: python
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
.. code-block:: json
{
"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
- For apispec see
apispec <https://apispec.readthedocs.io/en/latest/>
_ - For Flask Clasful view see
Flask classful <https://flask-classful.teracy.org/>
_ - For Schema see
marshmallow <https://marshmallow.readthedocs.io/>
_
License
MIT licensed. See the bundled LICENSE <https://github.com/dev-rijan/flask-classful-apispec/blob/master/LICENSE>
_ file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for flask-classful-apispec-0.1.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77d2ba9d46b6403109119d59703114dfff7b25090226e703d71cddb1edf93d47 |
|
MD5 | c11738a935bc754adaa7e03edcb0879b |
|
BLAKE2b-256 | 3ad92bdc772728f038a28ee3e00e7a2ce10c62407446829610fd40c6c85f410b |
Close
Hashes for flask_classful_apispec-0.1.7-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4aab2793b390a571f9636ab020c36bedf4cf561bfa3929722f3fffc8aa26e971 |
|
MD5 | 3e5654590d52a0d7fc4ddfd141a753ea |
|
BLAKE2b-256 | 48f1fcc1979c2f7e11f4a40f240a542e73b484a5a1c87888fe22a94d270e5318 |