diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bf2e589..02d35f75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api ## Unreleased +- Ensure HTTP response signatures load `OpenStruct` when the application has not loaded it. ## 16.4.0 (2026-11-05) - [#1481](https://github.com/Shopify/shopify-api-ruby/pull/1481) `ShopifyAPI::Auth::TokenExchange.exchange_token` now raises `ShopifyAPI::Errors::InvalidJwtTokenError` when token exchange rejects the session token with `invalid_identity_session`, matching the existing `invalid_subject_token` handling. diff --git a/Gemfile.lock b/Gemfile.lock index 5785f845..e5fe2477 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,6 +11,7 @@ PATH logger oj openssl + ostruct securerandom sorbet-runtime zeitwerk (~> 2.5) diff --git a/lib/shopify_api/clients/http_response.rb b/lib/shopify_api/clients/http_response.rb index e943b446..264e9caa 100644 --- a/lib/shopify_api/clients/http_response.rb +++ b/lib/shopify_api/clients/http_response.rb @@ -1,6 +1,8 @@ # typed: strict # frozen_string_literal: true +require "ostruct" + module ShopifyAPI module Clients class HttpResponse diff --git a/shopify_api.gemspec b/shopify_api.gemspec index babb52bc..c89a4776 100644 --- a/shopify_api.gemspec +++ b/shopify_api.gemspec @@ -41,6 +41,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency("logger") s.add_runtime_dependency("oj") s.add_runtime_dependency("openssl") + s.add_runtime_dependency("ostruct") s.add_runtime_dependency("securerandom") s.add_runtime_dependency("sorbet-runtime") s.add_runtime_dependency("zeitwerk", "~> 2.5") diff --git a/test/clients/http_response_test.rb b/test/clients/http_response_test.rb index 00eeb300..c124382e 100644 --- a/test/clients/http_response_test.rb +++ b/test/clients/http_response_test.rb @@ -11,6 +11,20 @@ def setup access_token: SecureRandom.alphanumeric(10)) end + def test_loads_ostruct_before_evaluating_the_response_signature + lib = File.expand_path("../../lib", __dir__) + script = <<~RUBY + require "shopify_api" + Object.send(:remove_const, :OpenStruct) if Object.const_defined?(:OpenStruct) + $LOADED_FEATURES.delete_if { |feature| feature.end_with?("/ostruct.rb") } + ShopifyAPI::Clients::HttpResponse.new(code: 200, headers: {}, body: {}) + RUBY + + output = IO.popen([RbConfig.ruby, "-I#{lib}", "-e", script], err: [:child, :out], &:read) + + assert_predicate(Process.last_status, :success?, output) + end + def test_ok assert(ShopifyAPI::Clients::HttpResponse.new(code: 200, headers: {}, body: "").ok?) end