RicoSuter/NJsonSchema
Not allowed characters in generated C# Code
Aberta
#552 aberto em 2 de nov. de 2017
help wantedtype: enhancement
Métricas do repositório
- Stars
- (1.581 estrelas)
- Métricas de merge de PR
- (Mesclagem média 39d 6h) (1 fundiu PR em 30d)
Description
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"]
}