【发布时间】:2018-03-15 09:04:31
【问题描述】:
我正在尝试设计一个 RESTFul API。我的模型是这样的:
VesselVisit // Parent object
Property1
Property2
Stages[] // Array of Stage type
我想实现这样的 POST 方法:
/VesselVisit/{vvId}/Stage/Track:
我的理解是我必须向 body 传递两个参数,vvId 和一个 Stage 对象。这是我的招摇规范:
/VesselVisit/{vvId}/Stage:
post:
tags:
- Stage
summary: Add a new stage to vessel visit
operationId: addStage
consumes:
- application/json
- application/xml
produces:
- application/json
- application/xml
parameters:
- in: body
name: body
description: Stage object that needs to be added to the vesselVisit
required: true
schema:
$ref: '#/definitions/Stage'
responses:
405:
description: Invalid input
我可以发送 Stage 对象,但我想将其发布到特定的 VesselVisit(父对象)中,如何指定第二个参数 vvId?
【问题讨论】:
-
我认为不是重复的;我知道如何用 GET 方法来做,但我问的是 POST 方法,我相信是不一样的。
-
GET 还是 POST 都没有关系。这个想法是您需要一个单独的
in: path参数(又名路径参数),如链接答案中所述。 -
我将参数类型更改为in: path,现在我需要指定我要发布一个$ref: '#/definitions/Track',我不知道该放在哪里
标签: rest api swagger restful-url