用于apispec的web框架插件。
apispec-webframeworks的Python项目详细描述
apispec插件 与各种web框架集成。
这些插件以前在apispec.ext中,但此后 被转移到他们自己的包裹里。
包含的插件:
- apispec_webframeworks.bottle
- apispec_webframeworks.flask
- apispec_webframeworks.tornado
从^{tt5}迁移$
要从旧版本的apispec迁移,请安装此软件包 使用
pip install apispec-webframeworks
更改导入,如下所示:
# apispec<1.0.0fromapispec.ext.flaskimportFlaskPlugin# apispec>=1.0.0fromapispec_webframeworks.flaskimportFlaskPlugin
示例用法
fromflaskimportFlaskfromapispecimportAPISpecfromapispec.ext.marshmallowimportMarshmallowPluginfromapispec_webframeworks.flaskimportFlaskPluginfrommarshmallowimportSchema,fieldsspec=APISpec(title='Gisty',version='1.0.0',info=dict(description='A minimal gist API'),plugins=[FlaskPlugin(),MarshmallowPlugin(),])app=Flask(__name__)classGistParameter(Schema):gist_id=fields.Int()classGistSchema(Schema):id=fields.Int()content=fields.Str()@app.route('/gists/<gist_id>')defgist_detail(gist_id):"""Gist detail view. --- get: parameters: - in: path schema: GistParameter responses: 200: schema: GistSchema """return'details about gist {}'.format(gist_id)# Since `path` inspects the view and its route,# we need to be in a Flask request contextwithapp.test_request_context():spec.path(view=gist_detail)
文件
有关特定插件的文档,请参阅其模块docstring。
开发
- 克隆并将CD放入此回购协议中
- 创建并激活虚拟环境
- 安装这个包(在可编辑模式下)并开发 依赖关系
$ pip install '.[dev]'
- 安装预提交挂钩
$ pre-commit install
运行测试
要运行所有测试:
$ pytest
运行语法检查:
$ tox -e lint
(可选)要在Python2.7、3.5、3.6和3.7虚拟环境上运行测试(必须安装每个解释器):
$ tox
许可证
麻省理工学院许可有关详细信息,请参阅捆绑的LICENSE文件。