diff --git a/openapi3/example_validation_test.go b/openapi3/example_validation_test.go index 85e158e6b..177360c13 100644 --- a/openapi3/example_validation_test.go +++ b/openapi3/example_validation_test.go @@ -26,7 +26,7 @@ func TestExamplesSchemaValidation(t *testing.T) { param1example: value: abcd `, - errContains: "invalid paths: param1example", + errContains: "invalid paths: invalid path /user: invalid operation POST: param1example", }, { name: "valid_parameter_examples", @@ -64,7 +64,7 @@ func TestExamplesSchemaValidation(t *testing.T) { email: bad password: short `, - errContains: "invalid paths: BadUser", + errContains: "invalid paths: invalid path /user: invalid operation POST: BadUser", }, { name: "valid_component_examples", diff --git a/openapi3/loader_test.go b/openapi3/loader_test.go index 64a923c39..d492e2471 100644 --- a/openapi3/loader_test.go +++ b/openapi3/loader_test.go @@ -96,7 +96,7 @@ func TestResolveSchemaRefWithNullSchemaRef(t *testing.T) { doc, err := loader.LoadFromData(source) require.NoError(t, err) err = doc.Validate(loader.Context) - require.EqualError(t, err, `invalid paths: found unresolved ref: ""`) + require.EqualError(t, err, `invalid paths: invalid path /foo: invalid operation POST: found unresolved ref: ""`) } func TestResolveResponseExampleRef(t *testing.T) { diff --git a/openapi3/path_item.go b/openapi3/path_item.go index 4801e5f83..940b1592a 100644 --- a/openapi3/path_item.go +++ b/openapi3/path_item.go @@ -134,7 +134,7 @@ func (pathItem *PathItem) Validate(ctx context.Context) error { for _, method := range methods { operation := operations[method] if err := operation.Validate(ctx); err != nil { - return err + return fmt.Errorf("invalid operation %s: %v", method, err) } } return nil diff --git a/openapi3/paths.go b/openapi3/paths.go index b116f6cb6..e3da7d05b 100644 --- a/openapi3/paths.go +++ b/openapi3/paths.go @@ -96,7 +96,7 @@ func (paths Paths) Validate(ctx context.Context) error { } if err := pathItem.Validate(ctx); err != nil { - return err + return fmt.Errorf("invalid path %s: %v", path, err) } } diff --git a/openapi3/response_issue224_test.go b/openapi3/response_issue224_test.go index 97c7e6b20..5de0525e4 100644 --- a/openapi3/response_issue224_test.go +++ b/openapi3/response_issue224_test.go @@ -457,5 +457,5 @@ func TestEmptyResponsesAreInvalid(t *testing.T) { require.NoError(t, err) require.Equal(t, doc.ExternalDocs.Description, "See AsyncAPI example") err = doc.Validate(context.Background()) - require.EqualError(t, err, `invalid paths: the responses object MUST contain at least one response code`) + require.EqualError(t, err, `invalid paths: invalid path /pet: invalid operation POST: the responses object MUST contain at least one response code`) }