Skip to content

Commit

Permalink
Disable Format Validation Bool (#202)
Browse files Browse the repository at this point in the history
Co-authored-by: Francis Lennon <francis.lennon@whitehatsec.com>
  • Loading branch information
FrancisLennon17 and francis-lennon-whs authored Apr 20, 2020
1 parent 156b7ea commit d315d71
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions openapi3/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var (
// SchemaErrorDetailsDisabled disables printing of details about schema errors.
SchemaErrorDetailsDisabled = false

//SchemaFormatValidationDisabled disables validation of schema type formats.
SchemaFormatValidationDisabled = false

errSchema = errors.New("Input does not match the schema")

ErrSchemaInputNaN = errors.New("NaN is not allowed")
Expand Down Expand Up @@ -496,15 +499,19 @@ func (schema *Schema) validate(c context.Context, stack []*Schema) (err error) {
switch format {
case "float", "double":
default:
return unsupportedFormat(format)
if !SchemaFormatValidationDisabled {
return unsupportedFormat(format)
}
}
}
case "integer":
if format := schema.Format; len(format) > 0 {
switch format {
case "int32", "int64":
default:
return unsupportedFormat(format)
if !SchemaFormatValidationDisabled {
return unsupportedFormat(format)
}
}
}
case "string":
Expand All @@ -520,7 +527,7 @@ func (schema *Schema) validate(c context.Context, stack []*Schema) (err error) {
case "json-pointer", "relative-json-pointer":
default:
// Try to check for custom defined formats
if _, ok := SchemaStringFormats[format]; !ok {
if _, ok := SchemaStringFormats[format]; !ok && !SchemaFormatValidationDisabled {
return unsupportedFormat(format)
}
}
Expand Down

0 comments on commit d315d71

Please sign in to comment.