Commit 60aaff3b authored by Robert May's avatar Robert May

Enable Grape/Gitlab::Json hook

Changelog: performance
parent f536b8cd
---
name: grape_gitlab_json
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/36472
rollout_issue_url:
milestone: '13.2'
type: development
group: group::source code
default_enabled: true
......@@ -180,9 +180,6 @@ module Gitlab
class GrapeFormatter
# Convert an object to JSON.
#
# This will default to the built-in Grape formatter if either :oj_json or :grape_gitlab_json
# flags are disabled.
#
# The `env` param is ignored because it's not needed in either our formatter or Grape's,
# but it is passed through for consistency.
#
......@@ -194,11 +191,7 @@ module Gitlab
def self.call(object, env = nil)
return object.to_s if object.is_a?(PrecompiledJson)
if Feature.enabled?(:grape_gitlab_json, default_enabled: true)
Gitlab::Json.dump(object)
else
Grape::Formatter::Json.call(object, env)
end
Gitlab::Json.dump(object)
end
end
......
......@@ -317,36 +317,14 @@ RSpec.describe Gitlab::Json do
let(:env) { {} }
let(:result) { "{\"test\":true}" }
context "grape_gitlab_json flag is enabled" do
before do
stub_feature_flags(grape_gitlab_json: true)
end
it "generates JSON" do
expect(subject).to eq(result)
end
it "uses Gitlab::Json" do
expect(Gitlab::Json).to receive(:dump).with(obj)
subject
end
it "generates JSON" do
expect(subject).to eq(result)
end
context "grape_gitlab_json flag is disabled" do
before do
stub_feature_flags(grape_gitlab_json: false)
end
it "uses Gitlab::Json" do
expect(Gitlab::Json).to receive(:dump).with(obj)
it "generates JSON" do
expect(subject).to eq(result)
end
it "uses Grape::Formatter::Json" do
expect(Grape::Formatter::Json).to receive(:call).with(obj, env)
subject
end
subject
end
context "precompiled JSON" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment