Skip to content
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 api/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "{{",
Expand Down
4 changes: 2 additions & 2 deletions api/swagger.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 3 additions & 2 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions cmd/cm-beetle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions deployments/docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 17 additions & 6 deletions pkg/api/rest/middlewares/response-dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions pkg/api/rest/model/beetle/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)

Expand All @@ -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] {
Expand All @@ -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,
Expand Down