From 54fd758ade56b42e2c7111ad53f0b7737da691fb Mon Sep 17 00:00:00 2001 From: Chan <55515281+sichanyoo@users.noreply.github.com> Date: Mon, 6 Jan 2025 13:02:58 -0800 Subject: [PATCH 1/7] Fix service name rendered on API reference docs. (#889) Co-authored-by: Sichan Yoo --- .../amazon/smithy/swift/codegen/ServiceGenerator.kt | 13 ++++++++++--- .../integration/HttpProtocolClientGenerator.kt | 4 +++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/ServiceGenerator.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/ServiceGenerator.kt index 4e9257ad8..ffb539bee 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/ServiceGenerator.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/ServiceGenerator.kt @@ -24,6 +24,7 @@ class ServiceGenerator() { * Renders the definition of operation, followed by no CR */ fun renderOperationDefinition( + serviceName: String, model: Model, service: ServiceShape, symbolProvider: SymbolProvider, @@ -42,7 +43,7 @@ class ServiceGenerator() { val outputShape = opIndex.getOutput(op).get() val outputShapeName = symbolProvider.toSymbol(outputShape).name - renderOperationDoc(model, service, op, writer) + renderOperationDoc(serviceName, model, service, op, writer) val accessSpecifier = if (insideProtocol) "" else "public " @@ -58,8 +59,14 @@ class ServiceGenerator() { /** * Helper method for generating in-line documentation for operation */ - private fun renderOperationDoc(model: Model, service: ServiceShape, op: OperationShape, writer: SwiftWriter) { - writer.writeDocs("Performs the \\`${op.id.name}\\` operation on the \\`${service.id.name}\\` service.") + private fun renderOperationDoc( + serviceName: String, + model: Model, + service: ServiceShape, + op: OperationShape, + writer: SwiftWriter + ) { + writer.writeDocs("Performs the \\`${op.id.name}\\` operation on the \\`${serviceName}\\` service.") writer.writeDocs("") writer.writeShapeDocs(op) writer.writeAvailableAttribute(model, op) diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HttpProtocolClientGenerator.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HttpProtocolClientGenerator.kt index 3906da510..f50a33e1a 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HttpProtocolClientGenerator.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HttpProtocolClientGenerator.kt @@ -14,6 +14,7 @@ import software.amazon.smithy.swift.codegen.middleware.MiddlewareExecutionGenera import software.amazon.smithy.swift.codegen.middleware.OperationMiddleware import software.amazon.smithy.swift.codegen.model.toUpperCamelCase import software.amazon.smithy.swift.codegen.swiftmodules.SmithyTypes +import software.amazon.smithy.swift.codegen.utils.toUpperCamelCase /** * Renders an implementation of a service interface for HTTP protocol @@ -46,7 +47,8 @@ open class HttpProtocolClientGenerator( writer.openBlock("extension \$L {", "}", serviceSymbol.name) { operations.forEach { - ServiceGenerator.renderOperationDefinition(model, serviceShape, symbolProvider, writer, operationsIndex, it) + val serviceName = ctx.settings.sdkId.toUpperCamelCase() + ServiceGenerator.renderOperationDefinition(serviceName, model, serviceShape, symbolProvider, writer, operationsIndex, it) writer.openBlock(" {", "}") { val operationStackName = "operation" val generator = MiddlewareExecutionGenerator(ctx, writer, httpBindingResolver, httpProtocolCustomizable, operationMiddleware, operationStackName) From f1ae901fb5a4e1452c5fdc646a57da46c2eb8c9a Mon Sep 17 00:00:00 2001 From: AWS SDK Swift Automation Date: Tue, 7 Jan 2025 19:12:40 +0000 Subject: [PATCH 2/7] chore: Updates version to 0.107.0 --- Package.version | 2 +- Package.version.next | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.version b/Package.version index 557134bcd..2500dbc62 100644 --- a/Package.version +++ b/Package.version @@ -1 +1 @@ -0.106.0 \ No newline at end of file +0.107.0 \ No newline at end of file diff --git a/Package.version.next b/Package.version.next index 2500dbc62..d215cd6e6 100644 --- a/Package.version.next +++ b/Package.version.next @@ -1 +1 @@ -0.107.0 \ No newline at end of file +0.108.0 \ No newline at end of file From c156751e282044eafdfdd20b52da9e9727f4c550 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Tue, 7 Jan 2025 14:06:42 -0600 Subject: [PATCH 3/7] fix: Resolve Swift 6-related sendability warnings (#890) --- .../Networking/Http/URLSession/FoundationStreamBridge.swift | 2 +- .../ClientRuntime/Telemetry/Logging/SDKLogHandlerFactory.swift | 2 +- Sources/ClientRuntime/Telemetry/Logging/SDKLogLevel.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/ClientRuntime/Networking/Http/URLSession/FoundationStreamBridge.swift b/Sources/ClientRuntime/Networking/Http/URLSession/FoundationStreamBridge.swift index 508b25613..da8a55133 100644 --- a/Sources/ClientRuntime/Networking/Http/URLSession/FoundationStreamBridge.swift +++ b/Sources/ClientRuntime/Networking/Http/URLSession/FoundationStreamBridge.swift @@ -30,7 +30,7 @@ import protocol Foundation.StreamDelegate /// `InputStream` is exposed as a property, and may be used to stream the data to other components. /// /// Used to permit SDK streaming request bodies to be used with `URLSession`-based HTTP requests. -class FoundationStreamBridge: NSObject, StreamDelegate { +class FoundationStreamBridge: NSObject, StreamDelegate, @unchecked Sendable { /// The max number of bytes to buffer between the `ReadableStream` and the Foundation `OutputStream` /// at any given time. diff --git a/Sources/ClientRuntime/Telemetry/Logging/SDKLogHandlerFactory.swift b/Sources/ClientRuntime/Telemetry/Logging/SDKLogHandlerFactory.swift index 3935b1b68..2feec6c49 100644 --- a/Sources/ClientRuntime/Telemetry/Logging/SDKLogHandlerFactory.swift +++ b/Sources/ClientRuntime/Telemetry/Logging/SDKLogHandlerFactory.swift @@ -8,7 +8,7 @@ import Logging /// Implement this protocol and add an instance of the implementation to `SDKLoggingSystem` to use custom log handlers. -public protocol SDKLogHandlerFactory { +public protocol SDKLogHandlerFactory: Sendable { var label: String { get } func construct(label: String) -> LogHandler } diff --git a/Sources/ClientRuntime/Telemetry/Logging/SDKLogLevel.swift b/Sources/ClientRuntime/Telemetry/Logging/SDKLogLevel.swift index 6c5bf73c4..e73ad3e13 100644 --- a/Sources/ClientRuntime/Telemetry/Logging/SDKLogLevel.swift +++ b/Sources/ClientRuntime/Telemetry/Logging/SDKLogLevel.swift @@ -8,7 +8,7 @@ import Logging /// Wrapper for Logger.Level; used by SDKLoggingSystem. -public enum SDKLogLevel: String, Codable, CaseIterable { +public enum SDKLogLevel: String, Codable, CaseIterable, Sendable { case trace case debug case info From fcf09b6a16a3afd1bb19bc2aa13fd2943d8bfc11 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Tue, 7 Jan 2025 14:25:20 -0600 Subject: [PATCH 4/7] fix: Sort package manifest dependencies for more deterministic lists (#891) --- .../swift/codegen/PackageManifestGenerator.kt | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/PackageManifestGenerator.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/PackageManifestGenerator.kt index 390faa94e..6cb01e527 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/PackageManifestGenerator.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/PackageManifestGenerator.kt @@ -30,24 +30,26 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { writer.write(".library(name: \$S, targets: [\$S])", ctx.settings.moduleName, ctx.settings.moduleName) } - val externalDependencies = dependencies.filter { - it.getProperty("url", String::class.java).getOrNull() != null || - it.getProperty("scope", String::class.java).getOrNull() != null - } + val externalDependencies = dependencies + .filter { + it.getProperty("url", String::class.java).getOrNull() != null || + it.getProperty("scope", String::class.java).getOrNull() != null + } + val dependenciesByURL = externalDependencies .distinctBy { it.getProperty("url", String::class.java).getOrNull() ?: "${it.getProperty("scope", String::class.java).get()}.${it.packageName}" } - .sorted() + .sortedBy { it.targetName() } writer.openBlock("dependencies: [", "],") { dependenciesByURL.forEach { writePackageDependency(writer, it) } } val dependenciesByTarget = externalDependencies - .distinctBy { it.expectProperty("target", String::class.java) + it.packageName } - .sorted() + .distinctBy { it.targetName() + it.packageName } + .sortedBy { it.targetName() } writer.openBlock("targets: [", "]") { writer.openBlock(".target(", "),") { @@ -84,7 +86,7 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { private fun writeTargetDependency(writer: SwiftWriter, dependency: SymbolDependency) { writer.openBlock(".product(", "),") { - val target = dependency.expectProperty("target", String::class.java) + val target = dependency.targetName() writer.write("name: \$S,", target) val scope = dependency.getProperty("scope", String::class.java).getOrNull() val packageName = scope?.let { "$it.${dependency.packageName}" } ?: dependency.packageName @@ -92,3 +94,7 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { } } } + +private fun SymbolDependency.targetName(): String { + return expectProperty("target", String::class.java) +} From 1fa5f6febe41f036860b2a44d554f2f0aa281af8 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Tue, 7 Jan 2025 15:59:14 -0600 Subject: [PATCH 5/7] chore: Update to aws-crt-swift 0.42.0 (#893) --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 9dcbdc426..9cb49c66c 100644 --- a/Package.swift +++ b/Package.swift @@ -55,7 +55,7 @@ let package = Package( ], dependencies: { var dependencies: [Package.Dependency] = [ - .package(url: "https://github.com/awslabs/aws-crt-swift.git", exact: "0.40.0"), + .package(url: "https://github.com/awslabs/aws-crt-swift.git", exact: "0.42.0"), .package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"), ] let isDocCEnabled = ProcessInfo.processInfo.environment["AWS_SWIFT_SDK_ENABLE_DOCC"] != nil From 4c816b5f948aa722865661eb98449272abef18b9 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Wed, 8 Jan 2025 11:05:33 -0600 Subject: [PATCH 6/7] fix: Proper formatting of generated structures (#894) --- .../swift/codegen/StructureGenerator.kt | 7 ++-- .../swift/codegen/ServiceRenamesTests.kt | 12 +++---- .../StructEncodeGenerationIsolatedTests.kt | 3 +- .../basicshapes/StructureGeneratorTests.kt | 36 +++++++------------ .../RecursiveShapeBoxerTests.kt | 12 +++---- .../NestedListEncodeJSONGenerationTests.kt | 3 +- 6 files changed, 27 insertions(+), 46 deletions(-) diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/StructureGenerator.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/StructureGenerator.kt index 88dcd287b..7f8d24f25 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/StructureGenerator.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/StructureGenerator.kt @@ -143,7 +143,8 @@ class StructureGenerator( val hasMembers = membersSortedByName.isNotEmpty() if (hasMembers) { - writer.openBlock("public init(", ")") { + writer.write("public init(") + writer.indent { for ((index, member) in membersSortedByName.withIndex()) { val (memberName, memberSymbol) = memberShapeDataContainer.getOrElse(member) { Pair(null, null) } if (memberName == null || memberSymbol == null) continue @@ -151,13 +152,15 @@ class StructureGenerator( writer.write("\$L: \$D$terminator", memberName, memberSymbol) } } - writer.openBlock("{", "}") { + writer.write(") {") + writer.indent { val path = "properties.".takeIf { error } ?: "" membersSortedByName.forEach { val (memberName, _) = memberShapeDataContainer.getOrElse(it) { return@forEach } writer.write("self.$path\$L = \$L", memberName, memberName) } } + writer.write("}") } else { writer.write("public init() { }") } diff --git a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/ServiceRenamesTests.kt b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/ServiceRenamesTests.kt index 415f75547..ba41e4acf 100644 --- a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/ServiceRenamesTests.kt +++ b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/ServiceRenamesTests.kt @@ -27,8 +27,7 @@ public struct MyTestOperationInput: Swift.Sendable { public init( bar: ExampleClientTypes.RenamedGreeting? = nil - ) - { + ) { self.bar = bar } } @@ -54,8 +53,7 @@ public struct MyTestOperationOutput: Swift.Sendable { public init( baz: ExampleClientTypes.GreetingStruct? = nil - ) - { + ) { self.baz = baz } } @@ -83,8 +81,7 @@ extension ExampleClientTypes { public init( hi: Swift.String? = nil - ) - { + ) { self.hi = hi } } @@ -113,8 +110,7 @@ extension ExampleClientTypes { public init( salutation: Swift.String? = nil - ) - { + ) { self.salutation = salutation } } diff --git a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/basicshapes/StructEncodeGenerationIsolatedTests.kt b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/basicshapes/StructEncodeGenerationIsolatedTests.kt index 77f9dce63..875acfa90 100644 --- a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/basicshapes/StructEncodeGenerationIsolatedTests.kt +++ b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/basicshapes/StructEncodeGenerationIsolatedTests.kt @@ -46,8 +46,7 @@ public struct EnumInputInput: Swift.Sendable { public init( enumHeader: ExampleClientTypes.MyEnum? = nil, nestedWithEnum: ExampleClientTypes.NestedEnum? = nil - ) - { + ) { self.enumHeader = enumHeader self.nestedWithEnum = nestedWithEnum } diff --git a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/basicshapes/StructureGeneratorTests.kt b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/basicshapes/StructureGeneratorTests.kt index 8a21ba2f7..c3ed35b81 100644 --- a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/basicshapes/StructureGeneratorTests.kt +++ b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/basicshapes/StructureGeneratorTests.kt @@ -55,8 +55,7 @@ public struct MyStruct: Swift.Sendable { bar: Swift.Int = 0, baz: Swift.Int? = nil, foo: Swift.String? = nil - ) - { + ) { self.bar = bar self.baz = baz self.foo = foo @@ -110,8 +109,7 @@ public struct PrimitiveTypesInput: Swift.Sendable { primitiveShortVal: Swift.Int16 = 0, shortVal: Swift.Int16? = nil, str: Swift.String? = nil - ) - { + ) { self.booleanVal = booleanVal self.byteVal = byteVal self.doubleVal = doubleVal @@ -154,8 +152,7 @@ public struct RecursiveShapesInputOutputNested1: Swift.Sendable { public init( foo: Swift.String? = nil, nested: RecursiveShapesInputOutputNested2? = nil - ) - { + ) { self.foo = foo self.nested = nested } @@ -168,8 +165,7 @@ public struct RecursiveShapesInputOutputNested2: Swift.Sendable { public init( bar: Swift.String? = nil, recursiveMember: RecursiveShapesInputOutputNested1? = nil - ) - { + ) { self.bar = bar self.recursiveMember = recursiveMember } @@ -181,8 +177,7 @@ public struct RecursiveShapesInputOutput: Swift.Sendable { public init( nested: RecursiveShapesInputOutputNested1? = nil - ) - { + ) { self.nested = nested } } @@ -211,8 +206,7 @@ public struct RecursiveShapesInputOutputNestedList1: Swift.Sendable { public init( foo: Swift.String? = nil, recursiveList: [RecursiveShapesInputOutputNested2]? = nil - ) - { + ) { self.foo = foo self.recursiveList = recursiveList } @@ -225,8 +219,7 @@ public struct RecursiveShapesInputOutputNested2: Swift.Sendable { public init( bar: Swift.String? = nil, recursiveMember: RecursiveShapesInputOutputNested1? = nil - ) - { + ) { self.bar = bar self.recursiveMember = recursiveMember } @@ -238,8 +231,7 @@ public struct RecursiveShapesInputOutputLists: Swift.Sendable { public init( nested: RecursiveShapesInputOutputNested1? = nil - ) - { + ) { self.nested = nested } } @@ -282,8 +274,7 @@ public struct MyError: ClientRuntime.ModeledError, ClientRuntime.ServiceError, C public init( baz: Swift.Int? = nil, message: Swift.String? = nil - ) - { + ) { self.properties.baz = baz self.properties.message = message } @@ -333,8 +324,7 @@ public struct JsonListsInput: Swift.Sendable { stringList: [Swift.String]? = nil, stringSet: Swift.Set? = nil, timestampList: [Foundation.Date]? = nil - ) - { + ) { self.booleanList = booleanList self.integerList = integerList self.nestedStringList = nestedStringList @@ -382,8 +372,7 @@ public struct JsonMapsInput: Swift.Sendable { sparseNumberMap: [Swift.String: Swift.Int?]? = nil, sparseStringMap: [Swift.String: Swift.String?]? = nil, sparseStructMap: [Swift.String: ExampleClientTypes.GreetingStruct?]? = nil - ) - { + ) { self.denseBooleanMap = denseBooleanMap self.denseNumberMap = denseNumberMap self.denseStringMap = denseStringMap @@ -420,8 +409,7 @@ public struct JsonMapsOutput: Swift.Sendable { sparseNumberMap: [Swift.String: Swift.Int?]? = nil, sparseStringMap: [Swift.String: Swift.String?]? = nil, sparseStructMap: [Swift.String: ExampleClientTypes.GreetingStruct?]? = nil - ) - { + ) { self.denseBooleanMap = denseBooleanMap self.denseNumberMap = denseNumberMap self.denseStringMap = denseStringMap diff --git a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/codegencomponents/RecursiveShapeBoxerTests.kt b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/codegencomponents/RecursiveShapeBoxerTests.kt index 0645d81b8..dff94fe90 100644 --- a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/codegencomponents/RecursiveShapeBoxerTests.kt +++ b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/codegencomponents/RecursiveShapeBoxerTests.kt @@ -57,8 +57,7 @@ public struct RecursiveShapesInput: Swift.Sendable { public init( nested: ExampleClientTypes.RecursiveShapesInputOutputNested1? = nil - ) - { + ) { self.nested = nested } } @@ -74,8 +73,7 @@ public struct RecursiveShapesOutput: Swift.Sendable { public init( nested: ExampleClientTypes.RecursiveShapesInputOutputNested1? = nil - ) - { + ) { self.nested = nested } } @@ -95,8 +93,7 @@ extension ExampleClientTypes { public init( foo: Swift.String? = nil, nested: ExampleClientTypes.RecursiveShapesInputOutputNested2? = nil - ) - { + ) { self.foo = foo self.nested = nested } @@ -116,8 +113,7 @@ extension ExampleClientTypes { public init( bar: Swift.String? = nil, recursiveMember: ExampleClientTypes.RecursiveShapesInputOutputNested1? = nil - ) - { + ) { self.bar = bar self.recursiveMember = recursiveMember } diff --git a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/protocolspecificserde/awsjson11/NestedListEncodeJSONGenerationTests.kt b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/protocolspecificserde/awsjson11/NestedListEncodeJSONGenerationTests.kt index 54efc5541..22998baa4 100644 --- a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/protocolspecificserde/awsjson11/NestedListEncodeJSONGenerationTests.kt +++ b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/protocolspecificserde/awsjson11/NestedListEncodeJSONGenerationTests.kt @@ -26,8 +26,7 @@ public struct ListOfMapsOperationInput: Swift.Sendable { public init( targetMaps: [[Swift.String: [Swift.String]]]? = nil - ) - { + ) { self.targetMaps = targetMaps } } From 47ff1bb94db986d4b1b8f7d1e54761615f629a02 Mon Sep 17 00:00:00 2001 From: AWS SDK Swift Automation Date: Wed, 8 Jan 2025 19:15:43 +0000 Subject: [PATCH 7/7] chore: Updates version to 0.108.0 --- Package.version | 2 +- Package.version.next | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.version b/Package.version index 2500dbc62..d215cd6e6 100644 --- a/Package.version +++ b/Package.version @@ -1 +1 @@ -0.107.0 \ No newline at end of file +0.108.0 \ No newline at end of file diff --git a/Package.version.next b/Package.version.next index d215cd6e6..2ee7a0d34 100644 --- a/Package.version.next +++ b/Package.version.next @@ -1 +1 @@ -0.108.0 \ No newline at end of file +0.109.0 \ No newline at end of file