/go-restful-swagger20

Swagger 2.0 extension to the go-restful package

Primary LanguageGoMIT LicenseMIT

go-restful-swagger20

overview

openapi extension to the go-restful package, OpenAPI-Specification version 2.0

dependencies

how to use

use it to replace go-restful-swagger12

config := swagger.Config{
		WebServices:    restful.DefaultContainer.RegisteredWebServices(), 
		FileStyle:	"json", //optional, default is yaml
		OpenService:     true,  //should show it in rest API service
		WebServicesUrl: "http://localhost:8080",
        ApiPath:        "/apidocs.json", //swagger doc api path
		OutFilePath: os.Getenv("SWAGGERFILEPATH"),
} 
swagger.RegisterSwaggerService(config, restful.DefaultContainer)

How to change or ignore the name of a field

go struct

	type X struct {
		A int
		B int `json:"C"`  //Will generate C here
		D int `json:"-"`  //Will ignore it
	}

result

	  "X": {
		"type": "object",
	   "properties": {
		"A": {
		 "type": "integer",
		 "format": "int32"
		},
		"C": {
		 "type": "integer",
		 "format": "int32"
		}
	   }
	  }

Example