Skip to content

Commit e924c39

Browse files
Increase namespace/type-name shortening threshold from 64 to 128
Reduce the aggressiveness of the recently-added namespace segment and type name shortening by raising the default length threshold from 64 to 128 characters. Names between 65 and 128 characters now keep their full names instead of being truncated with a hash suffix. - StringExtensions.DefaultMaxNameSegmentLength: 64 -> 128 - CommonLanguageRefiner.ShortenOversizedNamespaceSegments default: 64 -> 128 - Updated affected tests and CHANGELOG Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent de3d18d commit e924c39

7 files changed

Lines changed: 21 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Changed
1515

16+
- Reduced the aggressiveness of namespace segment and type name shortening by raising the length threshold from 64 to 128 characters, so names between 65 and 128 characters keep their full names.
17+
1618
## [1.33.0] - 2026-07-06
1719

1820
### Added

src/Kiota.Builder/Extensions/StringExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ public static string ShortenFileName(this string name, int length = 251) =>
7575
(!string.IsNullOrEmpty(name) && name.Length > length) ? HashString(name).ToLowerInvariant() : name;
7676
#pragma warning restore CA1308
7777

78-
private const int DefaultMaxNameSegmentLength = 64;
78+
private const int DefaultMaxNameSegmentLength = 128;
7979
private const int HashSuffixLength = 8;
8080
/// <summary>
8181
/// Shortens a name segment to the specified maximum length by truncating and appending a short hash suffix.
8282
/// Preserves human readability by keeping the first part of the original name.
8383
/// </summary>
8484
/// <param name="name">The name to potentially shorten</param>
85-
/// <param name="maxLength">The maximum allowed length. Default is 64.</param>
85+
/// <param name="maxLength">The maximum allowed length. Default is 128.</param>
8686
/// <returns>The original name if within limits, or a truncated name with hash suffix for uniqueness</returns>
8787
public static string ShortenNameSegment(this string name, int maxLength = DefaultMaxNameSegmentLength)
8888
{

src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ protected static void DeduplicateErrorMappings(CodeElement codeElement)
16351635
/// that map only namespaces to directories and group types into barrel files, where renaming types would
16361636
/// break downstream name-based generation without any file-system benefit.
16371637
/// </param>
1638-
protected static void ShortenOversizedNamespaceSegments(CodeElement currentElement, int maxSegmentLength = 64, bool shortenTypeNames = true)
1638+
protected static void ShortenOversizedNamespaceSegments(CodeElement currentElement, int maxSegmentLength = 128, bool shortenTypeNames = true)
16391639
{
16401640
if (currentElement is CodeNamespace codeNamespace && !string.IsNullOrEmpty(codeNamespace.Name))
16411641
{

tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,17 @@ public void ShortenNameSegmentReturnsOriginalWhenUnderLimit()
140140
[Fact]
141141
public void ShortenNameSegmentReturnsOriginalAtExactLimit()
142142
{
143-
var name = new string('a', 64);
143+
var name = new string('a', 128);
144144
Assert.Equal(name, name.ShortenNameSegment());
145145
}
146146
[Fact]
147147
public void ShortenNameSegmentTruncatesAndAppendsHashWhenOverLimit()
148148
{
149-
var longName = "MicrosoftGraphNetworkaccessDeviceReportWithStartDateTimeWithEndDateTimeWithDiscoveredApplicationSegmentId";
149+
var longName = "MicrosoftGraphNetworkaccessDeviceReportWithStartDateTimeWithEndDateTimeWithDiscoveredApplicationSegmentIdWithApplicationIdWithAiAgentIdWithCloudApplicationName";
150150
var result = longName.ShortenNameSegment();
151-
Assert.Equal(64, result.Length);
152-
// First 55 chars are preserved (64 - 8 hash - 1 underscore)
153-
Assert.StartsWith("MicrosoftGraphNetworkaccessDeviceReportWithStartDateTim", result);
151+
Assert.Equal(128, result.Length);
152+
// First 119 chars are preserved (128 - 8 hash - 1 underscore)
153+
Assert.StartsWith("MicrosoftGraphNetworkaccessDeviceReportWithStartDateTimeWithEndDateTimeWithDiscoveredApplicationSegmentIdWithApplicatio", result);
154154
Assert.Contains("_", result);
155155
}
156156
[Fact]

tests/Kiota.Builder.Tests/Refiners/JavaLanguageRefinerTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,11 @@ public async Task ShortensOversizedNamespaceSegmentsAsync()
791791
var nameSegments = childNs.Name.Split('.');
792792
foreach (var segment in nameSegments)
793793
{
794-
Assert.True(segment.Length <= 64, $"Segment '{segment}' exceeds 64 chars (length: {segment.Length})");
794+
Assert.True(segment.Length <= 128, $"Segment '{segment}' exceeds 128 chars (length: {segment.Length})");
795795
}
796796

797797
// Class name should be shortened
798-
Assert.True(requestBuilderClass.Name.Length <= 64, $"Class name '{requestBuilderClass.Name}' exceeds 64 chars (length: {requestBuilderClass.Name.Length})");
798+
Assert.True(requestBuilderClass.Name.Length <= 128, $"Class name '{requestBuilderClass.Name}' exceeds 128 chars (length: {requestBuilderClass.Name.Length})");
799799

800800
// Doc comment should contain original name for disambiguation
801801
Assert.Contains("Original name:", requestBuilderClass.Documentation.DescriptionTemplate);
@@ -830,7 +830,7 @@ public async Task ShorteningIsDeterministicAsync()
830830
public async Task ShortenedClassNameIsReflectedInMethodReturnTypeAsync()
831831
{
832832
// Simulate: parent request builder has a method returning a child request builder with a long name
833-
var longClassName = "MicrosoftGraphNetworkaccessDeviceReportWithStartDateTimeWithEndDateTimeRequestBuilder";
833+
var longClassName = "MicrosoftGraphNetworkaccessDeviceReportWithStartDateTimeWithEndDateTimeWithDiscoveredApplicationSegmentIdWithApplicationIdRequestBuilder";
834834
var parentNs = root.AddNamespace("com.microsoft.graph.beta.networkaccess.reports");
835835
var longSegment = "microsoftgraphnetworkaccessdevicereportwithstartdatetimewithenddatetime";
836836
var childNs = root.AddNamespace($"com.microsoft.graph.beta.networkaccess.reports.{longSegment}");
@@ -861,11 +861,11 @@ public async Task ShortenedClassNameIsReflectedInMethodReturnTypeAsync()
861861
await ILanguageRefiner.RefineAsync(new GenerationConfiguration { Language = GenerationLanguage.Java }, root, cancellationToken: TestContext.Current.CancellationToken);
862862

863863
// The class should be shortened
864-
Assert.True(targetClass.Name.Length <= 64, $"Class name '{targetClass.Name}' exceeds 64 chars");
864+
Assert.True(targetClass.Name.Length <= 128, $"Class name '{targetClass.Name}' exceeds 128 chars");
865865

866866
// The method's return type should automatically reflect the shortened name via TypeDefinition
867867
Assert.Equal(targetClass.Name, returnType.Name);
868-
Assert.True(returnType.Name.Length <= 64, $"Return type name '{returnType.Name}' exceeds 64 chars");
868+
Assert.True(returnType.Name.Length <= 128, $"Return type name '{returnType.Name}' exceeds 128 chars");
869869
}
870870
[Fact]
871871
public async Task ShorteningWorksWhenDocumentationIsNullAsync()
@@ -883,7 +883,7 @@ public async Task ShorteningWorksWhenDocumentationIsNullAsync()
883883
await ILanguageRefiner.RefineAsync(new GenerationConfiguration { Language = GenerationLanguage.Java }, root, cancellationToken: TestContext.Current.CancellationToken);
884884

885885
// Should shorten without throwing
886-
Assert.True(requestBuilderClass.Name.Length <= 64);
886+
Assert.True(requestBuilderClass.Name.Length <= 128);
887887
}
888888
#endregion
889889
}

tests/Kiota.Builder.Tests/Refiners/PhpLanguageRefinerTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,18 @@ public async Task ShortensOversizedNamespaceSegmentsAsync()
319319
// Namespace segment should be shortened
320320
foreach (var segment in childNs.Name.Split('.'))
321321
{
322-
Assert.True(segment.Length <= 64, $"Segment '{segment}' exceeds 64 chars (length: {segment.Length})");
322+
Assert.True(segment.Length <= 128, $"Segment '{segment}' exceeds 128 chars (length: {segment.Length})");
323323
}
324324

325325
// Class name should be shortened
326-
Assert.True(requestBuilderClass.Name.Length <= 64, $"Class name '{requestBuilderClass.Name}' exceeds 64 chars");
326+
Assert.True(requestBuilderClass.Name.Length <= 128, $"Class name '{requestBuilderClass.Name}' exceeds 128 chars");
327327
}
328328
[Fact]
329329
public async Task ShortenedClassImportsAreConsistentAsync()
330330
{
331331
// Parent request builder references a child with a long name via method return type
332332
var parentNs = root.AddNamespace("ApiSdk.NetworkAccess.Reports");
333-
var longSegment = "MicrosoftGraphNetworkaccessDeviceReportWithStartDateTimeWithEndDateTimeDiscoveredApplicationSegmentId";
333+
var longSegment = "MicrosoftGraphNetworkaccessDeviceReportWithStartDateTimeWithEndDateTimeDiscoveredApplicationSegmentIdDiscoveredApplicationSegmentIdApplicationIdApplicationId";
334334
var childNs = root.AddNamespace($"ApiSdk.NetworkAccess.Reports.{longSegment}");
335335

336336
var targetClass = childNs.AddClass(new CodeClass
@@ -363,7 +363,7 @@ public async Task ShortenedClassImportsAreConsistentAsync()
363363
var nsSegments = u.Name.Split('.');
364364
foreach (var seg in nsSegments)
365365
{
366-
Assert.True(seg.Length <= 64, $"Using namespace segment '{seg}' exceeds 64 chars — stale pre-shortened name");
366+
Assert.True(seg.Length <= 128, $"Using namespace segment '{seg}' exceeds 128 chars — stale pre-shortened name");
367367
}
368368
}
369369
}

tests/Kiota.Builder.Tests/Refiners/TypeScriptLanguageRefinerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public async Task ShortensOversizedNamespaceSegmentsAsync()
120120
// TypeScript maps namespaces (not type names) to directories, so only segments are shortened.
121121
foreach (var segment in childNs.Name.Split('.'))
122122
{
123-
Assert.True(segment.Length <= 64, $"Segment '{segment}' exceeds 64 chars (length: {segment.Length})");
123+
Assert.True(segment.Length <= 128, $"Segment '{segment}' exceeds 128 chars (length: {segment.Length})");
124124
}
125125

126126
// Type names must be left intact: TypeScript groups types into index.ts barrels and relies on

0 commit comments

Comments
 (0)