• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ruby-grape / grape / 33252737439
97%
master: 97%

Build:
Build:
LAST BUILD BRANCH: mount-refresh-internal
DEFAULT BRANCH: master
Ran 29 Aug 2026 12:32PM UTC
Jobs 32
Files 169
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

29 Aug 2026 12:31PM UTC coverage: 96.998% (+0.01%) from 96.988%
33252737439

Pull #2869

github

ericproulx
Add Grape::PrecompiledJson for bodies that are already JSON

The JSON formatters encode whatever the endpoint returned, so a String holding
pre-rendered JSON -- a blob cached in Redis, a json_agg column read straight
from Postgres, output from another serializer -- comes back encoded a second
time: '{"a":1}' becomes "\"{\\\"a\\\":1}\"".

The workarounds for this were accidents of implementation rather than
documented behaviour: :serializable_hash happens to return a String untouched,
and :binary has no formatter class at all, so it falls through to
DEFAULT_LAMBDA_FORMATTER -- but answers application/octet-stream.

PrecompiledJson marks one body as already rendered:

  get '/cached' do
    body Grape::PrecompiledJson.new(Rails.cache.read('payload'))
  end

Formatter::Json and Formatter::SerializableHash return it verbatim; everything
unwrapped encodes exactly as before. The opt-in is per response rather than per
API on purpose. A formatter that passed every String through could not tell
pre-rendered JSON from an endpoint returning 'hello', and would answer with a
bare hello -- invalid JSON, silently, and not something a type check can catch
since a String is precisely what it is looking for. A marker never has to
guess.

An Array is joined without its members being parsed, which is what makes a
cached collection cheap: N rendered blobs are spliced together rather than
round-tripped. This is load-bearing rather than a convenience -- handing an
encoder an array of wrappers renders them as ordinary objects
([{"value":"..."}]), so the join has to happen here. Array#join calls to_s, so
members may themselves be PrecompiledJson.

For the same reason a wrapper is only valid as the whole body; nesting one
inside a Hash is documented as unsupported, since no encoder knows to unwrap
it. A value that is neither String nor Array raises
Grape::Exceptions::InvalidFormatter, which the formatter middleware already
rescues into a 500, rather than letting a body Rack ca... (continued)
Pull Request #2869: Add Grape::PrecompiledJson for bodies that are already JSON

1247 of 1338 branches covered (93.2%)

Branch coverage included in aggregate %.

10 of 10 new or added lines in 3 files covered. (100.0%)

3891 of 3959 relevant lines covered (98.28%)

27154.01 hits per line

