diff --git a/api/docs.go b/api/docs.go index 1df3bb2..8b6c21f 100644 --- a/api/docs.go +++ b/api/docs.go @@ -8558,8 +8558,8 @@ var SwaggerInfo = &swag.Spec{ Host: "localhost:8056", BasePath: "/beetle", Schemes: []string{}, - Title: "CM-Beetle REST API", - Description: "CM-Beetle REST API", + Title: "CM-Beetle API", + Description: "CM-Beetle recommends optimal target cloud infrastructure and executes migration.", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, LeftDelim: "{{", diff --git a/api/swagger.json b/api/swagger.json index bfa3939..7815971 100644 --- a/api/swagger.json +++ b/api/swagger.json @@ -1,8 +1,8 @@ { "swagger": "2.0", "info": { - "description": "CM-Beetle REST API", - "title": "CM-Beetle REST API", + "description": "CM-Beetle recommends optimal target cloud infrastructure and executes migration.", + "title": "CM-Beetle API", "contact": { "name": "API Support", "url": "https://github.com/cloud-barista/cm-beetle/issues/new/choose" diff --git a/api/swagger.yaml b/api/swagger.yaml index 3d25201..326c494 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -4043,11 +4043,12 @@ info: contact: name: API Support url: https://github.com/cloud-barista/cm-beetle/issues/new/choose - description: CM-Beetle REST API + description: CM-Beetle recommends optimal target cloud infrastructure and executes + migration. license: name: Apache 2.0 url: http://www.apache.org/licenses/LICENSE-2.0.html - title: CM-Beetle REST API + title: CM-Beetle API version: latest paths: /httpVersion: diff --git a/cmd/cm-beetle/main.go b/cmd/cm-beetle/main.go index 83806ca..5aa5cae 100644 --- a/cmd/cm-beetle/main.go +++ b/cmd/cm-beetle/main.go @@ -124,9 +124,9 @@ func checkReadiness(url string) (bool, error) { return true, nil } -// @title CM-Beetle REST API +// @title CM-Beetle API // @version latest -// @description CM-Beetle REST API +// @description CM-Beetle recommends optimal target cloud infrastructure and executes migration. // // @termsOfService none // @contact.name API Support diff --git a/deployments/docker-compose/docker-compose.yaml b/deployments/docker-compose/docker-compose.yaml index 58db9bb..b6dee8e 100644 --- a/deployments/docker-compose/docker-compose.yaml +++ b/deployments/docker-compose/docker-compose.yaml @@ -29,10 +29,10 @@ services: # - BEETLE_ROOT=/app - BEETLE_SELF_ENDPOINT=localhost:8056 # - BEETLE_API_ALLOW_ORIGINS=* - - BEETLE_API_AUTH_ENABLED=true - - BEETLE_API_AUTH_MODE=basic - - BEETLE_API_USERNAME=default - - BEETLE_API_PASSWORD=default + # - BEETLE_API_AUTH_ENABLED=true + # - BEETLE_API_AUTH_MODE=basic + # - BEETLE_API_USERNAME=default + # - BEETLE_API_PASSWORD=default # - BEETLE_LKVSTORE_PATH=/app/db/beetle.db # - BEETLE_LOGFILE_PATH=/app/log/beetle.log # - BEETLE_LOGFILE_MAXSIZE=1000 diff --git a/pkg/api/rest/middlewares/response-dump.go b/pkg/api/rest/middlewares/response-dump.go index 8ce327a..47a8638 100644 --- a/pkg/api/rest/middlewares/response-dump.go +++ b/pkg/api/rest/middlewares/response-dump.go @@ -93,13 +93,24 @@ func ResponseBodyDump() echo.MiddlewareFunc { break processResponse } - if message, exists := lastResData["message"]; exists && message != nil { - if msgStr, ok := message.(string); ok { - details.ErrorResponse = msgStr - } else { - details.ErrorResponse = "Error response message is not a string" + // Prioritize 'error' field from ApiResponse + if errVal, exists := lastResData["error"]; exists && errVal != nil { + if errStr, ok := errVal.(string); ok { + details.ErrorResponse = errStr } - } else { + } + + // Fallback to 'message' field if 'error' is missing or empty + if details.ErrorResponse == "" { + if msgVal, exists := lastResData["message"]; exists && msgVal != nil { + if msgStr, ok := msgVal.(string); ok { + details.ErrorResponse = msgStr + } + } + } + + // Final fallback + if details.ErrorResponse == "" { details.ErrorResponse = "No error message found" } break processResponse diff --git a/pkg/api/rest/model/beetle/response.go b/pkg/api/rest/model/beetle/response.go index 10f8d04..4edde56 100644 --- a/pkg/api/rest/model/beetle/response.go +++ b/pkg/api/rest/model/beetle/response.go @@ -58,6 +58,7 @@ type Page[T any] struct { // ------------------------------------------------------------------- // SuccessResponse creates a successful API response for a single object or any generic data. +// T is the type of the response data. // Usage: // - Single Object: SuccessResponse(user) -> Data: User // - Raw List: SuccessResponse(users) -> Data: []User @@ -69,6 +70,7 @@ func SuccessResponse[T any](data T) ApiResponse[T] { } // SuccessResponseWithMessage creates a successful API response with a custom message. +// T is the type of the response data. func SuccessResponseWithMessage[T any](data T, message string) ApiResponse[T] { return ApiResponse[T]{ Success: true, @@ -80,6 +82,7 @@ func SuccessResponseWithMessage[T any](data T, message string) ApiResponse[T] { // SuccessListResponse is a convenience wrapper for list responses. // It explicitly takes a slice and returns ApiResponse[[]T]. // This ensures that the Data field is always a JSON array. +// T is the type of items in the list. func SuccessListResponse[T any](items []T) ApiResponse[[]T] { return ApiResponse[[]T]{ Success: true, @@ -88,6 +91,7 @@ func SuccessListResponse[T any](items []T) ApiResponse[[]T] { } // SuccessListResponseWithMessage creates a successful list API response with a custom message. +// T is the type of items in the list. func SuccessListResponseWithMessage[T any](items []T, message string) ApiResponse[[]T] { return ApiResponse[[]T]{ Success: true, @@ -98,6 +102,7 @@ func SuccessListResponseWithMessage[T any](items []T, message string) ApiRespons // SuccessPagedResponse creates a successful API response with pagination details. // It automatically wraps the items and metadata into a Page struct. +// T is the type of items in the page. func SuccessPagedResponse[T any](items []T, totalCount int64, page, size int) ApiResponse[Page[T]] { hasNext := totalCount > int64(page*size) @@ -115,6 +120,15 @@ func SuccessPagedResponse[T any](items []T, totalCount int64, page, size int) Ap } } +// SimpleSuccessResponse creates a successful API response with a simple message. +// T is set to 'any' as there is no data to return. +func SimpleSuccessResponse(message string) ApiResponse[any] { + return ApiResponse[any]{ + Success: true, + Message: message, + } +} + // ErrorResponse creates an error API response with a structured error. // T is set to 'any' as there is no data to return. func ErrorResponse(errorMessage, message string) ApiResponse[any] { @@ -126,6 +140,7 @@ func ErrorResponse(errorMessage, message string) ApiResponse[any] { } // SimpleErrorResponse creates an error API response from a simple error message. +// T is set to 'any' as there is no data to return. func SimpleErrorResponse(errorMessage string) ApiResponse[any] { return ApiResponse[any]{ Success: false,