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

ruby-grape / grape / 33321066959
97%
master: 100%

Build:
Build:
LAST BUILD BRANCH: fix/cascade-reader
DEFAULT BRANCH: master
Ran 30 Aug 2026 03:58PM 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

30 Aug 2026 03:56PM UTC coverage: 96.981% (+0.01%) from 96.971%
33321066959

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

1242 of 1334 branches covered (93.1%)

Branch coverage included in aggregate %.

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

3898 of 3966 relevant lines covered (98.29%)

27155.73 hits per line

Jobs
ID Job ID Ran Files Coverage
1 run-4.0-gemfiles/rack_2_2.gemfile - 33321066959.1 30 Aug 2026 03:59PM UTC 168
95.69
GitHub Action Run
2 run-4.0-gemfiles/grape_swagger.gemfile - 33321066959.2 30 Aug 2026 03:58PM UTC 168
55.27
GitHub Action Run
3 run-4.0-Gemfile - 33321066959.3 30 Aug 2026 03:59PM UTC 168
95.73
GitHub Action Run
4 run-3.3-gemfiles/rails_8_0.gemfile - 33321066959.4 30 Aug 2026 03:59PM UTC 169
95.73
GitHub Action Run
5 run-3.4-gemfiles/rack_3_2.gemfile - 33321066959.5 30 Aug 2026 03:58PM UTC 168
95.73
GitHub Action Run
6 run-3.3-gemfiles/rails_8_1.gemfile - 33321066959.6 30 Aug 2026 03:58PM UTC 169
95.73
GitHub Action Run
7 run-4.0-gemfiles/hashie.gemfile - 33321066959.7 30 Aug 2026 03:59PM UTC 168
61.71
GitHub Action Run
8 run-3.3-gemfiles/rails_7_2.gemfile - 33321066959.8 30 Aug 2026 03:58PM UTC 169
95.73
GitHub Action Run
9 run-4.0-gemfiles/rails_8_1.gemfile - 33321066959.9 30 Aug 2026 03:59PM UTC 169
95.73
GitHub Action Run
10 run-4.0-gemfiles/multi_xml_0_8.gemfile - 33321066959.10 30 Aug 2026 03:58PM UTC 168
46.79
GitHub Action Run
11 run-3.4-gemfiles/rack_3_1.gemfile - 33321066959.11 30 Aug 2026 03:59PM UTC 168
95.73
GitHub Action Run
12 run-4.0-gemfiles/rack_3_2.gemfile - 33321066959.12 30 Aug 2026 03:58PM UTC 168
95.73
GitHub Action Run
13 run-3.4-gemfiles/rails_7_2.gemfile - 33321066959.13 30 Aug 2026 03:59PM UTC 169
95.73
GitHub Action Run
14 run-3.3-gemfiles/rack_3_1.gemfile - 33321066959.14 30 Aug 2026 03:59PM UTC 168
95.73
GitHub Action Run
15 run-4.0-gemfiles/multi_json_1_20.gemfile - 33321066959.15 30 Aug 2026 03:58PM UTC 168
47.39
GitHub Action Run
16 run-3.3-Gemfile - 33321066959.16 30 Aug 2026 03:59PM UTC 168
95.73
GitHub Action Run
17 run-4.0-gemfiles/rails_7_2.gemfile - 33321066959.17 30 Aug 2026 03:58PM UTC 169
95.73
GitHub Action Run
18 run-4.0-gemfiles/rack_3_0.gemfile - 33321066959.18 30 Aug 2026 03:58PM UTC 168
95.73
GitHub Action Run
19 run-4.0-gemfiles/dry_validation.gemfile - 33321066959.19 30 Aug 2026 03:58PM UTC 168
57.76
GitHub Action Run
20 run-3.4-gemfiles/rack_2_2.gemfile - 33321066959.20 30 Aug 2026 03:58PM UTC 168
95.69
GitHub Action Run
21 run-4.0-gemfiles/rails_8_0.gemfile - 33321066959.21 30 Aug 2026 03:59PM UTC 169
95.73
GitHub Action Run
22 run-3.4-gemfiles/rails_8_1.gemfile - 33321066959.22 30 Aug 2026 03:59PM UTC 169
95.73
GitHub Action Run
23 run-3.3-gemfiles/rack_3_0.gemfile - 33321066959.23 30 Aug 2026 03:58PM UTC 168
95.73
GitHub Action Run
24 run-3.3-gemfiles/rack_3_2.gemfile - 33321066959.24 30 Aug 2026 03:59PM UTC 168
95.73
GitHub Action Run
25 run-4.0-gemfiles/multi_xml.gemfile - 33321066959.25 30 Aug 2026 03:59PM UTC 168
46.75
GitHub Action Run
26 run-4.0-gemfiles/grape_entity.gemfile - 33321066959.26 30 Aug 2026 03:59PM UTC 168
50.06
GitHub Action Run
27 run-3.4-gemfiles/rails_8_0.gemfile - 33321066959.27 30 Aug 2026 03:59PM UTC 169
95.73
GitHub Action Run
28 run-4.0-gemfiles/multi_json.gemfile - 33321066959.28 30 Aug 2026 03:59PM UTC 168
47.36
GitHub Action Run
29 run-3.4-gemfiles/rack_3_0.gemfile - 33321066959.29 30 Aug 2026 03:59PM UTC 168
95.73
GitHub Action Run
30 run-3.3-gemfiles/rack_2_2.gemfile - 33321066959.30 30 Aug 2026 03:58PM UTC 168
95.69
GitHub Action Run
31 run-3.4-Gemfile - 33321066959.31 30 Aug 2026 03:59PM UTC 168
95.73
GitHub Action Run
32 run-4.0-gemfiles/rack_3_1.gemfile - 33321066959.32 30 Aug 2026 03:59PM UTC 168
95.73
GitHub Action Run
Source Files on build 33321066959
  • 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 #33321066959
  • Pull Request #2869
  • PR Base - master (#33320781540)
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