Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 375
Arjun K S Avatar asked Dec 06 '25 05:12

Arjun K S


1 Answers

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
like image 171
csteph Avatar answered Dec 08 '25 19:12

csteph