RegisterOpenAPIHandler adds handlers to serve the OpenAPI specification and Swagger UI
()
| 482 | |
| 483 | // RegisterOpenAPIHandler adds handlers to serve the OpenAPI specification and Swagger UI |
| 484 | func (s *Server) RegisterOpenAPIHandler() { |
| 485 | swaggerFilesPath := os.Getenv("SWAGGER_BASE_PATH") |
| 486 | if swaggerFilesPath == "" { |
| 487 | log.Errorf("SWAGGER_BASE_PATH is not set") |
| 488 | return |
| 489 | } |
| 490 | |
| 491 | if _, err := os.Stat(swaggerFilesPath); os.IsNotExist(err) { |
| 492 | log.Errorf("API documentation directory %s does not exist", swaggerFilesPath) |
| 493 | return |
| 494 | } |
| 495 | |
| 496 | s.Router.HandleFunc(s.BasePath+"/docs", func(w http.ResponseWriter, r *http.Request) { |
| 497 | http.ServeFile(w, r, swaggerFilesPath+"/swagger-ui.html") |
| 498 | }) |
| 499 | |
| 500 | s.Router.HandleFunc(s.BasePath+"/docs/superplane.swagger.json", func(w http.ResponseWriter, r *http.Request) { |
| 501 | http.ServeFile(w, r, swaggerFilesPath+"/superplane.swagger.json") |
| 502 | }) |
| 503 | |
| 504 | log.Infof("OpenAPI specification available at %s", swaggerFilesPath) |
| 505 | log.Infof("Swagger UI available at %s", swaggerFilesPath) |
| 506 | log.Infof("Raw API JSON available at %s", swaggerFilesPath+"/superplane.swagger.json") |
| 507 | } |
| 508 | |
| 509 | func (s *Server) RegisterWebRoutes(webBasePath string) { |
| 510 | log.Infof("Registering web routes with base path: %s", webBasePath) |