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
28 changes: 27 additions & 1 deletion Scripts/openapi_generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ allowed_models=(
UserResponse
)

# Models that keep the generated Hashable conformance; every other model has its
# Hashable extension stripped in step 4d. Uses the post-rename names (step 4b),
# unlike allowed_models above which uses the generator's original names.
allowed_hashable_models=(
AppSettings
UploadConfig
)

# Exact membership test (macOS bash 3.2 — no associative arrays).
contains() {
local needle="$1"; shift
Expand Down Expand Up @@ -169,17 +177,35 @@ rename_generated Images GiphyImages
rename_generated_type Response EmptyResponse

# 4c. Expose selected generated models as public API. The class and its stored
# properties become public; the memberwise init and CodingKeys stay internal.
# properties become public, along with the generated Hashable conformance
# (== and hash(into:)); the memberwise init and CodingKeys stay internal.
publicize_model() {
local file="$OUTPUT_DIR_CHAT/models/$1.swift"
sed -i '' -E \
-e 's/^final class /public final class /' \
-e 's/^ let / public let /' \
-e 's/^ static func == / public static func == /' \
-e 's/^ func hash\(into / public func hash(into /' \
"$file"
}
publicize_model AppSettings
publicize_model UploadConfig

# 4d. Strip the generated Hashable conformance from every model not in
# allowed_hashable_models. The Hashable extension is always the last block in
# the file (opening at column 0, running to EOF), so delete from its opening
# line to end of file; swiftformat (step 5) tidies the leftover blank line.
strip_hashable_conformance() {
local f base
for f in "$OUTPUT_DIR_CHAT"/models/*.swift; do
[ -e "$f" ] || continue
base="$(basename "$f" .swift)"
contains "$base" "${allowed_hashable_models[@]}" && continue
sed -i '' -E "/^extension ${base}: Hashable \{\$/,\$d" "$f"
done
}
strip_hashable_conformance

# 5. Format.
swiftformat --config "$REPO_ROOT/.swiftformat" "$OUTPUT_DIR_CHAT"

Expand Down
22 changes: 22 additions & 0 deletions Sources/StreamChat/Generated/OpenAPI/models/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,25 @@ public final class AppSettings: Sendable, Codable, JSONEncodable {
case placement
}
}

extension AppSettings: Hashable {
public static func == (lhs: AppSettings, rhs: AppSettings) -> Bool {
lhs.asyncUrlEnrichEnabled == rhs.asyncUrlEnrichEnabled &&
lhs.autoTranslationEnabled == rhs.autoTranslationEnabled &&
lhs.fileUploadConfig == rhs.fileUploadConfig &&
lhs.id == rhs.id &&
lhs.imageUploadConfig == rhs.imageUploadConfig &&
lhs.name == rhs.name &&
lhs.placement == rhs.placement
}

public func hash(into hasher: inout Hasher) {
hasher.combine(asyncUrlEnrichEnabled)
hasher.combine(autoTranslationEnabled)
hasher.combine(fileUploadConfig)
hasher.combine(id)
hasher.combine(imageUploadConfig)
hasher.combine(name)
hasher.combine(placement)
}
}
18 changes: 18 additions & 0 deletions Sources/StreamChat/Generated/OpenAPI/models/UploadConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,21 @@ public final class UploadConfig: Sendable, Codable, JSONEncodable {
case sizeLimit = "size_limit"
}
}

extension UploadConfig: Hashable {
public static func == (lhs: UploadConfig, rhs: UploadConfig) -> Bool {
lhs.allowedFileExtensions == rhs.allowedFileExtensions &&
lhs.allowedMimeTypes == rhs.allowedMimeTypes &&
lhs.blockedFileExtensions == rhs.blockedFileExtensions &&
lhs.blockedMimeTypes == rhs.blockedMimeTypes &&
lhs.sizeLimit == rhs.sizeLimit
}

public func hash(into hasher: inout Hasher) {
hasher.combine(allowedFileExtensions)
hasher.combine(allowedMimeTypes)
hasher.combine(blockedFileExtensions)
hasher.combine(blockedMimeTypes)
hasher.combine(sizeLimit)
}
}
Loading