feat: add resources tags api (#2604)

Signed-off-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
liujian 2025-06-05 18:19:21 +08:00 committed by GitHub
parent 72680b80be
commit 878b69a9bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 6 deletions

View File

@ -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

View File

@ -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
}