swaggo / echo-swagger

echo middleware to automatically generate RESTful API documentation with Swagger 2.0.
MIT License
815 stars 127 forks source link

No operations defined in spec! #66

Open renektonwu opened 3 years ago

renektonwu commented 3 years ago

I follow the echo-wagger README tutorial and get the error bellow image And I google so many times and have no answer. so any help or suggesions would be appreciate.

FunnyEnd commented 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

ghost commented 2 years ago

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.

ElForastero commented 2 years ago

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.
dendianugerah commented 2 years ago

had same problem

gricar commented 2 years ago

had same problem

adrian-sturm commented 2 years ago

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

alikud commented 1 year ago

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

vsian commented 1 year ago

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 .......

HatemTemimi commented 1 year ago

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.

MichaelBonnet commented 1 year ago

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.

what is a properly done example of this?

asturm-fe commented 1 year ago

@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

ilhamasy commented 4 months ago

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/