Swagger-codegen: Request: Go server codegen

Created on 25 May 2016  Â·  11Comments  Â·  Source: swagger-api/swagger-codegen

First, forgive me if this is the wrong way to make this request. Thank you for the Go client generator. I would love to bring Swagger into my project (https://gokit.io) but to do that I'd need a Go server generator. I want to file the issue to register the interest and offer my help to review any PR someone could make — I don't have any Java chops, so I unfortunately won't be much help in making the PR :)

Go help wanted

All 11 comments

@peterbourgon I think there are many Go server-side framework out there. Why one do you prefer?

I reviewed before and would suggest https://github.com/gin-gonic/gin

Most Go web "frameworks" are nonidiomatic and should probably be avoided for codegen purposes, including Gin. I would recommend plain net/http handlers + selected pieces from https://github.com/gorilla as necessary; probably just https://github.com/gorilla/mux for routing is enough.

If anyone from the community wants to implement the Go server generator based on @peterbourgon suggestion or using some Go sever-side framework, please reply to let us know.

i could give it a shot tomorrow

I would like to see go-swagger in the server generator. @casualjim can you help?

@peterbougon ,Beego (a golang web framework) will be useful to you, You can write the API by Beego and use Beego command tool to generate document automatically for Swagger , more doc here
code such as like this:


// @Title Get Product list
// @Description Get Product list by some info
// @Success 200 {object} models.ZDTProduct.ProductList
// @Param   category_id     query   int false       "category id"
// @Param   brand_id    query   int false       "brand id"
// @Param   query   query   string  false       "query of search"
// @Param   segment query   string  false       "segment"
// @Param   sort    query   string  false       "sort option"
// @Param   dir     query   string  false       "direction asc or desc"
// @Param   offset  query   int     false       "offset"
// @Param   limit   query   int     false       "count limit"
// @Param   price           query   float       false       "price"
// @Param   special_price   query   bool        false       "whether this is special price"
// @Param   size            query   string      false       "size filter"
// @Param   color           query   string      false       "color filter"
// @Param   format          query   bool        false       "choose return format"
// @Failure 400 no enough input
// @Failure 500 get products common error
// @router /products [get]
func (c *CMSController) Product() {
       id,err:=c.GetInt("category_id")

      //success response 
      c.Data["json"]= []models.ZDTProduct.ProductList {  ... } 
      c.ServerJSON()

      //or error request 
      c.Abort("400")
}

You're suggesting to write Beego and use it to generate Swagger. But that's precisely the opposite of what I want. I want to write Swagger and use it to generate my own controllers/handlers/etc.

@peterbourgon https://github.com/go-swagger/go-swagger would do what you want, I have a slack team and you can reach me in the GoBridge slack team too, I'd love to discuss what is required because I think that go-kit would be a nice base actually.

@fehguy I can help, but swagger-codegen will need the ability to shell-out to call my go binary.
Should it be required to distribute this as jar, we can package all the binaries in a jar with a naming convention for platform/arch so that the right executable will be called.

So can we make swagger-codegen allow for out of process generators? I can help with the packaging etc but I'm time challenged to make the changes required in the swagger-codegen project atm

I don't think we'll be shelling out in swagger-codegen, but if you share the docs for the CLI, I'm sure we can help others with it.

@fehguy is this what you mean? http://goswagger.io/generate/server/

Was this page helpful?
0 / 5 - 0 ratings