RicoSuter/NSwag

OpenApi-C# generation with npm-cli does not handle invalid names correctly

Open

#2,811 建立於 2020年4月19日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)C# (6,291 star) (1,189 fork)batch import
help wanted

描述

Environment:

NSwag NPM CLI
NSwag command line tool for .NET Core NetCore21, toolchain v13.4.2.0 (NJsonSchema v10.1.11.0 (Newtonsoft.Json v11.0.0.0))

Scenario:

If you take a look at this Specification of the Microsoft vsts-rest-api-specs you will recognize a parameter named $scope in line 63.

Calling the following on this element

nswag openapi2csclient /input: dashboard.json 
                       /classname:Dashboard 
                       /namespace:MyNamespace 
                       /output:Dashboard.cs

Will generate the following enum-code:

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.11.0 (Newtonsoft.Json v11.0.0.0)")]
public enum $scope
{
    [System.Runtime.Serialization.EnumMember(Value = @"collection_User")]
    Collection_User = 0,

    [System.Runtime.Serialization.EnumMember(Value = @"project_Team")]
    Project_Team = 1,

}

The name $scope is invalid obviously in C#.

Expected:

The name of the member should be scope. nswag should take care of special characters.

貢獻者指南