Arjun K S
Arjun K S

Reputation: 51

go-swagger: no spec available to unmarshal

I am trying to define a swagger operation for my REST endpoint written in Golang. I need to specify the POST request body and responses.

// swagger:operation POST /user user createUser
//
// Creates user
//
// produces:
// - application/json
// parameters:
// - name: requestBody
//   in: body
//   description: user details
//   required: true
//   schema:
//     "$ref": "#/definitions/User"
// responses:
//  200: CommonResponse
//  400: CommonResponse
//  500: CommonResponse

// CreateUser will create user
func (h *UserHandler) CreateUser(c *gin.Context) {

But I am getting error an error when trying to generate spec for same

cd cmd/server && GO111MODULE=on swagger generate spec -o ../../api/swagger.json -m
operation (createUser): no spec available to unmarshal
Makefile:5: recipe for target 'generate-swagger' failed
make: *** [generate-swagger] Error 1

Please help me with these. What is the spec specified here. Advance Thanks

Upvotes: 3

Views: 1182

Answers (1)

csteph
csteph

Reputation: 116

I think you're missing a set of dashes --- which must go before the yaml section.

(See the line just above the example on this page: https://goswagger.io/use/spec/operation.html)

This updated comment should work for you:

// swagger:operation POST /user user createUser
//
// Creates user
//
// ---
// produces:
// - application/json
// parameters:
// - name: requestBody
//   in: body
//   description: user details
//   required: true
//   schema:
//     "$ref": "#/definitions/User"
// responses:
//  200: CommonResponse
//  400: CommonResponse
//  500: CommonResponse

Upvotes: 3

Related Questions