Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Atc.Rest.ApiGenerator.CLI/ApiOptionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
21 changes: 21 additions & 0 deletions src/Atc.Rest.ApiGenerator.Framework/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
15 changes: 10 additions & 5 deletions src/Atc.Rest.ApiGenerator.Framework/Factories/NamespaceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading