-
Notifications
You must be signed in to change notification settings - Fork 232
OpenAPI: Use generated ChannelCapabilities, VotingVisibility and PushPreferenceLevel #4224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
laevandus
wants to merge
1
commit into
develop
Choose a base branch
from
open-api-struct-over-enum
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -191,6 +191,7 @@ rm -rf "$OUTPUT_DIR_CHAT" | |
| ./build/chat-manager openapi generate-client --language swift \ | ||
| --opt immutable_models=true --opt access_modifier=internal \ | ||
| --opt encodable_filter_conditions=true \ | ||
| --opt struct_over_enum=true \ | ||
| --spec ./releases/v2/chat-clientside-api.yaml --output "$OUTPUT_DIR_CHAT" ) | ||
|
|
||
| # 2. Drop the generated async API client — the SDK ships its own APIClient. | ||
|
|
@@ -398,33 +399,19 @@ rename_generated ReactionResponse MessageReactionPayload | |
| rename_generated_type QueryReactionsResponse MessageReactionsPayload | ||
| rename_generated ChannelMemberResponse MemberPayload | ||
| rename_generated ChannelMute MutedChannelPayload | ||
| rename_generated ChannelOwnCapability ChannelCapability | ||
| rename_generated ChannelResponse ChannelDetailPayload | ||
| rename_generated MuteChannelResponse MutedChannelPayloadResponse | ||
|
|
||
| rename_generated_type CreatePollRequestVotingVisibility VotingVisibility | ||
| rename_generated_type PushPreferenceInputChatLevel PushPreferenceLevel | ||
|
|
||
| rename_generated_type HideChannelResponse EmptyResponse | ||
| rename_generated_type MarkDeliveredResponse EmptyResponse | ||
| rename_generated_type Response EmptyResponse | ||
| rename_generated_type ShowChannelResponse EmptyResponse | ||
| rename_generated_type UnmuteResponse EmptyResponse | ||
|
|
||
| # Remove a generated property (declaration, doc comment, init param, assignment, | ||
| # CodingKeys case). Runs before publicize, so there are no access modifiers to | ||
| # handle. Assumes the single-line init the generator emits (step 7 re-wraps). | ||
| remove_property() { | ||
| local file="$OUTPUT_DIR_CHAT/models/$1.swift" | ||
| awk -v p="$2" ' | ||
| function flush() { for (i = 1; i <= n; i++) print b[i]; n = 0 } | ||
| { s = $0; sub(/^[[:space:]]+/, "", s) } | ||
| s ~ /^(\/\/\/|@available)/ { b[++n] = $0; next } | ||
| s ~ "^let " p ": " { n = 0; next } | ||
| s ~ "^self\\." p " = " p "$" { next } | ||
| s ~ "^case " p "( =|$)" { next } | ||
| s ~ /^init\(/ { sub("\\(" p ": [^,)]*, ", "("); sub(", " p ": [^,)]*", ""); sub("\\(" p ": [^,)]*\\)", "()") } | ||
| { flush(); print } | ||
| ' "$file" > "$file.tmp" && mv "$file.tmp" "$file" | ||
| } | ||
| remove_property FileUploadResponse duration | ||
|
|
||
|
Comment on lines
-410
to
-427
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Script cleanup, it was a duplicate |
||
| retype_property PushPreference chatLevel String PushPreferenceLevel | ||
| rename_property PushPreference chatLevel level | ||
| restore_nonoptional_property PushPreference level PushPreferenceLevel .all | ||
|
|
@@ -460,6 +447,7 @@ remove_property() { | |
| perl -0777 -pi -e 's/ &&(\n\s*\})/$1/g' "$file" | ||
| } | ||
| remove_property CurrentUserUnreads duration | ||
| remove_property FileUploadResponse duration | ||
| remove_property MessageReactionsPayload duration | ||
| remove_property PushPreferenceInput callLevel | ||
| remove_property PushPreferenceInput chatPreferences | ||
|
|
@@ -485,17 +473,17 @@ retype_property ChannelDetailPayload config ChannelConfigWithInfo ChannelConfig | |
| # Will be changed on the generation side later | ||
| require_property ChannelDetailPayload config | ||
|
|
||
| remove_nested_enum() { | ||
| remove_type() { | ||
| local file="$OUTPUT_DIR_CHAT/models/$1.swift" | ||
| awk -v e="$2" ' | ||
| $0 ~ "^ enum " e ":" { skip = 1; next } | ||
| skip && /^ }$/ { skip = 0; next } | ||
| skip { next } | ||
| $0 ~ "^(enum|struct) " e ":" { skip = 1; next } | ||
| skip && /^}$/ { skip = 0; next } | ||
| skip { next } | ||
| { print } | ||
| ' "$file" > "$file.tmp" && mv "$file.tmp" "$file" | ||
| } | ||
| remove_nested_enum PushPreferenceInput PushPreferenceInputCallLevel | ||
| remove_nested_enum PushPreferenceInput PushPreferenceInputFeedsLevel | ||
| remove_type PushPreferenceInput PushPreferenceInputCallLevel | ||
| remove_type PushPreferenceInput PushPreferenceInputFeedsLevel | ||
|
|
||
| # 4c. Expose selected generated models as public API. The class and its stored | ||
| # properties become public, along with the generated Hashable conformance | ||
|
|
@@ -522,6 +510,27 @@ publicize_model UploadConfig | |
| publicize_model UserGroup | ||
| publicize_model UserGroupMember | ||
|
|
||
| # Expose a generated RawRepresentable struct as public API. Unlike publicize_model, the | ||
| # init must be public too — it is the RawRepresentable requirement — along with every | ||
| # static let holding a known value. The struct is looked up by name, since the file | ||
| # named after a model also holds the structs generated for its string properties. | ||
| publicize_raw_representable() { | ||
| local file="$OUTPUT_DIR_CHAT/models/$1.swift" | ||
| awk -v n="${2:-$1}" ' | ||
| $0 ~ "^struct " n ":" { sub(/^struct /, "public struct "); inside = 1; print; next } | ||
| inside && /^}$/ { inside = 0; print; next } | ||
| inside { | ||
| sub(/^ let /, " public let ") | ||
| sub(/^ init\(/, " public init(") | ||
| sub(/^ static let /, " public static let ") | ||
| } | ||
| { print } | ||
| ' "$file" > "$file.tmp" && mv "$file.tmp" "$file" | ||
| } | ||
| publicize_raw_representable ChannelCapability | ||
| publicize_raw_representable CreatePollRequestBody VotingVisibility | ||
| publicize_raw_representable PushPreferenceInput PushPreferenceLevel | ||
|
|
||
| # Drop `final` from a generated model so hand-written payloads can subclass it. | ||
| unfinalize_model() { | ||
| local file="$OUTPUT_DIR_CHAT/models/$1.swift" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Sources/StreamChat/Generated/OpenAPI/models/ChannelCapability.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // | ||
| // Copyright © 2026 Stream.io Inc. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| public struct ChannelCapability: RawRepresentable, Codable, Hashable, Sendable { | ||
| public let rawValue: String | ||
|
|
||
| public init(rawValue: String) { | ||
| self.rawValue = rawValue | ||
| } | ||
|
|
||
| public static let banChannelMembers = Self(rawValue: "ban-channel-members") | ||
| public static let castPollVote = Self(rawValue: "cast-poll-vote") | ||
| public static let connectEvents = Self(rawValue: "connect-events") | ||
| public static let createAttachment = Self(rawValue: "create-attachment") | ||
| public static let createMention = Self(rawValue: "create-mention") | ||
| public static let deleteAnyMessage = Self(rawValue: "delete-any-message") | ||
| public static let deleteChannel = Self(rawValue: "delete-channel") | ||
| public static let deleteOwnMessage = Self(rawValue: "delete-own-message") | ||
| public static let deliveryEvents = Self(rawValue: "delivery-events") | ||
| public static let flagMessage = Self(rawValue: "flag-message") | ||
| public static let freezeChannel = Self(rawValue: "freeze-channel") | ||
| public static let joinChannel = Self(rawValue: "join-channel") | ||
| public static let leaveChannel = Self(rawValue: "leave-channel") | ||
| public static let muteChannel = Self(rawValue: "mute-channel") | ||
| public static let notifyChannel = Self(rawValue: "notify-channel") | ||
| public static let notifyGroup = Self(rawValue: "notify-group") | ||
| public static let notifyHere = Self(rawValue: "notify-here") | ||
| public static let notifyRole = Self(rawValue: "notify-role") | ||
| public static let pinMessage = Self(rawValue: "pin-message") | ||
| public static let queryPollVotes = Self(rawValue: "query-poll-votes") | ||
| public static let quoteMessage = Self(rawValue: "quote-message") | ||
| public static let readEvents = Self(rawValue: "read-events") | ||
| public static let searchMessages = Self(rawValue: "search-messages") | ||
| public static let sendCustomEvents = Self(rawValue: "send-custom-events") | ||
| public static let sendLinks = Self(rawValue: "send-links") | ||
| public static let sendMessage = Self(rawValue: "send-message") | ||
| public static let sendPoll = Self(rawValue: "send-poll") | ||
| public static let sendReaction = Self(rawValue: "send-reaction") | ||
| public static let sendReply = Self(rawValue: "send-reply") | ||
| public static let sendRestrictedVisibilityMessage = Self(rawValue: "send-restricted-visibility-message") | ||
| public static let sendTypingEvents = Self(rawValue: "send-typing-events") | ||
| public static let setChannelCooldown = Self(rawValue: "set-channel-cooldown") | ||
| public static let shareLocation = Self(rawValue: "share-location") | ||
| public static let skipSlowMode = Self(rawValue: "skip-slow-mode") | ||
| public static let slowMode = Self(rawValue: "slow-mode") | ||
| public static let typingEvents = Self(rawValue: "typing-events") | ||
| public static let updateAnyMessage = Self(rawValue: "update-any-message") | ||
| public static let updateChannel = Self(rawValue: "update-channel") | ||
| public static let updateChannelMembers = Self(rawValue: "update-channel-members") | ||
| public static let updateOwnMessage = Self(rawValue: "update-own-message") | ||
| public static let updateThread = Self(rawValue: "update-thread") | ||
| public static let uploadFile = Self(rawValue: "upload-file") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 0 additions & 61 deletions
61
Sources/StreamChat/Generated/OpenAPI/models/ChannelOwnCapability.swift
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the option for changing enum generation to RawRepresentable based structs without nested types