Skip to content

Commit d8df1bd

Browse files
author
Hein
committed
feat(funcspec): ✨ add JSON and UUID handling in normalization
* Enhance normalization to support JSON strings as json.RawMessage * Add support for UUID formatting * Maintain existing behavior for other types
1 parent c0c669b commit d8df1bd

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

pkg/funcspec/function_api.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"strings"
1313
"time"
1414

15+
"github.com/google/uuid"
16+
1517
"github.com/bitechdev/ResolveSpec/pkg/common"
1618
"github.com/bitechdev/ResolveSpec/pkg/logger"
1719
"github.com/bitechdev/ResolveSpec/pkg/restheadspec"
@@ -1099,9 +1101,25 @@ func normalizePostgresValue(value interface{}) interface{} {
10991101
case map[string]interface{}:
11001102
// Recursively normalize nested maps
11011103
return normalizePostgresTypes(v)
1102-
1104+
case string:
1105+
var jsonObj interface{}
1106+
if err := json.Unmarshal([]byte(v), &jsonObj); err == nil {
1107+
// It's valid JSON, return as json.RawMessage so it's not double-encoded
1108+
return json.RawMessage(v)
1109+
}
1110+
return v
1111+
case uuid.UUID:
1112+
return v.String()
1113+
case time.Time:
1114+
return v.Format(time.RFC3339)
1115+
case bool, int, int8, int16, int32, int64, float32, float64, uint, uint8, uint16, uint32, uint64:
1116+
return v
11031117
default:
1104-
// For other types (int, float, string, bool, etc.), return as-is
1118+
// For other types (int, float, bool, etc.), return as-is
1119+
// Check stringers
1120+
if str, ok := v.(fmt.Stringer); ok {
1121+
return str.String()
1122+
}
11051123
return v
11061124
}
11071125
}

0 commit comments

Comments
 (0)