RicoSuter/NSwag

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

Open

#2811 aperta il 19 apr 2020

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)C# (1189 fork)batch import
help wanted

Metriche repository

Star
 (6291 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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.

Guida contributor