OpenAPITools / OpenAPITools/openapi-generator
[REQ] [ruby] Reduce code duplication
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
The code generated under Ruby contains a significant amount of duplication. This duplication leads to code bloat both in file size and runtime memory usage.
I propose a base class for models, from which all models would inherit that would contain a lot of this shared logic.
@cliffano @zlx @autopp
Describe the solution you'd like
Initially, I'd like to introduce a new ApiModelBase class from which all base models would inherit. All models that have a parent would continue to inherit from their parent. In the initial PR introducing this new base model, I will move in all model methods that are static and that don't change per child class. This will set up the pattern after which follow up PRs can start moving other common methods and logic down to further eliminate duplication.
Describe alternatives you've considered
N/A
Additional context
I've started a PR to see how feasible it is, and I've created a draft PR in #22052.
I've also executed this against one of my gems and the file size dropped from 16MB to 12MB (25% reduction) even with only the small handful of common methods pulled out. See https://github.com/ManageIQ/kubevirt-sdk-ruby/compare/master...Fryguy:kubevirt-sdk-ruby:reduce_gem_size
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
Start by reviewing draft PR #22052 and the generated Ruby model output to understand the proposed ApiModelBase pattern and current inheritance structure. Done means introducing the base model, preserving parent-model inheritance, and moving shared static methods into it without changing generated model behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100