# as_flask_docs
在flask中支持**数据校验**和openapi(swagger)**文档自动生成**
**[flask_docs](https://github.com/Dorain-An/flask-docs)** fork自[flask-siwadoc](https://github.com/lzjun567/flask-siwadoc),感谢原作者提供了主要功能的实现,原项目不支持flask中blueprint的使用因此魔改
## 特性
### 1、API接口自动生成文档
需要通过`CreateDoc(app)`,利用装饰器 `siwa.doc()`修饰flask视图函数,即可将该视图对应的路由加入openapi的paths中。
### 2、支持多种参数指定
可以将请求参数放置在 `query`、`path`、`header`、`cookie`、`body`5种不同的地方,完全支持openapi规范所定义的5种参数方式。
### 3、参数校验与自动转换
基于`pydantic`,请求参数可自动转换为对应的数据类型
### 4、ui切换
内置了`swagger`(默认)、`redoc`、`rapidoc`等多种UI界面,通过query参数"ui"控制
### 5、支持标签与分组
## 安装
```
pip install as-flask-docs
```
## 快速开始
```python
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](http://127.0.0.1:5000/docs) 就可以看到openapi文档页面
### [更多用法介绍请移步原项目](https://github.com/lzjun567/flask-siwadoc)
Raw data
{
"_id": null,
"home_page": "https://github.com/Dorain-An/flask-docs",
"name": "as-flask-docs",
"maintainer": "ansen",
"docs_url": null,
"requires_python": ">=3.7,<4.0",
"maintainer_email": "ansen921@gmail.com",
"keywords": "flask,api,docs,swagger,redoc,rapidoc",
"author": "liuzhijun",
"author_email": "lzjun567@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/22/89/f6a69f54de16e2a405a54fe5a7e58228a940d92f7bc0551e9df1de8e1132/as_flask_docs-1.0.4.tar.gz",
"platform": null,
"description": "# as_flask_docs\n\n\u5728flask\u4e2d\u652f\u6301**\u6570\u636e\u6821\u9a8c**\u548copenapi(swagger)**\u6587\u6863\u81ea\u52a8\u751f\u6210**\n\n**[flask_docs](https://github.com/Dorain-An/flask-docs)** fork\u81ea[flask-siwadoc](https://github.com/lzjun567/flask-siwadoc)\uff0c\u611f\u8c22\u539f\u4f5c\u8005\u63d0\u4f9b\u4e86\u4e3b\u8981\u529f\u80fd\u7684\u5b9e\u73b0\uff0c\u539f\u9879\u76ee\u4e0d\u652f\u6301flask\u4e2dblueprint\u7684\u4f7f\u7528\u56e0\u6b64\u9b54\u6539\n\n\n## \u7279\u6027\n\n### 1\u3001API\u63a5\u53e3\u81ea\u52a8\u751f\u6210\u6587\u6863\n\n\u9700\u8981\u901a\u8fc7`CreateDoc(app)`,\u5229\u7528\u88c5\u9970\u5668 `siwa.doc()`\u4fee\u9970flask\u89c6\u56fe\u51fd\u6570\uff0c\u5373\u53ef\u5c06\u8be5\u89c6\u56fe\u5bf9\u5e94\u7684\u8def\u7531\u52a0\u5165openapi\u7684paths\u4e2d\u3002\n\n### 2\u3001\u652f\u6301\u591a\u79cd\u53c2\u6570\u6307\u5b9a\n\n\u53ef\u4ee5\u5c06\u8bf7\u6c42\u53c2\u6570\u653e\u7f6e\u5728 `query`\u3001`path`\u3001`header`\u3001`cookie`\u3001`body`5\u79cd\u4e0d\u540c\u7684\u5730\u65b9\uff0c\u5b8c\u5168\u652f\u6301openapi\u89c4\u8303\u6240\u5b9a\u4e49\u76845\u79cd\u53c2\u6570\u65b9\u5f0f\u3002\n\n### 3\u3001\u53c2\u6570\u6821\u9a8c\u4e0e\u81ea\u52a8\u8f6c\u6362\n\n\u57fa\u4e8e`pydantic`\uff0c\u8bf7\u6c42\u53c2\u6570\u53ef\u81ea\u52a8\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684\u6570\u636e\u7c7b\u578b\n\n### 4\u3001ui\u5207\u6362\n\n\u5185\u7f6e\u4e86`swagger`\uff08\u9ed8\u8ba4\uff09\u3001`redoc`\u3001`rapidoc`\u7b49\u591a\u79cdUI\u754c\u9762\uff0c\u901a\u8fc7query\u53c2\u6570\"ui\"\u63a7\u5236\n\n### 5\u3001\u652f\u6301\u6807\u7b7e\u4e0e\u5206\u7ec4\n\n## \u5b89\u88c5\n\n```\npip install as-flask-docs\n```\n\n## \u5feb\u901f\u5f00\u59cb\n\n```python\nfrom flask import Flask\nfrom flask_docs import CreateDoc\n\napp = Flask(__name__)\nmodels = {}\nmodules = import_module('tests.bps')\n\nfor name in dir(modules):\n instance = getattr(modules, name)\n if isinstance(instance, Blueprint):\n app.register_blueprint(instance)\n if isinstance(instance, Docs):\n models.update(instance.models)\n\nCreateDoc(app, title=\"flask_docs\", description=\"\u4e00\u4e2a\u81ea\u52a8\u751f\u6210openapi\u6587\u6863\u7684\u5e93\", models=models)\n\n```\n\n```\nfrom flask import Blueprint\nfrom flask_siwadoc import Docs\nfrom pydantic import BaseModel\n\ntest1 = Blueprint(\"t1\", __name__, url_prefix=\"/api/t1\")\nd = Docs(tags=[\"1\"])\n\nclass A(BaseModel):\n a: int = 1\n\n@test1.get('')\n@d(body=A)\ndef fun(body: A):\n return 't1'\n```\n\n\u8fd0\u884c\u540e\uff0c\u8bbf\u95ee [http://127.0.0.1:5000/docs](http://127.0.0.1:5000/docs) \u5c31\u53ef\u4ee5\u770b\u5230openapi\u6587\u6863\u9875\u9762\n\n\n### [\u66f4\u591a\u7528\u6cd5\u4ecb\u7ecd\u8bf7\u79fb\u6b65\u539f\u9879\u76ee](https://github.com/lzjun567/flask-siwadoc)\n\n",
"bugtrack_url": null,
"license": "",
"summary": "\u5bf9flask\u63d0\u4f9b\u6570\u636e\u6821\u9a8c\u548copenapi(swagger)\u6587\u6863\u81ea\u52a8\u751f\u6210\u7684\u652f\u6301",
"version": "1.0.4",
"split_keywords": [
"flask",
"api",
"docs",
"swagger",
"redoc",
"rapidoc"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "193a7050d3c2913a8a1c3b78594e20566925c327abce233bf12a0e3ec4c21d99",
"md5": "76b97b1b61a444380471402ae125488d",
"sha256": "7b271c41f407908718697c2146e717b6d7a49517c05b71645b2872a11072a30d"
},
"downloads": -1,
"filename": "as_flask_docs-1.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "76b97b1b61a444380471402ae125488d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7,<4.0",
"size": 12401,
"upload_time": "2023-02-10T02:52:41",
"upload_time_iso_8601": "2023-02-10T02:52:41.694372Z",
"url": "https://files.pythonhosted.org/packages/19/3a/7050d3c2913a8a1c3b78594e20566925c327abce233bf12a0e3ec4c21d99/as_flask_docs-1.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2289f6a69f54de16e2a405a54fe5a7e58228a940d92f7bc0551e9df1de8e1132",
"md5": "bc965b1ab1183946d956dc6f12d9cd65",
"sha256": "6f5de27b9ad91354ed2366b93e2200670c7e27cc36ecbce3bd598ee1210c1d73"
},
"downloads": -1,
"filename": "as_flask_docs-1.0.4.tar.gz",
"has_sig": false,
"md5_digest": "bc965b1ab1183946d956dc6f12d9cd65",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7,<4.0",
"size": 10941,
"upload_time": "2023-02-10T02:52:43",
"upload_time_iso_8601": "2023-02-10T02:52:43.671459Z",
"url": "https://files.pythonhosted.org/packages/22/89/f6a69f54de16e2a405a54fe5a7e58228a940d92f7bc0551e9df1de8e1132/as_flask_docs-1.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-10 02:52:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Dorain-An",
"github_project": "flask-docs",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "as-flask-docs"
}