Skip to content

Commit 148a9ac

Browse files
committed
Fix whitespace handling in type mismatch error messages
1 parent e5d4465 commit 148a9ac

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

common.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ func parseInput[TInput any](app *OApiApp, c *fiber.Ctx, path string, options *Op
6767
fieldNameParts := strings.Split(fullFieldName, ".")
6868
fieldName := fieldNameParts[len(fieldNameParts)-1]
6969

70-
// Extract expected type
71-
expectedType := fieldParts[1]
70+
// Extract expected type and trim whitespace
71+
expectedType := strings.TrimSpace(fieldParts[1])
7272

73-
// Extract actual type from the first part
74-
typePart := strings.TrimPrefix(parts[0], "json: cannot unmarshal ")
73+
// Extract actual type from the first part and trim whitespace
74+
typePart := strings.TrimSpace(strings.TrimPrefix(parts[0], "json: cannot unmarshal "))
7575

7676
return input, fmt.Errorf("invalid type for field '%s': expected %s but got %s",
7777
fieldName, expectedType, typePart)

0 commit comments

Comments
 (0)