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
88 stars 33 forks source link

`-` in enum results in duplicate #163

Closed dickermoshe closed 5 months ago

dickermoshe commented 5 months ago

I have an enum that has all the filtering options

  1. By salePrice
  2. By Reverse salePrice

The values are salePrice and -salePrice. It's is quite common that a dash is used to denote a reverse ordering. The problem is that swagger_parser strips out the - Using this did not help:

replacement_rules:
    # Example of rule
    - pattern: "-"
      replacement: "reverse"

This is the generated enum

@JsonEnum()
enum O2 {

  @JsonValue('-salePrice')
  salePrice('-salePrice'), // <--Duplicate

  @JsonValue('salePrice')
  salePrice('salePrice'), // <--Duplicate

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

  const O2(this.json);

  factory O2.fromJson(String json) => values.firstWhere(
        (e) => e.json == json,
        orElse: () => $unknown,
      );

  final String? json;
}
dickermoshe commented 5 months ago

This only runs if it's a number :(

https://github.com/Carapacik/swagger_parser/blob/73f4eff75ec2d404caf4766a3706d5e4cccab2a4/swagger_parser/lib/src/utils/type_utils.dart#L132-L136