swaggo / swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.
MIT License
10.81k stars 1.21k forks source link

v1.7.0 failed to parse response #853

Open sdghchj opened 3 years ago

sdghchj commented 3 years ago

With v1.6.9 we get a warning but the docs are still generated:

${HOME}/go/bin/swag init --generalInfo internal/http/client.go --propertyStrategy snakecase --parseVendor --output spec
2020/12/08 07:28:49 Generate swagger docs....
2020/12/08 07:28:49 Generate general API Info, search dir:./
2020/12/08 07:28:49 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/mi/projects/localcover/code/svc/product-svc
2020/12/08 07:28:50 create docs.go at spec/docs.go
2020/12/08 07:28:50 create swagger.json at spec/swagger.json
2020/12/08 07:28:50 create swagger.yaml at spec/swagger.yaml
[product-svc] ${HOME}/go/bin/swag --version
swag version v1.6.9

And after upgrading to v1.7.0 the doc generation fails:

${HOME}/go/bin/swag init --generalInfo internal/http/client.go --propertyStrategy snakecase --parseVendor --output spec
2020/12/08 08:02:56 Generate swagger docs....
2020/12/08 08:02:56 Generate general API Info, search dir:./
2020/12/08 08:02:56 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/mi/projects/localcover/code/svc/product-svc
2020/12/08 08:02:58 ParseComment error in file internal/http/routes/merchant_cancel_process.go :can not parse response comment "400 "Failed to pass json schema""
[product-svc] ${HOME}/go/bin/swag --version
swag version v1.7.0

--parseDepth 1 has no effect on the error:

${HOME}/go/bin/swag init --generalInfo internal/http/client.go --parseDepth 1  --propertyStrategy snakecase --parseVendor --output spec
2020/12/08 08:07:50 Generate swagger docs....
2020/12/08 08:07:50 Generate general API Info, search dir:./
2020/12/08 08:07:51 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /Users/mi/projects/localcover/code/svc/product-svc
2020/12/08 08:07:52 ParseComment error in file internal/http/routes/merchant_return_period.go :can not parse response comment "400 "Failed to pass json schema""

Originally posted by @lc-chrisbarton in https://github.com/swaggo/swag/issues/852#issuecomment-740118468

drewsilcock commented 3 years ago

I'm seeing the same error trying and failing to parse the following comment on an endpoint (works on v1.6.9, fails on v1.7.0):

// @Success 204 "Sucessfully deleted user."

Output:

> swag init --parseDependency
2020/12/08 09:40:24 Generate swagger docs....
2020/12/08 09:40:24 Generate general API Info, search dir:./
2020/12/08 09:40:57 Generating [redacted]
2020/12/08 09:40:57 Generating [redacted]
2020/12/08 09:40:57 Generating [redacted]
2020/12/08 09:40:57 Generating [redacted]
2020/12/08 09:40:57 Generating [redacted]
2020/12/08 09:40:57 Generating [redacted]
2020/12/08 09:40:57 Generating [redacted]
2020/12/08 09:40:57 Generating [redacted]
2020/12/08 09:40:57 Generating [redacted]
2020/12/08 09:40:57 Generating [redacted]
2020/12/08 09:40:57 Generating echo.HTTPError
2020/12/08 09:40:57 Type definition of type '*ast.InterfaceType' is not supported yet. Using 'object' instead.
2020/12/08 09:40:57 Generating [redacted]
2020/12/08 09:40:57 ParseComment error in file [redacted] :can not parse response comment "204 "Sucessfully deleted user.""
odidev commented 3 years ago

I am working on the package ‘cloudfoundry/stratos’, which is successfully using swaggo/swag version 1.6.7. As we know, we need to upgrade the swag version to 1.7.0 for AArch64 support in stratos. However, after changing the version to 1.7.0 (go get github.com/swaggo/swag/cmd/swag@v1.7.0), and including checksum for swaggo/swag@1.7.0 in my go.sum file, as below:

github.com/swaggo/swag v1.7.0 h1:5bCA/MTLQoIqDXXyHfOpMeDvL9j68OY/udlK4pQoo4E=
github.com/swaggo/swag v1.7.0/go.mod h1:BdPIL73gvS9NBsdi7M1JOxLvlbfvNRaBP8m6WT6Aajo=

, I am getting the same error for the docs not getting generated, after executing (swag init) command. Facing below error in stratos after updating swag version to 1.7.0:

build github.com/cloudfoundry-incubator/stratos/src/jetstream: cannot load github.com/cloudfoundry-incubator/stratos/src/jetstream/docs: module github.com/cloudfoundry-incubator/stratos@latest found (v2.0.0-beta-001+incompatible), but does not contain package github.com/cloudfoundry-incubator/stratos/src/jetstream/docs

This is my go.sum file placed at ‘stratos/src/jetstream’: https://github.com/cloudfoundry/stratos/blob/master/src/jetstream/go.sum The same error has been seen with ‘swaggo/swag’ version 1.6.9.

I have also tried setting depth to 2 and 3, as suggested in the issue https://github.com/swaggo/swag/issues/852#issuecomment-739938826; but that has not helped.

swag init --parseDependency --parseInternal --depth 2

As this is a known issue after version 1.6.7, can you please check and resolve this issue, or else provide some pointers so that I can proceed to add arm64 support in stratos?

isgj commented 3 years ago

@drewsilcock for the 204 error you can try

// @Success 204 {null} nil "Your message here"