Jobs
ID Job ID Ran Files Coverage
1 run-3.4-gemfiles/rails_8_1.gemfile - 33252737439.1 29 Aug 2026 12:33PM UTC 169
95.75
GitHub Action Run
2 run-3.4-Gemfile - 33252737439.2 29 Aug 2026 12:33PM UTC 168
95.75
GitHub Action Run
3 run-4.0-gemfiles/rails_8_1.gemfile - 33252737439.3 29 Aug 2026 12:33PM UTC 169
95.75
GitHub Action Run
4 run-4.0-gemfiles/rack_3_0.gemfile - 33252737439.4 29 Aug 2026 12:33PM UTC 168
95.75
GitHub Action Run
5 run-4.0-gemfiles/dry_validation.gemfile - 33252737439.5 29 Aug 2026 12:32PM UTC 168
57.74
GitHub Action Run
6 run-3.4-gemfiles/rack_2_2.gemfile - 33252737439.6 29 Aug 2026 12:32PM UTC 168
95.71
GitHub Action Run
7 run-4.0-gemfiles/rails_8_0.gemfile - 33252737439.7 29 Aug 2026 12:33PM UTC 169
95.75
GitHub Action Run
8 run-3.3-gemfiles/rack_2_2.gemfile - 33252737439.8 29 Aug 2026 12:32PM UTC 168
95.71
GitHub Action Run
9 run-4.0-gemfiles/rack_2_2.gemfile - 33252737439.9 29 Aug 2026 12:32PM UTC 168
95.71
GitHub Action Run
10 run-4.0-gemfiles/multi_xml_0_8.gemfile - 33252737439.10 29 Aug 2026 12:33PM UTC 168
46.78
GitHub Action Run
11 run-3.3-gemfiles/rack_3_0.gemfile - 33252737439.11 29 Aug 2026 12:33PM UTC 168
95.75
GitHub Action Run
12 run-3.3-Gemfile - 33252737439.12 29 Aug 2026 12:32PM UTC 168
95.75
GitHub Action Run
13 run-3.4-gemfiles/rack_3_2.gemfile - 33252737439.13 29 Aug 2026 12:32PM UTC 168
95.75
GitHub Action Run
14 run-3.4-gemfiles/rails_8_0.gemfile - 33252737439.14 29 Aug 2026 12:33PM UTC 169
95.75
GitHub Action Run
15 run-3.3-gemfiles/rails_7_2.gemfile - 33252737439.15 29 Aug 2026 12:32PM UTC 169
95.75
GitHub Action Run
16 run-3.3-gemfiles/rack_3_2.gemfile - 33252737439.16 29 Aug 2026 12:32PM UTC 168
95.75
GitHub Action Run
17 run-4.0-gemfiles/grape_swagger.gemfile - 33252737439.17 29 Aug 2026 12:32PM UTC 168
55.07
GitHub Action Run
18 run-3.4-gemfiles/rack_3_1.gemfile - 33252737439.18 29 Aug 2026 12:33PM UTC 168
95.75
GitHub Action Run
19 run-3.4-gemfiles/rack_3_0.gemfile - 33252737439.19 29 Aug 2026 12:32PM UTC 168
95.75
GitHub Action Run
20 run-4.0-Gemfile - 33252737439.20 29 Aug 2026 12:33PM UTC 168
95.75
GitHub Action Run
21 run-4.0-gemfiles/multi_json.gemfile - 33252737439.21 29 Aug 2026 12:32PM UTC 168
47.34
GitHub Action Run
22 run-3.3-gemfiles/rails_8_0.gemfile - 33252737439.22 29 Aug 2026 12:33PM UTC 169
95.75
GitHub Action Run
23 run-3.3-gemfiles/rack_3_1.gemfile - 33252737439.23 29 Aug 2026 12:33PM UTC 168
95.75
GitHub Action Run
24 run-4.0-gemfiles/rack_3_2.gemfile - 33252737439.24 29 Aug 2026 12:32PM UTC 168
95.75
GitHub Action Run
25 run-4.0-gemfiles/grape_entity.gemfile - 33252737439.25 29 Aug 2026 12:33PM UTC 168
50.01
GitHub Action Run
26 run-4.0-gemfiles/hashie.gemfile - 33252737439.26 29 Aug 2026 12:33PM UTC 168
61.75
GitHub Action Run
27 run-4.0-gemfiles/rack_3_1.gemfile - 33252737439.27 29 Aug 2026 12:33PM UTC 168
95.75
GitHub Action Run
28 run-3.3-gemfiles/rails_8_1.gemfile - 33252737439.28 29 Aug 2026 12:33PM UTC 169
95.75
GitHub Action Run
29 run-3.4-gemfiles/rails_7_2.gemfile - 33252737439.29 29 Aug 2026 12:32PM UTC 169
95.75
GitHub Action Run
30 run-4.0-gemfiles/multi_xml.gemfile - 33252737439.30 29 Aug 2026 12:33PM UTC 168
46.74
GitHub Action Run
31 run-4.0-gemfiles/multi_json_1_20.gemfile - 33252737439.31 29 Aug 2026 12:35PM UTC 168
47.38
GitHub Action Run
32 run-4.0-gemfiles/rails_7_2.gemfile - 33252737439.32 29 Aug 2026 12:32PM UTC 169
95.75
GitHub Action Run
Source Files on build 33252737439
  • Tree
  • List 169
  • Changed 2
  • Source Changed 2
  • Coverage Changed 2
Coverage ∆ File Lines Relevant Covered Missed Hits/Line Branch Hits Branch Misses
  • Back to Repo
  • Github Actions Build #33252737439
  • Pull Request #2869
  • PR Base - master (#33120993402)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc