Go-swagger: Path parameter with request body

Created on 11 May 2018  路  4Comments  路  Source: go-swagger/go-swagger

Request body is not shown with following spec. What am I doing wrong?

// swagger:operation PATCH /v1/users/{id} users userUpdate
// ---
// summary: Updates user's contact information
// description: Updates user's contact information -> first name, last name, mobile, phone, address.
// parameters:
// - name: id
//   in: path
//   description: id of user
//   type: int
//   required: true
// - name: request
//   in: body
//   description: Request body
//   required: true
//   schema:
//     "$ref": "#/definitions/UserUpdate"
// responses:
//   "200":
//     "$ref": "#/responses/userResp"

RequestBody is empty.

image

Just downloaded go-swagger using go-get.

generate spec

All 4 comments

How is your model defined?
This works perfectly:

// Create area request
// swagger:model createAreaRequest
type createAreaRequest struct {
    Name string
    ControllerID uint
}
And annotation to operation:
// swagger:operation POST /areas Areas areas
// ---
// summary: Create new area
// description: Creates new area with specified parameters
// parameters:
// - name: area
//   in: body
//   description: area parameters
//   schema:
//     "$ref": "#/definitions/createAreaRequest"
//   required: true
// responses:
//   "200":
//     "$ref": "#/responses/areaResponse"
//   "400":
//     "$ref": "#/responses/badRequestError"

screenshot from 2018-09-03 15-54-00

Can you adding another parameter, e.g. id from my example?

It works too. Just added id from your example

// - name: id
//   in: path
//   description: id of user
//   type: int
//   required: true

Before pressing Try it out button
screenshot from 2018-09-03 20-51-33
screenshot from 2018-09-03 20-51-39
After Try it out button pressed (fields are displayed), example model value is in body field, but changing to model structure view is not available until you press Cancel, it is normal, as far as i know
screenshot from 2018-09-03 20-52-00

Now that I'm looking at it, I think I was using swagger:parameters instead of swagger:model for this one.

Works as expected when using swagger:model. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alihalabyah picture alihalabyah  路  4Comments

flier picture flier  路  5Comments

ikouchiha47 picture ikouchiha47  路  4Comments

Ragnar-BY picture Ragnar-BY  路  3Comments

CuBiC3D picture CuBiC3D  路  3Comments