Carapacik / swagger_parser

Dart package that takes an OpenApi definition file and generates REST clients based on retrofit and data classes for your project.
https://pub.dev/packages/swagger_parser
MIT License
90 stars 38 forks source link

Enums with the same name conflict #140

Closed elenaferr0 closed 8 months ago

elenaferr0 commented 9 months ago

Hi @Carapacik, I'm having an issue with enums which have the same name. I created a simplified version of my issue here: swagger schema. Basically, I have an endpoint which takes an enum value as path param (with reference to my swagger json example, the /{type} endpoint accepts a Type.paramValue1 or Type.paramValue2 enum value). But I also have a TestClass model, which contains another Type enum (which has 2 values: Type.propertyValue1 or Type.propertyValue2). Obviously, the two Type enums are not the same, they are two different entities. The generated code actually compiles, but the two enums are in conflict, in fact only the Type.propertyValue1 and Type.propertyValue2 enum is generated (and also referenced as a parameter in the findByType, where instead I would want to use Type.paramValue1 or Type.paramValue2. Basically, this code in test_client.dart:

  @GET('/{type}')
  Future<void> findByType({
    @Path('type') required Type type,
  });

and this code in test_class.dart:

const factory TestClass({
  /// Type used as property value
  required Type type,
}) = _TestClass;

both reference this Type enum (which is the only Type enum created, the other is ignored):

enum Type {
  @JsonValue('propertyValue1')
  propertyValue1('propertyValue1'),

  @JsonValue('propertyValue2')
  propertyValue2('propertyValue2'),

  /// Default value for all unparsed values, allows backward compatibility when adding new values on the backend.
  $unknown(null);
 /// ... etc ...
}