Skip to content
Merged
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
1 change: 1 addition & 0 deletions Sources/AWSSDKSwift/Services/ECS/ECS_Shapes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2398,6 +2398,7 @@ extension ECS {
public enum PropagateTags: String, CustomStringConvertible, Codable {
case taskDefinition = "TASK_DEFINITION"
case service = "SERVICE"
case none = "NONE"
public var description: String { return self.rawValue }
}

Expand Down
18 changes: 9 additions & 9 deletions Sources/AWSSDKSwift/Services/S3/S3_Shapes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4932,18 +4932,18 @@ extension S3 {
AWSShapeMember(label: "Key", required: false, type: .string),
AWSShapeMember(label: "LastModified", required: false, type: .timestamp),
AWSShapeMember(label: "Owner", required: false, type: .structure),
AWSShapeMember(label: "Size", required: false, type: .integer),
AWSShapeMember(label: "Size", required: false, type: .long),
AWSShapeMember(label: "StorageClass", required: false, type: .enum)
]
public let eTag: String?
public let key: String?
public let lastModified: TimeStamp?
public let owner: Owner?
public let size: Int32?
public let size: Int64?
/// The class of storage used to store the object.
public let storageClass: ObjectStorageClass?

public init(eTag: String? = nil, key: String? = nil, lastModified: TimeStamp? = nil, owner: Owner? = nil, size: Int32? = nil, storageClass: ObjectStorageClass? = nil) {
public init(eTag: String? = nil, key: String? = nil, lastModified: TimeStamp? = nil, owner: Owner? = nil, size: Int64? = nil, storageClass: ObjectStorageClass? = nil) {
self.eTag = eTag
self.key = key
self.lastModified = lastModified
Expand Down Expand Up @@ -5108,7 +5108,7 @@ extension S3 {
AWSShapeMember(label: "Key", required: false, type: .string),
AWSShapeMember(label: "LastModified", required: false, type: .timestamp),
AWSShapeMember(label: "Owner", required: false, type: .structure),
AWSShapeMember(label: "Size", required: false, type: .integer),
AWSShapeMember(label: "Size", required: false, type: .long),
AWSShapeMember(label: "StorageClass", required: false, type: .enum),
AWSShapeMember(label: "VersionId", required: false, type: .string)
]
Expand All @@ -5121,13 +5121,13 @@ extension S3 {
public let lastModified: TimeStamp?
public let owner: Owner?
/// Size in bytes of the object.
public let size: Int32?
public let size: Int64?
/// The class of storage used to store the object.
public let storageClass: ObjectVersionStorageClass?
/// Version ID of an object.
public let versionId: String?

public init(eTag: String? = nil, isLatest: Bool? = nil, key: String? = nil, lastModified: TimeStamp? = nil, owner: Owner? = nil, size: Int32? = nil, storageClass: ObjectVersionStorageClass? = nil, versionId: String? = nil) {
public init(eTag: String? = nil, isLatest: Bool? = nil, key: String? = nil, lastModified: TimeStamp? = nil, owner: Owner? = nil, size: Int64? = nil, storageClass: ObjectVersionStorageClass? = nil, versionId: String? = nil) {
self.eTag = eTag
self.isLatest = isLatest
self.key = key
Expand Down Expand Up @@ -5228,7 +5228,7 @@ extension S3 {
AWSShapeMember(label: "ETag", required: false, type: .string),
AWSShapeMember(label: "LastModified", required: false, type: .timestamp),
AWSShapeMember(label: "PartNumber", required: false, type: .integer),
AWSShapeMember(label: "Size", required: false, type: .integer)
AWSShapeMember(label: "Size", required: false, type: .long)
]
/// Entity tag returned when the part was uploaded.
public let eTag: String?
Expand All @@ -5237,9 +5237,9 @@ extension S3 {
/// Part number identifying the part. This is a positive integer between 1 and 10,000.
public let partNumber: Int32?
/// Size in bytes of the uploaded part data.
public let size: Int32?
public let size: Int64?

public init(eTag: String? = nil, lastModified: TimeStamp? = nil, partNumber: Int32? = nil, size: Int32? = nil) {
public init(eTag: String? = nil, lastModified: TimeStamp? = nil, partNumber: Int32? = nil, size: Int64? = nil) {
self.eTag = eTag
self.lastModified = lastModified
self.partNumber = partNumber
Expand Down
2 changes: 1 addition & 1 deletion Sources/CodeGenerator/AWSService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct AWSService {
}

init(fromAPIJSON apiJSON: JSON, docJSON: JSON, endpointJSON: JSON) throws {
self.apiJSON = apiJSON
self.apiJSON = patch(apiJSON)
self.docJSON = docJSON
self.endpointJSON = endpointJSON
self.shapes = try parseShapes()
Expand Down
89 changes: 89 additions & 0 deletions Sources/CodeGenerator/patch.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// Patch.swift
// AWSSDKSwift - CodeGenerator
//
// Created by Adam Fowler 2019/5/16
// Patches the JSON AWS model files as they are loaded into the CodeGenerator
//
import Foundation
import SwiftyJSON

//
// Patch operations
//
let servicePatches : [String: [Patch]] = [
"ECS" : [
Patch(operation:.add, entry:["shapes", "PropagateTags", "enum"], value:"NONE")
],
"ELB" : [
Patch(operation:.replace, entry:["shapes", "SecurityGroupOwnerAlias", "type"], value:"integer", originalValue:"string")
],
"S3": [
Patch(operation:.replace, entry:["shapes","ReplicationStatus","enum",0], value:"COMPLETED", originalValue:"COMPLETE"),
Patch(operation:.replace, entry:["shapes","Size","type"], value:"long", originalValue:"integer")
]
]

// structure defining a model patch
struct Patch {
enum Operation {
case replace
case add
}

init(operation: Operation, entry: [JSONSubscriptType], value: String, originalValue: String? = nil) {
self.operation = operation
self.entry = entry
self.value = value
self.originalValue = originalValue
}

let operation : Operation
let entry : [JSONSubscriptType]
let value : CustomStringConvertible
let originalValue : CustomStringConvertible?
}

/// patch model JSON
func patch(_ apiJSON: JSON) -> JSON {
let service = apiJSON["serviceName"].stringValue.toSwiftClassCase()
guard let patches = servicePatches[service] else {return apiJSON}
var patchedJSON = apiJSON

for patch in patches {
let field = patchedJSON[patch.entry]
guard field != JSON.null else {
print("Attempting to patch field \(patch.entry) that doesn't eixst")
exit(-1)
}

switch patch.operation {
case .replace:
if let originalValue = patch.originalValue {
guard originalValue.description == field.stringValue else {
print("Found an unexpected value while patching \(patch.entry). Expected \"\(originalValue)\", got \"\(field.stringValue)\"")
exit(-1)
}
}

patchedJSON[patch.entry].object = patch.value
case .add:
guard let array = field.array else {
print("Attempting to add a field to \(patch.entry) that cannot be added to.")
exit(-1)
}

guard array.first(where:{$0.stringValue == patch.value.description}) == nil else {
print("Attempting to add field \"\(patch.value)\" to array \(patch.entry) that aleady exists.")
exit(-1)
}

var newArray = field.arrayObject!
newArray.append(patch.value)
patchedJSON[patch.entry].arrayObject = newArray
}
}
return patchedJSON
}


2 changes: 1 addition & 1 deletion Tests/AWSSDKSwiftTests/Services/S3/S3Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class S3Tests: XCTestCase {
let output = try client.listObjects(S3.ListObjectsRequest(bucket: TestData.shared.bucket))
XCTAssertEqual(output.maxKeys, 1000)
XCTAssertEqual(output.contents?.first?.key, TestData.shared.key)
XCTAssertEqual(output.contents?.first?.size, Int32(TestData.shared.bodyData.count))
XCTAssertEqual(output.contents?.first?.size, Int64(TestData.shared.bodyData.count))
XCTAssertEqual(output.contents?.first?.eTag, putResult.eTag?.replacingOccurrences(of: "\"", with: ""))
}

Expand Down
2 changes: 1 addition & 1 deletion models/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
In order to keep up with rapidly updating AWS APIs, we use [the JSON model files utilized by the Go AWS SDK](https://github.com/aws/aws-sdk-go/tree/master/models).

IMPORTANT - There are a few known bugs in certain services api.json

These are now fixed up by the model patcher when loaded into the CodeGenerator, so there is no need to edit the models when you bring them across
1. s3 - ReplicationStatus enum should be `COMPLETED` past tense. (_not_ `COMPLETE` present tense)
2. elasticloadbalancing (not v2) - ensure ``"SecurityGroupOwnerAlias":{"type":"integer"}`` (_not_ "string")

Expand Down
2 changes: 1 addition & 1 deletion models/apis/elasticloadbalancing/2012-06-01/api-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@
"SSLCertificateId":{"type":"string"},
"SecurityGroupId":{"type":"string"},
"SecurityGroupName":{"type":"string"},
"SecurityGroupOwnerAlias":{"type":"integer"},
"SecurityGroupOwnerAlias":{"type":"string"},
"SecurityGroups":{
"type":"list",
"member":{"shape":"SecurityGroupId"}
Expand Down
2 changes: 1 addition & 1 deletion models/apis/s3/2006-03-01/api-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -5744,7 +5744,7 @@
"ReplicationStatus":{
"type":"string",
"enum":[
"COMPLETED",
"COMPLETE",
"PENDING",
"FAILED",
"REPLICA"
Expand Down