Add swagger (OpenAPI 2.0) support (#1245)

* Add swagger (OpenAPI 2.0) support
* Gererate swagger_doc before building bundle image
This commit is contained in:
Ta-Ching Chen
2019-08-21 15:49:41 +08:00
committed by GitHub
parent 9c63975497
commit b9997b2ece
27 changed files with 1710 additions and 659 deletions
+31
View File
@@ -22,9 +22,40 @@ import (
"net/http/httputil"
"net/url"
"github.com/emicklei/go-restful"
restfulspec "github.com/emicklei/go-restful-openapi"
"github.com/go-openapi/spec"
"go.uber.org/zap"
)
func RegisterStorageServiceProxyRoute(ws *restful.WebService) {
tags := []string{"StorageServiceProxy"}
specTag = append(specTag, spec.Tag{TagProps: spec.TagProps{Name: "StorageServiceProxy", Description: "StorageServiceProxy Operation"}})
// workaround as go-restful has to set HTTP method explicitly.
ws.Route(
ws.POST("/proxy/storage/v1/archive").
Doc("Create archive").
Metadata(restfulspec.KeyOpenAPITags, tags).
To(func(req *restful.Request, resp *restful.Response) {
resp.ResponseWriter.WriteHeader(http.StatusOK)
}))
ws.Route(
ws.GET("/proxy/storage/v1/archive").
Doc("Get archive").
Metadata(restfulspec.KeyOpenAPITags, tags).
To(func(req *restful.Request, resp *restful.Response) {
resp.ResponseWriter.WriteHeader(http.StatusOK)
}))
ws.Route(
ws.DELETE("/proxy/storage/v1/archive").
Doc("Delete archive").
Metadata(restfulspec.KeyOpenAPITags, tags).
To(func(req *restful.Request, resp *restful.Response) {
resp.ResponseWriter.WriteHeader(http.StatusOK)
}))
}
func (api *API) StorageServiceProxy(w http.ResponseWriter, r *http.Request) {
u := api.storageServiceUrl
ssUrl, err := url.Parse(u)