Skip to content

go-chassis/go-restful-swagger20

 
 

Repository files navigation

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

About

Swagger 2.0 extension to the go-restful package

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%