forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
swagger.go
57 lines (49 loc) · 2.17 KB
/
swagger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package master
import (
"github.com/emicklei/go-restful/swagger"
"github.com/golang/glog"
apiserver "k8s.io/apiserver/pkg/server"
"github.com/openshift/origin/pkg/api"
"github.com/openshift/origin/pkg/api/v1"
)
var apiInfo = map[string]swagger.Info{
api.Prefix + "/" + v1.SchemeGroupVersion.Version: {
Title: "OpenShift v1 REST API",
Description: `The OpenShift API exposes operations for managing an enterprise Kubernetes cluster, including security and user management, application deployments, image and source builds, HTTP(s) routing, and project management.`,
},
apiserver.DefaultLegacyAPIPrefix + "/v1": {
Title: "Kubernetes v1 REST API",
Description: `The Kubernetes API allows you to run containerized applications, bind persistent storage, link those applications through service discovery, and manage the cluster infrastructure.`,
},
}
// customizeSwaggerDefinition applies selective patches to the swagger API docs
// TODO: move most of these upstream or to go-restful
func customizeSwaggerDefinition(apiList *swagger.ApiDeclarationList) {
for path, info := range apiInfo {
if dec, ok := apiList.At(path); ok {
if len(info.Title) > 0 {
dec.Info.Title = info.Title
}
if len(info.Description) > 0 {
dec.Info.Description = info.Description
}
apiList.Put(path, dec)
} else {
glog.Warningf("No API exists for predefined swagger description %s", path)
}
}
for _, version := range []string{api.Prefix + "/" + v1.SchemeGroupVersion.Version} {
apiDeclaration, _ := apiList.At(version)
models := &apiDeclaration.Models
model, _ := models.At("runtime.RawExtension")
model.Required = []string{}
model.Properties = swagger.ModelPropertyList{}
model.Description = "this may be any JSON object with a 'kind' and 'apiVersion' field; and is preserved unmodified by processing"
models.Put("runtime.RawExtension", model)
model, _ = models.At("patch.Object")
model.Description = "represents an object patch, which may be any of: JSON patch (RFC 6902), JSON merge patch (RFC 7396), or the Kubernetes strategic merge patch"
models.Put("patch.Object", model)
apiDeclaration.Models = *models
apiList.Put(version, apiDeclaration)
}
}