import Foundation
import ServiceStack
public class JsonFileUploadRequest : JsonRequestDto
{
public var fileName:String
public var requestStream:Data
public var templateGuid:String
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case fileName
case requestStream
case templateGuid
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
fileName = try container.decodeIfPresent(String.self, forKey: .fileName)
requestStream = try container.decodeIfPresent(Data.self, forKey: .requestStream)
templateGuid = try container.decodeIfPresent(String.self, forKey: .templateGuid)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if fileName != nil { try container.encode(fileName, forKey: .fileName) }
if requestStream != nil { try container.encode(requestStream, forKey: .requestStream) }
if templateGuid != nil { try container.encode(templateGuid, forKey: .templateGuid) }
}
}
public class JsonRequestDto : JsonDto
{
public var clientCode:String
public var clientRegistrationCode:String
public var token:String
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case clientCode
case clientRegistrationCode
case token
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
clientCode = try container.decodeIfPresent(String.self, forKey: .clientCode)
clientRegistrationCode = try container.decodeIfPresent(String.self, forKey: .clientRegistrationCode)
token = try container.decodeIfPresent(String.self, forKey: .token)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if clientCode != nil { try container.encode(clientCode, forKey: .clientCode) }
if clientRegistrationCode != nil { try container.encode(clientRegistrationCode, forKey: .clientRegistrationCode) }
if token != nil { try container.encode(token, forKey: .token) }
}
}
public class JsonDto : Codable
{
required public init(){}
}
public class JsonFileUploadResponse : JsonDto
{
public var errorMessage:String
public var inError:Bool
public var templateGuid:String
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case errorMessage
case inError
case templateGuid
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
errorMessage = try container.decodeIfPresent(String.self, forKey: .errorMessage)
inError = try container.decodeIfPresent(Bool.self, forKey: .inError)
templateGuid = try container.decodeIfPresent(String.self, forKey: .templateGuid)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if errorMessage != nil { try container.encode(errorMessage, forKey: .errorMessage) }
if inError != nil { try container.encode(inError, forKey: .inError) }
if templateGuid != nil { try container.encode(templateGuid, forKey: .templateGuid) }
}
}
Swift JsonFileUploadRequest DTOs
To override the Content-type in your clients, use the HTTP Accept Header, append the .xml suffix or ?format=xml
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /xml/reply/JsonFileUploadRequest HTTP/1.1
Host: buildmax.org
Accept: application/xml
Content-Type: application/xml
Content-Length: length
<JsonFileUploadRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/ScannerVision.WebService.Json.Dto">
<ClientCode>String</ClientCode>
<ClientRegistrationCode>String</ClientRegistrationCode>
<Token>String</Token>
<FileName>String</FileName>
<RequestStream xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.IO" i:nil="true" />
<TemplateGuid>String</TemplateGuid>
</JsonFileUploadRequest>
HTTP/1.1 200 OK Content-Type: application/xml Content-Length: length <JsonFileUploadResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/ScannerVision.WebService.Json.Dto"> <ErrorMessage>String</ErrorMessage> <InError>false</InError> <TemplateGuid>String</TemplateGuid> </JsonFileUploadResponse>