How to configure go-swagger to generate specification from annotation

I follow the instructions to create the swagger specification here https://goswagger.io/generate/spec.html .

I have an existing project that requires an interface for the API. I want to use go swagger, but I'm completely confused https://github.com/go-swagger/go-swagger/tree/master/examples/todo-list I want to configure it to add annotations to the code and then run the command swagger generate spec, and it will generate the spec. However, whenever I run it, it prints{"swagger":"2.0","paths":{},"definitions":{}}

This is my team to run

...com/projectFolder]$ swagger generate spec                                                
{"swagger":"2.0","paths":{},"definitions":{}}

My project structure is as follows

project/ 
  main.go
  api/
    router.go

In main.go I have this annotation

//go:generate swagger generate spec
package main

In the router above one of my handlers, I have this annotation

// swagger:route GET /profile
//
// Gets profile of user
//
//     Produces:
//     - application/json
//     - application/x-protobuf
//
//     Schemes: http, https, ws, wss
//
//     Security:
//       api_key:
//       oauth: read, write
//
//     Responses:
//       default: genericError
//       200: someResponse
//       422: validationError
r.GET("/profile", profileHandler

, api . . , , , .

+4
1

, . , :

swagger generate (-b main.go, , ) (-o swagger.json)

, :

swagger generate spec -b ./main.go -o swagger.json

go, , , . , title:

// Project title (the dot in the end matters).
//
// Project description.
//
//     Schemes: http
//     Version: 0.1
//
//     Consumes:
//     - application/json
//
//     Produces:
//     - application/json
//
//
// swagger:meta
+1

Source: https://habr.com/ru/post/1657955/


All Articles