跳转到主要内容

为chalice添加响应描述

项目描述

PyPI PyPI - Python Version GitHub https://travis-ci.org/jsfehler/leangle.svg?branch=master https://coveralls.io/repos/github/jsfehler/leangle/badge.svg?branch=master

chalice的一个插件,用于改进API网关的文档。

截至版本1.13.0,chalice不支持请求或响应的模型。这意味着为API网关生成的任何文档都将非常不实用。

leangle通过为chalice路由函数提供一组装饰器以及内置对marshmallow模式的支持来改进这一点。

安装

通过pip

pip install leangle

Chalice自身是一个可选依赖项。这可以用于测试和验证,但不应用于部署到AWS的Chalice版本。

pip install leangle[chalice]

描述API参数

可以使用describe.parameter装饰器来描述API响应。它们将被添加为API网关的文档。它们应该在路由装饰器之后,并且可以堆叠。

import leangle


@app.route('/', methods=['POST'])
@leangle.describe.parameter(name='body', _in='body', description='Create a new widget', schema='WidgetSchema')
def index():
    return Response(status_code=201)

描述参数的‘in’字段

使用_in,因为in是Python中的一个保留词。

描述API响应

可以使用describe.response装饰器来描述API响应。它们将被添加为API网关的文档。它们应该在路由装饰器之后,并且可以堆叠。

import leangle


@app.route('/', methods=['POST'])
@leangle.describe.response(201, description='Created')
@leangle.describe.response(422, description='Missing Parameter')
def index():
    return Response(status_code=201)

描述方法标签

import leangle


@app.route('/', methods=['POST'])
@leangle.describe.tags(["x-large"])
def index():
    return Response(status_code=201)

添加模式

可以使用marshmallow定义模式对象。

当使用add_schema装饰器时,它们将被添加为API网关中的模型。

这些Schema类的名称可以在描述装饰器中使用。

import leangle
from marshmallow import Schema, fields


@leangle.add_schema()
class BaseSchema(Schema):
    name = fields.Str()


@app.route('/', methods=['POST'])
@leangle.describe.response(201, description='Created', schema='BaseSchema')
def index():
    return Response(status_code=201)

项目详情


下载文件

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

源代码分发

leangle-0.2.2.tar.gz (3.8 kB 查看哈希值)

上传时间 源代码

构建分发

leangle-0.2.2-py3-none-any.whl (6.4 kB 查看哈希值)

上传时间 Python 3

由以下支持