mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-01-20 09:34:27 +00:00
feat(funcspec): ✨ add JSON and UUID handling in normalization
Some checks failed
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in -27m50s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in -27m25s
Build , Vet Test, and Lint / Lint Code (push) Successful in -27m22s
Build , Vet Test, and Lint / Build (push) Successful in -27m31s
Tests / Unit Tests (push) Successful in -27m54s
Tests / Integration Tests (push) Failing after -28m3s
Some checks failed
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in -27m50s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in -27m25s
Build , Vet Test, and Lint / Lint Code (push) Successful in -27m22s
Build , Vet Test, and Lint / Build (push) Successful in -27m31s
Tests / Unit Tests (push) Successful in -27m54s
Tests / Integration Tests (push) Failing after -28m3s
* Enhance normalization to support JSON strings as json.RawMessage * Add support for UUID formatting * Maintain existing behavior for other types
This commit is contained in:
@@ -12,6 +12,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"github.com/bitechdev/ResolveSpec/pkg/common"
|
"github.com/bitechdev/ResolveSpec/pkg/common"
|
||||||
"github.com/bitechdev/ResolveSpec/pkg/logger"
|
"github.com/bitechdev/ResolveSpec/pkg/logger"
|
||||||
"github.com/bitechdev/ResolveSpec/pkg/restheadspec"
|
"github.com/bitechdev/ResolveSpec/pkg/restheadspec"
|
||||||
@@ -1099,9 +1101,25 @@ func normalizePostgresValue(value interface{}) interface{} {
|
|||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
// Recursively normalize nested maps
|
// Recursively normalize nested maps
|
||||||
return normalizePostgresTypes(v)
|
return normalizePostgresTypes(v)
|
||||||
|
case string:
|
||||||
|
var jsonObj interface{}
|
||||||
|
if err := json.Unmarshal([]byte(v), &jsonObj); err == nil {
|
||||||
|
// It's valid JSON, return as json.RawMessage so it's not double-encoded
|
||||||
|
return json.RawMessage(v)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
case uuid.UUID:
|
||||||
|
return v.String()
|
||||||
|
case time.Time:
|
||||||
|
return v.Format(time.RFC3339)
|
||||||
|
case bool, int, int8, int16, int32, int64, float32, float64, uint, uint8, uint16, uint32, uint64:
|
||||||
|
return v
|
||||||
default:
|
default:
|
||||||
// For other types (int, float, string, bool, etc.), return as-is
|
// For other types (int, float, bool, etc.), return as-is
|
||||||
|
// Check stringers
|
||||||
|
if str, ok := v.(fmt.Stringer); ok {
|
||||||
|
return str.String()
|
||||||
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user