Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2016 The Kubernetes Authors. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package routes |
| 18 | |
| 19 | import ( |
| 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. |
| 29 | type OpenAPI struct { |
| 30 | Config *common.Config |
| 31 | } |
| 32 | |
| 33 | // Install adds the SwaggerUI webservice to the given mux. |
| 34 | func (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 | } |