OpenAPITools / OpenAPITools/openapi-generator
[BUG] Cannot find class with ruby generator
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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: https://github.com/OpenAPITools/openapi-generator/issues/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: https://github.com/OpenAPITools/openapi-generator/issues/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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the documented openapi-generator command and the commercetools openapi.yaml, then build and require the generated gem. Start at lib/hackathon_ct_sdk.rb and models/category_created_message.rb, where the traceback references the missing Message constant. Compare the generated model references and class paths; done means the generated Ruby gem loads successfully without the NameError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, ruby
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100