Skip to content

Commit

Permalink
feature: Always show more specific error message
Browse files Browse the repository at this point in the history
  • Loading branch information
rtfpessoa committed Aug 4, 2021
1 parent 0b13715 commit 0b6e029
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 34 deletions.
12 changes: 0 additions & 12 deletions openapi3/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,10 +825,7 @@ func (schema *Schema) visitSetOperations(settings *schemaValidationSettings, val
if v == nil {
return foundUnresolvedRef(ref.Ref)
}
var oldfailfast bool
oldfailfast, settings.failfast = settings.failfast, true
err := v.visitJSON(settings, value)
settings.failfast = oldfailfast
if err == nil {
if settings.failfast {
return errSchema
Expand Down Expand Up @@ -869,10 +866,7 @@ func (schema *Schema) visitSetOperations(settings *schemaValidationSettings, val
continue
}

var oldfailfast bool
oldfailfast, settings.failfast = settings.failfast, true
err := v.visitJSON(settings, value)
settings.failfast = oldfailfast
if err != nil {
validationErrors = append(validationErrors, err)
continue
Expand Down Expand Up @@ -914,10 +908,7 @@ func (schema *Schema) visitSetOperations(settings *schemaValidationSettings, val
if v == nil {
return foundUnresolvedRef(item.Ref)
}
var oldfailfast bool
oldfailfast, settings.failfast = settings.failfast, true
err := v.visitJSON(settings, value)
settings.failfast = oldfailfast
if err == nil {
ok = true
break
Expand All @@ -940,10 +931,7 @@ func (schema *Schema) visitSetOperations(settings *schemaValidationSettings, val
if v == nil {
return foundUnresolvedRef(item.Ref)
}
var oldfailfast bool
oldfailfast, settings.failfast = settings.failfast, false
err := v.visitJSON(settings, value)
settings.failfast = oldfailfast
if err != nil {
if settings.failfast {
return errSchema
Expand Down
24 changes: 2 additions & 22 deletions routers/legacy/validate_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,6 @@ func Example() {
fmt.Println(err)
}
// Output:
// request body has an error: doesn't match the schema: Doesn't match schema "oneOf"
// Schema:
// {
// "discriminator": {
// "propertyName": "pet_type"
// },
// "oneOf": [
// {
// "$ref": "#/components/schemas/Cat"
// },
// {
// "$ref": "#/components/schemas/Dog"
// }
// ]
// }
//
// Value:
// {
// "bark": true,
// "breed": "Dingo",
// "pet_type": "Cat"
// }
// request body has an error: doesn't match the schema: input matches more than one oneOf schemas

}

0 comments on commit 0b6e029

Please sign in to comment.