Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/quicktype-core/src/language/Swift/SwiftRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}`);
Comment on lines +1189 to 1191

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep Swift 5 hashing behind the version option

For schemas that need JSONNull and are generated without --swift-5-support (the default, and the language is still exposed as swift4), this now emits hash(into:) and references Hasher unconditionally. Those APIs are not available on older Swift 4 toolchains, so the default Swift 4-compatible output will fail to compile even though the swift-5-support option is false.

Useful? React with 👍 / 👎.

}
}

this.ensureBlankLine();
Expand Down
27 changes: 27 additions & 0 deletions test/unit/swift-json-null-hashable.test.ts
Original file line number Diff line number Diff line change
@@ -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)");
});
Loading