fix: shorten oversized namespace segments and class names for Java, Python, PHP#7714
Merged
Merged
Conversation
gavinbarron
commented
May 21, 2026
…ython, PHP Adds ShortenNameSegment() extension method that truncates names exceeding 64 characters by keeping the first 55 chars + underscore + 8-char SHA256 hash suffix. This preserves human readability while ensuring uniqueness. Adds ShortenOversizedNamespaceSegments() in CommonLanguageRefiner that walks all CodeNamespace nodes and CodeClass instances, shortening any segment or class name exceeding the threshold. When a class is shortened, its doc comment is enriched with the original name for disambiguation. Called from JavaRefiner, PythonRefiner, and PhpRefiner after other naming transforms. This fixes Windows path limit violations caused by OData functions with many parameters (e.g., deviceReport with 7+ parameters generating 268+ char namespace segments). C#, Go, and TypeScript already avoid this via their own mechanisms (ShortenFileName in path segmenters, flat file layouts). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
b164335 to
2ed05cd
Compare
Member
|
@gavinbarron great on the general approach, it seems we've had a regression for PHP though (see integration tests). |
Reverts #7710 so the integration tests exercise the long-name patterns (deviceReport, userReport) that triggered path-length failures. Our shortening fix should now handle these correctly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
Integration tests doing their jobs nicely here. Good call on reverting that omission from the integration tests |
…ners ShortenOversizedNamespaceSegments must run BEFORE AddPropertiesAndMethodTypesImports so that CodeUsing.Name values reflect the shortened namespace paths. Otherwise, PHP 'use' statements contain stale pre-shortened namespace paths combined with shortened class names, causing PHPStan class.notFound errors. Java already had the correct order (shorten then imports). This aligns PHP and Python to match. Adds PHP refiner integration tests for shortening and import consistency. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
baywet
previously approved these changes
May 21, 2026
…rtening Directly setting codeElement.Name left stale keys in the parent's InnerChildElements dictionary. Later refiner steps (e.g., MoveClassesWithNamespaceNamesUnderNamespace, RemoveChildElement) that look up elements by Name failed with 'element to rename was not found'. Now uses parentNamespace.RenameChildElement(oldName, newName) which properly removes the old key and re-adds with the new shortened name. Iteration is materialized with .ToList() to avoid modifying the dictionary during enumeration. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…-namespace-segments
baywet
reviewed
May 21, 2026
ToArray() is more memory-efficient (no over-allocation) and aligns with the existing refiner convention in this codebase. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
baywet
approved these changes
May 22, 2026
Contributor
SummarySummary
Coveragekiota - 12.3%
Kiota.Builder - 83.9%
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #7713
OData functions with many parameters (e.g.,
deviceReportwith 7+ parameters) generate namespace segments and class names exceeding 268 characters, causing Windows MAX_PATH violations for Java, Python, and PHP.This PR shortens oversized names at the CodeDOM level (refiner phase) using truncation + 8-char SHA256 hash suffix, capping segments at 64 characters while preserving human readability and uniqueness.
Changes
Core shortening logic
StringExtensions.ShortenNameSegment()— Truncates names exceeding the limit by keeping the first 55 chars +_+ 8-char lowercase hex hash of the full original name. Deterministic and collision-resistant.CommonLanguageRefiner.ShortenOversizedNamespaceSegments()— Walks allCodeNamespacenodes, shortening any segment exceeding 64 chars. Also shortensCodeClass,CodeEnum, andCodeInterfacenames, enriching their doc comments with the original name for disambiguation.CommonLanguageRefiner.ShortenCodeElementNameIfOversized()— Helper that renames a code element and annotates its documentation. Handles null documentation defensively.Language refiner integration
LowerCaseNamespaceNames.ToSnakeCase()downstream (see Python: SnakeCaseNamespaceNames never executes — CrawlTree inside empty-name guard #7715 for a separate snake_case-at-CodeDOM-level fix)Why no fix needed for C#/Go/TypeScript
ShortenFileName()in its path segmenterShortenFileName(100)index.tsfilesType reference integrity
CodeType.Namehas a custom getter that delegates toTypeDefinition.Namewhen set (CodeType.cs:12). When we rename aCodeClass, allCodeTypeinstances pointing to it automatically return the new name — no manual update of return types or property types needed.Tests
ShortenNameSegmentandHashStringExample
Before (268 chars):
After (64 chars):