Skip to content

Commit 211bf19

Browse files
authored
fix: Add service client version to user-agent (#851)
1 parent 276d095 commit 211bf19

File tree

6 files changed

+60
-219
lines changed

6 files changed

+60
-219
lines changed

Diff for: smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/PackageManifestGenerator.kt

+1-4
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,9 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) {
5252
writer.openBlock("targets: [", "]") {
5353
writer.openBlock(".target(", "),") {
5454
writer.write("name: \$S,", ctx.settings.moduleName)
55-
writer.openBlock("dependencies: [", "],") {
55+
writer.openBlock("dependencies: [", "]") {
5656
dependenciesByTarget.forEach { writeTargetDependency(writer, it) }
5757
}
58-
writer.openBlock("resources: [", "]") {
59-
writer.write(".process(\"Resources\")")
60-
}
6158
}
6259
writer.openBlock(".testTarget(", ")") {
6360
writer.write("name: \$S,", ctx.settings.testModuleName)

Diff for: smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftDependency.kt

+34-198
Original file line numberDiff line numberDiff line change
@@ -58,204 +58,40 @@ class SwiftDependency(
5858
"aws-crt-swift",
5959
DistributionMethod.GIT,
6060
)
61-
val CLIENT_RUNTIME = SwiftDependency(
62-
"ClientRuntime",
63-
"main",
64-
"0.0.1",
65-
"aws-sdk-swift",
66-
"../../../smithy-swift",
67-
"smithy-swift",
68-
DistributionMethod.SPR,
69-
)
70-
val SMITHY = SwiftDependency(
71-
"Smithy",
72-
"main",
73-
"0.0.1",
74-
"aws-sdk-swift",
75-
"../../../smithy-swift",
76-
"smithy-swift",
77-
DistributionMethod.SPR,
78-
)
79-
val SMITHY_IDENTITY_API = SwiftDependency(
80-
"SmithyIdentityAPI",
81-
"main",
82-
"0.0.1",
83-
"aws-sdk-swift",
84-
"../../../smithy-swift",
85-
"smithy-swift",
86-
DistributionMethod.SPR,
87-
)
88-
val SMITHY_IDENTITY = SwiftDependency(
89-
"SmithyIdentity",
90-
"main",
91-
"0.0.1",
92-
"aws-sdk-swift",
93-
"../../../smithy-swift",
94-
"smithy-swift",
95-
DistributionMethod.SPR,
96-
)
97-
val SMITHY_RETRIES_API = SwiftDependency(
98-
"SmithyRetriesAPI",
99-
"main",
100-
"0.0.1",
101-
"aws-sdk-swift",
102-
"../../../smithy-swift",
103-
"smithy-swift",
104-
DistributionMethod.SPR,
105-
)
106-
val SMITHY_RETRIES = SwiftDependency(
107-
"SmithyRetries",
108-
"main",
109-
"0.0.1",
110-
"aws-sdk-swift",
111-
"../../../smithy-swift",
112-
"smithy-swift",
113-
DistributionMethod.SPR,
114-
)
115-
val SMITHY_HTTP_API = SwiftDependency(
116-
"SmithyHTTPAPI",
117-
"main",
118-
"0.0.1",
119-
"aws-sdk-swift",
120-
"../../../smithy-swift",
121-
"smithy-swift",
122-
DistributionMethod.SPR,
123-
)
124-
val SMITHY_HTTP_AUTH_API = SwiftDependency(
125-
"SmithyHTTPAuthAPI",
126-
"main",
127-
"0.0.1",
128-
"aws-sdk-swift",
129-
"../../../smithy-swift",
130-
"smithy-swift",
131-
DistributionMethod.SPR,
132-
)
133-
val SMITHY_HTTP_AUTH = SwiftDependency(
134-
"SmithyHTTPAuth",
135-
"main",
136-
"0.0.1",
137-
"aws-sdk-swift",
138-
"../../../smithy-swift",
139-
"smithy-swift",
140-
DistributionMethod.SPR,
141-
)
142-
val SMITHY_CHECKSUMS_API = SwiftDependency(
143-
"SmithyChecksumsAPI",
144-
"main",
145-
"0.0.1",
146-
"aws-sdk-swift",
147-
"../../../smithy-swift",
148-
"smithy-swift",
149-
DistributionMethod.SPR,
150-
)
151-
val SMITHY_CHECKSUMS = SwiftDependency(
152-
"SmithyChecksums",
153-
"main",
154-
"0.0.1",
155-
"aws-sdk-swift",
156-
"../../../smithy-swift",
157-
"smithy-swift",
158-
DistributionMethod.SPR,
159-
)
160-
val SMITHY_STREAMS = SwiftDependency(
161-
"SmithyStreams",
162-
"main",
163-
"0.0.1",
164-
"aws-sdk-swift",
165-
"../../../smithy-swift",
166-
"smithy-swift",
167-
DistributionMethod.SPR,
168-
)
169-
val SMITHY_EVENT_STREAMS_API = SwiftDependency(
170-
"SmithyEventStreamsAPI",
171-
"main",
172-
"0.0.1",
173-
"aws-sdk-swift",
174-
"../../../smithy-swift",
175-
"smithy-swift",
176-
DistributionMethod.SPR,
177-
)
178-
val SMITHY_EVENT_STREAMS_AUTH_API = SwiftDependency(
179-
"SmithyEventStreamsAuthAPI",
180-
"main",
181-
"0.0.1",
182-
"aws-sdk-swift",
183-
"../../../smithy-swift",
184-
"smithy-swift",
185-
DistributionMethod.SPR,
186-
)
187-
val SMITHY_EVENT_STREAMS = SwiftDependency(
188-
"SmithyEventStreams",
189-
"main",
190-
"0.0.1",
191-
"aws-sdk-swift",
192-
"../../../smithy-swift",
193-
"smithy-swift",
194-
DistributionMethod.SPR,
195-
)
196-
val SMITHY_TEST_UTIL = SwiftDependency(
197-
"SmithyTestUtil",
198-
"main",
199-
"0.0.1",
200-
"aws-sdk-swift",
201-
"../../../smithy-swift",
202-
"smithy-swift",
203-
DistributionMethod.SPR,
204-
)
205-
val SMITHY_READ_WRITE = SwiftDependency(
206-
"SmithyReadWrite",
207-
"main",
208-
"0.0.1",
209-
"aws-sdk-swift",
210-
"../../../smithy-swift",
211-
"smithy-swift",
212-
DistributionMethod.SPR,
213-
)
214-
val SMITHY_TIMESTAMPS = SwiftDependency(
215-
"SmithyTimestamps",
216-
"main",
217-
"0.0.1",
218-
"aws-sdk-swift",
219-
"../../../smithy-swift",
220-
"smithy-swift",
221-
DistributionMethod.SPR,
222-
)
223-
val SMITHY_XML = SwiftDependency(
224-
"SmithyXML",
225-
"main",
226-
"0.0.1",
227-
"aws-sdk-swift",
228-
"../../../smithy-swift",
229-
"smithy-swift",
230-
DistributionMethod.SPR,
231-
)
232-
val SMITHY_JSON = SwiftDependency(
233-
"SmithyJSON",
234-
"main",
235-
"0.0.1",
236-
"aws-sdk-swift",
237-
"../../../smithy-swift",
238-
"smithy-swift",
239-
DistributionMethod.SPR,
240-
)
241-
val SMITHY_FORM_URL = SwiftDependency(
242-
"SmithyFormURL",
243-
"main",
244-
"0.0.1",
245-
"aws-sdk-swift",
246-
"../../../smithy-swift",
247-
"smithy-swift",
248-
DistributionMethod.SPR,
249-
)
250-
val SMITHY_WAITERS_API = SwiftDependency(
251-
"SmithyWaitersAPI",
252-
"main",
253-
"0.0.1",
254-
"aws-sdk-swift",
255-
"../../../smithy-swift",
256-
"smithy-swift",
257-
DistributionMethod.SPR,
258-
)
61+
val CLIENT_RUNTIME = smithySwiftDependency("ClientRuntime")
62+
val SMITHY = smithySwiftDependency("Smithy")
63+
val SMITHY_IDENTITY_API = smithySwiftDependency("SmithyIdentityAPI")
64+
val SMITHY_IDENTITY = smithySwiftDependency("SmithyIdentity")
65+
val SMITHY_RETRIES_API = smithySwiftDependency("SmithyRetriesAPI")
66+
val SMITHY_RETRIES = smithySwiftDependency("SmithyRetries")
67+
val SMITHY_HTTP_API = smithySwiftDependency("SmithyHTTPAPI")
68+
val SMITHY_HTTP_AUTH_API = smithySwiftDependency("SmithyHTTPAuthAPI")
69+
val SMITHY_HTTP_AUTH = smithySwiftDependency("SmithyHTTPAuth")
70+
val SMITHY_CHECKSUMS_API = smithySwiftDependency("SmithyChecksumsAPI")
71+
val SMITHY_CHECKSUMS = smithySwiftDependency("SmithyChecksums")
72+
val SMITHY_STREAMS = smithySwiftDependency("SmithyStreams")
73+
val SMITHY_EVENT_STREAMS_API = smithySwiftDependency("SmithyEventStreamsAPI")
74+
val SMITHY_EVENT_STREAMS_AUTH_API = smithySwiftDependency("SmithyEventStreamsAuthAPI")
75+
val SMITHY_EVENT_STREAMS = smithySwiftDependency("SmithyEventStreams")
76+
val SMITHY_TEST_UTIL = smithySwiftDependency("SmithyTestUtil")
77+
val SMITHY_READ_WRITE = smithySwiftDependency("SmithyReadWrite")
78+
val SMITHY_TIMESTAMPS = smithySwiftDependency("SmithyTimestamps")
79+
val SMITHY_XML = smithySwiftDependency("SmithyXML")
80+
val SMITHY_JSON = smithySwiftDependency("SmithyJSON")
81+
val SMITHY_FORM_URL = smithySwiftDependency("SmithyFormURL")
82+
val SMITHY_WAITERS_API = smithySwiftDependency("SmithyWaitersAPI")
83+
84+
fun smithySwiftDependency(name: String): SwiftDependency {
85+
return SwiftDependency(
86+
name,
87+
"main",
88+
"0.0.1",
89+
"https://github.com/smithy-lang/smithy-swift",
90+
"../../../smithy-swift",
91+
"smithy-swift",
92+
DistributionMethod.GIT,
93+
)
94+
}
25995
}
26096

26197
override fun getDependencies(): List<SymbolDependency> {

Diff for: smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HttpProtocolServiceClient.kt

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ open class HttpProtocolServiceClient(
3030
ClientRuntimeTypes.Core.Client,
3131
) {
3232
writer.write("public static let clientName = \$S", serviceSymbol.name)
33+
writer.write("public static let version = \$S", ctx.settings.moduleVersion)
3334
writer.write("let client: \$N", ClientRuntimeTypes.Http.SdkHttpClient)
3435
writer.write("let config: \$L", serviceConfig.typeName)
3536
writer.write("let serviceName = \$S", serviceName)

Diff for: smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SmithyTestUtilTypes.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import software.amazon.smithy.swift.codegen.SwiftDeclaration
55
import software.amazon.smithy.swift.codegen.SwiftDependency
66

77
object SmithyTestUtilTypes {
8-
val TestInitializer = runtimeSymbol("TestInitializer")
9-
val TestBaseError = runtimeSymbol("TestBaseError")
8+
val TestInitializer = runtimeSymbol("TestInitializer", SwiftDeclaration.ENUM)
9+
val TestBaseError = runtimeSymbol("TestBaseError", SwiftDeclaration.STRUCT)
1010
val dummyIdentityResolver = runtimeSymbol("dummyIdentityResolver", SwiftDeclaration.FUNC)
1111
}
1212

Diff for: smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/HttpProtocolClientGeneratorTests.kt

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class HttpProtocolClientGeneratorTests {
1919
val expected = """
2020
public class RestJsonProtocolClient: ClientRuntime.Client {
2121
public static let clientName = "RestJsonProtocolClient"
22+
public static let version = "2019-12-16"
2223
let client: ClientRuntime.SdkHttpClient
2324
let config: RestJsonProtocolClient.RestJsonProtocolClientConfiguration
2425
let serviceName = "Rest Json Protocol"

Diff for: smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/manifestanddocs/PackageManifestGeneratorTests.kt

+21-15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package software.amazon.smithy.swift.codegen.manifestanddocs
66
*/
77

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

20+
@Test
21+
fun `it starts with a swift-tools-version statement`() {
22+
val packageManifest = testContext.manifest.getFileString("Package.swift.txt").get()
23+
assertNotNull(packageManifest)
24+
packageManifest.shouldStartWith("// swift-tools-version: 5.5.0")
25+
}
26+
1927
@Test
2028
fun `it renders package manifest file with macOS and iOS platforms block`() {
2129
val packageManifest = testContext.manifest.getFileString("Package.swift.txt").get()
2230
assertNotNull(packageManifest)
23-
packageManifest.shouldContain(
24-
"platforms: [\n" +
25-
" .macOS(.v10_15), .iOS(.v13)\n" +
26-
" ]"
27-
)
31+
val expected = """
32+
platforms: [
33+
.macOS(.v10_15), .iOS(.v13)
34+
],
35+
"""
36+
packageManifest.shouldContain(expected)
2837
}
2938

3039
@Test
3140
fun `it renders package manifest file with single library in product block`() {
3241
val packageManifest = testContext.manifest.getFileString("Package.swift.txt").get()
3342
assertNotNull(packageManifest)
34-
packageManifest.shouldContain(
35-
"products: [\n" +
36-
" .library(name: \"MockSDK\", targets: [\"MockSDK\"])\n" +
37-
" ]"
38-
)
43+
val expected = """
44+
products: [
45+
.library(name: "MockSDK", targets: ["MockSDK"])
46+
],
47+
"""
48+
packageManifest.shouldContain(expected)
3949
}
4050

4151
@Test
4252
fun `it renders package manifest file with target and test target`() {
43-
println(testContext.manifest.files)
4453
val packageManifest = testContext.manifest.getFileString("Package.swift.txt").get()
4554
assertNotNull(packageManifest)
4655
val expected = """
4756
targets: [
4857
.target(
4958
name: "MockSDK",
5059
dependencies: [
51-
],
52-
resources: [
53-
.process("Resources")
5460
]
5561
),
5662
.testTarget(
@@ -59,7 +65,7 @@ class PackageManifestGeneratorTests {
5965
"MockSDK",
6066
.product(
6167
name: "SmithyTestUtil",
62-
package: "aws-sdk-swift.smithy-swift"
68+
package: "smithy-swift"
6369
),
6470
]
6571
)

0 commit comments

Comments
 (0)