Skip to content

Commit d315d71

Browse files
FrancisLennon17francis-lennon-whs
andauthored
Disable Format Validation Bool (#202)
Co-authored-by: Francis Lennon <[email protected]>
1 parent 156b7ea commit d315d71

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

openapi3/schema.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ var (
1919
// SchemaErrorDetailsDisabled disables printing of details about schema errors.
2020
SchemaErrorDetailsDisabled = false
2121

22+
//SchemaFormatValidationDisabled disables validation of schema type formats.
23+
SchemaFormatValidationDisabled = false
24+
2225
errSchema = errors.New("Input does not match the schema")
2326

2427
ErrSchemaInputNaN = errors.New("NaN is not allowed")
@@ -496,15 +499,19 @@ func (schema *Schema) validate(c context.Context, stack []*Schema) (err error) {
496499
switch format {
497500
case "float", "double":
498501
default:
499-
return unsupportedFormat(format)
502+
if !SchemaFormatValidationDisabled {
503+
return unsupportedFormat(format)
504+
}
500505
}
501506
}
502507
case "integer":
503508
if format := schema.Format; len(format) > 0 {
504509
switch format {
505510
case "int32", "int64":
506511
default:
507-
return unsupportedFormat(format)
512+
if !SchemaFormatValidationDisabled {
513+
return unsupportedFormat(format)
514+
}
508515
}
509516
}
510517
case "string":
@@ -520,7 +527,7 @@ func (schema *Schema) validate(c context.Context, stack []*Schema) (err error) {
520527
case "json-pointer", "relative-json-pointer":
521528
default:
522529
// Try to check for custom defined formats
523-
if _, ok := SchemaStringFormats[format]; !ok {
530+
if _, ok := SchemaStringFormats[format]; !ok && !SchemaFormatValidationDisabled {
524531
return unsupportedFormat(format)
525532
}
526533
}

0 commit comments

Comments
 (0)