Husqvik / GraphQlClientGenerator

GraphQL C# client generator
MIT License
213 stars 49 forks source link

Multiple enum values which convert to the same PascalCase name cause duplicate values in generated enums #147

Closed SlyCedix closed 11 months ago

SlyCedix commented 11 months ago

Gitlab's Schema(https://gitlab.com/api/graphql) contains some enums with two instances of the same value, one in snake_case and deprecated the other in SCREAMING_SNAKE_CASE. For example, this section of the Schema(gitlab_schema.json):

{
  "kind": "ENUM",
  "name": "ContainerRepositorySort",
  "description": "Values for sorting container repositories",
  "fields": null,
  "inputFields": null,
  "interfaces": null,
  "enumValues": [
    {
      "name": "NAME_ASC",
      "description": "Name by ascending order.",
      "isDeprecated": false,
      "deprecationReason": null
    },
    {
      "name": "NAME_DESC",
      "description": "Name by descending order.",
      "isDeprecated": false,
      "deprecationReason": null
    },
    {
      "name": "updated_desc",
      "description": "Updated at descending order. Deprecated in 13.5: This was renamed.",
      "isDeprecated": true,
      "deprecationReason": "This was renamed. Please use `UPDATED_DESC`. Deprecated in 13.5."
    },
    {
      "name": "updated_asc",
      "description": "Updated at ascending order. Deprecated in 13.5: This was renamed.",
      "isDeprecated": true,
      "deprecationReason": "This was renamed. Please use `UPDATED_ASC`. Deprecated in 13.5."
    },
    {
      "name": "created_desc",
      "description": "Created at descending order. Deprecated in 13.5: This was renamed.",
      "isDeprecated": true,
      "deprecationReason": "This was renamed. Please use `CREATED_DESC`. Deprecated in 13.5."
    },
    {
      "name": "created_asc",
      "description": "Created at ascending order. Deprecated in 13.5: This was renamed.",
      "isDeprecated": true,
      "deprecationReason": "This was renamed. Please use `CREATED_ASC`. Deprecated in 13.5."
    },
    {
      "name": "UPDATED_DESC",
      "description": "Updated at descending order.",
      "isDeprecated": false,
      "deprecationReason": null
    },
    {
      "name": "UPDATED_ASC",
      "description": "Updated at ascending order.",
      "isDeprecated": false,
      "deprecationReason": null
    },
    {
      "name": "CREATED_DESC",
      "description": "Created at descending order.",
      "isDeprecated": false,
      "deprecationReason": null
    },
    {
      "name": "CREATED_ASC",
      "description": "Created at ascending order.",
      "isDeprecated": false,
      "deprecationReason": null
    }
  ],
  "possibleTypes": null
},

This results in the uncompilable generated code:

public enum ContainerRepositorySort
{
    [EnumMember(Value = "NAME_ASC")] NameAsc,
    [EnumMember(Value = "NAME_DESC")] NameDesc,
    [EnumMember(Value = "updated_desc")] UpdatedDesc,
    [EnumMember(Value = "updated_asc")] UpdatedAsc,
    [EnumMember(Value = "created_desc")] CreatedDesc,
    [EnumMember(Value = "created_asc")] CreatedAsc,
    [EnumMember(Value = "UPDATED_DESC")] UpdatedDesc,
    [EnumMember(Value = "UPDATED_ASC")] UpdatedAsc,
    [EnumMember(Value = "CREATED_DESC")] CreatedDesc,
    [EnumMember(Value = "CREATED_ASC")] CreatedAsc
}
0>GraphQlClient.cs(5037,46): Error CS0102 : The type 'ContainerRepositorySort' already contains a definition for 'UpdatedDesc'
0>GraphQlClient.cs(5041,45): Error CS0102 : The type 'ContainerRepositorySort' already contains a definition for 'UpdatedAsc'
0>GraphQlClient.cs(5045,46): Error CS0102 : The type 'ContainerRepositorySort' already contains a definition for 'CreatedDesc'
0>GraphQlClient.cs(5049,45): Error CS0102 : The type 'ContainerRepositorySort' already contains a definition for 'CreatedAsc'
SlyCedix commented 11 months ago

This issue can be fixed by changing the EnumValueNaming to Original.

Regular behavior should probably be that if a name is already taken, fall back on the original name