Skip to content

fix: Fix issues in box-openapi (box/box-openapi#527) #454

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

Closed
wants to merge 16 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "c6650a9", "specHash": "a8825be", "version": "0.6.1" }
{ "engineHash": "20cb559", "specHash": "a54170e", "version": "0.6.1" }
2 changes: 1 addition & 1 deletion Sources/Box/CcgAuth/BoxCCGAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class BoxCCGAuth: Authentication {
/// - Returns: The `AccessToken`.
/// - Throws: The `GeneralError`.
public func downscopeToken(scopes: [String], resource: String? = nil, sharedLink: String? = nil, networkSession: NetworkSession? = nil) async throws -> AccessToken {
let token: AccessToken? = try await self.tokenStorage.get()
let token: AccessToken? = try await self.retrieveToken(networkSession: networkSession)
if token == nil {
throw BoxSDKError(message: "No access token is available. Make an API call to retrieve a token before calling this method.")
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Box/DeveloperTokenAuth/BoxDeveloperTokenAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class BoxDeveloperTokenAuth: Authentication {
/// - Returns: The `AccessToken`.
/// - Throws: The `GeneralError`.
public func downscopeToken(scopes: [String], resource: String? = nil, sharedLink: String? = nil, networkSession: NetworkSession? = nil) async throws -> AccessToken {
let token: AccessToken? = try await self.tokenStorage.get()
let token: AccessToken? = try await self.retrieveToken(networkSession: networkSession)
if token == nil || token!.accessToken == nil {
throw BoxSDKError(message: "No access token is available.")
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Box/Oauth/BoxOAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class BoxOAuth: Authentication {
/// - Returns: The `AccessToken`.
/// - Throws: The `GeneralError`.
public func downscopeToken(scopes: [String], resource: String? = nil, sharedLink: String? = nil, networkSession: NetworkSession? = nil) async throws -> AccessToken {
let token: AccessToken? = try await self.tokenStorage.get()
let token: AccessToken? = try await self.retrieveToken(networkSession: networkSession)
if token == nil || token!.accessToken == nil {
throw BoxSDKError(message: "No access token is available.")
}
Expand Down
23 changes: 23 additions & 0 deletions Sources/Internal/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ public enum Utils {
/// - value: An instance of any type.
/// - Returns: A string representation of the provided parameter, or nil when this is not possible.
public static func toString(value: Any?) -> String? {
if let date = value as? Date {
if Utils.Dates.isDateOnly(date) {
return Utils.Dates.dateToString(date: date)
} else {
return Utils.Dates.dateTimeToString(dateTime: date)
}
}

if let parameterConvertible = value as? ParameterConvertible {
return parameterConvertible.paramValue
} else if let encodable = value as? Encodable {
Expand Down Expand Up @@ -170,6 +178,21 @@ public enum Utils {
public static func dateToString(date: Date) -> String {
dateFormatter.string(from: date)
}

/// Checks if the date is in date only format
/// - Parameters:
/// - date: Date
/// - Returns: True if the date is in date only format, otherwise false.
public static func isDateOnly(_ date: Date) -> Bool {
var calendar = Calendar.current
calendar.timeZone = TimeZone(secondsFromGMT: 0)!
let components = calendar.dateComponents([.hour, .minute, .second, .nanosecond], from: date)

return (components.hour == 0 &&
components.minute == 0 &&
components.second == 0 &&
components.nanosecond == 0)
}
}

/// Creates and returns a string created from the UUID
Expand Down
6 changes: 6 additions & 0 deletions Sources/Managers/Files/UpdateFileByIdRequestBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class UpdateFileByIdRequestBody: Codable, RawJSONReadable {

/// An optional different name for the file. This can be used to
/// rename the file.
///
/// File names must be unique within their parent folder. The name check is case-insensitive, so a file
/// named `New File` cannot be created in a parent folder that already contains a folder named `new file`.
public let name: String?

/// The description for a file. This can be seen in the right-hand sidebar panel
Expand Down Expand Up @@ -78,6 +81,9 @@ public class UpdateFileByIdRequestBody: Codable, RawJSONReadable {
/// - Parameters:
/// - name: An optional different name for the file. This can be used to
/// rename the file.
///
/// File names must be unique within their parent folder. The name check is case-insensitive, so a file
/// named `New File` cannot be created in a parent folder that already contains a folder named `new file`.
/// - description: The description for a file. This can be seen in the right-hand sidebar panel
/// when viewing a file in the Box web app. Additionally, this index is used in
/// the search index of the file, allowing users to find the file by the content
Expand Down
22 changes: 12 additions & 10 deletions Sources/Managers/Folders/CreateFolderRequestBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ public class CreateFolderRequestBody: Codable, RawJSONReadable {

/// The name for the new folder.
///
/// There are some restrictions to the file name. Names containing
/// The following restrictions to folder names apply: names containing
/// non-printable ASCII characters, forward and backward slashes
/// (`/`, `\`), as well as names with trailing spaces are
/// prohibited.
/// (`/`, `\`), names with trailing spaces, and names `.` and `..` are
/// not allowed.
///
/// Additionally, the names `.` and `..` are
/// not allowed either.
/// Folder names must be unique within their parent folder. The name check is case-insensitive,
/// so a folder named `New Folder` cannot be created in a parent folder that already contains
/// a folder named `new folder`.
public let name: String

/// The parent folder to create the new folder within.
Expand All @@ -43,13 +44,14 @@ public class CreateFolderRequestBody: Codable, RawJSONReadable {
/// - Parameters:
/// - name: The name for the new folder.
///
/// There are some restrictions to the file name. Names containing
/// The following restrictions to folder names apply: names containing
/// non-printable ASCII characters, forward and backward slashes
/// (`/`, `\`), as well as names with trailing spaces are
/// prohibited.
/// (`/`, `\`), names with trailing spaces, and names `.` and `..` are
/// not allowed.
///
/// Additionally, the names `.` and `..` are
/// not allowed either.
/// Folder names must be unique within their parent folder. The name check is case-insensitive,
/// so a folder named `New Folder` cannot be created in a parent folder that already contains
/// a folder named `new folder`.
/// - parent: The parent folder to create the new folder within.
/// - folderUploadEmail:
/// - syncState: Specifies whether a folder should be synced to a
Expand Down
18 changes: 18 additions & 0 deletions Sources/Managers/Folders/UpdateFolderByIdRequestBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ public class UpdateFolderByIdRequestBody: Codable, RawJSONReadable {


/// The optional new name for this folder.
///
/// The following restrictions to folder names apply: names containing
/// non-printable ASCII characters, forward and backward slashes
/// (`/`, `\`), names with trailing spaces, and names `.` and `..` are
/// not allowed.
///
/// Folder names must be unique within their parent folder. The name check is case-insensitive,
/// so a folder named `New Folder` cannot be created in a parent folder that already contains
/// a folder named `new folder`.
public let name: String?

/// The optional description of this folder
Expand Down Expand Up @@ -89,6 +98,15 @@ public class UpdateFolderByIdRequestBody: Codable, RawJSONReadable {
///
/// - Parameters:
/// - name: The optional new name for this folder.
///
/// The following restrictions to folder names apply: names containing
/// non-printable ASCII characters, forward and backward slashes
/// (`/`, `\`), names with trailing spaces, and names `.` and `..` are
/// not allowed.
///
/// Folder names must be unique within their parent folder. The name check is case-insensitive,
/// so a folder named `New Folder` cannot be created in a parent folder that already contains
/// a folder named `new folder`.
/// - description: The optional description of this folder
/// - syncState: Specifies whether a folder should be synced to a
/// user's device or not. This is used by Box Sync
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public enum CreateLegalHoldPolicyAssignmentRequestBodyAssignToTypeField: Codable
case fileVersion
case folder
case user
case ownership
case interaction
case customValue(String)

public init(rawValue value: String) {
Expand All @@ -17,6 +19,10 @@ public enum CreateLegalHoldPolicyAssignmentRequestBodyAssignToTypeField: Codable
self = .folder
case "user".lowercased():
self = .user
case "ownership".lowercased():
self = .ownership
case "interaction".lowercased():
self = .interaction
default:
self = .customValue(value)
}
Expand All @@ -32,6 +38,10 @@ public enum CreateLegalHoldPolicyAssignmentRequestBodyAssignToTypeField: Codable
return "folder"
case .user:
return "user"
case .ownership:
return "ownership"
case .interaction:
return "interaction"
case .customValue(let value):
return value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public enum GetLegalHoldPolicyAssignmentsQueryParamsAssignToTypeField: CodableSt
case fileVersion
case folder
case user
case ownership
case interactions
case customValue(String)

public init(rawValue value: String) {
Expand All @@ -17,6 +19,10 @@ public enum GetLegalHoldPolicyAssignmentsQueryParamsAssignToTypeField: CodableSt
self = .folder
case "user".lowercased():
self = .user
case "ownership".lowercased():
self = .ownership
case "interactions".lowercased():
self = .interactions
default:
self = .customValue(value)
}
Expand All @@ -32,6 +38,10 @@ public enum GetLegalHoldPolicyAssignmentsQueryParamsAssignToTypeField: CodableSt
return "folder"
case .user:
return "user"
case .ownership:
return "ownership"
case .interactions:
return "interactions"
case .customValue(let value):
return value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public class UploadFileRequestBodyAttributesField: Codable, RawJSONReadable {
}


/// The name of the file
/// The name of the file.
///
/// File names must be unique within their parent folder. The name check is case-insensitive, so a file
/// named `New File` cannot be created in a parent folder that already contains a folder named `new file`.
public let name: String

/// The parent folder to upload the file to
Expand All @@ -36,7 +39,10 @@ public class UploadFileRequestBodyAttributesField: Codable, RawJSONReadable {
/// Initializer for a UploadFileRequestBodyAttributesField.
///
/// - Parameters:
/// - name: The name of the file
/// - name: The name of the file.
///
/// File names must be unique within their parent folder. The name check is case-insensitive, so a file
/// named `New File` cannot be created in a parent folder that already contains a folder named `new file`.
/// - parent: The parent folder to upload the file to
/// - contentCreatedAt: Defines the time the file was originally created at.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public class UploadWithPreflightCheckRequestBodyAttributesField: Codable, RawJSO
}


/// The name of the file
/// The name of the file.
///
/// File names must be unique within their parent folder. The name check is case-insensitive, so a file
/// named `New File` cannot be created in a parent folder that already contains a folder named `new file`.
public let name: String

/// The parent folder to upload the file to
Expand All @@ -40,7 +43,10 @@ public class UploadWithPreflightCheckRequestBodyAttributesField: Codable, RawJSO
/// Initializer for a UploadWithPreflightCheckRequestBodyAttributesField.
///
/// - Parameters:
/// - name: The name of the file
/// - name: The name of the file.
///
/// File names must be unique within their parent folder. The name check is case-insensitive, so a file
/// named `New File` cannot be created in a parent folder that already contains a folder named `new file`.
/// - parent: The parent folder to upload the file to
/// - size: The size of the file in bytes
/// - contentCreatedAt: Defines the time the file was originally created at.
Expand Down
2 changes: 2 additions & 0 deletions Sources/Networking/BoxNetworkClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ public class BoxNetworkClient: NetworkClient {
let nonNullQueryParams: [String: String] = params.compactMapValues { $0?.paramValue }
var components = URLComponents(url: URL(string: url)!, resolvingAgainstBaseURL: true)!
components.queryItems = nonNullQueryParams.map { URLQueryItem(name: $0.key, value: $0.value) }
components.percentEncodedQuery = components.percentEncodedQuery?
.replacingOccurrences(of: "+", with: "%2B")

return components.url!
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/Networking/DefaultNetworkClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ public class DefaultNetworkClient: NetworkClient {
let nonNullQueryParams: [String: String] = params.compactMapValues { $0?.paramValue }
var components = URLComponents(url: URL(string: url)!, resolvingAgainstBaseURL: true)!
components.queryItems = nonNullQueryParams.map { URLQueryItem(name: $0.key, value: $0.value) }
components.percentEncodedQuery = components.percentEncodedQuery?
.replacingOccurrences(of: "+", with: "%2B")

return components.url!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public enum AiAgentAllowedEntity: Codable {
}

default:
throw DecodingError.typeMismatch(AiAgentAllowedEntity.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "The Decoded object contains an unexpected value for key type"))

break
}
}

Expand Down
16 changes: 15 additions & 1 deletion Sources/Schemas/AiAgentAsk/AiAgentAsk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class AiAgentAsk: Codable, RawJSONReadable {
case basicText = "basic_text"
case longTextMulti = "long_text_multi"
case basicTextMulti = "basic_text_multi"
case basicImage = "basic_image"
case basicImageMulti = "basic_image_multi"
}

/// Internal backing store for rawData. Used to store raw dictionary data associated with the instance.
Expand All @@ -30,6 +32,10 @@ public class AiAgentAsk: Codable, RawJSONReadable {

public let basicTextMulti: AiAgentBasicTextTool?

public let basicImage: AiAgentBasicTextTool?

public let basicImageMulti: AiAgentBasicTextTool?

/// Initializer for a AiAgentAsk.
///
/// - Parameters:
Expand All @@ -38,12 +44,16 @@ public class AiAgentAsk: Codable, RawJSONReadable {
/// - basicText:
/// - longTextMulti:
/// - basicTextMulti:
public init(type: AiAgentAskTypeField = AiAgentAskTypeField.aiAgentAsk, longText: AiAgentLongTextTool? = nil, basicText: AiAgentBasicTextTool? = nil, longTextMulti: AiAgentLongTextTool? = nil, basicTextMulti: AiAgentBasicTextTool? = nil) {
/// - basicImage:
/// - basicImageMulti:
public init(type: AiAgentAskTypeField = AiAgentAskTypeField.aiAgentAsk, longText: AiAgentLongTextTool? = nil, basicText: AiAgentBasicTextTool? = nil, longTextMulti: AiAgentLongTextTool? = nil, basicTextMulti: AiAgentBasicTextTool? = nil, basicImage: AiAgentBasicTextTool? = nil, basicImageMulti: AiAgentBasicTextTool? = nil) {
self.type = type
self.longText = longText
self.basicText = basicText
self.longTextMulti = longTextMulti
self.basicTextMulti = basicTextMulti
self.basicImage = basicImage
self.basicImageMulti = basicImageMulti
}

required public init(from decoder: Decoder) throws {
Expand All @@ -53,6 +63,8 @@ public class AiAgentAsk: Codable, RawJSONReadable {
basicText = try container.decodeIfPresent(AiAgentBasicTextTool.self, forKey: .basicText)
longTextMulti = try container.decodeIfPresent(AiAgentLongTextTool.self, forKey: .longTextMulti)
basicTextMulti = try container.decodeIfPresent(AiAgentBasicTextTool.self, forKey: .basicTextMulti)
basicImage = try container.decodeIfPresent(AiAgentBasicTextTool.self, forKey: .basicImage)
basicImageMulti = try container.decodeIfPresent(AiAgentBasicTextTool.self, forKey: .basicImageMulti)
}

public func encode(to encoder: Encoder) throws {
Expand All @@ -62,6 +74,8 @@ public class AiAgentAsk: Codable, RawJSONReadable {
try container.encodeIfPresent(basicText, forKey: .basicText)
try container.encodeIfPresent(longTextMulti, forKey: .longTextMulti)
try container.encodeIfPresent(basicTextMulti, forKey: .basicTextMulti)
try container.encodeIfPresent(basicImage, forKey: .basicImage)
try container.encodeIfPresent(basicImageMulti, forKey: .basicImageMulti)
}

/// Sets the raw JSON data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public enum AiAgentAskOrAiAgentExtractOrAiAgentExtractStructuredOrAiAgentTextGen
}

default:
throw DecodingError.typeMismatch(AiAgentAskOrAiAgentExtractOrAiAgentExtractStructuredOrAiAgentTextGen.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "The Decoded object contains an unexpected value for key type"))

break
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public enum AiAgentAskOrAiAgentReference: Codable {
}

default:
throw DecodingError.typeMismatch(AiAgentAskOrAiAgentReference.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "The Decoded object contains an unexpected value for key type"))

break
}
}

Expand Down
Loading