From 88e8d1736dd58c926aaad085e600e77730f05515 Mon Sep 17 00:00:00 2001 From: Jihoon Seo Date: Wed, 19 Oct 2022 15:21:15 +0900 Subject: [PATCH] Add Swagger godoc for CustomImage REST APIs --- src/api/rest/docs/docs.go | 233 +++++++++++++++++++++++- src/api/rest/docs/swagger.json | 233 +++++++++++++++++++++++- src/api/rest/docs/swagger.yaml | 153 ++++++++++++++++ src/api/rest/server/mcir/customimage.go | 75 +++++++- 4 files changed, 691 insertions(+), 3 deletions(-) diff --git a/src/api/rest/docs/docs.go b/src/api/rest/docs/docs.go index 6314722ce..b4bcf86f3 100644 --- a/src/api/rest/docs/docs.go +++ b/src/api/rest/docs/docs.go @@ -3550,6 +3550,85 @@ const docTemplate = `{ } }, "/ns/{nsId}/resources/customImage": { + "get": { + "description": "List all customImages or customImages' ID", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] MCIR Custom Image management" + ], + "summary": "List all customImages or customImages' ID", + "parameters": [ + { + "type": "string", + "default": "ns01", + "description": "Namespace ID", + "name": "nsId", + "in": "path", + "required": true + }, + { + "enum": [ + "id" + ], + "type": "string", + "description": "Option", + "name": "option", + "in": "query" + }, + { + "type": "string", + "description": "Field key for filtering (ex:guestOS)", + "name": "filterKey", + "in": "query" + }, + { + "type": "string", + "description": "Field value for filtering (ex: Ubuntu18.04)", + "name": "filterVal", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Different return structures by the given option param", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/mcir.JSONResult" + }, + { + "type": "object", + "properties": { + "[DEFAULT]": { + "$ref": "#/definitions/mcir.RestGetAllCustomImageResponse" + }, + "[ID]": { + "$ref": "#/definitions/common.IdList" + } + } + } + ] + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + }, "post": { "description": "Create Custom Image", "consumes": [ @@ -3578,7 +3657,8 @@ const docTemplate = `{ "type": "string", "description": "Option: ", "name": "option", - "in": "query" + "in": "query", + "required": true }, { "description": "Details for an Custom Image object", @@ -3610,6 +3690,146 @@ const docTemplate = `{ } } } + }, + "delete": { + "description": "Delete all customImages", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] MCIR Custom Image management" + ], + "summary": "Delete all customImages", + "parameters": [ + { + "type": "string", + "default": "ns01", + "description": "Namespace ID", + "name": "nsId", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "", + "description": "Delete resources containing matched ID-substring only", + "name": "match", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/common.IdList" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, + "/ns/{nsId}/resources/customImage/{customImageId}": { + "get": { + "description": "Get customImage", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] MCIR Custom Image management" + ], + "summary": "Get customImage", + "parameters": [ + { + "type": "string", + "default": "ns01", + "description": "Namespace ID", + "name": "nsId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "customImage ID", + "name": "customImageId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mcir.TbCustomImageInfo" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + }, + "delete": { + "description": "Delete customImage", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] MCIR Custom Image management" + ], + "summary": "Delete customImage", + "parameters": [ + { + "type": "string", + "default": "ns01", + "description": "Namespace ID", + "name": "nsId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "customImage ID", + "name": "customImageId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } } }, "/ns/{nsId}/resources/dataDisk": { @@ -6820,6 +7040,17 @@ const docTemplate = `{ } } }, + "mcir.RestGetAllCustomImageResponse": { + "type": "object", + "properties": { + "customImage": { + "type": "array", + "items": { + "$ref": "#/definitions/mcir.TbCustomImageInfo" + } + } + } + }, "mcir.RestGetAllDataDiskResponse": { "type": "object", "properties": { diff --git a/src/api/rest/docs/swagger.json b/src/api/rest/docs/swagger.json index dabb935cd..9c99c5dc4 100644 --- a/src/api/rest/docs/swagger.json +++ b/src/api/rest/docs/swagger.json @@ -3542,6 +3542,85 @@ } }, "/ns/{nsId}/resources/customImage": { + "get": { + "description": "List all customImages or customImages' ID", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] MCIR Custom Image management" + ], + "summary": "List all customImages or customImages' ID", + "parameters": [ + { + "type": "string", + "default": "ns01", + "description": "Namespace ID", + "name": "nsId", + "in": "path", + "required": true + }, + { + "enum": [ + "id" + ], + "type": "string", + "description": "Option", + "name": "option", + "in": "query" + }, + { + "type": "string", + "description": "Field key for filtering (ex:guestOS)", + "name": "filterKey", + "in": "query" + }, + { + "type": "string", + "description": "Field value for filtering (ex: Ubuntu18.04)", + "name": "filterVal", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Different return structures by the given option param", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/mcir.JSONResult" + }, + { + "type": "object", + "properties": { + "[DEFAULT]": { + "$ref": "#/definitions/mcir.RestGetAllCustomImageResponse" + }, + "[ID]": { + "$ref": "#/definitions/common.IdList" + } + } + } + ] + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + }, "post": { "description": "Create Custom Image", "consumes": [ @@ -3570,7 +3649,8 @@ "type": "string", "description": "Option: ", "name": "option", - "in": "query" + "in": "query", + "required": true }, { "description": "Details for an Custom Image object", @@ -3602,6 +3682,146 @@ } } } + }, + "delete": { + "description": "Delete all customImages", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] MCIR Custom Image management" + ], + "summary": "Delete all customImages", + "parameters": [ + { + "type": "string", + "default": "ns01", + "description": "Namespace ID", + "name": "nsId", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "", + "description": "Delete resources containing matched ID-substring only", + "name": "match", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/common.IdList" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, + "/ns/{nsId}/resources/customImage/{customImageId}": { + "get": { + "description": "Get customImage", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] MCIR Custom Image management" + ], + "summary": "Get customImage", + "parameters": [ + { + "type": "string", + "default": "ns01", + "description": "Namespace ID", + "name": "nsId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "customImage ID", + "name": "customImageId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mcir.TbCustomImageInfo" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + }, + "delete": { + "description": "Delete customImage", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] MCIR Custom Image management" + ], + "summary": "Delete customImage", + "parameters": [ + { + "type": "string", + "default": "ns01", + "description": "Namespace ID", + "name": "nsId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "customImage ID", + "name": "customImageId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } } }, "/ns/{nsId}/resources/dataDisk": { @@ -6812,6 +7032,17 @@ } } }, + "mcir.RestGetAllCustomImageResponse": { + "type": "object", + "properties": { + "customImage": { + "type": "array", + "items": { + "$ref": "#/definitions/mcir.TbCustomImageInfo" + } + } + } + }, "mcir.RestGetAllDataDiskResponse": { "type": "object", "properties": { diff --git a/src/api/rest/docs/swagger.yaml b/src/api/rest/docs/swagger.yaml index ab83822f3..63aa82ae3 100644 --- a/src/api/rest/docs/swagger.yaml +++ b/src/api/rest/docs/swagger.yaml @@ -270,6 +270,13 @@ definitions: $ref: '#/definitions/mcir.TbSpecInfo' type: array type: object + mcir.RestGetAllCustomImageResponse: + properties: + customImage: + items: + $ref: '#/definitions/mcir.TbCustomImageInfo' + type: array + type: object mcir.RestGetAllDataDiskResponse: properties: dataDisk: @@ -4701,6 +4708,86 @@ paths: tags: - '[Infra service] MCIS Provisioning management' /ns/{nsId}/resources/customImage: + delete: + consumes: + - application/json + description: Delete all customImages + parameters: + - default: ns01 + description: Namespace ID + in: path + name: nsId + required: true + type: string + - default: "" + description: Delete resources containing matched ID-substring only + in: query + name: match + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/common.IdList' + "404": + description: Not Found + schema: + $ref: '#/definitions/common.SimpleMsg' + summary: Delete all customImages + tags: + - '[Infra resource] MCIR Custom Image management' + get: + consumes: + - application/json + description: List all customImages or customImages' ID + parameters: + - default: ns01 + description: Namespace ID + in: path + name: nsId + required: true + type: string + - description: Option + enum: + - id + in: query + name: option + type: string + - description: Field key for filtering (ex:guestOS) + in: query + name: filterKey + type: string + - description: 'Field value for filtering (ex: Ubuntu18.04)' + in: query + name: filterVal + type: string + produces: + - application/json + responses: + "200": + description: Different return structures by the given option param + schema: + allOf: + - $ref: '#/definitions/mcir.JSONResult' + - properties: + '[DEFAULT]': + $ref: '#/definitions/mcir.RestGetAllCustomImageResponse' + '[ID]': + $ref: '#/definitions/common.IdList' + type: object + "404": + description: Not Found + schema: + $ref: '#/definitions/common.SimpleMsg' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/common.SimpleMsg' + summary: List all customImages or customImages' ID + tags: + - '[Infra resource] MCIR Custom Image management' post: consumes: - application/json @@ -4717,6 +4804,7 @@ paths: - register in: query name: option + required: true type: string - description: Details for an Custom Image object in: body @@ -4742,6 +4830,71 @@ paths: summary: Create Custom Image tags: - '[Infra resource] MCIR Custom Image management' + /ns/{nsId}/resources/customImage/{customImageId}: + delete: + consumes: + - application/json + description: Delete customImage + parameters: + - default: ns01 + description: Namespace ID + in: path + name: nsId + required: true + type: string + - description: customImage ID + in: path + name: customImageId + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/common.SimpleMsg' + "404": + description: Not Found + schema: + $ref: '#/definitions/common.SimpleMsg' + summary: Delete customImage + tags: + - '[Infra resource] MCIR Custom Image management' + get: + consumes: + - application/json + description: Get customImage + parameters: + - default: ns01 + description: Namespace ID + in: path + name: nsId + required: true + type: string + - description: customImage ID + in: path + name: customImageId + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/mcir.TbCustomImageInfo' + "404": + description: Not Found + schema: + $ref: '#/definitions/common.SimpleMsg' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/common.SimpleMsg' + summary: Get customImage + tags: + - '[Infra resource] MCIR Custom Image management' /ns/{nsId}/resources/dataDisk: delete: consumes: diff --git a/src/api/rest/server/mcir/customimage.go b/src/api/rest/server/mcir/customimage.go index e53a9731e..a38e00060 100644 --- a/src/api/rest/server/mcir/customimage.go +++ b/src/api/rest/server/mcir/customimage.go @@ -30,7 +30,7 @@ import ( // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) -// @Param option query string false "Option: " Enums(register) +// @Param option query string true "Option: " Enums(register) // @Param customImageInfo body mcir.TbCustomImageReq true "Details for an Custom Image object" // @Success 200 {object} mcir.TbCustomImageInfo // @Failure 404 {object} common.SimpleMsg @@ -61,3 +61,76 @@ func RestPostCustomImage(c echo.Context) error { } return c.JSON(http.StatusCreated, content) } + +// RestGetCustomImage godoc +// @Summary Get customImage +// @Description Get customImage +// @Tags [Infra resource] MCIR Custom Image management +// @Accept json +// @Produce json +// @Param nsId path string true "Namespace ID" default(ns01) +// @Param customImageId path string true "customImage ID" +// @Success 200 {object} mcir.TbCustomImageInfo +// @Failure 404 {object} common.SimpleMsg +// @Failure 500 {object} common.SimpleMsg +// @Router /ns/{nsId}/resources/customImage/{customImageId} [get] +func RestGetCustomImage(c echo.Context) error { + // This is a dummy function for Swagger. + return nil +} + +// Response structure for RestGetAllCustomImage +type RestGetAllCustomImageResponse struct { + CustomImage []mcir.TbCustomImageInfo `json:"customImage"` +} + +// RestGetAllCustomImage godoc +// @Summary List all customImages or customImages' ID +// @Description List all customImages or customImages' ID +// @Tags [Infra resource] MCIR Custom Image management +// @Accept json +// @Produce json +// @Param nsId path string true "Namespace ID" default(ns01) +// @Param option query string false "Option" Enums(id) +// @Param filterKey query string false "Field key for filtering (ex:guestOS)" +// @Param filterVal query string false "Field value for filtering (ex: Ubuntu18.04)" +// @Success 200 {object} JSONResult{[DEFAULT]=RestGetAllCustomImageResponse,[ID]=common.IdList} "Different return structures by the given option param" +// @Failure 404 {object} common.SimpleMsg +// @Failure 500 {object} common.SimpleMsg +// @Router /ns/{nsId}/resources/customImage [get] +func RestGetAllCustomImage(c echo.Context) error { + // This is a dummy function for Swagger. + return nil +} + +// RestDelCustomImage godoc +// @Summary Delete customImage +// @Description Delete customImage +// @Tags [Infra resource] MCIR Custom Image management +// @Accept json +// @Produce json +// @Param nsId path string true "Namespace ID" default(ns01) +// @Param customImageId path string true "customImage ID" +// @Success 200 {object} common.SimpleMsg +// @Failure 404 {object} common.SimpleMsg +// @Router /ns/{nsId}/resources/customImage/{customImageId} [delete] +func RestDelCustomImage(c echo.Context) error { + // This is a dummy function for Swagger. + return nil +} + +// RestDelAllCustomImage godoc +// @Summary Delete all customImages +// @Description Delete all customImages +// @Tags [Infra resource] MCIR Custom Image management +// @Accept json +// @Produce json +// @Param nsId path string true "Namespace ID" default(ns01) +// @Param match query string false "Delete resources containing matched ID-substring only" default() +// @Success 200 {object} common.IdList +// @Failure 404 {object} common.SimpleMsg +// @Router /ns/{nsId}/resources/customImage [delete] +func RestDelAllCustomcustomImage(c echo.Context) error { + // This is a dummy function for Swagger. + return nil +}