Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/const/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ const (
// This tag is used to identify and categorize KubeKey-specific resources
// in the system, making it easier to filter and manage them
KubeKeyTag = "kubekey"

// OpenAPITag is the tag used for OpenAPI documentation
// This tag helps organize and identify OpenAPI/Swagger documentation
// related to the KubeKey API endpoints
OpenAPITag = "api"
// ResourceTag is the tag used for resource-related endpoints
// This tag helps organize and identify API endpoints that deal with
// resource management and operations
ResourceTag = "resources"

// StatusOK represents a successful operation status
// Used to indicate that an API operation completed successfully
Expand Down
13 changes: 8 additions & 5 deletions pkg/web/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ package web
import (
"net/http"

restfulspec "github.com/emicklei/go-restful-openapi/v2"
"github.com/emicklei/go-restful/v3"

_const "github.com/kubesphere/kubekey/v4/pkg/const"
)

// NewSchemaService creates a new WebService that serves schema files from the specified root path.
// It sets up a route that handles GET requests to /schema/{subpath} and serves files from the rootPath directory.
// The {subpath:*} parameter allows for matching any path under /schema/.
// It sets up a route that handles GET requests to /resources/schema/{subpath} and serves files from the rootPath directory.
// The {subpath:*} parameter allows for matching any path under /resources/schema/.
func NewSchemaService(rootPath string) *restful.WebService {
ws := new(restful.WebService)
ws.Path("/schema")
ws.Path("resources/schema")

ws.Route(ws.GET("/{subpath:*}").To(func(req *restful.Request, resp *restful.Response) {
http.StripPrefix("/schema/", http.FileServer(http.Dir(rootPath))).ServeHTTP(resp.ResponseWriter, req.Request)
}))
http.StripPrefix("resources/schema/", http.FileServer(http.Dir(rootPath))).ServeHTTP(resp.ResponseWriter, req.Request)
}).Metadata(restfulspec.KeyOpenAPITags, []string{_const.ResourceTag}))

return ws
}