From 878b69a9bdc9e6851eeafeb47eea993f80d2a2c8 Mon Sep 17 00:00:00 2001 From: liujian Date: Thu, 5 Jun 2025 18:19:21 +0800 Subject: [PATCH] feat: add resources tags api (#2604) Signed-off-by: joyceliu --- pkg/const/web.go | 5 ++++- pkg/web/schema.go | 13 ++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/const/web.go b/pkg/const/web.go index bb309ae5..945d8dab 100644 --- a/pkg/const/web.go +++ b/pkg/const/web.go @@ -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 diff --git a/pkg/web/schema.go b/pkg/web/schema.go index 55f3e5ff..46b4b297 100644 --- a/pkg/web/schema.go +++ b/pkg/web/schema.go @@ -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 }