Skip to content

Commit e113161

Browse files
Merge pull request #214 from atc-net/feature/allow-projectname-to-be-uppercase
feat: allow projectName to be uppercase
2 parents 6af09a7 + 09a1f67 commit e113161

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

src/Atc.Rest.ApiGenerator.CLI/ApiOptionsHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ private static void ApplyGeneratorOverrides(
256256
}
257257
}
258258

259-
apiOptions.Generator.ProjectName = apiOptions.Generator.ProjectName.EnsureNamespaceFormat();
260-
apiOptions.Generator.ProjectSuffixName = apiOptions.Generator.ProjectSuffixName.EnsureNamespaceFormat();
259+
apiOptions.Generator.ProjectName = apiOptions.Generator.ProjectName.EnsureNamespaceFormatPart();
260+
apiOptions.Generator.ProjectSuffixName = apiOptions.Generator.ProjectSuffixName.EnsureNamespaceFormatPart();
261261
}
262262
}

src/Atc.Rest.ApiGenerator.Framework/Extensions/StringExtensions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,25 @@ public static string EnsureNamespaceFormat(
1313
.Replace('.', ' ')
1414
.PascalCase()
1515
.Replace(' ', '.');
16+
17+
public static string EnsureNamespaceFormatPart(
18+
this string value)
19+
{
20+
if (string.IsNullOrEmpty(value))
21+
{
22+
return value;
23+
}
24+
25+
if (value.Contains('-', StringComparison.Ordinal))
26+
{
27+
return value
28+
.Trim()
29+
.PascalCase(removeSeparators: true);
30+
}
31+
32+
return value
33+
.Replace('\\', ' ')
34+
.Replace('-', ' ')
35+
.Trim();
36+
}
1637
}

src/Atc.Rest.ApiGenerator.Framework/Factories/NamespaceFactory.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@ public static class NamespaceFactory
55
public static string Create(
66
params string[] values)
77
{
8-
if (values is null)
8+
if (values is null || values.Length == 0)
99
{
1010
return string.Empty;
1111
}
1212

13-
var fullNamespace = string
14-
.Join(' ', values)
15-
.Replace(" . ", " ", StringComparison.Ordinal);
13+
var formattedValues = values
14+
.Select((value, index) =>
15+
index == 0
16+
? value.EnsureNamespaceFormatPart()
17+
: value.EnsureNamespaceFormat())
18+
.Where(value => !string.IsNullOrEmpty(value));
1619

17-
return fullNamespace.EnsureNamespaceFormat();
20+
var fullNamespace = string.Join('.', formattedValues);
21+
22+
return fullNamespace;
1823
}
1924
}

test/Atc.Rest.ApiGenerator.Framework.Tests/Factories/NamespaceFactoryTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public class NamespaceFactoryTests
1414
[InlineData(new[] { "MyProject", "nested.folder", "Users", "MyUser" }, "MyProject.Nested.Folder.Users.MyUser")]
1515
[InlineData(new[] { "MyProject", @"nested\folder", "Users", "MyUser" }, "MyProject.Nested.Folder.Users.MyUser")]
1616
[InlineData(new[] { "MyProject", ".", "Users", "MyUser" }, "MyProject.Users.MyUser")]
17+
[InlineData(new[] { "IoT", "SubNamespace" }, "IoT.SubNamespace")]
18+
[InlineData(new[] { "hallo-world", "SubNamespace" }, "HalloWorld.SubNamespace")]
19+
[InlineData(new[] { "AAA", "SubNamespace" }, "AAA.SubNamespace")]
1720
public void Create_ShouldReturnCorrect_Namespace(
1821
string[] values,
1922
string expected)

0 commit comments

Comments
 (0)