Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure we catch all OpenAPIParser::OpenAPIError classes when coercing path parameters for OpenAPI 3 #228

Merged
merged 2 commits into from
Jul 18, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def coerce_path_parameter(validator_option)
return {} unless options.coerce_value

request_operation.validate_path_params(options)
rescue OpenAPIParser::NotExistRequiredKey => e
rescue OpenAPIParser::OpenAPIError => e
raise Committee::InvalidRequest.new(e.message)
end

Expand Down
11 changes: 11 additions & 0 deletions test/middleware/request_validation_open_api_3_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@ def app
assert_match(/required parameters query_string not exist in/i, e.message)
end

it "raises error when required path parameter is invalid" do
@app = new_rack_app(raise: true, schema: open_api_3_schema)

e = assert_raises(Committee::InvalidRequest) do
not_an_integer = 'abc'
get "/coerce_path_params/#{not_an_integer}", nil
end

assert_match(/is String but it's not valid integer in/i, e.message)
end

it "optionally raises an error" do
@app = new_rack_app(raise: true, schema: open_api_3_schema)
header "Content-Type", "application/json"
Expand Down