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:: pyhton
{
"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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask-classful-apispec-0.1.9.tar.gz.
File metadata
- Download URL: flask-classful-apispec-0.1.9.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f9f0381a3208ee5ab9e11e36f6c635a57cd5e8240b1c4ff9c6d0a32b6596e58
|
|
| MD5 |
5b736618575fe44dd7c1c6a1b2d7b66c
|
|
| BLAKE2b-256 |
d07dd2e29af76bbb9ee12da41612d84a2bd2ca1d09ef1b5bf4ba5026b4eb35af
|
File details
Details for the file flask_classful_apispec-0.1.9-py2.py3-none-any.whl.
File metadata
- Download URL: flask_classful_apispec-0.1.9-py2.py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e005c0501a7a75dddeb1ad84e563e63c7a0e1ca55d2701a1e5526a5438c165ff
|
|
| MD5 |
199d6aef6f0428b7e7177b5e3c385fb5
|
|
| BLAKE2b-256 |
fdf88f778254a63659e070f041ed56e7f94a99e921f029a88fcb0f9a0c82b68a
|