fix(Java): normalize PascalCase acronyms in class/enum names to prevent casing mismatch#7663
Closed
ramsessanchez wants to merge 3 commits intomainfrom
Closed
fix(Java): normalize PascalCase acronyms in class/enum names to prevent casing mismatch#7663ramsessanchez wants to merge 3 commits intomainfrom
ramsessanchez wants to merge 3 commits intomainfrom
Conversation
…nt casing mismatch When OpenAPI metadata changes acronym casing (e.g. Dlp to DLP), git with core.ignorecase=true preserves the old file name on disk while the class declaration uses the new casing, causing Java compilation failures. Normalize consecutive uppercase acronyms in model class and enum names during Java refinement so the generated output is deterministic regardless of upstream acronym casing changes. Fixes #7654 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…duplicate check CorrectNames uses FindChildByName which relies on InnerChildElements (OrdinalIgnoreCase dictionary). For case-only renames like DLP→Dlp, FindChildByName finds the existing element and blocks the rename. NormalizeAcronymCasing skips the duplicate check since case-only renames are safe with the OrdinalIgnoreCase dictionary - RenameChildElement removes by old key and re-adds with new casing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
Closing the pull request as the solution is to instead add a check to our sdk's that prevent case changes such as that from being passed, especially in v1.0 as they present a binary breaking change. |
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 #7654 — Java class name / file name casing mismatch for acronyms causes compilation failure.
Root Cause
When OpenAPI metadata changes the casing of acronyms in type names (e.g.
ComplianceDlpApplicationsAuditRecord→ComplianceDLPApplicationsAuditRecord), the generated Java class declaration uses the new casing, but git does not recognize case-only file name changes whencore.ignorecase=true(the default on Windows and often inherited by repos initialized there). This means:ubuntu-latest) produces a file namedComplianceDLPApplicationsAuditRecord.javawithpublic class ComplianceDLPApplicationsAuditRecordinside.git addwithcore.ignorecase=truetreats the new file as a modification to the old-cased pathComplianceDlpApplicationsAuditRecord.java, preserving the old file name in the index.class X is public, should be declared in a file named X.java).This caused 19 compilation errors in microsoftgraph/msgraph-beta-sdk-java#1309.
Fix
Normalize consecutive uppercase acronyms in model class and enum names during Java refinement so the output is deterministic regardless of upstream acronym casing changes:
ComplianceDLPApplicationsAuditRecordComplianceDlpApplicationsAuditRecordPowerBIAuditRecordPowerBiAuditRecordOnPremisesSharePointScannerDLPAuditRecordOnPremisesSharePointScannerDlpAuditRecordWhether the metadata says
DLPorDlp, the generated Java code always producesDlp— matching Java PascalCase conventions for acronyms.Changes
StringExtensions.cs: AddedNormalizePascalCaseAcronyms()extension methodJavaRefiner.cs: Added aCorrectNamespass using the normalizer (runs after the existing underscore-to-PascalCase pass)