From 0ba43a9e68b710222fcc164150dc66045b636d89 Mon Sep 17 00:00:00 2001 From: Tyler Young Date: Mon, 27 May 2024 00:58:11 -0400 Subject: [PATCH] prefix any property name not starting with valid initial character with _ --- src/libs/OpenApiGenerator.Core/Models/PropertyData.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libs/OpenApiGenerator.Core/Models/PropertyData.cs b/src/libs/OpenApiGenerator.Core/Models/PropertyData.cs index 0ef2d9ad02..06328d86e3 100644 --- a/src/libs/OpenApiGenerator.Core/Models/PropertyData.cs +++ b/src/libs/OpenApiGenerator.Core/Models/PropertyData.cs @@ -47,6 +47,12 @@ public static PropertyData FromSchema( .UseWordSeparator('_', '+', '-', '/') .Replace("[", string.Empty) .Replace("]", string.Empty); + + if (name[0] is not ('_' or >= 'A' and <= 'Z' or >= 'a' and <= 'z')) + { + name = $"_{name}"; + } + if (parents.Length != 0) { name = name.FixPropertyName(parents.Last().ClassName);