RicoSuter/NSwag

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

Open

#2,647 创建于 2020年1月23日

在 GitHub 查看
 (6 评论) (0 反应) (0 负责人)C# (6,291 star) (1,189 fork)batch import
help wanted

描述

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

贡献者指南