【问题标题】:Swagger multiple parameters POSTSwagger 多个参数 POST
【发布时间】: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


【解决方案1】:

感谢 cmets,我找到了解决方案。它是关于在路径中有一个参数,在正文中有另一个参数。看起来是这样的:

/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

【讨论】:

    猜你喜欢
    • 2019-06-27
    • 2011-07-21
    • 1970-01-01
    • 2016-04-09
    • 1970-01-01
    • 1970-01-01
    • 2013-01-02
    • 2010-09-15
    相关资源
    最近更新 更多