Skip to content
Closed
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
2 changes: 1 addition & 1 deletion platforms/swift/.swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
--allman false
--semicolons inline
--trimwhitespace always
--disable redundantReturn,hoistAwait,preferKeyPath,redundantInternal,redundantPublic
--disable redundantReturn,hoistAwait,preferKeyPath,redundantInternal,redundantPublic,duplicateImports
--swiftversion 5.7.1
--extensionacl on-declarations
--exclude Sources/ShopifyCheckoutKit/Models.swift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4144,18 +4144,14 @@ func newJSONEncoder() -> JSONEncoder {

// MARK: - Encode/decode helpers

public class JSONNull: Codable, Hashable {
public final class JSONNull: Codable, Hashable, Sendable {

public static func == (lhs: JSONNull, rhs: JSONNull) -> Bool {
return true
}

public var hashValue: Int {
return 0
}

public func hash(into hasher: inout Hasher) {
// No-op
hasher.combine(0)
}

public init() {}
Expand Down Expand Up @@ -4193,7 +4189,7 @@ final class JSONCodingKey: CodingKey, Sendable {
}
}

public class JSONAny: Codable {
public final class JSONAny: Codable, @unchecked Sendable {

public let value: Any

Expand Down
46 changes: 38 additions & 8 deletions protocol/scripts/generate_models.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ async function generateSwift(specDir, output) {
await runQuicktype([
"--lang",
"swift",
"--swift-5-support",
"--access-level",
"public",
"--sendable",
Expand All @@ -334,16 +333,47 @@ async function generateSwift(specDir, output) {

await normalizeGeneratedFile(output, (source) => {
// quicktype's --sendable option marks generated models as Sendable, but quicktype 23.2.6
// still emits the dynamic JSON coding key helper as a non-final, non-Sendable class.
// Removing --swift-5-support does not change this output, so normalize the helper here.
const result = source.replace(
// still emits dynamic JSON helper types that are not fully Swift 6 concurrency-safe.
// Removing --swift-5-support does not fix these helpers, so normalize them here.
const replaceRequired = (input, pattern, replacement, description) => {
const result = input.replace(pattern, replacement);
if (result === input) {
throw new Error(`${description} normalization failed; quicktype output may have changed`);
}
return result;
};

let result = source;
result = replaceRequired(
result,
/^public class JSONNull: Codable, Hashable \{/m,
"public final class JSONNull: Codable, Hashable, Sendable {",
"JSONNull Sendable",
);
result = replaceRequired(
result,
/\n public var hashValue: Int \{\n return 0\n \}\n\n/,
"\n",
"JSONNull hashValue removal",
);
result = replaceRequired(
result,
/^ public func hash\(into (?:_:|hasher:) inout Hasher\) \{\n \/\/ No-op\n \}/m,
" public func hash(into hasher: inout Hasher) {\n hasher.combine(0)\n }",
"JSONNull hash(into:) implementation",
);
result = replaceRequired(
result,
/^class JSONCodingKey: CodingKey \{/m,
"final class JSONCodingKey: CodingKey, Sendable {",
"JSONCodingKey Sendable",
);
result = replaceRequired(
result,
/^public class JSONAny: Codable \{/m,
"public final class JSONAny: Codable, @unchecked Sendable {",
"JSONAny Sendable",
);

if (result === source) {
throw new Error("JSONCodingKey Sendable normalization failed; quicktype output may have changed");
}

return result;
});
Expand Down
Loading