RicoSuter/NJsonSchema

Not allowed characters in generated C# Code

Aperta

#552 aperta il 2 nov 2017

 (1 commento) (0 reazioni) (0 assegnatari)C# (549 fork)github user discovery
help wantedtype: enhancement

Metriche repository

Star
 (1578 stelle)
Metriche merge PR
 (Merge medio 39g 6h) (1 PR mergiata in 30 g)

Descrizione

I'm trying to generate C# Code from a given JSONSchema. The Schema contains a property of type string with possible enum values. One of the enum values contains a "?". When generating the C# code, the name of this enum value is also generated with the "?". Since "?" is an invalid character the generated code is invalid. The workaround for this issue was creating a new IEnumNameGenerator which replaces the "?". Sample code: C#-Enum

    [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "6.8.6197.43075")]
    public enum KitchenDataCookingstyle
    {
        [System.Runtime.Serialization.EnumMember(Value = "Schnell und einfach")]
        Schnell_und_einfach = 0,
    
        [System.Runtime.Serialization.EnumMember(Value = "Gesunde und frische Ernährung")]
        Gesunde_und_frische_Ernährung = 1,
    
        [System.Runtime.Serialization.EnumMember(Value = "Mehrgängige Menüs für Gäste")]
        Mehrgängige_Menüs_für_Gäste = 2,
    
        [System.Runtime.Serialization.EnumMember(Value = "Anspruchsvoll auf Profi-Niveau")]
        Anspruchsvoll_auf_ProfiNiveau = 3,
    
        [System.Runtime.Serialization.EnumMember(Value = "Torten Plätzchen und Desserts")]
        Torten_Plätzchen_und_Desserts = 4,
    
        [System.Runtime.Serialization.EnumMember(Value = "Kochen? Ich gehe lieber essen")]
        Kochen?_Ich_gehe_lieber_essen = 5,
    
    }

JSONSchema

"Cookingstyle": {
					"title": "Kochart",
					"type": "string",
					"enum": ["Schnell und einfach", "Gesunde und frische Ernährung", "Mehrgängige Menüs für Gäste", "Anspruchsvoll auf Profi-Niveau", "Torten Plätzchen und Desserts", "Kochen? Ich gehe lieber essen"]
				}

Guida contributor