mirror of
https://github.com/hanzoai/swift-sdk.git
synced 2026-10-30 18:20:19 +00:00
The forge tree held the package scaffolding and none of the generated sources — 2,435 files of APIs, Models and Infrastructure, including BaseAPI, were simply absent, so anything depending on this copy had a package that compiled to nothing usable. Generated from the current API document rather than reconciled with the other copy: a client is a function of the spec, so regenerating answers "which history wins" without anyone having to choose. .spec-lock records which document, so the next reader can tell.
57 lines
1.7 KiB
Swift
57 lines
1.7 KiB
Swift
//
|
|
// JSONDataEncoding.swift
|
|
//
|
|
// Generated by openapi-generator
|
|
// https://openapi-generator.tech
|
|
//
|
|
|
|
import Foundation
|
|
#if canImport(FoundationNetworking)
|
|
import FoundationNetworking
|
|
#endif
|
|
|
|
public struct JSONDataEncoding: Sendable {
|
|
|
|
// MARK: Properties
|
|
|
|
private static let jsonDataKey = "jsonData"
|
|
|
|
// MARK: Encoding
|
|
|
|
/// Creates a URL request by encoding parameters and applying them onto an existing request.
|
|
///
|
|
/// - parameter urlRequest: The request to have parameters applied.
|
|
/// - parameter parameters: The parameters to apply. This should have a single key/value
|
|
/// pair with "jsonData" as the key and a Data object as the value.
|
|
///
|
|
/// - throws: An `Error` if the encoding process encounters an error.
|
|
///
|
|
/// - returns: The encoded request.
|
|
public func encode(request: URLRequest, with parameters: [String: any Sendable]?) -> URLRequest {
|
|
var urlRequest = request
|
|
|
|
guard let jsonData = parameters?[JSONDataEncoding.jsonDataKey] as? Data, !jsonData.isEmpty else {
|
|
return urlRequest
|
|
}
|
|
|
|
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
|
|
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
}
|
|
|
|
urlRequest.httpBody = jsonData
|
|
|
|
return urlRequest
|
|
}
|
|
|
|
public static func encodingParameters(jsonData: Data?) -> [String: any Sendable]? {
|
|
var returnedParams: [String: any Sendable]?
|
|
if let jsonData = jsonData, !jsonData.isEmpty {
|
|
var params: [String: any Sendable] = [:]
|
|
params[jsonDataKey] = jsonData
|
|
returnedParams = params
|
|
}
|
|
return returnedParams
|
|
}
|
|
|
|
}
|