From 0b6e02983a0fc16f3e2d40da900583c496e0faa9 Mon Sep 17 00:00:00 2001 From: Rodrigo Fernandes Date: Wed, 4 Aug 2021 11:35:25 +0100 Subject: [PATCH] feature: Always show more specific error message --- openapi3/schema.go | 12 ------------ routers/legacy/validate_request_test.go | 24 ++---------------------- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/openapi3/schema.go b/openapi3/schema.go index fa9441d45..99c072a23 100644 --- a/openapi3/schema.go +++ b/openapi3/schema.go @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/routers/legacy/validate_request_test.go b/routers/legacy/validate_request_test.go index 7737f5028..5b9518c78 100644 --- a/routers/legacy/validate_request_test.go +++ b/routers/legacy/validate_request_test.go @@ -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 + }