Skip to content

Commit

Permalink
Merge pull request #15920 from opf/fix/bump_grape
Browse files Browse the repository at this point in the history
bump grape
  • Loading branch information
ulferts authored Jun 28, 2024
2 parents 20f68b3 + 50b1ac7 commit f676295
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ end
gem "bootsnap", "~> 1.18.0", require: false

# API gems
gem "grape", "~> 2.0.0"
gem "grape", "~> 2.1.0"
gem "grape_logging", "~> 1.8.4"
gem "roar", "~> 1.2.0"

Expand Down
17 changes: 7 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,12 @@ GEM
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
grape (2.0.0)
activesupport (>= 5)
builder
grape (2.1.0)
activesupport (>= 6)
dry-types (>= 1.1)
mustermann-grape (~> 1.0.0)
rack (>= 1.3.0)
rack-accept
mustermann-grape (~> 1.1.0)
rack (>= 2)
zeitwerk
grape_logging (1.8.4)
grape
rack
Expand Down Expand Up @@ -733,7 +732,7 @@ GEM
multi_json (1.15.0)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
mustermann-grape (1.0.2)
mustermann-grape (1.1.0)
mustermann (>= 1.0.0)
mutex_m (0.2.0)
net-http (0.4.1)
Expand Down Expand Up @@ -849,8 +848,6 @@ GEM
raabro (1.4.0)
racc (1.8.0)
rack (2.2.9)
rack-accept (0.4.5)
rack (>= 0.4)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
rack-cors (2.0.2)
Expand Down Expand Up @@ -1216,7 +1213,7 @@ DEPENDENCIES
good_job (= 3.26.2)
google-apis-gmail_v1
googleauth
grape (~> 2.0.0)
grape (~> 2.1.0)
grape_logging (~> 1.8.4)
grids!
html-pipeline (~> 2.14.0)
Expand Down
4 changes: 2 additions & 2 deletions lib/api/root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Root < ::API::RootAPI

parser :json, API::V3::Parser.new

error_representer ::API::V3::Errors::ErrorRepresenter, "hal+json"
error_representer ::API::V3::Errors::ErrorRepresenter, "application/hal+json; charset=utf-8"
authentication_scope OpenProject::Authentication::Scope::API_V3

OpenProject::Authentication.handle_failure(scope: API_V3) do |warden, _opts|
Expand All @@ -44,7 +44,7 @@ class Root < ::API::RootAPI
api_error = ::API::Errors::Unauthenticated.new error_message
representer = ::API::V3::Errors::ErrorRepresenter.new api_error

e.error_response status: 401, message: representer.to_json, headers: warden.headers, log: false
e.error! representer.to_json, 401, warden.headers
end

version "v3", using: :path do
Expand Down
8 changes: 6 additions & 2 deletions lib/api/utilities/grape_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def initialize(env)
@env = env
@options = {}
end

def error!(message, status = nil, headers = nil, backtrace = nil, original_exception = nil)
super
end
end

def grape_error_for(env, api)
Expand Down Expand Up @@ -67,15 +71,15 @@ def default_error_response(headers, log)
original_exception = $!
representer = error_representer.new e
resp_headers = instance_exec &headers
env["api.format"] = error_content_type
resp_headers["Content-Type"] = error_content_type

if log == true
OpenProject.logger.error original_exception, reference: :APIv3
elsif log.respond_to?(:call)
log.call(original_exception)
end

error_response status: e.code, message: representer.to_json, headers: resp_headers
error!(representer.to_json, e.code, resp_headers)
}
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/api/v3/root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ class Root < ::API::OpenProjectAPI

API::OpenAPI.spec.to_yaml
end

# Catch all unknown routes (therefore have it at the end of the file)
# and return a properly formatted 404 error.
route :any, "*path" do
raise API::Errors::NotFound
end
end
end
end
2 changes: 1 addition & 1 deletion modules/bim/app/controllers/bim/bcf/api/root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Root < ::API::RootAPI

default_format :json

error_representer ::Bim::Bcf::API::V2_1::Errors::ErrorRepresenter, :json
error_representer ::Bim::Bcf::API::V2_1::Errors::ErrorRepresenter, "application/json; charset=utf-8"
error_formatter :json, ::Bim::Bcf::API::ErrorFormatter::Json

authentication_scope OpenProject::Authentication::Scope::BCF_V2_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@
context "invalid id" do
let(:get_path) { api_v3_paths.budget "bogus" }

it_behaves_like "param validation error" do
let(:id) { "bogus" }
end
it_behaves_like "not found"
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@
context "invalid id" do
let(:get_path) { api_v3_paths.cost_type "bogus" }

it_behaves_like "param validation error" do
let(:id) { "bogus" }
end
it_behaves_like "not found"
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@
context "invalid id" do
let(:get_path) { api_v3_paths.cost_type "bogus" }

it_behaves_like "param validation error" do
let(:id) { "bogus" }
end
it_behaves_like "not found"
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@
context "when invalid id" do
let(:get_path) { api_v3_paths.budget "bogus" }

it_behaves_like "param validation error" do
let(:id) { "bogus" }
end
it_behaves_like "not found"
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/features/work_packages/navigation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
visit "/projects/#{project.identifier}/work_packages?#{url_query}"

wp_table.expect_toast message: "Your view is erroneous and could not be processed.", type: :error
expect(page).to have_css "li", text: "Bad request: id is invalid"
expect(page).to have_css "li", text: "The requested resource could not be found"
end
end
end
10 changes: 2 additions & 8 deletions spec/requests/api/v3/category_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@
context "invalid priority id" do
let(:get_path) { api_v3_paths.category "bogus" }

it_behaves_like "param validation error" do
let(:id) { "bogus" }
let(:type) { "Category" }
end
it_behaves_like "not found"
end
end

Expand All @@ -116,10 +113,7 @@
get get_path
end

it_behaves_like "param validation error" do
let(:id) { "bogus" }
let(:type) { "Category" }
end
it_behaves_like "not found"
end
end
end
5 changes: 1 addition & 4 deletions spec/requests/api/v3/help_texts/help_texts_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@
context "invalid type id" do
let(:get_path) { api_v3_paths.type "bogus" }

it_behaves_like "param validation error" do
let(:id) { "bogus" }
let(:type) { "HelpText" }
end
it_behaves_like "not found"
end

context "invisible type id" do
Expand Down
5 changes: 1 addition & 4 deletions spec/requests/api/v3/priority_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@
context "invalid priority id" do
let(:get_path) { api_v3_paths.priority "bogus" }

it_behaves_like "param validation error" do
let(:id) { "bogus" }
let(:type) { "IssuePriority" }
end
it_behaves_like "not found"
end
end

Expand Down
5 changes: 1 addition & 4 deletions spec/requests/api/v3/status_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@
context "invalid status id" do
let(:get_path) { api_v3_paths.status "bogus" }

it_behaves_like "param validation error" do
let(:id) { "bogus" }
let(:type) { "Status" }
end
it_behaves_like "not found"
end
end

Expand Down
5 changes: 1 addition & 4 deletions spec/requests/api/v3/types/type_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@
context "invalid type id" do
let(:get_path) { api_v3_paths.type "bogus" }

it_behaves_like "param validation error" do
let(:id) { "bogus" }
let(:type) { "Type" }
end
it_behaves_like "not found"
end
end

Expand Down

0 comments on commit f676295

Please sign in to comment.