我尝试使用以下路径创建一个swagger文件:paths:/ v1/customers/{id}/summary:
但是我马上得到以下错误:
API需要路径参数,但未定义:路径id/v1/customers/{id}/summary中的id
它似乎不喜欢'id'参数.谁能告诉我如何纠正这个问题?
如果我深入研究这个,我会看到以下内容:
Details
Object
swaggerError: Object
errors: Array [1]
0: Object
code: "MISSING_API_PATH_PARAMETER"
message: "API requires path parameter but it is not defined: id"
data: "/v1/customers/{id}/summary"
path: Array [2]
warnings: Array [0]
Run Code Online (Sandbox Code Playgroud)
Ron*_*Ron 89
基本上,您通过使用路径模板声明其中包含路径参数的路径.在这种情况下,{id}声明一个名为的路径参数id.
声明这样的路径时,意味着必须将该path参数声明为操作的一部分.
看看这个YAML示例:
/pets/{id}:
get:
description: Returns a user based on a single ID, if the user does not have access to the pet
operationId: findPetById
produces:
- application/json
- application/xml
- text/xml
- text/html
parameters:
- name: id
in: path
description: ID of pet to fetch
required: true
type: integer
format: int64
responses:
'200':
description: pet response
schema:
$ref: '#/definitions/pet'
default:
description: unexpected error
schema:
$ref: '#/definitions/errorModel'
Run Code Online (Sandbox Code Playgroud)
您可以看到{id}路径中有一个,以及相应的id参数定义.没有它,规范将无效.
| 归档时间: |
|
| 查看次数: |
41986 次 |
| 最近记录: |