go swagger client code usage

434 views
Skip to first unread message

RS

unread,
May 6, 2020, 12:31:15 PM5/6/20
to golang-nuts
Hi, 
via swagger generate client -f file.json I have created client side golang codes. The question is how can I use those generated codes for each REST API in my golang project as consumer. 
As a golang/swagger-newbie an example would be appreciated. 

Thanks 
Larisa 

Maciej Gałkowski

unread,
May 14, 2020, 5:53:00 PM5/14/20
to golang-nuts
There are a few code generators for swagger.  The answer kind of depends on which you are using, for example, https://github.com/OpenAPITools/openapi-generator can generate a whole project or just some packages. It depends on the flags used. 
In general, the swagger generate client -f file.json command should generate some files. The files contain go code, and make up a package. You need to put these files into a project directory, in its own separate directory named after the package name. There are resources on how to structure your go repository like this one. Then you import your generated package from another file ( could be main.go, or any other package and use it). 
The first step would be to read the generated code and familiarise yourself with the public API. 
Reply all
Reply to author
Forward
0 new messages