diff --git a/src/Atc.Rest.ApiGenerator.CLI/ApiOptionsHelper.cs b/src/Atc.Rest.ApiGenerator.CLI/ApiOptionsHelper.cs index ca3e5346d..d9d09ac63 100644 --- a/src/Atc.Rest.ApiGenerator.CLI/ApiOptionsHelper.cs +++ b/src/Atc.Rest.ApiGenerator.CLI/ApiOptionsHelper.cs @@ -256,7 +256,7 @@ private static void ApplyGeneratorOverrides( } } - apiOptions.Generator.ProjectName = apiOptions.Generator.ProjectName.EnsureNamespaceFormat(); - apiOptions.Generator.ProjectSuffixName = apiOptions.Generator.ProjectSuffixName.EnsureNamespaceFormat(); + apiOptions.Generator.ProjectName = apiOptions.Generator.ProjectName.EnsureNamespaceFormatPart(); + apiOptions.Generator.ProjectSuffixName = apiOptions.Generator.ProjectSuffixName.EnsureNamespaceFormatPart(); } } \ No newline at end of file diff --git a/src/Atc.Rest.ApiGenerator.Framework/Extensions/StringExtensions.cs b/src/Atc.Rest.ApiGenerator.Framework/Extensions/StringExtensions.cs index fa3a163b5..ccb84b02e 100644 --- a/src/Atc.Rest.ApiGenerator.Framework/Extensions/StringExtensions.cs +++ b/src/Atc.Rest.ApiGenerator.Framework/Extensions/StringExtensions.cs @@ -13,4 +13,25 @@ public static string EnsureNamespaceFormat( .Replace('.', ' ') .PascalCase() .Replace(' ', '.'); + + public static string EnsureNamespaceFormatPart( + this string value) + { + if (string.IsNullOrEmpty(value)) + { + return value; + } + + if (value.Contains('-', StringComparison.Ordinal)) + { + return value + .Trim() + .PascalCase(removeSeparators: true); + } + + return value + .Replace('\\', ' ') + .Replace('-', ' ') + .Trim(); + } } \ No newline at end of file diff --git a/src/Atc.Rest.ApiGenerator.Framework/Factories/NamespaceFactory.cs b/src/Atc.Rest.ApiGenerator.Framework/Factories/NamespaceFactory.cs index 79d84f979..da0e302fd 100644 --- a/src/Atc.Rest.ApiGenerator.Framework/Factories/NamespaceFactory.cs +++ b/src/Atc.Rest.ApiGenerator.Framework/Factories/NamespaceFactory.cs @@ -5,15 +5,20 @@ public static class NamespaceFactory public static string Create( params string[] values) { - if (values is null) + if (values is null || values.Length == 0) { return string.Empty; } - var fullNamespace = string - .Join(' ', values) - .Replace(" . ", " ", StringComparison.Ordinal); + var formattedValues = values + .Select((value, index) => + index == 0 + ? value.EnsureNamespaceFormatPart() + : value.EnsureNamespaceFormat()) + .Where(value => !string.IsNullOrEmpty(value)); - return fullNamespace.EnsureNamespaceFormat(); + var fullNamespace = string.Join('.', formattedValues); + + return fullNamespace; } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.Framework.Tests/Factories/NamespaceFactoryTests.cs b/test/Atc.Rest.ApiGenerator.Framework.Tests/Factories/NamespaceFactoryTests.cs index 49961cb6d..cde525ab0 100644 --- a/test/Atc.Rest.ApiGenerator.Framework.Tests/Factories/NamespaceFactoryTests.cs +++ b/test/Atc.Rest.ApiGenerator.Framework.Tests/Factories/NamespaceFactoryTests.cs @@ -14,6 +14,9 @@ public class NamespaceFactoryTests [InlineData(new[] { "MyProject", "nested.folder", "Users", "MyUser" }, "MyProject.Nested.Folder.Users.MyUser")] [InlineData(new[] { "MyProject", @"nested\folder", "Users", "MyUser" }, "MyProject.Nested.Folder.Users.MyUser")] [InlineData(new[] { "MyProject", ".", "Users", "MyUser" }, "MyProject.Users.MyUser")] + [InlineData(new[] { "IoT", "SubNamespace" }, "IoT.SubNamespace")] + [InlineData(new[] { "hallo-world", "SubNamespace" }, "HalloWorld.SubNamespace")] + [InlineData(new[] { "AAA", "SubNamespace" }, "AAA.SubNamespace")] public void Create_ShouldReturnCorrect_Namespace( string[] values, string expected)