Skip to content

Commit 318cb05

Browse files
committed
misc: pr feedback
1 parent 1244d0e commit 318cb05

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/ModuleDocumentationIntegration.kt

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import software.amazon.smithy.kotlin.codegen.model.getTrait
99
import software.amazon.smithy.model.Model
1010
import software.amazon.smithy.model.shapes.ServiceShape
1111
import software.amazon.smithy.model.traits.TitleTrait
12+
import java.io.IOException
1213

1314
/**
14-
* Maps a services SKD ID to its code examples
15+
* Maps a service's SDK ID to its code examples
1516
*/
16-
private val currentCodeExamplesServices = mapOf(
17+
private val CODE_EXAMPLES_SERVICES_MAP = mapOf(
1718
"API Gateway" to "https://docs.aws.amazon.com/code-library/latest/ug/kotlin_1_api-gateway_code_examples.html",
1819
"Auto Scaling" to "https://docs.aws.amazon.com/code-library/latest/ug/kotlin_1_auto-scaling_code_examples.html",
1920
"Bedrock" to "https://docs.aws.amazon.com/code-library/latest/ug/kotlin_1_bedrock_code_examples.html",
@@ -38,10 +39,10 @@ private val currentCodeExamplesServices = mapOf(
3839
)
3940

4041
/**
41-
* Maps a services SKD ID to its handwritten module documentation file in the `resources` dir.
42+
* Maps a service's SDK ID to its handwritten module documentation file in the `resources` dir.
4243
* The module documentation files MUST be markdown files.
4344
*/
44-
private val currentHandWrittenServices = mapOf(
45+
private val HAND_WRITTEN_SERVICES_MAP = mapOf(
4546
"S3" to "S3.md",
4647
)
4748

@@ -55,8 +56,8 @@ private val currentHandWrittenServices = mapOf(
5556
* See: https://github.com/awslabs/aws-sdk-kotlin/blob/0581f5c5eeaa14dcd8af4ea0dfc088b1057f5ba5/build.gradle.kts#L68-L75
5657
*/
5758
class ModuleDocumentationIntegration(
58-
private val codeExamples: Map<String, String> = currentCodeExamplesServices,
59-
private val handWritten: Map<String, String> = currentHandWrittenServices,
59+
private val codeExamples: Map<String, String> = CODE_EXAMPLES_SERVICES_MAP,
60+
private val handWritten: Map<String, String> = HAND_WRITTEN_SERVICES_MAP,
6061
) : KotlinIntegration {
6162
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean =
6263
model.expectShape<ServiceShape>(settings.service).sdkId.let {
@@ -77,21 +78,21 @@ class ModuleDocumentationIntegration(
7778
append(
7879
generateBoilerPlate(ctx),
7980
)
80-
if (codeExamples.keys.contains(sdkId)) {
81+
if (handWritten.keys.contains(sdkId)) {
8182
append(
82-
generateCodeExamplesDocs(sdkId),
83+
generateHandWrittenDocs(sdkId),
8384
)
8485
appendLine()
8586
}
86-
if (handWritten.keys.contains(sdkId)) {
87+
if (codeExamples.keys.contains(sdkId)) {
8788
append(
88-
generateHandWrittenDocs(sdkId),
89+
generateCodeExamplesDocs(ctx),
8990
)
9091
}
9192
}
9293

9394
private fun generateBoilerPlate(ctx: CodegenContext) = buildString {
94-
// Title must me "Module" followed by the exact module name or dokka won't render it
95+
// Title must be "Module" followed by the exact module name or dokka won't render it
9596
appendLine("# Module ${ctx.settings.pkg.name.split(".").last()}")
9697
appendLine()
9798
ctx
@@ -105,9 +106,18 @@ class ModuleDocumentationIntegration(
105106
}
106107
}
107108

108-
private fun generateCodeExamplesDocs(sdkId: String) = buildString {
109+
private fun generateCodeExamplesDocs(ctx: CodegenContext) = buildString {
110+
val sdkId = ctx.settings.sdkId
111+
val codeExampleLink = codeExamples[sdkId]
112+
val title = ctx
113+
.model
114+
.expectShape<ServiceShape>(ctx.settings.service)
115+
.getTrait<TitleTrait>()
116+
?.value
117+
109118
appendLine("## Code Examples")
110-
appendLine("To see full code examples, see the $sdkId examples in the AWS Code Library. See ${codeExamples[sdkId]}")
119+
append("To see full code examples, see the ${title ?: sdkId} examples in the AWS code example library. ")
120+
appendLine("See $codeExampleLink")
111121
appendLine()
112122
}
113123

@@ -117,5 +127,5 @@ class ModuleDocumentationIntegration(
117127
.getResourceAsStream("aws/sdk/kotlin/codegen/moduledocumentation/${handWritten[sdkId]}")
118128
?.bufferedReader()
119129
?.readText()
120-
?: throw Exception("Unable to read from file ${handWritten[sdkId]}")
130+
?: throw IOException("Unable to read from file ${handWritten[sdkId]}")
121131
}

codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/ModuleDocumentationIntegrationTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private val model = """
1616
use aws.api#service
1717
1818
@service(sdkId: "Test")
19-
@title("A test service")
19+
@title("Test Service")
2020
service Test {
2121
version: "1.0.0",
2222
operations: []
@@ -60,7 +60,7 @@ class ModuleDocumentationIntegrationTest {
6060
"""
6161
# Module test
6262
63-
A test service
63+
Test Service
6464
""".trimIndent(),
6565
)
6666

@@ -76,7 +76,7 @@ class ModuleDocumentationIntegrationTest {
7676
.shouldContainOnlyOnceWithDiff(
7777
"""
7878
## Code Examples
79-
To see full code examples, see the Test examples in the AWS Code Library. See https://example.com
79+
To see full code examples, see the Test Service examples in the AWS code example library. See https://example.com
8080
""".trimIndent(),
8181
)
8282

@@ -88,7 +88,7 @@ class ModuleDocumentationIntegrationTest {
8888
.generateModuleDocumentation(
8989
ctx.toGenerationContext(),
9090
"Test",
91-
).replace("\r\n", "\n") // Handle CRLF on Windows
91+
).replace("\r\n", "\n") // Handle CRLF on Windows
9292
.shouldContainOnlyOnceWithDiff(
9393
"""
9494
## Subtitle

0 commit comments

Comments
 (0)