Skip to content

Commit fcb5fc5

Browse files
liavweissLiav Weiss (EXT-Nokia)
andauthored
feat(ws): fix swagger warnings and only generate json output (#424)
* feat(ws): Clean and fix swagger warnings and errors Signed-off-by: Liav Weiss (EXT-Nokia) <[email protected]> * feat(ws): Clean and fix swagger warnings and errors Signed-off-by: Liav Weiss (EXT-Nokia) <[email protected]> --------- Signed-off-by: Liav Weiss (EXT-Nokia) <[email protected]> Co-authored-by: Liav Weiss (EXT-Nokia) <[email protected]>
1 parent 24a4472 commit fcb5fc5

File tree

6 files changed

+26
-1034
lines changed

6 files changed

+26
-1034
lines changed

workspaces/backend/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ SWAG_DIRS := cmd,$(ALL_GO_DIRS_NO_CMD)
7474
.PHONY: swag
7575
swag: SWAGGER
7676
$(SWAGGER) fmt -g main.go -d $(SWAG_DIRS)
77-
$(SWAGGER) init --parseDependency -q -g main.go -d $(SWAG_DIRS) --output openapi
77+
$(SWAGGER) init --parseDependency -q -g main.go -d $(SWAG_DIRS) --output openapi --outputTypes go,json
7878

7979
##@ Build
8080

workspaces/backend/api/workspacekinds_handler.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@ type WorkspaceKindEnvelope Envelope[models.WorkspaceKind]
4242
// @Tags workspacekinds
4343
// @Accept json
4444
// @Produce json
45-
// @Param name path string true "Name of the workspace kind" example(jupyterlab)
45+
// @Param name path string true "Name of the workspace kind" extensions(x-example=jupyterlab)
4646
// @Success 200 {object} WorkspaceKindEnvelope "Successful operation. Returns the requested workspace kind details."
4747
// @Failure 400 {object} ErrorEnvelope "Bad Request. Invalid workspace kind name format."
4848
// @Failure 401 {object} ErrorEnvelope "Unauthorized. Authentication is required."
4949
// @Failure 403 {object} ErrorEnvelope "Forbidden. User does not have permission to access the workspace kind."
5050
// @Failure 404 {object} ErrorEnvelope "Not Found. Workspace kind does not exist."
5151
// @Failure 500 {object} ErrorEnvelope "Internal server error. An unexpected error occurred on the server."
5252
// @Router /workspacekinds/{name} [get]
53-
// @Security ApiKeyAuth
5453
func (a *App) GetWorkspaceKindHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
5554
name := ps.ByName(ResourceNamePathParam)
5655

@@ -102,7 +101,6 @@ func (a *App) GetWorkspaceKindHandler(w http.ResponseWriter, r *http.Request, ps
102101
// @Failure 403 {object} ErrorEnvelope "Forbidden. User does not have permission to list workspace kinds."
103102
// @Failure 500 {object} ErrorEnvelope "Internal server error. An unexpected error occurred on the server."
104103
// @Router /workspacekinds [get]
105-
// @Security ApiKeyAuth
106104
func (a *App) GetWorkspaceKindsHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
107105
// =========================== AUTH ===========================
108106
authPolicies := []*auth.ResourcePolicy{

workspaces/backend/api/workspaces_handler.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,15 @@ type WorkspaceEnvelope Envelope[models.Workspace]
4646
// @Tags workspaces
4747
// @Accept json
4848
// @Produce json
49-
// @Param namespace path string true "Namespace of the workspace" example(kubeflow-user-example-com)
50-
// @Param workspace_name path string true "Name of the workspace" example(my-workspace)
49+
// @Param namespace path string true "Namespace of the workspace" extensions(x-example=kubeflow-user-example-com)
50+
// @Param workspace_name path string true "Name of the workspace" extensions(x-example=my-workspace)
5151
// @Success 200 {object} WorkspaceEnvelope "Successful operation. Returns the requested workspace details."
5252
// @Failure 400 {object} ErrorEnvelope "Bad Request. Invalid namespace or workspace name format."
5353
// @Failure 401 {object} ErrorEnvelope "Unauthorized. Authentication is required."
5454
// @Failure 403 {object} ErrorEnvelope "Forbidden. User does not have permission to access the workspace."
5555
// @Failure 404 {object} ErrorEnvelope "Not Found. Workspace does not exist."
5656
// @Failure 500 {object} ErrorEnvelope "Internal server error. An unexpected error occurred on the server."
5757
// @Router /workspaces/{namespace}/{workspace_name} [get]
58-
// @Security ApiKeyAuth
5958
func (a *App) GetWorkspaceHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
6059
namespace := ps.ByName(NamespacePathParam)
6160
workspaceName := ps.ByName(ResourceNamePathParam)
@@ -109,15 +108,14 @@ func (a *App) GetWorkspaceHandler(w http.ResponseWriter, r *http.Request, ps htt
109108
// @Tags workspaces
110109
// @Accept json
111110
// @Produce json
112-
// @Param namespace path string false "Namespace to filter workspaces. If not provided, returns all workspaces across all namespaces." example(kubeflow-user-example-com)
111+
// @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)
113112
// @Success 200 {object} WorkspaceListEnvelope "Successful operation. Returns a list of workspaces."
114113
// @Failure 400 {object} ErrorEnvelope "Bad Request. Invalid namespace format."
115114
// @Failure 401 {object} ErrorEnvelope "Unauthorized. Authentication is required."
116115
// @Failure 403 {object} ErrorEnvelope "Forbidden. User does not have permission to list workspaces."
117116
// @Failure 500 {object} ErrorEnvelope "Internal server error. An unexpected error occurred on the server."
118117
// @Router /workspaces [get]
119118
// @Router /workspaces/{namespace} [get]
120-
// @Security ApiKeyAuth
121119
func (a *App) GetWorkspacesHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
122120
namespace := ps.ByName(NamespacePathParam)
123121

@@ -171,7 +169,7 @@ func (a *App) GetWorkspacesHandler(w http.ResponseWriter, r *http.Request, ps ht
171169
// @Tags workspaces
172170
// @Accept json
173171
// @Produce json
174-
// @Param namespace path string true "Namespace for the workspace" example(kubeflow-user-example-com)
172+
// @Param namespace path string true "Namespace for the workspace" extensions(x-example=kubeflow-user-example-com)
175173
// @Param body body WorkspaceCreateEnvelope true "Workspace creation configuration"
176174
// @Success 201 {object} WorkspaceEnvelope "Workspace created successfully"
177175
// @Failure 400 {object} ErrorEnvelope "Bad Request. Invalid request body or namespace format."
@@ -180,7 +178,6 @@ func (a *App) GetWorkspacesHandler(w http.ResponseWriter, r *http.Request, ps ht
180178
// @Failure 409 {object} ErrorEnvelope "Conflict. Workspace with the same name already exists."
181179
// @Failure 500 {object} ErrorEnvelope "Internal server error. An unexpected error occurred on the server."
182180
// @Router /workspaces/{namespace} [post]
183-
// @Security ApiKeyAuth
184181
func (a *App) CreateWorkspaceHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
185182
namespace := ps.ByName(NamespacePathParam)
186183

@@ -266,16 +263,15 @@ func (a *App) CreateWorkspaceHandler(w http.ResponseWriter, r *http.Request, ps
266263
// @Tags workspaces
267264
// @Accept json
268265
// @Produce json
269-
// @Param namespace path string true "Namespace of the workspace" example(kubeflow-user-example-com)
270-
// @Param workspace_name path string true "Name of the workspace" example(my-workspace)
266+
// @Param namespace path string true "Namespace of the workspace" extensions(x-example=kubeflow-user-example-com)
267+
// @Param workspace_name path string true "Name of the workspace" extensions(x-example=my-workspace)
271268
// @Success 204 {object} nil "Workspace deleted successfully"
272269
// @Failure 400 {object} ErrorEnvelope "Bad Request. Invalid namespace or workspace name format."
273270
// @Failure 401 {object} ErrorEnvelope "Unauthorized. Authentication is required."
274271
// @Failure 403 {object} ErrorEnvelope "Forbidden. User does not have permission to delete the workspace."
275272
// @Failure 404 {object} ErrorEnvelope "Not Found. Workspace does not exist."
276273
// @Failure 500 {object} ErrorEnvelope "Internal server error. An unexpected error occurred on the server."
277274
// @Router /workspaces/{namespace}/{workspace_name} [delete]
278-
// @Security ApiKeyAuth
279275
func (a *App) DeleteWorkspaceHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
280276
namespace := ps.ByName(NamespacePathParam)
281277
workspaceName := ps.ByName(ResourceNamePathParam)

workspaces/backend/openapi/docs.go

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ const docTemplate = `{
8585
},
8686
"/workspacekinds": {
8787
"get": {
88-
"security": [
89-
{
90-
"ApiKeyAuth": []
91-
}
92-
],
9388
"description": "Returns a list of all available workspace kinds. Workspace kinds define the different types of workspaces that can be created in the system.",
9489
"consumes": [
9590
"application/json"
@@ -131,11 +126,6 @@ const docTemplate = `{
131126
},
132127
"/workspacekinds/{name}": {
133128
"get": {
134-
"security": [
135-
{
136-
"ApiKeyAuth": []
137-
}
138-
],
139129
"description": "Returns details of a specific workspace kind identified by its name. Workspace kinds define the available types of workspaces that can be created.",
140130
"consumes": [
141131
"application/json"
@@ -150,7 +140,7 @@ const docTemplate = `{
150140
"parameters": [
151141
{
152142
"type": "string",
153-
"example": "jupyterlab",
143+
"x-example": "jupyterlab",
154144
"description": "Name of the workspace kind",
155145
"name": "name",
156146
"in": "path",
@@ -199,11 +189,6 @@ const docTemplate = `{
199189
},
200190
"/workspaces": {
201191
"get": {
202-
"security": [
203-
{
204-
"ApiKeyAuth": []
205-
}
206-
],
207192
"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)",
208193
"consumes": [
209194
"application/json"
@@ -251,11 +236,6 @@ const docTemplate = `{
251236
},
252237
"/workspaces/{namespace}": {
253238
"get": {
254-
"security": [
255-
{
256-
"ApiKeyAuth": []
257-
}
258-
],
259239
"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)",
260240
"consumes": [
261241
"application/json"
@@ -270,10 +250,11 @@ const docTemplate = `{
270250
"parameters": [
271251
{
272252
"type": "string",
273-
"example": "kubeflow-user-example-com",
253+
"x-example": "kubeflow-user-example-com",
274254
"description": "Namespace to filter workspaces. If not provided, returns all workspaces across all namespaces.",
275255
"name": "namespace",
276-
"in": "path"
256+
"in": "path",
257+
"required": true
277258
}
278259
],
279260
"responses": {
@@ -310,11 +291,6 @@ const docTemplate = `{
310291
}
311292
},
312293
"post": {
313-
"security": [
314-
{
315-
"ApiKeyAuth": []
316-
}
317-
],
318294
"description": "Creates a new workspace in the specified namespace.",
319295
"consumes": [
320296
"application/json"
@@ -329,7 +305,7 @@ const docTemplate = `{
329305
"parameters": [
330306
{
331307
"type": "string",
332-
"example": "kubeflow-user-example-com",
308+
"x-example": "kubeflow-user-example-com",
333309
"description": "Namespace for the workspace",
334310
"name": "namespace",
335311
"in": "path",
@@ -387,11 +363,6 @@ const docTemplate = `{
387363
},
388364
"/workspaces/{namespace}/{workspace_name}": {
389365
"get": {
390-
"security": [
391-
{
392-
"ApiKeyAuth": []
393-
}
394-
],
395366
"description": "Returns details of a specific workspace identified by namespace and workspace name.",
396367
"consumes": [
397368
"application/json"
@@ -406,15 +377,15 @@ const docTemplate = `{
406377
"parameters": [
407378
{
408379
"type": "string",
409-
"example": "kubeflow-user-example-com",
380+
"x-example": "kubeflow-user-example-com",
410381
"description": "Namespace of the workspace",
411382
"name": "namespace",
412383
"in": "path",
413384
"required": true
414385
},
415386
{
416387
"type": "string",
417-
"example": "my-workspace",
388+
"x-example": "my-workspace",
418389
"description": "Name of the workspace",
419390
"name": "workspace_name",
420391
"in": "path",
@@ -461,11 +432,6 @@ const docTemplate = `{
461432
}
462433
},
463434
"delete": {
464-
"security": [
465-
{
466-
"ApiKeyAuth": []
467-
}
468-
],
469435
"description": "Deletes a specific workspace identified by namespace and workspace name.",
470436
"consumes": [
471437
"application/json"
@@ -480,15 +446,15 @@ const docTemplate = `{
480446
"parameters": [
481447
{
482448
"type": "string",
483-
"example": "kubeflow-user-example-com",
449+
"x-example": "kubeflow-user-example-com",
484450
"description": "Namespace of the workspace",
485451
"name": "namespace",
486452
"in": "path",
487453
"required": true
488454
},
489455
{
490456
"type": "string",
491-
"example": "my-workspace",
457+
"x-example": "my-workspace",
492458
"description": "Name of the workspace",
493459
"name": "workspace_name",
494460
"in": "path",

0 commit comments

Comments
 (0)