Skip to content

Commit 6025bf4

Browse files
ericproulxclaude
andcommitted
Detect the MultiXML constant to avoid the multi_xml deprecation
multi_xml 0.9.0 deprecated the `MultiXml` constant in favor of `MultiXML` (removed in v1.0); the legacy constant warns on access/use. Grape detected the backend via `::MultiXml` and called `Grape::Xml.parse`, so users on multi_xml >= 0.9 would hit the deprecation. Detect `::MultiXML` first, falling back to the legacy `::MultiXml` constant and then `ActiveSupport::XmlMini`. Unlike multi_json, no facade is needed: `parse` is canonical (not renamed) and Grape only calls `parse`, so a direct alias suffices on every backend. Cover both multi_xml lines in CI: pin gemfiles/multi_xml.gemfile to >= 0.9 and add gemfiles/multi_xml_0_8.gemfile (< 0.9), each running the spec/integration/multi_xml suite. The integration spec now drives a real Grape API that parses an XML request body through Grape::Xml.parse. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 1477dc5 commit 6025bf4

6 files changed

Lines changed: 36 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ jobs:
5353
- ruby: '4.0'
5454
gemfile: gemfiles/multi_xml.gemfile
5555
specs: 'spec/integration/multi_xml'
56+
- ruby: '4.0'
57+
gemfile: gemfiles/multi_xml_0_8.gemfile
58+
specs: 'spec/integration/multi_xml'
5659
runs-on: ubuntu-latest
5760
env:
5861
BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
* [#2706](https://github.com/ruby-grape/grape/pull/2706): Fix `optional :foo, message: 'oops'` raising `UnknownValidator` - [@ericproulx](https://github.com/ericproulx).
7676
* [#2751](https://github.com/ruby-grape/grape/pull/2751): Fix structured error messages leaking the raw i18n key for an undefined optional step such as `summary` (closes #2748) - [@ericproulx](https://github.com/ericproulx).
7777
* [#2759](https://github.com/ruby-grape/grape/pull/2759): Use `create_additions: false` in `Grape::Json.load` to prevent object instantiation via the `json_class` key when using the stdlib JSON fallback - [@dblock](https://github.com/dblock).
78+
* [#2765](https://github.com/ruby-grape/grape/pull/2765): Detect the `MultiXML` constant to avoid the multi_xml 0.9 `MultiXml` deprecation - [@ericproulx](https://github.com/ericproulx).
7879
* Your contribution here.
7980

8081
### 3.2.1 (2026-04-16)

gemfiles/multi_xml.gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

3-
gem 'multi_xml'
3+
gem 'multi_xml', '>= 0.9'
44

55
eval_gemfile '../Gemfile'

gemfiles/multi_xml_0_8.gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
gem 'multi_xml', '< 0.9'
4+
5+
eval_gemfile '../Gemfile'

lib/grape/xml.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# frozen_string_literal: true
22

33
module Grape
4-
if defined?(::MultiXml)
4+
# Since multi_xml 0.9.0 the canonical constant is MultiXML; MultiXml is a
5+
# deprecated alias (removed in v1.0) that warns on use. Prefer MultiXML so
6+
# Grape::Xml.parse doesn't trip the deprecation, falling back to the legacy
7+
# constant and then ActiveSupport::XmlMini.
8+
# https://github.com/sferik/multi_xml/blob/v0.9.1/CHANGELOG.md
9+
if defined?(::MultiXML)
10+
Xml = ::MultiXML
11+
elsif defined?(::MultiXml)
512
Xml = ::MultiXml
613
else
714
Xml = ::ActiveSupport::XmlMini
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
# frozen_string_literal: true
22

33
describe Grape::Xml, if: defined?(MultiXml) do
4-
subject { described_class }
4+
# Exercise the full request stack: a Grape API parses an XML body through the
5+
# active multi_xml backend (MultiXML on >= 0.9, the legacy MultiXml alias on
6+
# < 0.9). Calling parse through the deprecated MultiXml constant would raise
7+
# via the suite's deprecation handler (see spec/support/deprecated_warning_handlers.rb).
8+
let(:app) do
9+
Class.new(Grape::API) do
10+
post '/request_body' do
11+
params[:user]
12+
end
13+
end
14+
end
515

6-
it { is_expected.to eq(MultiXml) }
16+
it 'parses an XML request body into params' do
17+
env = Rack::MockRequest.env_for('/request_body', method: 'POST', input: '<user>Bobby T.</user>', 'CONTENT_TYPE' => 'application/xml')
18+
response = Rack::MockResponse[*app.call(env)]
19+
20+
expect(response.status).to eq(201)
21+
expect(response.body).to eq('Bobby T.')
22+
end
723
end

0 commit comments

Comments
 (0)