Skip to content

Commit fa5d9a9

Browse files
authored
Improve error message when path validation fails (#605)
1 parent 62f85cf commit fa5d9a9

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

openapi3/example_validation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestExamplesSchemaValidation(t *testing.T) {
2626
param1example:
2727
value: abcd
2828
`,
29-
errContains: "invalid paths: param1example",
29+
errContains: "invalid paths: invalid path /user: invalid operation POST: param1example",
3030
},
3131
{
3232
name: "valid_parameter_examples",
@@ -64,7 +64,7 @@ func TestExamplesSchemaValidation(t *testing.T) {
6464
email: bad
6565
password: short
6666
`,
67-
errContains: "invalid paths: BadUser",
67+
errContains: "invalid paths: invalid path /user: invalid operation POST: BadUser",
6868
},
6969
{
7070
name: "valid_component_examples",

openapi3/loader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestResolveSchemaRefWithNullSchemaRef(t *testing.T) {
9696
doc, err := loader.LoadFromData(source)
9797
require.NoError(t, err)
9898
err = doc.Validate(loader.Context)
99-
require.EqualError(t, err, `invalid paths: found unresolved ref: ""`)
99+
require.EqualError(t, err, `invalid paths: invalid path /foo: invalid operation POST: found unresolved ref: ""`)
100100
}
101101

102102
func TestResolveResponseExampleRef(t *testing.T) {

openapi3/path_item.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (pathItem *PathItem) Validate(ctx context.Context) error {
134134
for _, method := range methods {
135135
operation := operations[method]
136136
if err := operation.Validate(ctx); err != nil {
137-
return err
137+
return fmt.Errorf("invalid operation %s: %v", method, err)
138138
}
139139
}
140140
return nil

openapi3/paths.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (paths Paths) Validate(ctx context.Context) error {
9696
}
9797

9898
if err := pathItem.Validate(ctx); err != nil {
99-
return err
99+
return fmt.Errorf("invalid path %s: %v", path, err)
100100
}
101101
}
102102

openapi3/response_issue224_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,5 +457,5 @@ func TestEmptyResponsesAreInvalid(t *testing.T) {
457457
require.NoError(t, err)
458458
require.Equal(t, doc.ExternalDocs.Description, "See AsyncAPI example")
459459
err = doc.Validate(context.Background())
460-
require.EqualError(t, err, `invalid paths: the responses object MUST contain at least one response code`)
460+
require.EqualError(t, err, `invalid paths: invalid path /pet: invalid operation POST: the responses object MUST contain at least one response code`)
461461
}

0 commit comments

Comments
 (0)