openapi 3规范的客户端和验证器

openapi3的Python项目详细描述


python 3的pythonOpenAPI 3 Specification客户端和验证器。

https://travis-ci.org/Dorthu/openapi3.svg?branch=master

注释

这是一项正在进行的工作,今后可能会有重大变化。许多 目前缺乏特性,许多常见情况可能无法实现

验证模式

此模块可以针对spec文件运行以进行验证,如下所示:

python3 -m openapi /path/to/spec

作为客户使用

这个库还可以作为任意OpenAPI 3的交互客户机 规格。例如,使用Linode’s OpenAPI 3 Specification作为参考:

from openapi3 import OpenAPI

# load the spec file and read the yaml
with open('openapi.yaml') as f:
    spec = yaml.safe_load(f.read())

# parse the spec into python - this will raise if the spec is invalid
api = OpenAPI(spec)

# call operations and receive result models
regions = api.call_getRegions()

# authenticate using a securityScheme defined in the spec's components.securtiySchemes
api.authenticate('personalAccessToken', my_token)

# call an operation that requires authentication
linodes  = api.call_getLinodeInstances()

# call an opertaion with parameters
linode = api.call_getLinodeInstance(parameters={"linodeId": 123})

# the models returns are all of the same (generated) type
print(type(linode))                      # openapi.schemas.Linode
type(linode) == type(linodes.data[0])    # True

# call an operation with a request body
new_linode = api.call_createLinodeInstance(data={"region":"us-east","type":"g6-standard-2"})

# the returned models is still of the correct type
type(new_linode) == type(linode)     # True

http基本身份验证和http摘要身份验证的工作方式如下:

# authenticate using a securityScheme defined in the spec's components.securtiySchemes
# Tuple with (username, password) as second argument
api.authenticate('basicAuth', ('username', 'password'))

路线图

仍然需要做以下工作:

  • 请求主体模型、创建和验证。
  • 参数与验证和显式类型化接口。
  • 支持更多身份验证类型。
  • 支持非json请求/响应内容
  • 完全支持规范中定义的所有对象。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用无循环和乘法的递归调用查找值   java字符串大小冲突   在一组Java文件对象中查找唯一的超级目录   没有Eclipse控制台输出窗口(Java)?   java这怎么等于105而不是15?   java Adempiere列调出,用于不处理从(代码)选项导入和创建行的字段   java tomcat、2个webapps、2个log4js,但这两个应用都记录到一个文件中   lambda理解Java谓词   HotspotFX上的Java EOF问题   java google应用程序引擎:如何向连接/断开通道“ping”添加信息?   java如何使用VTDXML获取一个元素的所有名称空间声明?   java如何使用drawLine()获得一条线以随机方向拍摄?   java transactionManager应该使用哪个SessionFactory?   java在安卓上播放声音   在Mac上使用JBDC对SQL Server进行java Windows身份验证   java基本列表和字符串[]   java NamedParameterJdbcTemplate从中选择*   扩展上的java Android可扩展列表视图   使用ApacheAxis2的java SOAP附件