Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Cannot find class with ruby generator #12854

Open
5 of 6 tasks
bark-mshort opened this issue Jul 13, 2022 · 4 comments
Open
5 of 6 tasks

[BUG] Cannot find class with ruby generator #12854

bark-mshort opened this issue Jul 13, 2022 · 4 comments

Comments

@bark-mshort
Copy link

bark-mshort commented Jul 13, 2022

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

After importing the API spec for commercetools, the newly created ruby client is unable to load the class Message. An issue was initially opened with commercetools regarding the spec, but after being able to properly generate the client, we are still unable to properly initialize the client via both our rails application and the regular irb console.

openapi-generator version
openapi-generator --version
openapi-generator-cli 6.0.1
  commit : 9e412ed
  built  : 2022-07-03T16:21:27Z
  source : https://github.com/openapitools/openapi-generator
  docs   : https://openapi-generator.tech/
OpenAPI declaration file content or url

https://raw.githubusercontent.com/commercetools/commercetools-api-reference/main/oas/openapi.yaml

Generation Details

Install Generator

brew install openapi-generator

Create Ruby Client

openapi-generator generate -i \
https://raw.githubusercontent.com/commercetools/commercetools-api-reference/main/oas/openapi.yaml \
--additional-properties=gemName=hackathon_ct_sdk,moduleName=HackathonCtSdk -g ruby
Steps to reproduce

As defined by setup instructions in the automatically generated client, build the gem and install locally:

gem build hackathon_ct_sdk.gemspec
gem install ./hackathon_ct_sdk-1.0.0.gem

Load irb console and require gem:

hackathon-ct-sdk ➜ irb                                     
irb(main):001:0> require 'hackathon_ct_sdk'
Traceback (most recent call last):
       14: from /Users/mirandashort/.rbenv/versions/2.7.4/bin/ruby_executable_hooks:22:in `<main>'
       13: from /Users/mirandashort/.rbenv/versions/2.7.4/bin/ruby_executable_hooks:22:in `eval'
       12: from /Users/mirandashort/.rbenv/versions/2.7.4/bin/irb:23:in `<main>'
       11: from /Users/mirandashort/.rbenv/versions/2.7.4/bin/irb:23:in `load'
       10: from /Users/mirandashort/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
        9: from (irb):1
        8: from /Users/mirandashort/.rbenv/versions/2.7.4/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:147:in `require'
        7: from /Users/mirandashort/.rbenv/versions/2.7.4/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:158:in `rescue in require'
        6: from /Users/mirandashort/.rbenv/versions/2.7.4/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:158:in `require'
        5: from /Users/mirandashort/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/hackathon_ct_sdk-1.0.0/lib/hackathon_ct_sdk.rb:1176:in `<top (required)>'
        4: from /Users/mirandashort/.rbenv/versions/2.7.4/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
        3: from /Users/mirandashort/.rbenv/versions/2.7.4/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
        2: from /Users/mirandashort/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/hackathon_ct_sdk-1.0.0/lib/hackathon_ct_sdk/models/category_created_message.rb:16:in `<top (required)>'
        1: from /Users/mirandashort/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/hackathon_ct_sdk-1.0.0/lib/hackathon_ct_sdk/models/category_created_message.rb:17:in `<module:HackathonCtSdk>'
NameError (uninitialized constant HackathonCtSdk::Message)
Did you mean?  HackathonCtSdk::MessageAllOf
Related issues/PRs

There is an open issue for adding support to autoload classes: #12648

This kind of error is something I do typically encounter in our rails application whenever there is an issue with autoloading classes (specifically if the path does not match the class name), so it could possibly be related. It could also be this issue with inheritance, which does reference the above issue: #4690. It's unclear to me if this is the same issue though.

Suggest a fix

Ultimately the client is unable to load the class Message, but not sure where specifically the code is breaking.

@bark-mshort
Copy link
Author

I actually think it is the same problem as #4690 but it's closed. It looks like when I require 'message' in category_created_message, it now has trouble finding message_all_of. I'm not sure what the actual order needs to be for all classes to get loaded, but it seems to be that they are required in the module alphabetically. Autoloading the classes may fix that.

@Fryguy
Copy link
Contributor

Fryguy commented Aug 16, 2022

When you call openapi-generator generate, can you try passing the new useAutoload parameter as it's not the default? This should fix any require ordering issues.

@bark-mshort
Copy link
Author

My coworker @BARK-TWOFFORD has taken the reigns on this project so I will defer to him! I've sent him the issue to test out

@SalvatoreT
Copy link

@Fryguy, I had an uninitialized constant issue as well, and setting useAutoload with OPENAPI_GENERATOR_VERSION=6.1.0-SNAPSHOT resolved it. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants