0

I am trying to design a RESTFul API. My model is like that:

VesselVisit // Parent object 
    Property1
    Property2
    Stages[] // Array of Stage type  

And I would like to implement a POST method like this:
/VesselVisit/{vvId}/Stage/Track:
My understanding is I have to pass into body two parameters, vvId and a Stage object. This is my swagger specification:

/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

I am able to send the Stage object, but I want to post it in a specific VesselVisit (parent object), how I can specify this second parameter vvId?

jre
  • 23
  • 1
  • 7
  • 3
    Possible duplicate of [Swagger:Issue with Path parameter](https://stackoverflow.com/questions/27155516/swaggerissue-with-path-parameter) – Helen Mar 15 '18 at 10:29
  • I think it is not duplicate; I know how to do it with GET method, but I am asking of the POST method that, I believe is not the same. – jre Mar 15 '18 at 10:52
  • It doesn't matter if it's GET or POST. The idea is that you need a separate `in: path` parameter (aka path parameter), as explained in the linked answer. – Helen Mar 15 '18 at 10:53
  • I changed the parameter type to in: path, now I need to specify I want to post a $ref: '#/definitions/Track', I am not able to figure out where to put it – jre Mar 15 '18 at 11:04

1 Answers1

0

I found the solution thank to the comments. It is about have one parameter in path and the other one in the body. This is how it looks:

/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
jre
  • 23
  • 1
  • 7