From 7a233c5bc4d165eb20288bd8748c6bb09356ea6e Mon Sep 17 00:00:00 2001 From: Aysajan Eziz Date: Mon, 13 Jul 2026 16:15:02 -0400 Subject: [PATCH] fix(swift): emit JSONNull hash(into:) by default Signed-off-by: Aysajan Eziz --- .../src/language/Swift/SwiftRenderer.ts | 6 ++--- test/unit/swift-json-null-hashable.test.ts | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 test/unit/swift-json-null-hashable.test.ts diff --git a/packages/quicktype-core/src/language/Swift/SwiftRenderer.ts b/packages/quicktype-core/src/language/Swift/SwiftRenderer.ts index b9fae90ee9..fa77615b20 100644 --- a/packages/quicktype-core/src/language/Swift/SwiftRenderer.ts +++ b/packages/quicktype-core/src/language/Swift/SwiftRenderer.ts @@ -1185,12 +1185,10 @@ encoder.dateEncodingStrategy = .formatted(formatter)`); return 0 }`); - if (this._options.swift5Support) { - this.ensureBlankLine(); - this.emitMultiline(` public func hash(into hasher: inout Hasher) { + this.ensureBlankLine(); + this.emitMultiline(` public func hash(into hasher: inout Hasher) { // No-op }`); - } } this.ensureBlankLine(); diff --git a/test/unit/swift-json-null-hashable.test.ts b/test/unit/swift-json-null-hashable.test.ts new file mode 100644 index 0000000000..78c9cf9288 --- /dev/null +++ b/test/unit/swift-json-null-hashable.test.ts @@ -0,0 +1,27 @@ +import { + InputData, + JSONSchemaInput, + quicktype, +} from "../../packages/quicktype-core/src/index.js"; +import { expect, test } from "vitest"; + +const schema = JSON.stringify({ + type: "object", + properties: { + value: {}, + }, + required: ["value"], +}); + +test("emits hash(into:) for JSONNull by default", async () => { + const schemaInput = new JSONSchemaInput(undefined); + await schemaInput.addSource({ name: "TopLevel", schema }); + + const inputData = new InputData(); + inputData.addInput(schemaInput); + + const result = await quicktype({ inputData, lang: "swift" }); + const output = result.lines.join("\n"); + + expect(output).toContain("public func hash(into hasher: inout Hasher)"); +});