Skip to content

Commit

Permalink
fix: Add service client version to user-agent (#851)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins authored Nov 6, 2024
1 parent 276d095 commit 211bf19
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) {
writer.openBlock("targets: [", "]") {
writer.openBlock(".target(", "),") {
writer.write("name: \$S,", ctx.settings.moduleName)
writer.openBlock("dependencies: [", "],") {
writer.openBlock("dependencies: [", "]") {
dependenciesByTarget.forEach { writeTargetDependency(writer, it) }
}
writer.openBlock("resources: [", "]") {
writer.write(".process(\"Resources\")")
}
}
writer.openBlock(".testTarget(", ")") {
writer.write("name: \$S,", ctx.settings.testModuleName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,204 +58,40 @@ class SwiftDependency(
"aws-crt-swift",
DistributionMethod.GIT,
)
val CLIENT_RUNTIME = SwiftDependency(
"ClientRuntime",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY = SwiftDependency(
"Smithy",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_IDENTITY_API = SwiftDependency(
"SmithyIdentityAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_IDENTITY = SwiftDependency(
"SmithyIdentity",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_RETRIES_API = SwiftDependency(
"SmithyRetriesAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_RETRIES = SwiftDependency(
"SmithyRetries",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_HTTP_API = SwiftDependency(
"SmithyHTTPAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_HTTP_AUTH_API = SwiftDependency(
"SmithyHTTPAuthAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_HTTP_AUTH = SwiftDependency(
"SmithyHTTPAuth",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_CHECKSUMS_API = SwiftDependency(
"SmithyChecksumsAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_CHECKSUMS = SwiftDependency(
"SmithyChecksums",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_STREAMS = SwiftDependency(
"SmithyStreams",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_EVENT_STREAMS_API = SwiftDependency(
"SmithyEventStreamsAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_EVENT_STREAMS_AUTH_API = SwiftDependency(
"SmithyEventStreamsAuthAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_EVENT_STREAMS = SwiftDependency(
"SmithyEventStreams",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_TEST_UTIL = SwiftDependency(
"SmithyTestUtil",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_READ_WRITE = SwiftDependency(
"SmithyReadWrite",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_TIMESTAMPS = SwiftDependency(
"SmithyTimestamps",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_XML = SwiftDependency(
"SmithyXML",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_JSON = SwiftDependency(
"SmithyJSON",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_FORM_URL = SwiftDependency(
"SmithyFormURL",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_WAITERS_API = SwiftDependency(
"SmithyWaitersAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val CLIENT_RUNTIME = smithySwiftDependency("ClientRuntime")
val SMITHY = smithySwiftDependency("Smithy")
val SMITHY_IDENTITY_API = smithySwiftDependency("SmithyIdentityAPI")
val SMITHY_IDENTITY = smithySwiftDependency("SmithyIdentity")
val SMITHY_RETRIES_API = smithySwiftDependency("SmithyRetriesAPI")
val SMITHY_RETRIES = smithySwiftDependency("SmithyRetries")
val SMITHY_HTTP_API = smithySwiftDependency("SmithyHTTPAPI")
val SMITHY_HTTP_AUTH_API = smithySwiftDependency("SmithyHTTPAuthAPI")
val SMITHY_HTTP_AUTH = smithySwiftDependency("SmithyHTTPAuth")
val SMITHY_CHECKSUMS_API = smithySwiftDependency("SmithyChecksumsAPI")
val SMITHY_CHECKSUMS = smithySwiftDependency("SmithyChecksums")
val SMITHY_STREAMS = smithySwiftDependency("SmithyStreams")
val SMITHY_EVENT_STREAMS_API = smithySwiftDependency("SmithyEventStreamsAPI")
val SMITHY_EVENT_STREAMS_AUTH_API = smithySwiftDependency("SmithyEventStreamsAuthAPI")
val SMITHY_EVENT_STREAMS = smithySwiftDependency("SmithyEventStreams")
val SMITHY_TEST_UTIL = smithySwiftDependency("SmithyTestUtil")
val SMITHY_READ_WRITE = smithySwiftDependency("SmithyReadWrite")
val SMITHY_TIMESTAMPS = smithySwiftDependency("SmithyTimestamps")
val SMITHY_XML = smithySwiftDependency("SmithyXML")
val SMITHY_JSON = smithySwiftDependency("SmithyJSON")
val SMITHY_FORM_URL = smithySwiftDependency("SmithyFormURL")
val SMITHY_WAITERS_API = smithySwiftDependency("SmithyWaitersAPI")

fun smithySwiftDependency(name: String): SwiftDependency {
return SwiftDependency(
name,
"main",
"0.0.1",
"https://github.com/smithy-lang/smithy-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.GIT,
)
}
}

override fun getDependencies(): List<SymbolDependency> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ open class HttpProtocolServiceClient(
ClientRuntimeTypes.Core.Client,
) {
writer.write("public static let clientName = \$S", serviceSymbol.name)
writer.write("public static let version = \$S", ctx.settings.moduleVersion)
writer.write("let client: \$N", ClientRuntimeTypes.Http.SdkHttpClient)
writer.write("let config: \$L", serviceConfig.typeName)
writer.write("let serviceName = \$S", serviceName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import software.amazon.smithy.swift.codegen.SwiftDeclaration
import software.amazon.smithy.swift.codegen.SwiftDependency

object SmithyTestUtilTypes {
val TestInitializer = runtimeSymbol("TestInitializer")
val TestBaseError = runtimeSymbol("TestBaseError")
val TestInitializer = runtimeSymbol("TestInitializer", SwiftDeclaration.ENUM)
val TestBaseError = runtimeSymbol("TestBaseError", SwiftDeclaration.STRUCT)
val dummyIdentityResolver = runtimeSymbol("dummyIdentityResolver", SwiftDeclaration.FUNC)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class HttpProtocolClientGeneratorTests {
val expected = """
public class RestJsonProtocolClient: ClientRuntime.Client {
public static let clientName = "RestJsonProtocolClient"
public static let version = "2019-12-16"
let client: ClientRuntime.SdkHttpClient
let config: RestJsonProtocolClient.RestJsonProtocolClientConfiguration
let serviceName = "Rest Json Protocol"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package software.amazon.smithy.swift.codegen.manifestanddocs
*/

import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldStartWith
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Test
import software.amazon.smithy.swift.codegen.PackageManifestGenerator
Expand All @@ -16,41 +17,46 @@ import software.amazon.smithy.swift.codegen.protocolgeneratormocks.MockHTTPAWSJs
class PackageManifestGeneratorTests {
private val testContext = setupTests("simple-service-with-operation-and-dependency.smithy", "smithy.example#Example")

@Test
fun `it starts with a swift-tools-version statement`() {
val packageManifest = testContext.manifest.getFileString("Package.swift.txt").get()
assertNotNull(packageManifest)
packageManifest.shouldStartWith("// swift-tools-version: 5.5.0")
}

@Test
fun `it renders package manifest file with macOS and iOS platforms block`() {
val packageManifest = testContext.manifest.getFileString("Package.swift.txt").get()
assertNotNull(packageManifest)
packageManifest.shouldContain(
"platforms: [\n" +
" .macOS(.v10_15), .iOS(.v13)\n" +
" ]"
)
val expected = """
platforms: [
.macOS(.v10_15), .iOS(.v13)
],
"""
packageManifest.shouldContain(expected)
}

@Test
fun `it renders package manifest file with single library in product block`() {
val packageManifest = testContext.manifest.getFileString("Package.swift.txt").get()
assertNotNull(packageManifest)
packageManifest.shouldContain(
"products: [\n" +
" .library(name: \"MockSDK\", targets: [\"MockSDK\"])\n" +
" ]"
)
val expected = """
products: [
.library(name: "MockSDK", targets: ["MockSDK"])
],
"""
packageManifest.shouldContain(expected)
}

@Test
fun `it renders package manifest file with target and test target`() {
println(testContext.manifest.files)
val packageManifest = testContext.manifest.getFileString("Package.swift.txt").get()
assertNotNull(packageManifest)
val expected = """
targets: [
.target(
name: "MockSDK",
dependencies: [
],
resources: [
.process("Resources")
]
),
.testTarget(
Expand All @@ -59,7 +65,7 @@ class PackageManifestGeneratorTests {
"MockSDK",
.product(
name: "SmithyTestUtil",
package: "aws-sdk-swift.smithy-swift"
package: "smithy-swift"
),
]
)
Expand Down

0 comments on commit 211bf19

Please sign in to comment.