Skip to content

Commit

Permalink
Improve error message when path validation fails (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
praneetloke authored Sep 22, 2022
1 parent 62f85cf commit fa5d9a9
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions openapi3/example_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion openapi3/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion openapi3/path_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion openapi3/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion openapi3/response_issue224_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}

0 comments on commit fa5d9a9

Please sign in to comment.