Skip to content

Commit 4041dc6

Browse files
author
luigi
committed
fix
1 parent 904c906 commit 4041dc6

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/protocol/HttpBindingProtocolGenerator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ abstract class HttpBindingProtocolGenerator : ProtocolGenerator {
184184
ctx.delegator.useSymbolWriter(serializerSymbol) { writer ->
185185
// FIXME: this works only for Cbor protocol now
186186
if (ctx.settings.build.generateServiceProject) {
187+
require(protocolName == "smithyRpcv2cbor") { "service project accepts only Cbor protocol" }
187188
writer
188189
.openBlock("internal class #T {", serializerSymbol)
189190
.call {

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/KtorStubGenerator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ internal class KtorStubGenerator(
497497
withBlock("if (incoming == #T.Any || allowed.none { incoming.match(it) }) {", "}", RuntimeTypes.KtorServerHttp.ContentType) {
498498
withBlock("throw #T(", ")", ServiceTypes(pkgName).errorEnvelope) {
499499
write("#T.UnsupportedMediaType.value, ", RuntimeTypes.KtorServerHttp.HttpStatusCode)
500-
write("#S", "Allowed Content-Type(s): \${allowed.joinToString()}")
500+
write("#S", "Not acceptable ContentType found: '\${incoming}'. Accepted content types: \${allowed.joinToString()}")
501501
}
502502
}
503503
}
@@ -557,7 +557,7 @@ internal class KtorStubGenerator(
557557
withBlock("if (!isOk) {", "}") {
558558
withBlock("throw #T(", ")", ServiceTypes(pkgName).errorEnvelope) {
559559
write("#T.NotAcceptable.value, ", RuntimeTypes.KtorServerHttp.HttpStatusCode)
560-
write("#S", "Supported Accept(s): \${allowed.joinToString()}")
560+
write("#S", "Not acceptable Accept type found: '\${accepted}'. Accepted types: \${allowed.joinToString()}")
561561
}
562562
}
563563
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package com.test
7+
8+
import java.nio.file.Path
9+
import java.nio.file.Paths
10+
import kotlin.io.path.exists
11+
import kotlin.test.Test
12+
import kotlin.test.assertTrue
13+
14+
class ServiceFileTest {
15+
val packageName = "com.test"
16+
val packagePath = packageName.replace('.', '/')
17+
18+
val projectDir: Path = Paths.get("build/generated-service")
19+
20+
@Test
21+
fun `generates service and all necessary files`() {
22+
assertTrue(projectDir.resolve("build.gradle.kts").exists())
23+
assertTrue(projectDir.resolve("settings.gradle.kts").exists())
24+
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/Main.kt").exists())
25+
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/Routing.kt").exists())
26+
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/config/ServiceFrameworkConfig.kt").exists())
27+
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/framework/ServiceFramework.kt").exists())
28+
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/plugins/ContentTypeGuard.kt").exists())
29+
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/plugins/ErrorHandler.kt").exists())
30+
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/utils/Logging.kt").exists())
31+
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/auth/Authentication.kt").exists())
32+
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/auth/Validation.kt").exists())
33+
34+
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/model/PostTestRequest.kt").exists())
35+
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/model/PostTestResponse.kt").exists())
36+
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/serde/PostTestOperationSerializer.kt").exists())
37+
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/serde/PostTestOperationDeserializer.kt").exists())
38+
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/operations/PostTestOperation.kt").exists())
39+
}
40+
}

tests/codegen/service-codegen-tests/src/test/kotlin/com/test/ServiceGeneratorTest.kt

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,11 @@ data class ErrorTestRequest(
5959

6060
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
6161
class ServiceGeneratorTest {
62-
val packageName = "com.test"
6362
val closeGracePeriodMillis: Long = 5_000L
6463
val closeTimeoutMillis: Long = 1_000L
6564
val requestBodyLimit: Long = 10L * 1024 * 1024
6665
val port: Int = ServerSocket(0).use { it.localPort }
6766

68-
val packagePath = packageName.replace('.', '/')
6967
val baseUrl = "http://localhost:$port"
7068

7169
val projectDir: Path = Paths.get("build/generated-service")
@@ -82,27 +80,6 @@ class ServiceGeneratorTest {
8280
@AfterAll
8381
fun shutdown() = cleanupService(proc)
8482

85-
@Test
86-
fun `generates service and all necessary files`() {
87-
assertTrue(projectDir.resolve("build.gradle.kts").exists())
88-
assertTrue(projectDir.resolve("settings.gradle.kts").exists())
89-
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/Main.kt").exists())
90-
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/Routing.kt").exists())
91-
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/config/ServiceFrameworkConfig.kt").exists())
92-
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/framework/ServiceFramework.kt").exists())
93-
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/plugins/ContentTypeGuard.kt").exists())
94-
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/plugins/ErrorHandler.kt").exists())
95-
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/utils/Logging.kt").exists())
96-
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/auth/Authentication.kt").exists())
97-
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/auth/Validation.kt").exists())
98-
99-
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/model/PostTestRequest.kt").exists())
100-
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/model/PostTestResponse.kt").exists())
101-
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/serde/PostTestOperationSerializer.kt").exists())
102-
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/serde/PostTestOperationDeserializer.kt").exists())
103-
assertTrue(projectDir.resolve("src/main/kotlin/$packagePath/operations/PostTestOperation.kt").exists())
104-
}
105-
10683
@Test
10784
fun `checks service with netty engine`() {
10885
val nettyPort: Int = ServerSocket(0).use { it.localPort }

0 commit comments

Comments
 (0)