Пример #1
0
// Install adds the SwaggerUI webservice to the given mux.
func (s Swagger) Install(c *mux.APIContainer) {
	swagger.RegisterSwaggerService(swagger.Config{
		WebServicesUrl:  "https://" + s.ExternalAddress,
		WebServices:     c.RegisteredWebServices(),
		ApiPath:         "/swaggerapi/",
		SwaggerPath:     "/swaggerui/",
		SwaggerFilePath: "/swagger-ui/",
		SchemaFormatHandler: func(typeName string) string {
			switch typeName {
			case "metav1.Time", "*metav1.Time":
				return "date-time"
			}
			return ""
		},
	}, c.Container)
}
Пример #2
0
// Install adds the Index webservice to the given mux.
func (i Index) Install(c *mux.APIContainer) {
	c.UnlistedRoutes.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		status := http.StatusOK
		if r.URL.Path != "/" && r.URL.Path != "/index.html" {
			// Since "/" matches all paths, handleIndex is called for all paths for which there is no handler registered.
			// We want to return a 404 status with a list of all valid paths, incase of an invalid URL request.
			status = http.StatusNotFound
		}
		var handledPaths []string
		// Extract the paths handled using restful.WebService
		for _, ws := range c.RegisteredWebServices() {
			handledPaths = append(handledPaths, ws.RootPath())
		}
		// Extract the paths handled using mux handler.
		handledPaths = append(handledPaths, c.NonSwaggerRoutes.HandledPaths()...)
		sort.Strings(handledPaths)
		responsewriters.WriteRawJSON(status, metav1.RootPaths{Paths: handledPaths}, w)
	})
}
Пример #3
0
// Install adds the SwaggerUI webservice to the given mux.
func (oa OpenAPI) Install(c *mux.APIContainer) {
	err := openapi.RegisterOpenAPIService("/swagger.json", c.RegisteredWebServices(), oa.Config, c)
	if err != nil {
		glog.Fatalf("Failed to register open api spec for root: %v", err)
	}
}
Пример #4
0
// Install adds the SwaggerUI webservice to the given mux.
func (s Swagger) Install(c *mux.APIContainer) {
	s.Config.WebServices = c.RegisteredWebServices()
	swagger.RegisterSwaggerService(*s.Config, c.Container)
}