blob: 06c723d37531ee8637ed56eb309dc752b09fa27f [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001/*
2Copyright 2016 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package routes
18
19import (
20 restful "github.com/emicklei/go-restful"
21 "github.com/golang/glog"
22
23 "k8s.io/apiserver/pkg/server/mux"
24 "k8s.io/kube-openapi/pkg/common"
25 "k8s.io/kube-openapi/pkg/handler"
26)
27
28// OpenAPI installs spec endpoints for each web service.
29type OpenAPI struct {
30 Config *common.Config
31}
32
33// Install adds the SwaggerUI webservice to the given mux.
34func (oa OpenAPI) Install(c *restful.Container, mux *mux.PathRecorderMux) {
35 // NOTE: [DEPRECATION] We will announce deprecation for format-separated endpoints for OpenAPI spec,
36 // and switch to a single /openapi/v2 endpoint in Kubernetes 1.10. The design doc and deprecation process
37 // are tracked at: https://docs.google.com/document/d/19lEqE9lc4yHJ3WJAJxS_G7TcORIJXGHyq3wpwcH28nU.
38 _, err := handler.BuildAndRegisterOpenAPIService("/swagger.json", c.RegisteredWebServices(), oa.Config, mux)
39 if err != nil {
40 glog.Fatalf("Failed to register open api spec for root: %v", err)
41 }
42 _, err = handler.BuildAndRegisterOpenAPIVersionedService("/openapi/v2", c.RegisteredWebServices(), oa.Config, mux)
43 if err != nil {
44 glog.Fatalf("Failed to register versioned open api spec for root: %v", err)
45 }
46}