RicoSuter/NSwag

Enum naming in c# client generator for enums in list on a model does not take name from model

Open

#2647 opened on Jan 23, 2020

View on GitHub
 (6 comments) (0 reactions) (0 assignees)C# (6,291 stars) (1,189 forks)batch import
help wanted

Description

When generating c# class from a swagger definition, enums take name from their model, which is nice.

However, if a model contains a list of enums, the enum name ends up being the property name for the list instead of being ModelnamePropertyname.

I would guess that this is a bug.

Except of example swagger.json:

[...]

"definitions": {
  "MyModel": {
    "type": "object",
    "ListOfEnumValues": {
      "description": "Blah, blah 1",
      "uniqueItems": false,
      "type": "array",
      "items": {
        "enum": [
          "ValueOneOne",
          "ValueOneTwo"
        ],
        "type": "string"
      }
    },
    "SomeEnum": {
      "description": "Blah, blah 2",
      "enum": [
          "ValueTwoOne",
          "ValueTwoTwo"
       ],
      "type": "string"
    }
  }
}

[...]

The generated C# code would be something like this:

[...]

public partial class MyModel {
  public System.Collections.Generic.IEnumerable<ListOfEnumValues> ListOfEnumValues { get; set; }
  public MyModelSomeEnum? SomeEnum{ get; set; }
}

[...]

public enum ListOfEnumValues {
  ValueOneOne = 0,
  ValueOneTwo = 1
}

[...]

public enum MyModelSomeEnum {
  ValueTwoOne = 0,
  ValueTwoTwo = 1
}

[...]

I would, however, have expted that the enum ListOfEnumValues was named MyModelListOfEnumValues

Contributor guide