Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Correctly parse api request with application/hal+json content type

Christophe Bliardbf687d9d222f
diff --git a/lib/api/root.rb b/lib/api/root.rb
index fe64cde5e91..b13d1697767 100644
--- a/lib/api/root.rb
+++ b/lib/api/root.rb
@@ -31,6 +31,7 @@ module API
content_type "hal+json", "application/hal+json; charset=utf-8"
format "hal+json"
formatter "hal+json", API::Formatter.new
+ parser "hal+json", Grape::Parser::Json
default_format "hal+json"
parser :json, API::V3::Parser.new
diff --git a/spec/requests/api/v3/root_resource_spec.rb b/spec/requests/api/v3/root_resource_spec.rb
index 46501b452b6..069ca3dbe22 100644
--- a/spec/requests/api/v3/root_resource_spec.rb
+++ b/spec/requests/api/v3/root_resource_spec.rb
@@ -86,6 +86,17 @@ RSpec.describe "API v3 Root resource" do
expect(subject).to have_json_path("instanceName")
end
end
+
+ context "with content-type application/hal+json" do
+ before do
+ header("Content-Type", "application/hal+json")
+ end
+
+ it "responds with 200" do
+ get get_path
+ expect(response).to have_http_status(:ok)
+ end
+ end
end
end
end
diff --git a/spec/requests/api/v3/work_packages/update_resource_spec.rb b/spec/requests/api/v3/work_packages/update_resource_spec.rb
index 9113592e44f..73fa9d24a45 100644
--- a/spec/requests/api/v3/work_packages/update_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/update_resource_spec.rb
@@ -69,6 +69,12 @@ RSpec.describe "API v3 Work package resource",
end
end
+ shared_context "with application/hal+json content type" do
+ before do
+ header("Content-Type", "application/hal+json")
+ end
+ end
+
context "user without needed permissions" do
context "no permission to see the work package" do
let(:work_package) { create(:work_package) }
@@ -157,6 +163,7 @@ RSpec.describe "API v3 Work package resource",
context "subject" do
let(:params) { valid_params.merge(subject: "Updated subject") }
+ include_context "with application/hal+json content type"
include_context "patch request"
it { expect(response).to have_http_status(:ok) }