From c493d10be19034960d96560fa4bd393eb52e0bc1 Mon Sep 17 00:00:00 2001 From: Mladen Jablanovic Date: Mon, 3 Aug 2026 09:57:07 +0200 Subject: [PATCH 1/2] fix(ruby): pin link-header-parser to >=7.0 and fix its new keyword arg link-header-parser 7.0 renamed the base: keyword to base_uri: and changed group_by_relation_type to return string keys instead of symbols, crashing any paginated response with an ArgumentError. Update response.rb to use the new API and constrain the gemspec dependency accordingly. Fixes phrase/phrase-ruby#11 Co-Authored-By: Claude Sonnet 5 --- .gitignore | 1 + clients/ruby/lib/phrase/response.rb | 2 +- clients/ruby/spec/response_spec.rb | 53 +++++++++++++++++++ .../templates/ruby-client/gemspec.mustache | 2 +- 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 clients/ruby/spec/response_spec.rb diff --git a/.gitignore b/.gitignore index 74c0ca53c..924db5e51 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ clients/ruby/git_push.sh clients/ruby/openapitools.json clients/ruby/*.gemspec clients/ruby/spec/*.rb +!clients/ruby/spec/response_spec.rb clients/ruby/spec/api/* clients/ruby/spec/models/ clients/ruby/docs diff --git a/clients/ruby/lib/phrase/response.rb b/clients/ruby/lib/phrase/response.rb index c1c2b1b7d..121e079e1 100644 --- a/clients/ruby/lib/phrase/response.rb +++ b/clients/ruby/lib/phrase/response.rb @@ -10,7 +10,7 @@ def initialize(data, headers) link_headers = headers["link"] if link_headers @paginated = true - parsed_links = LinkHeaderParser.parse(link_headers, base: 'https://api.phrase.com').group_by_relation_type + parsed_links = LinkHeaderParser.parse(link_headers, base_uri: 'https://api.phrase.com').group_by_relation_type.transform_keys(&:to_sym) next_page_link = parsed_links[:next]&.first if next_page_link @next_page = CGI.parse(URI.parse(next_page_link.target_uri).query)["page"]&.first&.to_i diff --git a/clients/ruby/spec/response_spec.rb b/clients/ruby/spec/response_spec.rb new file mode 100644 index 000000000..f091fa278 --- /dev/null +++ b/clients/ruby/spec/response_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe Phrase::Response do + context 'without a link header' do + it 'is not paginated' do + response = Phrase::Response.new({ 'foo' => 'bar' }, {}) + + expect(response.paginated?).to eq(false) + expect(response.next_page?).to eq(false) + expect(response.next_page).to be_nil + end + end + + context 'with a link header that has a next page' do + let(:headers) do + { + 'link' => '; rel="next", ' \ + '; rel="last"' + } + end + + it 'parses the next page number without raising' do + response = Phrase::Response.new({ 'foo' => 'bar' }, headers) + + expect(response.paginated?).to eq(true) + expect(response.next_page?).to eq(true) + expect(response.next_page).to eq(2) + end + end + + context 'with a link header that has no next page' do + let(:headers) do + { + 'link' => '; rel="first", ' \ + '; rel="last"' + } + end + + it 'is paginated but has no next page' do + response = Phrase::Response.new({ 'foo' => 'bar' }, headers) + + expect(response.paginated?).to eq(true) + expect(response.next_page?).to eq(false) + expect(response.next_page).to be_nil + end + end + + it 'delegates missing methods to the underlying data' do + response = Phrase::Response.new({ 'foo' => 'bar' }, {}) + + expect(response['foo']).to eq('bar') + end +end diff --git a/openapi-generator/templates/ruby-client/gemspec.mustache b/openapi-generator/templates/ruby-client/gemspec.mustache index c5dd6d398..b73e212f7 100644 --- a/openapi-generator/templates/ruby-client/gemspec.mustache +++ b/openapi-generator/templates/ruby-client/gemspec.mustache @@ -32,7 +32,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'typhoeus', '>= 1.0.1' {{/isFaraday}} s.add_runtime_dependency 'json', '>= 2.1.0' - s.add_runtime_dependency 'link-header-parser' + s.add_runtime_dependency 'link-header-parser', '>= 7.0' s.add_development_dependency 'rspec', '>= 3.6.0' From 6a14a705a6d44761bcab1a4904c0ad7fee0d5f85 Mon Sep 17 00:00:00 2001 From: Mladen Jablanovic Date: Mon, 3 Aug 2026 10:08:04 +0200 Subject: [PATCH 2/2] fix(ruby): drop unnecessary symbol conversion of Link header relation types Since the gemspec now requires link-header-parser >= 7.0, which always returns string keys from group_by_relation_type, there's no need to convert remote-derived relation-type strings into symbols. Addresses Copilot review feedback on #1229. Co-Authored-By: Claude Sonnet 5 --- clients/ruby/lib/phrase/response.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clients/ruby/lib/phrase/response.rb b/clients/ruby/lib/phrase/response.rb index 121e079e1..8ed9eb9e9 100644 --- a/clients/ruby/lib/phrase/response.rb +++ b/clients/ruby/lib/phrase/response.rb @@ -10,8 +10,8 @@ def initialize(data, headers) link_headers = headers["link"] if link_headers @paginated = true - parsed_links = LinkHeaderParser.parse(link_headers, base_uri: 'https://api.phrase.com').group_by_relation_type.transform_keys(&:to_sym) - next_page_link = parsed_links[:next]&.first + parsed_links = LinkHeaderParser.parse(link_headers, base_uri: 'https://api.phrase.com').group_by_relation_type + next_page_link = parsed_links["next"]&.first if next_page_link @next_page = CGI.parse(URI.parse(next_page_link.target_uri).query)["page"]&.first&.to_i end