swagger-api / swagger-api/swagger-codegen

[RUBY] Generator should fail if model classes shadow standard classes in the same namespace

Open
#8,283 1 comment 0 reactions 0 assignees View on GitHub

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
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
  1. Generate ruby code with the command line from above
  2. Have a look at the two generated files ./namespace-issue/lib/namespace_issue/api_error.rb and ./namespace-issue/lib/namespace_issue/models/api_error.rb: they both define the same class ApiError in 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.