Skip to content

Commit 7e29ebe

Browse files
Merge pull request #15 from apivideo/handle-null-and-missing-values
feat(java) handle null and missing values
2 parents 107f2f9 + eb59add commit 7e29ebe

File tree

7 files changed

+42
-5
lines changed

7 files changed

+42
-5
lines changed

.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Sources/Models/LiveStreamSessionSession.swift
4747
Sources/Models/LiveStreamUpdatePayload.swift
4848
Sources/Models/Metadata.swift
4949
Sources/Models/NotFound.swift
50+
Sources/Models/NullableString.swift
5051
Sources/Models/Pagination.swift
5152
Sources/Models/PaginationLink.swift
5253
Sources/Models/PlayerSessionEvent.swift
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
43e1986a9224df34d0c23236ebb78435c9a93cf59b9543391a5038bdfd07639e
1+
89d90eb8417142f456f0e11aab66e6714f24bea291cb3c8cbd38de96f1d52dbe

Sources/Models/NullableString.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Foundation
2+
3+
public struct NullableString: Codable, Hashable {
4+
5+
public static let NULL = NullableString(value: nil)
6+
7+
public var value: String?
8+
9+
public init(value: String? = nil) {
10+
self.value = value
11+
}
12+
13+
// Encodable protocol methods
14+
15+
public func encode(to encoder: Encoder) throws {
16+
var container = encoder.singleValueContainer()
17+
try container.encode(self.value)
18+
}
19+
}

Sources/Models/VideoUpdatePayload.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import AnyCodable
1313
public struct VideoUpdatePayload: Codable, Hashable {
1414

1515
/** The unique ID for the player you want to associate with your video. */
16-
public var playerId: String?
16+
public var playerId: NullableString?
1717
/** The title you want to use for your video. */
1818
public var title: String?
1919
/** A brief description of the video. */
@@ -29,7 +29,7 @@ public struct VideoUpdatePayload: Codable, Hashable {
2929
/** A list (array) of dictionaries where each dictionary contains a key value pair that describes the video. As with tags, you must send the complete list of metadata you want as whatever you send here will overwrite the existing metadata for the video. [Dynamic Metadata](https://api.video/blog/endpoints/dynamic-metadata) allows you to define a key that allows any value pair. */
3030
public var metadata: [Metadata]?
3131

32-
public init(playerId: String? = nil, title: String? = nil, description: String? = nil, _public: Bool? = nil, panoramic: Bool? = nil, mp4Support: Bool? = nil, tags: [String]? = nil, metadata: [Metadata]? = nil) {
32+
public init(playerId: NullableString? = nil, title: String? = nil, description: String? = nil, _public: Bool? = nil, panoramic: Bool? = nil, mp4Support: Bool? = nil, tags: [String]? = nil, metadata: [Metadata]? = nil) {
3333
self.playerId = playerId
3434
self.title = title
3535
self.description = description

Tests/ApiVideoClient/Integration/VideosApiTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,20 @@ class ProgressiveUploadWithTokenTests: UploadWithTokenTestCase {
231231
uploadPart(file: SharedResources.v10m_partc!, isLastPart: true)
232232
}
233233
}
234+
235+
class UpdateTests: XCTestCase {
236+
func testPlayerIdEncoding() {
237+
do {
238+
let json1 = try CodableHelper.jsonEncoder.encode(VideoUpdatePayload(playerId: nil, title: "title"))
239+
XCTAssertFalse(String(decoding: json1, as: UTF8.self).contains("playerId"))
240+
241+
let json2 = try CodableHelper.jsonEncoder.encode(VideoUpdatePayload(playerId: NullableString.NULL, title: "title"))
242+
XCTAssertTrue(String(decoding: json2, as: UTF8.self).contains("\"playerId\" : null"))
243+
244+
let json3 = try CodableHelper.jsonEncoder.encode(VideoUpdatePayload(playerId: NullableString(value: "1234"), title: "title"))
245+
XCTAssertTrue(String(decoding: json3, as: UTF8.self).contains("\"playerId\" : \"1234\""))
246+
} catch {
247+
248+
}
249+
}
250+
}

docs/VideoUpdatePayload.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Properties
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
6-
**playerId** | **String** | The unique ID for the player you want to associate with your video. | [optional]
6+
**playerId** | **NullableString** | The unique ID for the player you want to associate with your video. | [optional]
77
**title** | **String** | The title you want to use for your video. | [optional]
88
**description** | **String** | A brief description of the video. | [optional]
99
**_public** | **Bool** | Whether the video is publicly available or not. False means it is set to private. Default is true. Tutorials on [private videos](https://api.video/blog/endpoints/private-videos). | [optional]

docs/VideosAPI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ Use this endpoint to update the parameters associated with your video. The video
247247
import ApiVideoClient
248248

249249
let videoId = "videoId_example" // String | The video ID for the video you want to delete.
250-
let videoUpdatePayload = video-update-payload(playerId: "playerId_example", title: "title_example", description: "description_example", _public: true, panoramic: false, mp4Support: true, tags: ["tags_example"], metadata: [metadata(key: "key_example", value: "value_example")]) // VideoUpdatePayload |
250+
let videoUpdatePayload = video-update-payload(playerId: NullableString(value: "pl4k0jvEUuaTdRAEjQ4Jfrgz"), title: "title_example", description: "description_example", _public: true, panoramic: false, mp4Support: true, tags: ["tags_example"], metadata: [metadata(key: "key_example", value: "value_example")]) // VideoUpdatePayload |
251251

252252
// Update a video
253253
VideosAPI.update(videoId: videoId, videoUpdatePayload: videoUpdatePayload) { (response, error) in

0 commit comments

Comments
 (0)