所以,我需要使用Swagger重新创建我的休息端点。为此,我使用了位于editor.swagger.io的Swagger编辑器。
要调用我的实际休息端点,我需要这个路径。http://localhost:8080/phonenumbersmanagement/api/v1/areacodes/1
遗憾的是,Swagger编辑器创建了一个类似的路径,我无法使用。http://localhost:8080/phonenumbersmanagement/api/v1/areacodes?id=1
这是一个GET -request. 我得到的是 405 - Method not allowed
我在Swagger编辑器中的代码是这样的。
/areacodes:
post:
tags:
- "areacode"
summary: "Add AreaCode"
description: ""
operationId: "addAreaCode"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "body"
name: "body"
description: "add areacode"
required: true
schema:
$ref: "#/definitions/AreaCode"
responses:
"405":
description: "Invalid input"
get:
tags:
- "areacode"
summary: "Get Areacode"
description: ""
operationId: "getAreaCodeById"
produces:
- "application/json"
parameters:
- name: "id"
in: "query"
description: "Status values that need to be considered for filter"
required: true
type: "integer"
format: "int32"
responses:
"200":
description: "successful operation"
schema:
type: "array"
items:
$ref: "#/definitions/AreaCode"
"400":
description: "Invalid status value"
有人知道怎么解决这个问题吗?
在 .../areacodes/1
,1是一个 路径参数因此,该参数必须定义为 in: path
而非 in: query
. 此外,带有路径参数的端点必须使用路径模板来定义--。.../areacodes/{id}
,其中 {id}
表示路径参数,名为 id
.
考虑到这一点,你的GET操作需要定义如下。
paths:
/areacodes/{id}: # <------
get:
...
parameters:
- name: "id"
in: path # <------
description: "Status values that need to be considered for filter"
required: true
type: "integer"
format: "int32"