Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion errors/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ func TestErr(t *testing.T) {

err = err.WithError(otherError)

assert.Equal(t, otherError.Error(), err.Error())
assert.Equal(t, expectedMessage, err.Error(), "WithError should not override an explicit error message")
assert.Equal(t, otherError, errors.Unwrap(err), "WithError should set the source error for debug/logging")
}
9 changes: 9 additions & 0 deletions middleware/body_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ func (m BodyDecoder) Doc(builder *openapi.DocBuilder) error {
builder.WithBody(m.BodyPtr, openapi.WithMimeType(contentType))
}

builder.
WithError(400, "invalid_content_type", "Unable to resolve content type").
WithError(400, "body_error", "Failed to read request body").
WithError(400, "invalid_body_format", "Failed to decode request body").
WithError(400, "missing_param", "A required field is missing").
WithError(400, "body_validation_failed", "A field does not match the required pattern").
WithError(400, "enum_validation_failed", "A field value is not in the allowed enum values").
WithError(400, "invalid_body", "Body validation failed")

return builder.Error()
}

Expand Down
6 changes: 5 additions & 1 deletion middleware/path_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,9 @@ func (m PathParameters) Doc(builder *openapi.DocBuilder) error {
return nil
}

return builder.WithParams(m.Parameters).Error()
builder.
WithParams(m.Parameters).
WithError(400, "invalid_param_type", "A path parameter has an invalid type")

return builder.Error()
}
6 changes: 5 additions & 1 deletion middleware/query_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ func (m QueryParameters) Doc(builder *openapi.DocBuilder) error {
return nil
}

return builder.WithParams(m.Parameters).Error()
builder.
WithParams(m.Parameters).
WithError(422, "query_params_encoding", "Failed to decode query parameters")

return builder.Error()
}