您的位置:首页 > 编程语言 > Python开发

RAML规范的Python参考实现ramlfications详解

2017-06-27 10:12 309 查看
ramlfications是RAML规范的一个参考实现,使用Python语言编写。

1. ramlfications的组成

类库
命令行工具

通过ramlfications的类库,能够开发解析并验证RAML文件的Python软件。

通过ramlfications的命令行工具,可以验证RAML API,并以树状结构可视化显示。

2. ramlfications的安装

pip install ramlfications


3. ramlfications的更新

安装ramlfications后,可以直接通过ramlfications命令更新。

$ ramlfications update


4. ramlfications类库的用法

1).解析

通过Python代码解析RAML文件
import ramlfications
RAML_FILE = "/path/to/my-api.raml"
api = ramlfications.parse(RAML_FILE)
api.title
api.version


通过配置文件,定制解析RAML文件
通过配置文件,可以使RAML API支持额外的协议或响应代码,或定制的认证模式(但是不推荐)

定义配置文件my-config.ini示例如下:

[main]
validate = True

[custom]
append = True
resp_codes = 420, 421, 422
auth_schemes = oauth_3_0, oauth_4_0
media_types = application/vnd.github.v3, foo/bar
protocols = FTP
raml_versions = 0.8


结合配置文件解析RAML文件如下:

import ramlfications
RAML_FILE = "/path/to/my-api.raml"
CONFIG_FILE = "/path/to/my-config.ini"
api = ramlfications.parse(RAML_FILE, CONFIG_FILE)


2).验证

验证RAML文件是否遵循RAML 1.0规范。

from ramlfications import validate
RAML_FILE = "/path/to/my-api.raml"
validate(RAML_FILE)


5. ramlfications命令行工具的用法

ramlfications命令行工具的基本使用格式

$ ramlfications [OPTIONS] COMMAND [ARGS]


ramlfications命令行工具的3个基本命令:

validate

$ ramlfications validate /path/to/my-api.raml


$ ramlfications -c /path/to/my-config.ini validate /path/to/my-api.raml


tree

$ ramlfications tree /path/to/my-api.raml [-C|--color light|dark] [-v|vv|vvv] [-o|--output fileName]

$ ramlfications -c /path/to/my-config.ini tree /path/to/my-api.raml [-C|--color light|dark] [-v|vv|vvv] [-o|--output fileName]

update
$ ramlfications update


参考链接:
https://github.com/spotify/ramlfications https://ramlfications.readthedocs.io/en/latest/index.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息