From 0fb568e27fbf81e839f608eeacc2b5a79175f24f Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Mon, 20 Jul 2026 17:24:48 -0400 Subject: [PATCH] fix(swift): honor --acronym-style for leading acronyms (#1599) 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 --- .../src/language/Swift/utils.ts | 2 +- test/unit/swift-acronym-names.test.ts | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/unit/swift-acronym-names.test.ts diff --git a/packages/quicktype-core/src/language/Swift/utils.ts b/packages/quicktype-core/src/language/Swift/utils.ts index 5c068a5a05..228ddeae14 100644 --- a/packages/quicktype-core/src/language/Swift/utils.ts +++ b/packages/quicktype-core/src/language/Swift/utils.ts @@ -69,7 +69,7 @@ export function swiftNameStyle( legalizeName, isUpper ? firstUpperWordStyle : allLowerWordStyle, firstUpperWordStyle, - isUpper ? allUpperWordStyle : allLowerWordStyle, + isUpper ? acronymsStyle : allLowerWordStyle, acronymsStyle, "", isStartCharacter, diff --git a/test/unit/swift-acronym-names.test.ts b/test/unit/swift-acronym-names.test.ts new file mode 100644 index 0000000000..bc9310510b --- /dev/null +++ b/test/unit/swift-acronym-names.test.ts @@ -0,0 +1,45 @@ +// The fixture harness cannot catch acronym casing in Swift type names: the +// generated identifiers are self-consistent, so the code still compiles and +// round-trips JSON successfully. Generate Swift directly and assert on the +// emitted struct declaration instead. + +import { + InputData, + jsonInputForTargetLanguage, + quicktype, +} from "../../packages/quicktype-core/src/index.js"; +import { describe, expect, test } from "vitest"; + +async function swiftStructName(acronymStyle: string): Promise { + const jsonInput = jsonInputForTargetLanguage("swift"); + await jsonInput.addSource({ + name: "FaqCoordinate", + samples: ['{"x":1,"y":2}'], + }); + + const inputData = new InputData(); + inputData.addInput(jsonInput); + + const result = await quicktype({ + inputData, + lang: "swift", + rendererOptions: { "acronym-style": acronymStyle }, + }); + const output = result.lines.join("\n"); + const match = output.match(/^struct (\w+): Codable \{$/m); + + // biome-ignore lint/suspicious/noMisplacedAssertion: helper is only called from within tests + expect(match, `generated Swift output:\n${output}`).not.toBeNull(); + return match?.[1] ?? ""; +} + +describe("Swift leading acronym casing", () => { + test.each([ + ["original", "FaqCoordinate"], + ["pascal", "FAQCoordinate"], + ["camel", "FaqCoordinate"], + ["lowerCase", "faqCoordinate"], + ])("honors acronym-style=%s for struct names", async (acronymStyle, expectedName) => { + await expect(swiftStructName(acronymStyle)).resolves.toBe(expectedName); + }); +});