Skip to content

feat(ws): add @ID swag annotation to handlers #488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
4 changes: 2 additions & 2 deletions workspaces/backend/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ func (a *App) Routes() http.Handler {
router.GET(AllNamespacesPath, a.GetNamespacesHandler)

// workspaces
router.GET(AllWorkspacesPath, a.GetWorkspacesHandler)
router.GET(WorkspacesByNamespacePath, a.GetWorkspacesHandler)
router.GET(AllWorkspacesPath, a.GetAllWorkspacesHandler)
router.GET(WorkspacesByNamespacePath, a.GetWorkspacesByNamespaceHandler)
router.GET(WorkspacesByNamePath, a.GetWorkspaceHandler)
router.POST(WorkspacesByNamespacePath, a.CreateWorkspaceHandler)
router.DELETE(WorkspacesByNamePath, a.DeleteWorkspaceHandler)
Expand Down
1 change: 1 addition & 0 deletions workspaces/backend/api/healthcheck_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
// @Summary Returns the health status of the application
// @Description Provides a healthcheck response indicating the status of key services.
// @Tags healthcheck
// @ID getHealthcheck
// @Produce application/json
// @Success 200 {object} health_check.HealthCheck "Successful healthcheck response"
// @Failure 500 {object} ErrorEnvelope "Internal server error"
Expand Down
1 change: 1 addition & 0 deletions workspaces/backend/api/namespaces_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type NamespaceListEnvelope Envelope[[]models.Namespace]
// @Summary Returns a list of all namespaces
// @Description Provides a list of all namespaces that the user has access to
// @Tags namespaces
// @ID listNamespaces
// @Produce application/json
// @Success 200 {object} NamespaceListEnvelope "Successful namespaces response"
// @Failure 401 {object} ErrorEnvelope "Unauthorized"
Expand Down
1 change: 1 addition & 0 deletions workspaces/backend/api/workspace_actions_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type WorkspaceActionPauseEnvelope Envelope[*models.WorkspaceActionPause]
// @Summary Pause or unpause a workspace
// @Description Pauses or unpauses a workspace, stopping or resuming all associated pods.
// @Tags workspaces
// @ID updateWorkspacePauseState
// @Accept json
// @Produce json
// @Param namespace path string true "Namespace of the workspace" extensions(x-example=default)
Expand Down
3 changes: 3 additions & 0 deletions workspaces/backend/api/workspacekinds_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type WorkspaceKindEnvelope Envelope[models.WorkspaceKind]
// @Summary Get workspace kind
// @Description Returns details of a specific workspace kind identified by its name. Workspace kinds define the available types of workspaces that can be created.
// @Tags workspacekinds
// @ID getWorkspaceKind
// @Accept json
// @Produce json
// @Param name path string true "Name of the workspace kind" extensions(x-example=jupyterlab)
Expand Down Expand Up @@ -101,6 +102,7 @@ func (a *App) GetWorkspaceKindHandler(w http.ResponseWriter, r *http.Request, ps
// @Summary List workspace kinds
// @Description Returns a list of all available workspace kinds. Workspace kinds define the different types of workspaces that can be created in the system.
// @Tags workspacekinds
// @ID listWorkspaceKinds
// @Accept json
// @Produce json
// @Success 200 {object} WorkspaceKindListEnvelope "Successful operation. Returns a list of all available workspace kinds."
Expand Down Expand Up @@ -136,6 +138,7 @@ func (a *App) GetWorkspaceKindsHandler(w http.ResponseWriter, r *http.Request, _
// @Summary Create workspace kind
// @Description Creates a new workspace kind.
// @Tags workspacekinds
// @ID createWorkspaceKind
// @Accept application/yaml
// @Produce json
// @Param body body string true "Kubernetes YAML manifest of a WorkspaceKind"
Expand Down
2 changes: 1 addition & 1 deletion workspaces/backend/api/workspacekinds_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ var _ = Describe("WorkspaceKinds Handler", func() {
By("setting the auth headers")
req.Header.Set(userIdHeader, adminUser)

By("executing GetWorkspacesHandler")
By("executing GetWorkspaceKindsHandler")
ps := httprouter.Params{}
rr := httptest.NewRecorder()
a.GetWorkspaceKindsHandler(rr, req, ps)
Expand Down
41 changes: 32 additions & 9 deletions workspaces/backend/api/workspaces_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type WorkspaceEnvelope Envelope[models.Workspace]
// @Summary Get workspace
// @Description Returns details of a specific workspace identified by namespace and workspace name.
// @Tags workspaces
// @ID getWorkspace
// @Accept json
// @Produce json
// @Param namespace path string true "Namespace of the workspace" extensions(x-example=kubeflow-user-example-com)
Expand Down Expand Up @@ -99,24 +100,44 @@ func (a *App) GetWorkspaceHandler(w http.ResponseWriter, r *http.Request, ps htt
a.dataResponse(w, r, responseEnvelope)
}

// GetWorkspacesHandler returns a list of workspaces.
// GetAllWorkspacesHandler returns a list of all workspaces across all namespaces.
//
// @Summary List workspaces
// @Description Returns a list of workspaces. The endpoint supports two modes:
// @Description 1. List all workspaces across all namespaces (when no namespace is provided)
// @Description 2. List workspaces in a specific namespace (when namespace is provided)
// @Summary List all workspaces
// @Description Returns a list of all workspaces across all namespaces.
// @Tags workspaces
// @ID listAllWorkspaces
// @Accept json
// @Produce json
// @Param namespace path string true "Namespace to filter workspaces. If not provided, returns all workspaces across all namespaces." extensions(x-example=kubeflow-user-example-com)
// @Success 200 {object} WorkspaceListEnvelope "Successful operation. Returns a list of workspaces."
// @Success 200 {object} WorkspaceListEnvelope "Successful operation. Returns a list of all workspaces."
// @Failure 401 {object} ErrorEnvelope "Unauthorized. Authentication is required."
// @Failure 403 {object} ErrorEnvelope "Forbidden. User does not have permission to list workspaces."
// @Failure 500 {object} ErrorEnvelope "Internal server error. An unexpected error occurred on the server."
// @Router /workspaces [get]
func (a *App) GetAllWorkspacesHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
a.getWorkspacesHandler(w, r, ps)
}

// GetWorkspacesByNamespaceHandler returns a list of workspaces in a specific namespace.
//
// @Summary List workspaces by namespace
// @Description Returns a list of workspaces in a specific namespace.
// @Tags workspaces
// @ID listWorkspacesByNamespace
// @Accept json
// @Produce json
// @Param namespace path string true "Namespace to filter workspaces" extensions(x-example=kubeflow-user-example-com)
// @Success 200 {object} WorkspaceListEnvelope "Successful operation. Returns a list of workspaces in the specified namespace."
// @Failure 400 {object} ErrorEnvelope "Bad Request. Invalid namespace format."
// @Failure 401 {object} ErrorEnvelope "Unauthorized. Authentication is required."
// @Failure 403 {object} ErrorEnvelope "Forbidden. User does not have permission to list workspaces."
// @Failure 500 {object} ErrorEnvelope "Internal server error. An unexpected error occurred on the server."
// @Router /workspaces [get]
// @Router /workspaces/{namespace} [get]
func (a *App) GetWorkspacesHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
func (a *App) GetWorkspacesByNamespaceHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
a.getWorkspacesHandler(w, r, ps)
}

// getWorkspacesHandler is the internal implementation for listing workspaces.
func (a *App) getWorkspacesHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
namespace := ps.ByName(NamespacePathParam)

// validate path parameters
Expand Down Expand Up @@ -167,6 +188,7 @@ func (a *App) GetWorkspacesHandler(w http.ResponseWriter, r *http.Request, ps ht
// @Summary Create workspace
// @Description Creates a new workspace in the specified namespace.
// @Tags workspaces
// @ID createWorkspace
// @Accept json
// @Produce json
// @Param namespace path string true "Namespace for the workspace" extensions(x-example=kubeflow-user-example-com)
Expand Down Expand Up @@ -267,6 +289,7 @@ func (a *App) CreateWorkspaceHandler(w http.ResponseWriter, r *http.Request, ps
// @Summary Delete workspace
// @Description Deletes a specific workspace identified by namespace and workspace name.
// @Tags workspaces
// @ID deleteWorkspace
// @Accept json
// @Produce json
// @Param namespace path string true "Namespace of the workspace" extensions(x-example=kubeflow-user-example-com)
Expand Down
20 changes: 10 additions & 10 deletions workspaces/backend/api/workspaces_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ var _ = Describe("Workspaces Handler", func() {
By("setting the auth headers")
req.Header.Set(userIdHeader, adminUser)

By("executing GetWorkspacesHandler")
By("executing GetAllWorkspacesHandler")
ps := httprouter.Params{}
rr := httptest.NewRecorder()
a.GetWorkspacesHandler(rr, req, ps)
a.GetAllWorkspacesHandler(rr, req, ps)
rs := rr.Result()
defer rs.Body.Close()

Expand Down Expand Up @@ -219,12 +219,12 @@ var _ = Describe("Workspaces Handler", func() {
By("setting the auth headers")
req.Header.Set(userIdHeader, adminUser)

By("executing GetWorkspacesHandler")
By("executing GetWorkspacesByNamespaceHandler")
ps := httprouter.Params{
httprouter.Param{Key: NamespacePathParam, Value: namespaceName1},
}
rr := httptest.NewRecorder()
a.GetWorkspacesHandler(rr, req, ps)
a.GetWorkspacesByNamespaceHandler(rr, req, ps)
rs := rr.Result()
defer rs.Body.Close()

Expand Down Expand Up @@ -429,12 +429,12 @@ var _ = Describe("Workspaces Handler", func() {
By("setting the auth headers")
req.Header.Set(userIdHeader, adminUser)

By("executing GetWorkspacesHandler")
By("executing GetWorkspacesByNamespaceHandler")
ps := httprouter.Params{
httprouter.Param{Key: NamespacePathParam, Value: namespaceName1},
}
rr := httptest.NewRecorder()
a.GetWorkspacesHandler(rr, req, ps)
a.GetWorkspacesByNamespaceHandler(rr, req, ps)
rs := rr.Result()
defer rs.Body.Close()

Expand Down Expand Up @@ -543,10 +543,10 @@ var _ = Describe("Workspaces Handler", func() {
By("setting the auth headers")
req.Header.Set(userIdHeader, adminUser)

By("executing GetWorkspacesHandler")
By("executing GetAllWorkspacesHandler")
ps := httprouter.Params{}
rr := httptest.NewRecorder()
a.GetWorkspacesHandler(rr, req, ps)
a.GetAllWorkspacesHandler(rr, req, ps)
rs := rr.Result()
defer rs.Body.Close()

Expand Down Expand Up @@ -577,12 +577,12 @@ var _ = Describe("Workspaces Handler", func() {
By("setting the auth headers")
req.Header.Set(userIdHeader, adminUser)

By("executing GetWorkspacesHandler")
By("executing GetWorkspacesByNamespaceHandler")
ps := httprouter.Params{
httprouter.Param{Key: NamespacePathParam, Value: missingNamespace},
}
rr := httptest.NewRecorder()
a.GetWorkspacesHandler(rr, req, ps)
a.GetWorkspacesByNamespaceHandler(rr, req, ps)
rs := rr.Result()
defer rs.Body.Close()

Expand Down
31 changes: 18 additions & 13 deletions workspaces/backend/openapi/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const docTemplate = `{
"healthcheck"
],
"summary": "Returns the health status of the application",
"operationId": "getHealthcheck",
"responses": {
"200": {
"description": "Successful healthcheck response",
Expand All @@ -55,6 +56,7 @@ const docTemplate = `{
"namespaces"
],
"summary": "Returns a list of all namespaces",
"operationId": "listNamespaces",
"responses": {
"200": {
"description": "Successful namespaces response",
Expand Down Expand Up @@ -96,6 +98,7 @@ const docTemplate = `{
"workspacekinds"
],
"summary": "List workspace kinds",
"operationId": "listWorkspaceKinds",
"responses": {
"200": {
"description": "Successful operation. Returns a list of all available workspace kinds.",
Expand Down Expand Up @@ -135,6 +138,7 @@ const docTemplate = `{
"workspacekinds"
],
"summary": "Create workspace kind",
"operationId": "createWorkspaceKind",
"parameters": [
{
"description": "Kubernetes YAML manifest of a WorkspaceKind",
Expand Down Expand Up @@ -217,6 +221,7 @@ const docTemplate = `{
"workspacekinds"
],
"summary": "Get workspace kind",
"operationId": "getWorkspaceKind",
"parameters": [
{
"type": "string",
Expand Down Expand Up @@ -269,7 +274,7 @@ const docTemplate = `{
},
"/workspaces": {
"get": {
"description": "Returns a list of workspaces. The endpoint supports two modes:\n1. List all workspaces across all namespaces (when no namespace is provided)\n2. List workspaces in a specific namespace (when namespace is provided)",
"description": "Returns a list of all workspaces across all namespaces.",
"consumes": [
"application/json"
],
Expand All @@ -279,20 +284,15 @@ const docTemplate = `{
"tags": [
"workspaces"
],
"summary": "List workspaces",
"summary": "List all workspaces",
"operationId": "listAllWorkspaces",
"responses": {
"200": {
"description": "Successful operation. Returns a list of workspaces.",
"description": "Successful operation. Returns a list of all workspaces.",
"schema": {
"$ref": "#/definitions/api.WorkspaceListEnvelope"
}
},
"400": {
"description": "Bad Request. Invalid namespace format.",
"schema": {
"$ref": "#/definitions/api.ErrorEnvelope"
}
},
"401": {
"description": "Unauthorized. Authentication is required.",
"schema": {
Expand All @@ -316,7 +316,7 @@ const docTemplate = `{
},
"/workspaces/{namespace}": {
"get": {
"description": "Returns a list of workspaces. The endpoint supports two modes:\n1. List all workspaces across all namespaces (when no namespace is provided)\n2. List workspaces in a specific namespace (when namespace is provided)",
"description": "Returns a list of workspaces in a specific namespace.",
"consumes": [
"application/json"
],
Expand All @@ -326,20 +326,21 @@ const docTemplate = `{
"tags": [
"workspaces"
],
"summary": "List workspaces",
"summary": "List workspaces by namespace",
"operationId": "listWorkspacesByNamespace",
"parameters": [
{
"type": "string",
"x-example": "kubeflow-user-example-com",
"description": "Namespace to filter workspaces. If not provided, returns all workspaces across all namespaces.",
"description": "Namespace to filter workspaces",
"name": "namespace",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Successful operation. Returns a list of workspaces.",
"description": "Successful operation. Returns a list of workspaces in the specified namespace.",
"schema": {
"$ref": "#/definitions/api.WorkspaceListEnvelope"
}
Expand Down Expand Up @@ -382,6 +383,7 @@ const docTemplate = `{
"workspaces"
],
"summary": "Create workspace",
"operationId": "createWorkspace",
"parameters": [
{
"type": "string",
Expand Down Expand Up @@ -466,6 +468,7 @@ const docTemplate = `{
"workspaces"
],
"summary": "Pause or unpause a workspace",
"operationId": "updateWorkspacePauseState",
"parameters": [
{
"type": "string",
Expand Down Expand Up @@ -564,6 +567,7 @@ const docTemplate = `{
"workspaces"
],
"summary": "Get workspace",
"operationId": "getWorkspace",
"parameters": [
{
"type": "string",
Expand Down Expand Up @@ -633,6 +637,7 @@ const docTemplate = `{
"workspaces"
],
"summary": "Delete workspace",
"operationId": "deleteWorkspace",
"parameters": [
{
"type": "string",
Expand Down
Loading