![]() |
8 年之前 | |
---|---|---|
.. | ||
test_package | 8 年之前 | |
CHANGES.md | 8 年之前 | |
README.md | 8 年之前 | |
api_declaration_list.go | 8 年之前 | |
config.go | 8 年之前 | |
model_builder.go | 8 年之前 | |
model_builder_test.go | 8 年之前 | |
model_list.go | 8 年之前 | |
model_list_test.go | 8 年之前 | |
model_property_ext.go | 8 年之前 | |
model_property_ext_test.go | 8 年之前 | |
model_property_list.go | 8 年之前 | |
model_property_list_test.go | 8 年之前 | |
ordered_route_map.go | 8 年之前 | |
ordered_route_map_test.go | 8 年之前 | |
postbuild_model_test.go | 8 年之前 | |
swagger.go | 8 年之前 | |
swagger_builder.go | 8 年之前 | |
swagger_test.go | 8 年之前 | |
swagger_webservice.go | 8 年之前 | |
utils_test.go | 8 年之前 |
Get the Swagger UI sources (version 1.2 only)
git clone https://github.com/wordnik/swagger-ui.git
The project contains a "dist" folder. Its contents has all the Swagger UI files you need.
The index.html
has an url
set to http://petstore.swagger.wordnik.com/api/api-docs
.
You need to change that to match your WebService JSON endpoint e.g. http://localhost:8080/apidocs.json
Now, you can install the Swagger WebService for serving the Swagger specification in JSON.
config := swagger.Config{
WebServices: restful.RegisteredWebServices(),
ApiPath: "/apidocs.json",
SwaggerPath: "/apidocs/",
SwaggerFilePath: "/Users/emicklei/Projects/swagger-ui/dist"}
swagger.InstallSwaggerService(config)
Currently there are 2 ways to document your structs in the go-restful Swagger.
Here is an example with an Address
struct and the documentation for each of the fields. The ""
is a special entry for documenting the struct itself.
type Address struct {
Country string `json:"country,omitempty"`
PostCode int `json:"postcode,omitempty"`
}
func (Address) SwaggerDoc() map[string]string {
return map[string]string{
"": "Address doc",
"country": "Country doc",
"postcode": "PostCode doc",
}
}
This example will generate a JSON like this
{
"Address": {
"id": "Address",
"description": "Address doc",
"properties": {
"country": {
"type": "string",
"description": "Country doc"
},
"postcode": {
"type": "integer",
"format": "int32",
"description": "PostCode doc"
}
}
}
}
Very Important Notes:
SwaggerDoc()
is using a NON-Pointer receiver (e.g. func (Address) and not func (*Address))"postcode"
and not "PostCode"
)