diff --git a/Gemfile b/Gemfile index 106cbf2eff6d..4c7f40441afc 100644 --- a/Gemfile +++ b/Gemfile @@ -385,7 +385,7 @@ group :development, :test do end # API gems -gem "grape", "~> 3.2.0" +gem "grape", "~> 3.3.0" gem "grape_logging", "~> 3.0.0" gem "roar", "~> 1.2.0" diff --git a/Gemfile.lock b/Gemfile.lock index 071a6a3b7f45..1592533ae033 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -693,13 +693,13 @@ GEM os (>= 0.9, < 2.0) pstore (~> 0.1) signet (>= 0.16, < 2.a) - grape (3.2.1) + grape (3.3.0) activesupport (>= 7.2) - dry-configurable + dry-configurable (>= 1.0) dry-types (>= 1.1) - mustermann-grape (~> 1.1.0) - rack (>= 2) - zeitwerk + mustermann (>= 4.0) + rack (>= 2.2.4) + zeitwerk (>= 2.6) grape_logging (3.0.0) grape (>= 2.4.0) rack @@ -856,8 +856,6 @@ GEM msgpack (1.8.3) multi_json (1.21.1) mustermann (4.0.0) - mustermann-grape (1.1.0) - mustermann (>= 1.0.0) net-http (0.9.1) uri (>= 0.11.1) net-imap (0.6.4.1) @@ -1638,7 +1636,7 @@ DEPENDENCIES good_job (~> 4.19.1) google-apis-gmail_v1 googleauth - grape (~> 3.2.0) + grape (~> 3.3.0) grape_logging (~> 3.0.0) grids! html-pipeline (~> 2.14.0) @@ -1967,7 +1965,7 @@ CHECKSUMS google-protobuf (4.35.1-x86_64-linux-musl) sha256=91890eb0002934a339fdb7d77a147c46b7474b6799db27872b747b905837f744 googleapis-common-protos-types (1.23.0) sha256=992e740a523794d9fc5f29a504465d8fc737aaa16c930fe7228e3346860faf0a googleauth (1.17.1) sha256=0f7e6fc70e204cee1b2d71f1e1de2d3b349d432404197fe68ebf7fa23d0821b9 - grape (3.2.1) sha256=448072f55904e5a4dca2e3781f0a373942514be65402cafb6177f5bc73db1b94 + grape (3.3.0) sha256=65e48ad2e396d25304cde91f0ec307e6cafc76bb78adcdb070fbbcc2ec3d4361 grape_logging (3.0.0) sha256=7b62d984ce96df15d120508668debe307e6a59ac1c511f1d9b5f3b4bea793e13 gravatar_image_tag (1.2.0) sha256=eb5630fea846b711e713b934a0178fb9785f02f4eb9ced8d6faa4d537c40fdcf grids (1.0.0) @@ -2032,7 +2030,6 @@ CHECKSUMS msgpack (1.8.3) sha256=8bda4a6428d3244e50d6bd55854d354edbada88a4e1f4f5731a39a0f86bee6a1 multi_json (1.21.1) sha256=e6126a31808e3b4d19f483c775ceac34df190dffa62adfb63a165ee14ba68080 mustermann (4.0.0) sha256=91f67411bb208d1d93c41e6128cb3b0f8ddd9ec7c45966f1007e1c43c08040d7 - mustermann-grape (1.1.0) sha256=8d258a986004c8f01ce4c023c0b037c168a9ed889cf5778068ad54398fa458c5 my_page (1.0.0) net-http (0.9.1) sha256=25ba0b67c63e89df626ed8fac771d0ad24ad151a858af2cc8e6a716ca4336996 net-imap (0.6.4.1) sha256=29f0360d75a7efd3539f16ac1957dea5c0a51ddeceb348db4553c3120914ea0d diff --git a/lib/api/utilities/grape_helper.rb b/lib/api/utilities/grape_helper.rb index b1ffd7915c5a..32f6c52773b0 100644 --- a/lib/api/utilities/grape_helper.rb +++ b/lib/api/utilities/grape_helper.rb @@ -34,9 +34,9 @@ module GrapeHelper # outside of the Grape context. We use it outside of the Grape context because # OpenProject authentication happens in a middleware upstream of Grape. class GrapeError < Grape::Middleware::Error - def initialize(env) + def initialize(env, content_types:, format:) + super(nil, content_types:, format:) @env = env - @options = {} end def error!(message, status = nil, headers = nil, backtrace = nil, original_exception = nil) @@ -45,13 +45,10 @@ def error!(message, status = nil, headers = nil, backtrace = nil, original_excep end def grape_error_for(env, api) - GrapeError.new(env).tap do |e| - e.options[:content_types] = api.content_types - e.options[:format] = "hal+json" - end + GrapeError.new(env, content_types: api.content_types, format: "hal+json") end - def error_response(rescued_error, error = nil, rescue_subclasses: nil, headers: -> { {} }, log: true) + def error_response(rescued_error, error = nil, rescue_subclasses: true, headers: -> { {} }, log: true) error_response_lambda = default_error_response(headers, log) response = diff --git a/lib/api/utilities/json_gem_parser.rb b/lib/api/utilities/json_gem_parser.rb deleted file mode 100644 index a097eafd55cd..000000000000 --- a/lib/api/utilities/json_gem_parser.rb +++ /dev/null @@ -1,11 +0,0 @@ -# Forces using the classic json gem when parsing. -# This might be beneficial in cases where other parsers, orchestrated by MultiJSON misbehave. -# This is e.g. the case with oj which sometimes turns numbers into BigDecimal values. -module API::Utilities::JsonGemParser - def self.call(object, _) - ::Grape::Json.load(object, adapter: :json_gem) - rescue ::Grape::Json::ParseError - # handle JSON parsing errors via the rescue handlers or provide error message - raise Grape::Exceptions::InvalidMessageBody, "application/json" - end -end diff --git a/lib/api/v3/utilities/eprops_conversion.rb b/lib/api/v3/utilities/eprops_conversion.rb index b1fbd702175b..c1ce154f4875 100644 --- a/lib/api/v3/utilities/eprops_conversion.rb +++ b/lib/api/v3/utilities/eprops_conversion.rb @@ -37,8 +37,9 @@ module EpropsConversion DECOMPRESS_CHUNK_SIZE = 16 * 1024 def raise_invalid_eprops(error, i18n_key) - mapped_error = OpenStruct.new(params: [:eprops], message: I18n.t(i18n_key, message: error.message)) - raise ::Grape::Exceptions::ValidationErrors.new errors: [mapped_error] + mapped_error = ::Grape::Exceptions::Validation.new(params: [:eprops], + message: I18n.t(i18n_key, message: error.message)) + raise ::Grape::Exceptions::ValidationErrors.new(exceptions: [mapped_error]) end def transform_eprops diff --git a/lib/open_project/patches/grape_dsl_routing.rb b/lib/open_project/patches/grape_dsl_routing.rb index d95311b0b886..c7825b5a8d17 100644 --- a/lib/open_project/patches/grape_dsl_routing.rb +++ b/lib/open_project/patches/grape_dsl_routing.rb @@ -56,6 +56,6 @@ def patches end end -OpenProject::Patches.patch_gem_version "grape", "3.2.1" do +OpenProject::Patches.patch_gem_version "grape", "3.3.1" do Grape::DSL::Routing.include OpenProject::Patches::GrapeDslRouting end diff --git a/modules/bim/app/controllers/bim/bcf/api/v2_1/viewpoints/api.rb b/modules/bim/app/controllers/bim/bcf/api/v2_1/viewpoints/api.rb index 8a4b390d341f..6715a34e2a0f 100644 --- a/modules/bim/app/controllers/bim/bcf/api/v2_1/viewpoints/api.rb +++ b/modules/bim/app/controllers/bim/bcf/api/v2_1/viewpoints/api.rb @@ -29,9 +29,6 @@ module Bim::Bcf::API::V2_1 module Viewpoints class API < ::API::OpenProjectAPI - # Avoid oj parsing numbers into BigDecimal - parser :json, ::API::Utilities::JsonGemParser - resources :viewpoints do get do @issue diff --git a/modules/bim/app/formatters/bim/bcf/api/error_formatter/bcf_json.rb b/modules/bim/app/formatters/bim/bcf/api/error_formatter/bcf_json.rb index 4c852c0fbf4e..9005647145a6 100644 --- a/modules/bim/app/formatters/bim/bcf/api/error_formatter/bcf_json.rb +++ b/modules/bim/app/formatters/bim/bcf/api/error_formatter/bcf_json.rb @@ -31,8 +31,8 @@ module API module ErrorFormatter class BcfJson < Grape::ErrorFormatter::Base class << self - def call(message, _backtrace, _options = {}, env = nil, _original_exception = nil) - present(message, env) + def call(error:, env: nil, **_) + present(error.message, env) end end end