-
Notifications
You must be signed in to change notification settings - Fork 234
Replace Device struct with the OpenAPI generated model #4161
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
Changes from all commits
a97a491
92562a5
2297a68
37fcc33
ad46c6e
0256f81
89b2c29
4253bcf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ allowed_models=( | |
| # unlike allowed_models above which uses the generator's original names. | ||
| allowed_hashable_models=( | ||
| AppSettings | ||
| Device | ||
| UploadConfig | ||
| ) | ||
|
|
||
|
|
@@ -164,11 +165,23 @@ prune_models() { | |
| } | ||
| prune_models | ||
|
|
||
| # Relax selected generated stored properties back to optional. Some models are | ||
| # exposed as public API where a property was historically optional (e.g. | ||
| # Device.createdAt was Date? before the OpenAPI migration). | ||
| optionalize_property() { | ||
| local file="$OUTPUT_DIR_CHAT/models/$1.swift" | ||
| sed -i '' -E \ | ||
| -e "s/^( let $2: [^?]+)$/\1?/" \ | ||
| "$file" | ||
| } | ||
| optionalize_property DeviceResponse createdAt | ||
|
|
||
| # 4b. Rename selected generated models for clarity and to avoid generic-name | ||
| # pollution / collisions with hand-written SDK types. Runs AFTER prune_models | ||
| # so allowed_models above still matches the generator's original names. | ||
| rename_generated Action AttachmentActionPayload | ||
| rename_generated AppResponseFields AppSettings | ||
| rename_generated DeviceResponse Device | ||
| rename_generated Field AttachmentFieldPayload | ||
| rename_generated FileUploadConfig UploadConfig | ||
| rename_generated ImageData GiphyImageData | ||
|
|
@@ -189,6 +202,7 @@ publicize_model() { | |
| "$file" | ||
| } | ||
| publicize_model AppSettings | ||
| publicize_model Device | ||
|
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. OpenAPI models is not used as public model for Device type |
||
| publicize_model UploadConfig | ||
|
|
||
| # 4d. Strip the generated Hashable conformance from every model not in | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,13 @@ import Foundation | |
| class DeviceDTO: NSManagedObject { | ||
| @NSManaged var id: String | ||
| @NSManaged var createdAt: DBDate? | ||
| @NSManaged var disabled: NSNumber? | ||
|
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. Represents |
||
| @NSManaged var disabledReason: String? | ||
| @NSManaged var hardwareId: String? | ||
| @NSManaged var pushProvider: String | ||
| @NSManaged var pushProviderName: String? | ||
| @NSManaged var userId: String | ||
| @NSManaged var voip: NSNumber? | ||
|
|
||
| @NSManaged var user: CurrentUserDTO | ||
| } | ||
|
|
@@ -46,6 +53,16 @@ extension DeviceDTO { | |
| extension DeviceDTO { | ||
| func asModel() throws -> Device { | ||
| try isNotDeleted() | ||
| return Device(id: id, createdAt: createdAt?.bridgeDate) | ||
| return Device( | ||
| createdAt: createdAt?.bridgeDate ?? Date(timeIntervalSince1970: 0), | ||
| disabled: disabled?.boolValue, | ||
| disabledReason: disabledReason, | ||
| hardwareId: hardwareId, | ||
| id: id, | ||
| pushProvider: pushProvider, | ||
| pushProviderName: pushProviderName, | ||
| userId: userId, | ||
| voip: voip?.boolValue | ||
| ) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // | ||
| // Copyright Β© 2026 Stream.io Inc. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| /// A unique identifier of a device. | ||
| public typealias DeviceId = String | ||
|
|
||
| extension Data { | ||
| /// Generates a device id string from device token data. | ||
| var deviceId: DeviceId { map { String(format: "%02x", $0) }.joined() } | ||
| } | ||
|
|
||
| extension Device: Identifiable {} |
This file was deleted.
This file was deleted.
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.
In v6 this can be removed. Because Device is now public model, but our current model has createdAt as optional value, I need to change the generated model to match the current public model for avoiding API breaking changes in v5. Of course, in v6 we delete this and make a small breaking change.