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
+70
View File
@@ -22,6 +22,9 @@ import (
"io/ioutil"
"net/http"
"github.com/emicklei/go-restful"
restfulspec "github.com/emicklei/go-restful-openapi"
"github.com/go-openapi/spec"
"github.com/gorilla/mux"
"go.uber.org/zap"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -31,6 +34,73 @@ import (
config "github.com/fission/fission/pkg/featureconfig"
)
func RegisterCanaryConfigRoute(ws *restful.WebService) {
tags := []string{"CanaryConfig"}
specTag = append(specTag, spec.Tag{TagProps: spec.TagProps{Name: "CanaryConfig", Description: "CanaryConfig Operation"}})
ws.Route(
ws.GET("/v2/canaryconfigs").
Doc("List all canary configs").
Metadata(restfulspec.KeyOpenAPITags, tags).
To(func(req *restful.Request, resp *restful.Response) {
resp.ResponseWriter.WriteHeader(http.StatusOK)
}).
Param(ws.QueryParameter("namespace", "Namespace of canaryConfig").DataType("string").DefaultValue(metav1.NamespaceAll).Required(false)).
Produces(restful.MIME_JSON).
Writes([]fv1.CanaryConfig{}).
Returns(http.StatusOK, "List of canaryConfigs", []fv1.CanaryConfig{}))
ws.Route(
ws.POST("/v2/canaryconfigs").
Doc("Create canary config").
Metadata(restfulspec.KeyOpenAPITags, tags).
To(func(req *restful.Request, resp *restful.Response) {
resp.ResponseWriter.WriteHeader(http.StatusOK)
}).
Produces(restful.MIME_JSON).
Reads(fv1.CanaryConfig{}).
Writes(metav1.ObjectMeta{}).
Returns(http.StatusCreated, "Metadata of created canaryConfig", metav1.ObjectMeta{}))
ws.Route(
ws.GET("/v2/canaryconfigs/{canaryConfig}").
Doc("Get detail of canary config").
Metadata(restfulspec.KeyOpenAPITags, tags).
To(func(req *restful.Request, resp *restful.Response) {
resp.ResponseWriter.WriteHeader(http.StatusOK)
}).
Param(ws.PathParameter("canaryConfig", "CanaryConfig name").DataType("string").DefaultValue("").Required(true)).
Param(ws.QueryParameter("namespace", "Namespace of canaryConfig").DataType("string").DefaultValue(metav1.NamespaceAll).Required(false)).
Produces(restful.MIME_JSON).
Writes(fv1.CanaryConfig{}). // on the response
Returns(http.StatusOK, "A canaryConfig", fv1.CanaryConfig{}))
ws.Route(
ws.PUT("/v2/canaryconfigs/{canaryConfig}").
Doc("Update canary config").
Metadata(restfulspec.KeyOpenAPITags, tags).
To(func(req *restful.Request, resp *restful.Response) {
resp.ResponseWriter.WriteHeader(http.StatusOK)
}).
Param(ws.PathParameter("canaryConfig", "CanaryConfig name").DataType("string").DefaultValue("").Required(true)).
Produces(restful.MIME_JSON).
Reads(fv1.CanaryConfig{}).
Writes(metav1.ObjectMeta{}). // on the response
Returns(http.StatusOK, "Metadata of updated canaryConfig", metav1.ObjectMeta{}))
ws.Route(
ws.DELETE("/v2/canaryconfigs/{canaryConfig}").
Doc("Delete canary config").
Metadata(restfulspec.KeyOpenAPITags, tags).
To(func(req *restful.Request, resp *restful.Response) {
resp.ResponseWriter.WriteHeader(http.StatusOK)
}).
Param(ws.PathParameter("canaryConfig", "CanaryConfig name").DataType("string").DefaultValue("").Required(true)).
Param(ws.QueryParameter("namespace", "Namespace of canaryConfig").DataType("string").DefaultValue(metav1.NamespaceAll).Required(false)).
Produces(restful.MIME_JSON).
Returns(http.StatusOK, "Only HTTP status returned", nil))
}
func (a *API) CanaryConfigApiCreate(w http.ResponseWriter, r *http.Request) {
featureErr := a.featureStatus[config.CanaryFeature]
if len(featureErr) > 0 {