echo-swagger icon indicating copy to clipboard operation
echo-swagger copied to clipboard

No operations defined in spec!

Open renektonwu opened this issue 2 years ago • 11 comments

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.

renektonwu avatar Nov 10 '21 10:11 renektonwu

I caught the same issue. the previous version is working fine for me.

go get github.com/swaggo/echo-swagger/tree/v1.1.4

FunnyEnd avatar Nov 13 '21 14:11 FunnyEnd

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.

ghost avatar Nov 29 '21 13:11 ghost

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.

ElForastero avatar Feb 19 '22 19:02 ElForastero

had same problem

dendianugerah avatar Sep 09 '22 10:09 dendianugerah

had same problem

gricar avatar Nov 08 '22 20:11 gricar

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

adrian-sturm avatar Nov 22 '22 09:11 adrian-sturm

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

alikud avatar Jan 15 '23 18:01 alikud

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

vsian avatar Feb 12 '23 10:02 vsian

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.

HatemTemimi avatar Aug 07 '23 12:08 HatemTemimi

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?

MichaelBonnet avatar Oct 17 '23 21:10 MichaelBonnet

@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

asturm-fe avatar Oct 23 '23 07:10 asturm-fe