You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Custom function to change schema error messages
203
+
204
+
By default, the error message returned when validating a value includes the error reason, the schema, and the input value.
205
+
206
+
For example, given the following schema:
207
+
208
+
```json
209
+
{
210
+
"type": "string",
211
+
"allOf": [
212
+
{ "pattern": "[A-Z]" },
213
+
{ "pattern": "[a-z]" },
214
+
{ "pattern": "[0-9]" },
215
+
{ "pattern": "[!@#$%^&*()_+=-?~]" }
216
+
]
217
+
}
218
+
```
219
+
220
+
Passing the input value `"secret"` to this schema will produce the following error message:
221
+
222
+
```
223
+
string doesn't match the regular expression "[A-Z]"
224
+
Schema:
225
+
{
226
+
"pattern": "[A-Z]"
227
+
}
228
+
229
+
Value:
230
+
"secret"
231
+
```
232
+
233
+
Including the original value in the error message can be helpful for debugging, but it may not be appropriate for sensitive information such as secrets.
234
+
235
+
To disable the extra details in the schema error message, you can set the `openapi3.SchemaErrorDetailsDisabled` option to `true`:
236
+
237
+
```go
238
+
funcmain() {
239
+
// ...
240
+
241
+
// Disable schema error detailed error messages
242
+
openapi3.SchemaErrorDetailsDisabled = true
243
+
244
+
// ... other validate codes
245
+
}
246
+
```
247
+
248
+
This will shorten the error message to present only the reason:
249
+
250
+
```
251
+
string doesn't match the regular expression "[A-Z]"
252
+
```
253
+
254
+
For more fine-grained control over the error message, you can pass a custom `openapi3filter.Options` object to `openapi3filter.RequestValidationInput` that includes a `openapi3filter.CustomSchemaErrorFunc`.
0 commit comments