RicoSuter/NSwag

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

Open

#2 811 ouverte le 19 avr. 2020

Voir sur GitHub
 (1 commentaire) (0 réactions) (0 assignés)C# (1 189 forks)batch import
help wanted

Métriques du dépôt

Stars
 (6 291 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

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.

Guide contributeur