RicoSuter/NSwag

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

Open

#2.811 geöffnet am 19. Apr. 2020

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)C# (1.189 Forks)batch import
help wanted

Repository-Metriken

Stars
 (6.291 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

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.

Contributor Guide