Open renektonwu opened 3 years ago
I caught the same issue. the previous version is working fine for me.
go get github.com/swaggo/echo-swagger/tree/v1.1.4
Because you are using the wrong file to init your documentation. Moreover, I observed a very silly mistake I stuck with while generating docs, the line gap between doc statements and function declaration would fail including swagger for that API.
I had a similar issue.
Please double check if you imported your autogenerated docs
package in your main
file.
Like this:
// replace it with your package path
_ "github.com/swaggo/echo-swagger/example/docs" // docs is generated by Swag CLI, you have to import it.
had same problem
had same problem
I had some trouble myself getting swaggo to find all my annotations in the project structure.
After fiddling around with the cli a bit I found out that you can specify the file where the main api docs are via the -g myfile.go
flag and ALSO you need to include the relative paths to all packages containing swaggo-annotations in the -d
flag.
For me this results in the generator-call:
swag init -d pkg/api/,pkg/api/handler/,pkg/model/ -g api.go
And, of course, don't forget to import your generated docs.
Edit: See also this issue
Same, maybe we should define path with router to swag init or some like that? I run swag init in main, where create Echo object, but i had router in other package
Because you are using the wrong file to init your documentation. Moreover, I observed a very silly mistake I stuck with while generating docs, the line gap between doc statements and function declaration would fail including swagger for that API.
This helps a lot, can't believe this cost me a whole afternoon .......
Because you are using the wrong file to init your documentation. Moreover, I observed a very silly mistake I stuck with while generating docs, the line gap between doc statements and function declaration would fail including swagger for that API.
This should really be mentionned in the docs! Do not keep an empty line between annotations and the api function or it won't parse it, and it also won't say anything about it, so be careful.
I had a similar issue.
Please double check if you imported your autogenerated
docs
package in yourmain
file.Like this:
// replace it with your package path _ "github.com/swaggo/echo-swagger/example/docs" // docs is generated by Swag CLI, you have to import it.
what is a properly done example of this?
@MichaelBonnet There is nothing more to it than that. By default, swag init
will generate the documentation files in a local directory named "/docs". In order to roll out this documentation with your application, you need to import this newly generated directory somewhere in your application (usually in the package where you define the documentation-endpoint for your api).
So if your go-module is named github.com/foo/sample-api
and you execute swag init
in the root directory of your application, the docs
can be imported with _ "github.com/foo/sample-api/docs
. Note that you make an unnamed import with _
as you don't specifically reference the imported package in your code.
For a full example on how to define a documentation, refer to the official echo-swagger docs
If you used in golang, I think you should follow this tutorials: https://santoshk.dev/posts/2022/how-to-integrate-swagger-ui-in-go-backend-gin-edition/
I follow the echo-wagger README tutorial and get the error bellow And I google so many times and have no answer. so any help or suggesions would be appreciate.