as_flask_docs
在flask中支持数据校验和openapi(swagger)文档自动生成
flask_docs fork自flask-siwadoc,感谢原作者提供了主要功能的实现,原项目不支持flask中blueprint的使用因此魔改
特性
1、API接口自动生成文档
需要通过CreateDoc(app),利用装饰器 siwa.doc()修饰flask视图函数,即可将该视图对应的路由加入openapi的paths中。
2、支持多种参数指定
可以将请求参数放置在 query、path、header、cookie、body5种不同的地方,完全支持openapi规范所定义的5种参数方式。
3、参数校验与自动转换
基于pydantic,请求参数可自动转换为对应的数据类型
4、ui切换
内置了swagger(默认)、redoc、rapidoc等多种UI界面,通过query参数"ui"控制
5、支持标签与分组
安装
pip install as-flask-docs
快速开始
from flask import Flask
from flask_docs import CreateDoc
app = Flask(__name__)
models = {}
modules = import_module('tests.bps')
for name in dir(modules):
instance = getattr(modules, name)
if isinstance(instance, Blueprint):
app.register_blueprint(instance)
if isinstance(instance, Docs):
models.update(instance.models)
CreateDoc(app, title="flask_docs", description="一个自动生成openapi文档的库", models=models)
from flask import Blueprint
from flask_siwadoc import Docs
from pydantic import BaseModel
test1 = Blueprint("t1", __name__, url_prefix="/api/t1")
d = Docs(tags=["1"])
class A(BaseModel):
a: int = 1
@test1.get('')
@d(body=A)
def fun(body: A):
return 't1'
运行后,访问 http://127.0.0.1:5000/docs 就可以看到openapi文档页面
更多用法介绍请移步原项目
Metadata
Release files for as-flask-docs 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| as_flask_docs-1.0.5.tar.gz | 11.0 kB | Without provenance | Details for as_flask_docs-1.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| as_flask_docs-1.0.5-py3-none-any.whl | Python 3 | none | any | Details for as_flask_docs-1.0.5-py3-none-any.whl |
Total release size: 23.4 kB
Release files / as_flask_docs-1.0.5.tar.gz
| Download URL | as_flask_docs-1.0.5.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5bcfca411dca54474e3ce89b3cb9572e9a2d28dbdc8821c26a82ad2eea5a33f8
|
|
BLAKE2b-256 checksum How to use checksums |
8ccb0b00af6061bee1dc39b1e4eb92602738cd617468f2dd42f2e6929181c693
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.0
|
Release files / as_flask_docs-1.0.5-py3-none-any.whl
| Download URL | as_flask_docs-1.0.5-py3-none-any.whl |
|---|---|
| Size | 12.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2510f6e9bcfd86f8d30613cca639b6b0ca9655b6e41a1375e37412d7fa06461c
|
|
BLAKE2b-256 checksum How to use checksums |
5bf175cc11527ed65430a94503d6e404d28f7ac4396e08794a404419e317ef72
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.0
|
Security for as-flask-docs 1.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.