1 year ago

#357622

test-img

p0937507934

Automatically generate swagger descriptions from golang code

I have many routers like these with gin server.

I want to automatically generate swagger descriptions above the handler function. Because I need to write these descriptions with 90% same words for every api.

So I want to write a script or golang program to get every handler functions and find its request struct and response struct to generate these swagger descriptions.

Is there any good ideas to do this ?

router.Get("/test", api.TestGetAll)
router.POST("/test", api.TestInsert)
// TestGetAll
// @Summary Get All Test
// @Produce json
// @Accept json
// @Tags Test
// @Security Bearer
// @Success 200 {object} apires.TestGetAllRes
// @Router /test [get]
func TestGetAll(c *gin.Context){
    req := &apireq.TestGetAllReq{}
}

// TestInsert
// @Summary Insert Test
// @Produce json
// @Accept json
// @Tags Test
// @Security Bearer
// @Success 200 {object} apires.TestInsertRes
// @Router /test [post]
func TestInsert(c *gin.Context){
    req := &apireq.TestInsertReq{}
}

go

swagger

code-generation

0 Answers

Your Answer

Accepted video resources