Skip to content

Commit

Permalink
Update PropertyNameGenerator - escape "|" character in property names (
Browse files Browse the repository at this point in the history
…#1684)

Some swagger documents contain | character in property names which is a reserved character in C# and is not valid for use in property names. This code change replaces vertical line character |with an underscore character _ to generate a valid (in C#) property name
  • Loading branch information
AntonYeurasau committed Mar 26, 2024
1 parent 3585d60 commit 01ee840
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -11,7 +11,7 @@ namespace NJsonSchema.CodeGeneration.CSharp
/// <summary>Generates the property name for a given CSharp <see cref="JsonSchemaProperty"/>.</summary>
public sealed class CSharpPropertyNameGenerator : IPropertyNameGenerator
{
private static readonly char[] _reservedFirstPassChars = { '"', '\'', '@', '?', '!', '$', '[', ']', '(', ')', '.', '=', '+' };
private static readonly char[] _reservedFirstPassChars = { '"', '\'', '@', '?', '!', '$', '[', ']', '(', ')', '.', '=', '+', '|' };
private static readonly char[] _reservedSecondPassChars = { '*', ':', '-', '#', '&' };

/// <summary>Generates the property name.</summary>
Expand All @@ -35,7 +35,8 @@ public string Generate(JsonSchemaProperty property)
.Replace(")", string.Empty)
.Replace(".", "-")
.Replace("=", "-")
.Replace("+", "plus");
.Replace("+", "plus")
.Replace("|", "_");
}

name = ConversionUtilities.ConvertToUpperCamelCase(name, true);
Expand All @@ -53,4 +54,4 @@ public string Generate(JsonSchemaProperty property)
return name;
}
}
}
}

0 comments on commit 01ee840

Please sign in to comment.