Dredd 将尾随方括号传递给 API
Dredd passing trailing square bracket to API
我正在使用 Dredd 来测试我写的 API。它工作正常,直到我尝试改变资源中的操作 uri。当我执行
形式的操作时
## Retrieve Task [GET /task/{id}]
它向 Drakov 发送了一个附加了 ]
的请求。这个 Drakov 服务器是 运行 蓝图文件。
Drakov 0.1.16 Listening on port 8090
[LOG] GET /task/myid]
[LOG] DELETE /task/myid]
[LOG] GET /task/myid]
你可以看到这个请求最后多了一个]
。
这是我的蓝图。它是 Api Blueprint examples:
示例的子集
FORMAT: 1A
# Advanced Action API
A resource action is – in fact – a state transition. This API example demonstrates an action - state transition - to another resource.
## API Blueprint
# Tasks [/tasks/tasks{?status,priority}]
+ Parameters
+ status `test` (string)
+ priority `1` (number)
## Retrieve Task [GET /task/{id}]
This is a state transition to another resource
+ Parameters
+ id: `myid` (string)
+ Response 200 (application/json)
{
"id": 123,
"name": "Go to gym",
"done": false,
"type": "task"
}
我做错了什么?
您的 API 蓝图有多个错误。例如,
+ Parameters
+ status `test` (string)
+ priority `1` (number)
...应该是:
+ Parameters
+ status: `test` (string)
+ priority: `1` (number)
此外,您正在使用 URI 模板 /tasks/tasks{?status,priority}
定义资源 Tasks
,然后尝试使用不同的 URI 模板为资源定义 GET
操作。这令人困惑。
我尝试创建示例 API 蓝图(另存为 sample-blueprint.md
),如下所示:
FORMAT: 1A
# My API
## Task [/task/{id}]
### Retrieve Task [GET]
+ Parameters
+ id: `123` (string)
+ Response 200 (application/json)
{
"id": 123,
"name": "Go to gym",
"done": false,
"type": "task"
}
然后我像这样在一个终端中启动了一个 Drakov 服务器:
drakov -f *.md
然后我尝试运行 Dredd:
dredd sample-blueprint.md http://localhost:3000
一切都正确通过:
$ dredd sample-blueprint.md http://localhost:3000
info: Beginning Dredd testing...
pass: GET /task/123 duration: 42ms
complete: 1 passing, 0 failing, 0 errors, 0 skipped, 1 total
complete: Tests took 50ms
这是您最初想要实现的目标吗?
我正在使用 Dredd 来测试我写的 API。它工作正常,直到我尝试改变资源中的操作 uri。当我执行
形式的操作时## Retrieve Task [GET /task/{id}]
它向 Drakov 发送了一个附加了 ]
的请求。这个 Drakov 服务器是 运行 蓝图文件。
Drakov 0.1.16 Listening on port 8090
[LOG] GET /task/myid]
[LOG] DELETE /task/myid]
[LOG] GET /task/myid]
你可以看到这个请求最后多了一个]
。
这是我的蓝图。它是 Api Blueprint examples:
示例的子集FORMAT: 1A
# Advanced Action API
A resource action is – in fact – a state transition. This API example demonstrates an action - state transition - to another resource.
## API Blueprint
# Tasks [/tasks/tasks{?status,priority}]
+ Parameters
+ status `test` (string)
+ priority `1` (number)
## Retrieve Task [GET /task/{id}]
This is a state transition to another resource
+ Parameters
+ id: `myid` (string)
+ Response 200 (application/json)
{
"id": 123,
"name": "Go to gym",
"done": false,
"type": "task"
}
我做错了什么?
您的 API 蓝图有多个错误。例如,
+ Parameters
+ status `test` (string)
+ priority `1` (number)
...应该是:
+ Parameters
+ status: `test` (string)
+ priority: `1` (number)
此外,您正在使用 URI 模板 /tasks/tasks{?status,priority}
定义资源 Tasks
,然后尝试使用不同的 URI 模板为资源定义 GET
操作。这令人困惑。
我尝试创建示例 API 蓝图(另存为 sample-blueprint.md
),如下所示:
FORMAT: 1A
# My API
## Task [/task/{id}]
### Retrieve Task [GET]
+ Parameters
+ id: `123` (string)
+ Response 200 (application/json)
{
"id": 123,
"name": "Go to gym",
"done": false,
"type": "task"
}
然后我像这样在一个终端中启动了一个 Drakov 服务器:
drakov -f *.md
然后我尝试运行 Dredd:
dredd sample-blueprint.md http://localhost:3000
一切都正确通过:
$ dredd sample-blueprint.md http://localhost:3000
info: Beginning Dredd testing...
pass: GET /task/123 duration: 42ms
complete: 1 passing, 0 failing, 0 errors, 0 skipped, 1 total
complete: Tests took 50ms
这是您最初想要实现的目标吗?