okapi是一个简单的工具,可以为您的api创建文档并用测试覆盖它。它基于可重构的文本格式,非常容易学习。
tz-okapi的Python项目详细描述
okapi
使api文档正常。
okapi是为api和cover创建documentation的简单工具 它带有测试。它基于restructedtext格式,非常容易学习。
内容:
Installation
sudo pip3 install tz-okapi
从源安装:
python setup.py install
从软件包安装:
pip install wheel pip install tz_okapi-*.whl
在windows上,您可以将python添加到路径:
setx path "%path%;C:\Python34;C:\Python34\Scripts;"
Usage
okapi Usage: okapi [<in> -cdo <out> --url=<url> --config=<config> --headers=<headers> -v <verbosity> --prototype] Options: -c Enable persistent cache for responses. -d Allow debug mode. -o <out> Output directory -v <verbosity> Verbosity level [default: 2] 0 - no output 1 - summary 2 - failed tests 3 - all --url=<url> URL against the requests are made --headers=<headers> Custom headers sent to API, not visible in doc. (Comma separated). --config=<config> Config file. [default: okapi.cfg] --prototype Run in prototype mode (no requests are made). Example: okapi notebook.rst -o index.html --url=http://www.notebook.com/
Example configuration file
[base]file=notebook-api.rstoutput=docs/apiurl=http://www.mynotebook/cache=1templates=docs/api/templatesverbosity=2
Example
Notebook API documentation========================== Notebook is a project to create and read notes. In every request, it should be sent this headers: ..code::headers Accept-Type: application/json Accept-Language: en,fr Create new note--------------- To create new note use this POST method. Note can be created only with authenticated user. ..code::request POST /api/note/create/ Authentication: johnsmith:topsecretpass { "title": "My Note Title", "text": "Very long text..." } > status_code == 201 > 'id' in json() If user is not successfully authenticated, status code ``401`` is returned: ..code::request POST /api/note/create/ > status_code == 401 Get note detail--------------- To get note detail, you have to provide its ``id``. For example: ..code::request GET /api/note/{id:1}/ > status_code == 200 > 'title' in json() > 'text' in json() Get notes list-------------- To get all notes use this request: ..code::request GET /api/notes/ > status_code == 200 It is possible to filter by creation date: ..code::request GET /api/notes/?date=2015-01-01 > status_code == 200
还不够吗?继续阅读…
Motivation
我们花了很长时间寻找一个工具来为 我们的项目。我们试过Apiary,我们试过 Swagger和越来越多的工具,但没有一个让我们满意。
我们需要的工具是:
- dry.我们懒得重复我们自己。重复是犯许多错误的一种方式。
- kiss.团队中的每个成员都应该能够在不知道某些内容的情况下编辑它 特殊的语法或规则。如此愚蠢简单。
- 可更改。这意味着,此人在数小时后不会编辑文档 API的每一个小变化。
- 可读原始格式。
- 可用于non-rest api(当然,也可用于restapi)。
- testable.不包含在测试中的文档很难维护。
Specification
request
块来描述API请求。它有四个部分:
- 方法和URL(必需)
- 标题(可选)
- 有效载荷(可选)
- 测试(推荐)
.. code:: request (GET|POST|PUT|PATCH|DELETE|OPTIONS|HEAD|TRACE|CONNECT) (URL) [HTTP_VERSION] [HEADER_NAME: HEADER_VALUE] ... [{ ... json payload ... }] [ > tests > .. ]
Change log
Release 0.2.10 (2015/09/24)
- 在API请求中禁用重定向。
Release 0.2.9 (2015/09/22)
- 在保存输出时修复unicodeencodeerror。
Release 0.2.8 (2015/08/05)
- #32-添加MIT许可证
- #33-修复错误的解释器错误。
Release 0.2.7 (2015/08/04)
- #12-使用include指令修复路径。
Release 0.2.6 (2015/08/04)
- #30-添加了--prototype选项以在原型模式下运行。原型模式 不执行任何请求,响应是假的。
- #31-将自动生成的边栏目录添加到默认模板。
Release 0.2.5 (2015/07/27)
- #27-添加了点击滚动功能。请求和响应不是 默认情况下可滚动,用户必须点击它们。
- #26-修复了显示响应状态代码的默认模板,即使响应 是空的。