Skip to content
This repository has been archived by the owner on Nov 23, 2019. It is now read-only.

Commit

Permalink
Merge aws-sdk-swift branch 'upstream/appleos'
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Aug 18, 2019
2 parents 34825c3 + b4e205d commit 8fee71e
Show file tree
Hide file tree
Showing 575 changed files with 63,847 additions and 8,806 deletions.
64 changes: 14 additions & 50 deletions CodeGenerator/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,39 @@
"object": {
"pins": [
{
"package": "AWSSDKSwiftCore",
"repositoryURL": "https://github.com/swift-aws/aws-sdk-swift-core.git",
"state": {
"branch": "master",
"revision": "fe381ab45774eab36ca5a87953d0cd0038bc4947",
"version": null
}
},
{
"package": "HypertextApplicationLanguage",
"repositoryURL": "https://github.com/Yasumoto/HypertextApplicationLanguage.git",
"state": {
"branch": null,
"revision": "2302002502fe573494577cc6e8df686e385519f8",
"version": "1.1.0"
}
},
{
"package": "INIParser",
"repositoryURL": "https://github.com/PerfectlySoft/Perfect-INIParser.git",
"state": {
"branch": null,
"revision": "0952aac9ca54324ff25191569fd9c48eec424772",
"version": "3.0.2"
}
},
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"package": "PathKit",
"repositoryURL": "https://github.com/kylef/PathKit.git",
"state": {
"branch": null,
"revision": "ba7970fe396e8198b84c6c1b44b38a1d4e2eb6bd",
"version": "1.14.1"
}
},
{
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "0f3999f3e3c359cc74480c292644c3419e44a12f",
"version": "1.4.0"
"revision": "73f8e9dca9b7a3078cb79128217dc8f2e585a511",
"version": "1.0.0"
}
},
{
"package": "swift-nio-ssl-support",
"repositoryURL": "https://github.com/apple/swift-nio-ssl-support.git",
"package": "Spectre",
"repositoryURL": "https://github.com/kylef/Spectre.git",
"state": {
"branch": null,
"revision": "c02eec4e0e6d351cd092938cf44195a8e669f555",
"version": "1.0.0"
"revision": "f14ff47f45642aa5703900980b014c2e9394b6e5",
"version": "0.9.0"
}
},
{
"package": "swift-nio-zlib-support",
"repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git",
"package": "Stencil",
"repositoryURL": "https://github.com/swift-aws/Stencil.git",
"state": {
"branch": null,
"revision": "37760e9a52030bb9011972c5213c3350fa9d41fd",
"version": "1.0.0"
"revision": "3fff29f0140dcbabae6b5966ba99322dd169fe95",
"version": "0.13.2"
}
},
{
"package": "SwiftyJSON",
"repositoryURL": "https://github.com/IBM-Swift/SwiftyJSON.git",
"state": {
"branch": null,
"revision": "f2612ea3ac29996ae9601bdcb00cc1c29e26f104",
"version": "17.0.4"
"revision": "f9b4754017cfad4701f0838b2e507b442eaca70a",
"version": "17.0.5"
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions CodeGenerator/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ let package = Package(
.executable(name: "aws-sdk-swift-codegen", targets: ["CodeGenerator"])
],
dependencies: [
.package(url: "https://github.com/swift-aws/aws-sdk-swift-core.git", .branch("master")),
.package(url: "https://github.com/IBM-Swift/SwiftyJSON.git", .upToNextMajor(from: "17.0.2"))
.package(url: "https://github.com/IBM-Swift/SwiftyJSON.git", .upToNextMajor(from: "17.0.2")),
.package(url: "https://github.com/swift-aws/Stencil.git", .upToNextMajor(from: "0.13.2"))
],
targets: [
.target(name: "CodeGenerator", dependencies: ["AWSSDKSwiftCore", "SwiftyJSON"])
.target(name: "CodeGenerator", dependencies: ["SwiftyJSON", "Stencil"])
]
)
98 changes: 90 additions & 8 deletions CodeGenerator/Sources/CodeGenerator/AWSService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,23 @@

import Foundation
import SwiftyJSON
import AWSSDKSwiftCore

/*
List of model tags we are currently not processing:
exception: This appears to be used to tag errors returned by AWS
synthetic: not dealt with, always seems to pair up with "exception"
error: details http return status for error, also can include a "code" and flag "senderFault"
fault: not sure how this is different from "exception". Looks to be server issues, most return 5xx http status
sensitive: indicates sensitive data
wrapper: not sure what this is
box: not sure what this is
streaming:
eventstream:
event: pairs with "eventstream"
xmlOrder: defines order of members in xml (GetMetricStatisticsInput,PutMetricAlarmInput)
timestampFormat: need to deal with "unixTimestamp" for MediaConvert
documentation: additional documentation, only used once in apigateway
*/

enum AWSServiceError: Error {
case eventStreamingCodeGenerationsAreUnsupported
Expand Down Expand Up @@ -68,6 +84,9 @@ struct AWSService {
endpoint["endpoints"].dictionaryValue.forEach {
if let hostname = $0.value["hostname"].string {
endpointMap[$0.key] = hostname
} else if partitionEndpoint != nil {
// if there is a partition endpoint, then default this regions endpoint to ensure partition endpoint doesn't override it. Only an issue for S3 at the moment.
endpointMap[$0.key] = "\(endpointPrefix).\($0.key).amazonaws.com"
}
}
return endpointMap
Expand Down Expand Up @@ -123,7 +142,9 @@ struct AWSService {
let shapeJSON = apiJSON["shapes"][json["member"]["shape"].stringValue]
let _type = try shapeType(from: shapeJSON, level: level+1)
let shape = Shape(name: json["member"]["shape"].stringValue, type: _type)
type = .list(shape)
let max = json["max"].int
let min = json["min"].int
type = .list(shape, max: max, min: min)

case "structure":
// Note that we need to do some extra preprocessing to clean up the formatting of the structure. Sometimes we have a "flattened" object which does not have extra fields (typically named `members`) wrapping the contents. Other times we do, and need to clear that out.
Expand All @@ -133,7 +154,10 @@ struct AWSService {
structure[_struct["shape"].stringValue] = try shapeType(from: shapeJSON, level: level+1)
}

let members: [Member] = try json["members"].dictionaryValue.map { name, memberJSON in
let members: [Member] = try json["members"].dictionaryValue.compactMap { name, memberJSON in
if memberJSON["deprecated"].bool == true {
return nil
}
let name = name
let memberDict = try JSONSerialization.jsonObject(with: memberJSON.rawData(), options: []) as? [String: Any] ?? [:]
let shapeName = memberJSON["shape"].stringValue
Expand Down Expand Up @@ -163,7 +187,7 @@ struct AWSService {
}
}
}

default:
break
}
Expand All @@ -172,6 +196,14 @@ struct AWSService {
location = Location(json: shapeJSON["member"])
locationName = memberLocationName
}
var options : Member.Options = []
if memberJSON["streaming"].bool == true {
options.insert(.streaming)
}
if memberJSON["idempotencyToken"].bool == true {
options.insert(.idempotencyToken)
}

return Member(
name: name,
required: requireds.contains(name),
Expand All @@ -180,11 +212,13 @@ struct AWSService {
locationName: locationName,
shapeEncoding: encoding,
xmlNamespace: XMLNamespace(dictionary: memberDict),
isStreaming: memberJSON["streaming"].bool ?? false
options: options
)
}.sorted{ $0.name < $1.name }
}.sorted{ $0.name.lowercased() < $1.name.lowercased() }

let shape = StructureShape(members: members, payload: json["payload"].string)
let payloadMember = members.first(where:{$0.name == json["payload"].string})
let xmlNamespace = payloadMember?.xmlNamespace?.attributeMap["uri"] as? String
let shape = StructureShape(members: members, payload: json["payload"].string, xmlNamespace: xmlNamespace)
type = .structure(shape)

case "map":
Expand Down Expand Up @@ -267,6 +301,42 @@ struct AWSService {
return shapes.sorted{ $0.name < $1.name }
}

/// flag which shape are used as input shapes and output shapes
private func setShapeUsed(shape: Shape, inInput: Bool = false, inOutput: Bool = false) {
if inInput {
// if value is already set then don't set again. This avoids recursive loops where shapes reference themselves
guard shape.usedInInput != true else {return}
shape.usedInInput = true
}
if inOutput {
// if value is already set then don't set again. This avoids recursive loops where shapes reference themselves
guard shape.usedInOutput != true else {return}
shape.usedInOutput = true
}

// cannot just set children shapes to be used. The shapes that are actually output are the top level shapes. Instead I need to find the top level shape with the same name. If there isn't a toplevel shape then I use the child shape to ensure the values are propagated to any children of that child.
switch shape.type {
case .structure(let shape):
shape.members.forEach { member in
let memberShape = shapes.first(where: {$0.name == member.shape.name}) ?? member.shape
setShapeUsed(shape: memberShape, inInput: inInput, inOutput: inOutput)
}
case .list(let shape,_,_):
let memberShape = shapes.first(where: {$0.name == shape.name}) ?? shape
setShapeUsed(shape: memberShape, inInput: inInput, inOutput: inOutput)

case .map(let key, let value):
let keyShape = shapes.first(where: {$0.name == key.name}) ?? key
setShapeUsed(shape: keyShape, inInput: inInput, inOutput: inOutput)

let valueShape = shapes.first(where: {$0.name == value.name}) ?? value
setShapeUsed(shape: valueShape, inInput: inInput, inOutput: inOutput)

default:
break
}
}

private func parseOperation(shapes: [Shape]) throws -> ([Operation], [String]) {
var operations: [Operation] = []
var errorShapeNames: [String] = []
Expand All @@ -278,16 +348,27 @@ struct AWSService {
}
}

var deprecatedMessage : String? = nil
if json["deprecated"].bool == true {
if let message = json["deprecatedMessage"].string {
deprecatedMessage = message
} else {
deprecatedMessage = "\(json["name"].stringValue) is deprecated."
}
}

var inputShape: Shape?
if let inputShapeName = json["input"]["shape"].string {
if let index = shapes.firstIndex(where: { inputShapeName == $0.name }) {
setShapeUsed(shape: shapes[index], inInput: true)
inputShape = shapes[index]
}
}

var outputShape: Shape?
if let outputShapeName = json["output"]["shape"].string {
if let index = shapes.firstIndex(where: { outputShapeName == $0.name }) {
setShapeUsed(shape: shapes[index], inOutput: true)
outputShape = shapes[index]
}
}
Expand All @@ -297,7 +378,8 @@ struct AWSService {
httpMethod: json["http"]["method"].stringValue,
path: json["http"]["requestUri"].stringValue,
inputShape: inputShape,
outputShape: outputShape
outputShape: outputShape,
deprecatedMessage: deprecatedMessage
)

operations.append(operation)
Expand Down
Loading

0 comments on commit 8fee71e

Please sign in to comment.