Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PropertyNameGenerator - escape "|" character in property names #1684

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
}
}
}