跳转到主要内容

apispec的Web框架插件。

项目描述

PyPI package Build status marshmallow 3 compatible

apispec 插件,用于与各种Web框架集成。

这些插件曾经位于 apispec.ext 中,但后来已移至自己的包。

包含的插件

  • apispec_webframeworks.aiohttp

  • apispec_webframeworks.bottle

  • apispec_webframeworks.flask

  • apispec_webframeworks.tornado

apispec<1.0.0 迁移

要从较旧版本的apispec迁移,请使用以下命令安装此包

pip install apispec-webframeworks

更改导入,如下所示

# apispec<1.0.0
from apispec.ext.flask import FlaskPlugin

# apispec>=1.0.0
from apispec_webframeworks.flask import FlaskPlugin

示例用法

from flask import Flask
from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from apispec_webframeworks.flask import FlaskPlugin
from marshmallow import Schema, fields

spec = APISpec(
    title="Gisty",
    version="1.0.0",
    info=dict(description="A minimal gist API"),
    plugins=[FlaskPlugin(), MarshmallowPlugin()],
)


app = Flask(__name__)


class GistParameter(Schema):
    gist_id = fields.Int()


class GistSchema(Schema):
    id = fields.Int()
    content = fields.Str()


@app.route("/gists/<gist_id>")
def gist_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 context
with app.test_request_context():
    spec.path(view=gist_detail)

文档

有关特定插件的文档,请参阅其模块文档字符串。

开发

  • 克隆并进入此仓库

  • 创建并激活一个虚拟环境

  • 以可编辑模式安装此包(以及开发依赖项)

$ pip install '.[dev]'
  • 安装pre-commit钩子

$ pre-commit install

运行测试

要运行所有测试

$ pytest

要运行语法检查

$ tox -e lint

(可选)要运行所有受支持的Python版本的测试(必须在每个虚拟环境中安装每个解释器)

$ tox

许可证

MIT许可证。有关更多详细信息,请参阅捆绑的 LICENSE 文件。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

apispec_webframeworks-1.2.0.tar.gz (10.8 kB 查看哈希值)

上传时间 源代码

构建分发

apispec_webframeworks-1.2.0-py3-none-any.whl (9.1 kB 查看哈希值)

上传时间 Python 3

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面