Shopify / shopify-api-ruby

ShopifyAPI is a lightweight gem for accessing the Shopify admin REST and GraphQL web services.
MIT License
1.06k stars 469 forks source link

Wrong sorbet type of Shop#google_apps_login_enabled #1334

Closed kirillplatonov closed 2 months ago

kirillplatonov commented 2 months ago

Issue summary

When trying to read Shop#google_apps_login_enabled attribute with boolean value we're getting an error:

[6] pry(main)> loaded_shop.google_apps_login_enabled
TypeError: Return value: Expected type T.nilable(String), got type TrueClass
Caller: (pry):10
Definition: /Users/kirill/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/shopify_api-14.4.0/lib/shopify_api/rest/resources/2024_04/shop.rb:125 (ShopifyAPI::Shop#google_apps_login_enabled)
from /Users/kirill/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11514/lib/types/configuration.rb:296:in `call_validation_error_handler_default'

Expected behavior

Should get attribute value.

Actual behavior

Getting sorbet exception.

Steps to reproduce the problem

The following snippet can be used to reproduce the issue:

shop = Shop.last
shopify_shop = shop.with_shopify_session do
  ShopifyAPI::Shop.all.first
end
shop_data = shopify_shop.to_hash
shop_data["google_apps_login_enabled"] = true
loaded_shop = shop.with_shopify_session do
  ShopifyAPI::Shop.new(from_hash: shop_data)
end
loaded_shop.google_apps_login_enabled
paulomarg commented 2 months ago

Thanks for raising this, and for providing a clear repro scenario!

I'll add it to our tracking, and we'll look into it.

kirillplatonov commented 2 months ago

I can open a PR for that. But not sure if it will be enough to just fix resources in lib/shopify_api/rest/resources folder or some hidden internal schema still needs to be fixed in Shopify? As I understand, resources will be re-generated during next Shopify bump and the schema for that is not open-sourced yet.

paulomarg commented 2 months ago

Thanks! We can fix it in the existing files so we don't have to re-generate them, and we'll make sure it gets propagated to future versions.