Open cgrothaus opened 6 years ago
I just ran into this as well, but I think the solution offered can be improved. The presence of a collision is not an indication of an error in the swagger definition file and as such, the compiler should succeed; however, the compiled code should be designed so as to prevent such a conflict from occurring in the first place.
A proper solution would be to namespace the models under a Models
(or similar) namespace, so that a collision cannot occur with other supporting code within the generated API client.
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
orDefaultApi
. 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
./namespace-issue/lib/namespace_issue/api_error.rb
and./namespace-issue/lib/namespace_issue/models/api_error.rb
: they both define the same classApiError
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.