go-swagger: Generate spec fails with invalid type error
Problem statement
It seems that during the last few days, there has been a change (probably the one regarding supporting go modules) that has broken functionality of generating spec.
I had a sample code for generating spec here, a few days ago I ran make swagger and swagger.yaml was generated successfully. Now with last version of go-swagger it results in the following error:
which swagger || (GO111MODULE=off go get -u github.com/go-swagger/go-swagger/cmd/swagger)
/Users/parhamalvani/Documents/Go/bin/swagger
GO111MODULE=on go mod vendor && GO111MODULE=off swagger generate spec -o ./swagger.yaml --scan-models
unsupported type "invalid type"
make: *** [swagger] Error 1
I did some investingation, it seems that if i change
// swagger:route POST /foobar foobar-tag idOfFoobarEndpoint
// Foobar does some amazing stuff.
// responses:
// 200: foobarResponse
// This text will appear as description of your response body.
// swagger:response foobarResponse
type foobarResponseWrapper struct {
// in:body
Body api.FooBarResponse
}
// swagger:parameters idOfFoobarEndpoint
type foobarParamsWrapper struct {
// This text will appear as description of your request body.
// in:body
Body api.FooBarRequest
}
to the following, everything works.
// swagger:route POST /foobar foobar-tag idOfFoobarEndpoint
// Foobar does some amazing stuff.
// responses:
// 200: foobarResponse
// This text will appear as description of your response body.
// swagger:response foobarResponse
type foobarResponseWrapper struct {
// in:body
Body struct { A int `json:"int"` }
}
// swagger:parameters idOfFoobarEndpoint
type foobarParamsWrapper struct {
// This text will appear as description of your request body.
// in:body
Body struct { A int `json:"int"` }
}
Therefore I assume, the problem is it does not scan types inside other packages. (i.e. Because api.FoobarRequest is defined outside of docs package, the code scanner fails to find its
This also happens to me in a real world project causing us to not be able to generate spec.
Environment
swagger version: dev go version: 1.12.5 OS: MacOS High Sierra
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 22 (5 by maintainers)
GO111MODULE=off swagger generate spec -o ./doc/swagger.yaml --scan-modelsdidn’t work removingGO111MODULE=offhelpedswagger generate spec -o ./doc/swagger.yaml --scan-modelsworkIt worked @cesarvspr, btw I want to host swagger-ui or redoc on an endpoint other than
/docshow to do that? could you help around this?I have tested it with the master branch and the issue still occurs.