Skip to content

fix(Java): normalize PascalCase acronyms in class/enum names to prevent casing mismatch#7663

Closed
ramsessanchez wants to merge 3 commits intomainfrom
fix/java-acronym-casing-7654
Closed

fix(Java): normalize PascalCase acronyms in class/enum names to prevent casing mismatch#7663
ramsessanchez wants to merge 3 commits intomainfrom
fix/java-acronym-casing-7654

Conversation

@ramsessanchez
Copy link
Copy Markdown
Contributor

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. ComplianceDlpApplicationsAuditRecordComplianceDLPApplicationsAuditRecord), the generated Java class declaration uses the new casing, but git does not recognize case-only file name changes when core.ignorecase=true (the default on Windows and often inherited by repos initialized there). This means:

  1. The generation pipeline (running on ubuntu-latest) produces a file named ComplianceDLPApplicationsAuditRecord.java with public class ComplianceDLPApplicationsAuditRecord inside.
  2. git add with core.ignorecase=true treats the new file as a modification to the old-cased path ComplianceDlpApplicationsAuditRecord.java, preserving the old file name in the index.
  3. The committed file has old-cased name but new-cased class → Java compilation error on CI (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:

Before After
ComplianceDLPApplicationsAuditRecord ComplianceDlpApplicationsAuditRecord
PowerBIAuditRecord PowerBiAuditRecord
OnPremisesSharePointScannerDLPAuditRecord OnPremisesSharePointScannerDlpAuditRecord

Whether the metadata says DLP or Dlp, the generated Java code always produces Dlp — matching Java PascalCase conventions for acronyms.

Changes

  • StringExtensions.cs: Added NormalizePascalCaseAcronyms() extension method
  • JavaRefiner.cs: Added a CorrectNames pass using the normalizer (runs after the existing underscore-to-PascalCase pass)
  • Tests: Added unit tests for the string extension and Java refiner integration tests for both classes and enums

…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>
@msgraph-bot msgraph-bot Bot added this to Kiota Apr 28, 2026
@ramsessanchez ramsessanchez marked this pull request as ready for review April 29, 2026 18:42
@ramsessanchez ramsessanchez requested a review from a team as a code owner April 29, 2026 18:42
…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>
@ramsessanchez
Copy link
Copy Markdown
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.

@github-project-automation github-project-automation Bot moved this to Done ✔️ in Kiota Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

[Java] Class name / file name casing mismatch for acronyms causes compilation failure

1 participant