Skip to content

Commit

Permalink
feat(java) handle null and missing values
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierapivideo authored Jan 13, 2022
1 parent 107f2f9 commit eb59add
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Sources/Models/LiveStreamSessionSession.swift
Sources/Models/LiveStreamUpdatePayload.swift
Sources/Models/Metadata.swift
Sources/Models/NotFound.swift
Sources/Models/NullableString.swift
Sources/Models/Pagination.swift
Sources/Models/PaginationLink.swift
Sources/Models/PlayerSessionEvent.swift
Expand Down
2 changes: 1 addition & 1 deletion .openapi-generator/oas_apivideo.yaml-defaut-cli.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
43e1986a9224df34d0c23236ebb78435c9a93cf59b9543391a5038bdfd07639e
89d90eb8417142f456f0e11aab66e6714f24bea291cb3c8cbd38de96f1d52dbe
19 changes: 19 additions & 0 deletions Sources/Models/NullableString.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Foundation

public struct NullableString: Codable, Hashable {

public static let NULL = NullableString(value: nil)

public var value: String?

public init(value: String? = nil) {
self.value = value
}

// Encodable protocol methods

public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(self.value)
}
}
4 changes: 2 additions & 2 deletions Sources/Models/VideoUpdatePayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import AnyCodable
public struct VideoUpdatePayload: Codable, Hashable {

/** The unique ID for the player you want to associate with your video. */
public var playerId: String?
public var playerId: NullableString?
/** The title you want to use for your video. */
public var title: String?
/** A brief description of the video. */
Expand All @@ -29,7 +29,7 @@ public struct VideoUpdatePayload: Codable, Hashable {
/** 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. */
public var metadata: [Metadata]?

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) {
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) {
self.playerId = playerId
self.title = title
self.description = description
Expand Down
17 changes: 17 additions & 0 deletions Tests/ApiVideoClient/Integration/VideosApiTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,20 @@ class ProgressiveUploadWithTokenTests: UploadWithTokenTestCase {
uploadPart(file: SharedResources.v10m_partc!, isLastPart: true)
}
}

class UpdateTests: XCTestCase {
func testPlayerIdEncoding() {
do {
let json1 = try CodableHelper.jsonEncoder.encode(VideoUpdatePayload(playerId: nil, title: "title"))
XCTAssertFalse(String(decoding: json1, as: UTF8.self).contains("playerId"))

let json2 = try CodableHelper.jsonEncoder.encode(VideoUpdatePayload(playerId: NullableString.NULL, title: "title"))
XCTAssertTrue(String(decoding: json2, as: UTF8.self).contains("\"playerId\" : null"))

let json3 = try CodableHelper.jsonEncoder.encode(VideoUpdatePayload(playerId: NullableString(value: "1234"), title: "title"))
XCTAssertTrue(String(decoding: json3, as: UTF8.self).contains("\"playerId\" : \"1234\""))
} catch {

}
}
}
2 changes: 1 addition & 1 deletion docs/VideoUpdatePayload.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**playerId** | **String** | The unique ID for the player you want to associate with your video. | [optional]
**playerId** | **NullableString** | The unique ID for the player you want to associate with your video. | [optional]
**title** | **String** | The title you want to use for your video. | [optional]
**description** | **String** | A brief description of the video. | [optional]
**_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]
Expand Down
2 changes: 1 addition & 1 deletion docs/VideosAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Use this endpoint to update the parameters associated with your video. The video
import ApiVideoClient

let videoId = "videoId_example" // String | The video ID for the video you want to delete.
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 |
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 |

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

0 comments on commit eb59add

Please sign in to comment.