Skip to content

Commit 3406b99

Browse files
committed
feat: formatting some error messages
This commits adds some clarity to the end users about what it is failing on their end, adding values does not match, value X is not part of the enum, etc.. So for end-users it's a bit easier to understand. Signed-off-by: Eloy Coto <eloy.coto@acalustra.com>
1 parent 83dd2ff commit 3406b99

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

openapi3/schema.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ func (schema *Schema) visitSetOperations(settings *schemaValidationSettings, val
883883
Value: value,
884884
Schema: schema,
885885
SchemaField: "enum",
886-
Reason: "value is not one of the allowed values",
886+
Reason: fmt.Sprintf("value %q is not one of the allowed values", value),
887887
customizeMessageError: settings.customizeMessageError,
888888
}
889889
}
@@ -1085,7 +1085,7 @@ func (schema *Schema) visitJSONNumber(settings *schemaValidationSettings, value
10851085
Value: value,
10861086
Schema: schema,
10871087
SchemaField: "type",
1088-
Reason: "Value must be an integer",
1088+
Reason: fmt.Sprintf("Value \"%g\" must be an integer", value),
10891089
customizeMessageError: settings.customizeMessageError,
10901090
}
10911091
if !settings.multiError {
@@ -1305,7 +1305,7 @@ func (schema *Schema) visitJSONString(settings *schemaValidationSettings, value
13051305
Value: value,
13061306
Schema: schema,
13071307
SchemaField: "pattern",
1308-
Reason: fmt.Sprintf(`string doesn't match the regular expression "%s"`, schema.Pattern),
1308+
Reason: fmt.Sprintf(`value %q doesn't match the regular expression "%s"`, value, schema.Pattern),
13091309
customizeMessageError: settings.customizeMessageError,
13101310
}
13111311
if !settings.multiError {
@@ -1322,7 +1322,7 @@ func (schema *Schema) visitJSONString(settings *schemaValidationSettings, value
13221322
switch {
13231323
case f.regexp != nil && f.callback == nil:
13241324
if cp := f.regexp; !cp.MatchString(value) {
1325-
formatStrErr = fmt.Sprintf(`string doesn't match the format %q (regular expression "%s")`, format, cp.String())
1325+
formatStrErr = fmt.Sprintf(`value %q doesn't match the format %q (regular expression "%s")`, value, format, cp.String())
13261326
}
13271327
case f.regexp == nil && f.callback != nil:
13281328
if err := f.callback(value); err != nil {
@@ -1650,7 +1650,7 @@ func (schema *Schema) expectedType(settings *schemaValidationSettings, typ strin
16501650
Value: typ,
16511651
Schema: schema,
16521652
SchemaField: "type",
1653-
Reason: "Field must be set to " + schema.Type + " or not be present",
1653+
Reason: fmt.Sprintf("Field must be set to %q or not be present", schema.Type),
16541654
customizeMessageError: settings.customizeMessageError,
16551655
}
16561656
}

0 commit comments

Comments
 (0)