Skip to content

fix(swift): honor --acronym-style for leading acronyms#3006

Merged
schani merged 1 commit into
masterfrom
agent/fix-issue-1599
Jul 22, 2026
Merged

fix(swift): honor --acronym-style for leading acronyms#3006
schani merged 1 commit into
masterfrom
agent/fix-issue-1599

Conversation

@schani

@schani schani commented Jul 20, 2026

Copy link
Copy Markdown
Member

Bug

With --acronym-style set to anything other than the default (pascal),
Swift type names with a leading acronym word ignored the option. For
example, with --acronym-style original the JSON key FaqCoordinate
incorrectly produced:

struct FAQCoordinate: Codable {

while AFaqCoordinate (where the acronym "Faq" is not the first word)
correctly produced:

struct AFaqCoordinate: Codable {

Root cause

swiftNameStyle in packages/quicktype-core/src/language/Swift/utils.ts
calls combineWords with separate style functions for the first word vs.
the rest of a name, and separately again for acronym vs. non-acronym words.
The style used for a first-word acronym was hardcoded to
isUpper ? allUpperWordStyle : allLowerWordStyle, instead of being derived
from the acronymsStyle parameter that carries the user's
--acronym-style choice. The style used for a later-word acronym
(restAcronymStyle) already correctly used acronymsStyle. So acronyms
anywhere but the first word honored the option; the first word did not.

Fix

Changed the hardcoded firstWordAcronymStyle argument to use acronymsStyle
(matching how Kotlin's equivalent kotlinNameStyle already wires this up)
when isUpper is true:

-        isUpper ? allUpperWordStyle : allLowerWordStyle,
+        isUpper ? acronymsStyle : allLowerWordStyle,

Non-upper (camelCase, e.g. property names) first words are left as
allLowerWordStyle, matching existing behavior and JS/Swift lowerCamelCase
identifier conventions.

Test coverage

Added test/unit/swift-acronym-names.test.ts, which generates Swift output
directly via quicktype() for a type whose only property-bearing name is
FaqCoordinate and asserts on the emitted struct declaration name across
--acronym-style values original, pascal, camel, and lowerCase.

A unit test (rather than a JSON/JSON Schema fixture) is used because this
class of bug is invisible to the fixture harness: fixture tests round-trip
JSON through the generated code and diff the result, but the identifier
casing bug only affects the generated source identifier (the struct/type
name), not the JSON keys/values that get serialized and compared — the
mangled identifier is still self-consistent, compiles, and round-trips
correctly. This mirrors the precedent set by test/unit/java-acronym-names.test.ts
(added in #2851 for a related Java enum-constant acronym-casing bug), which
documents the same reasoning.

Verification

  • Added the regression test first and confirmed it failed on unfixed code
    (3 of 4 acronym-style cases produced FAQCoordinate instead of the
    expected casing).
  • Applied the fix; the regression test now passes (4/4).
  • Ran the full unit suite (npx vitest run test/unit): 167/167 passing, no
    regressions.
  • npm run build passes.
  • Manually re-ran the CLI repro from the issue
    (node dist/index.js -l swift --acronym-style original input.json) and
    confirmed FaqCoordinate now renders correctly, while re-checking
    --acronym-style pascal (the default) still renders FAQCoordinate as
    before (no behavior change for the default style).
  • The Swift fixture/compile tests (FIXTURE=swift script/test) were not run
    locally — the swiftc toolchain is not available in this environment.
    This will be validated by CI; note that fixture tests would not have
    caught this bug in the first place (see above), so the unit test is the
    operative coverage here.

Fixes #1599

🤖 Generated with Claude Code

The Swift name-styling helper hardcoded allUpperWordStyle/allLowerWordStyle
for the first word of a name whenever it was recognized as an acronym,
ignoring the acronymsStyle derived from the --acronym-style option. Later
words in the same name already used acronymsStyle correctly, so an acronym
appearing anywhere but the first position was styled correctly while the
leading position always came out upper/lower-cased regardless of the option.

Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
@schani
schani merged commit c7ebaa2 into master Jul 22, 2026
28 checks passed
@schani
schani deleted the agent/fix-issue-1599 branch July 22, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--acronym-style is not working properly for SWIFT

1 participant