swagger-api / swagger-api/swagger-codegen
[RUBY] Generator should fail if model classes shadow standard classes in the same namespace
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The ruby code generator should fail if one of the generated model classes shadows a standard class.
The code generator generates the model classes in the same namespace as the standard classes like for example ApiClient, ApiError, Configuration or DefaultApi. If there is a definition in the declaration file with the same name, the model class that is generated from that definition shadows the standard class. For ruby this means the model class and the standard class are mixed into one big class with unpredictable effects.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
- namespace-issue-swagger-spec.yaml https://gist.github.com/cgrothaus/f3d9d4f8f4099a309fbe1a019ee70297
- codegen.json https://gist.github.com/cgrothaus/483fcaeadf64b9a978b1d8578a898e13
Command line used for generation
swagger-codegen generate -i ./namespace-issue-swagger-spec.yaml -l ruby -o ./namespace-issue/ -c ./codegen.json
Steps to reproduce
- Generate ruby code with the command line from above
- Have a look at the two generated files
./namespace-issue/lib/namespace_issue/api_error.rband./namespace-issue/lib/namespace_issue/models/api_error.rb: they both define the same classApiErrorin the same module namespace.
Related issues/PRs
Nothing known to me.
Suggest a fix/enhancement
The generator should fail under such circumstances. Definitions in the swagger declaration should not be allowed to shadow standard class names.
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 issue with namespace-issue-swagger-spec.yaml, codegen.json, and the shown swagger-codegen command. Compare lib/namespace_issue/api_error.rb with lib/namespace_issue/models/api_error.rb, then verify that generation fails when both define ApiError in the same module namespace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100