我正在尝试设计RESTFul API。我的模型是这样的:
VesselVisit // Parent object
Property1
Property2
Stages[] // Array of Stage type
我想实现这样的POST方法:
的 / VesselVisit / {vvId} /阶段/追踪:
我的理解是我必须将两个参数传递给 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 ?
答案 0 :(得分:0)
我感谢评论,我找到了解决方案。它在路径中有一个参数,在体内有另一个参数。这是它的外观:
/VesselVisit/{vvId}/Stage:
post:
tags:
- Stage
summary: Add a new stage to vessel visit
operationId: addStageById
consumes:
- application/json
- application/xml
produces:
- application/json
- application/xml
parameters:
- in: path
name: vvId
description: Stage object that needs to be added to the vesselVisit
required: true
type: string
format: string
- in: body
name: body
description: Pet object that needs to be added to the store
required: true
schema:
$ref: '#/definitions/Stage'
responses:
405:
description: Invalid input