@@ -9,11 +9,12 @@ import software.amazon.smithy.kotlin.codegen.model.getTrait
99import software.amazon.smithy.model.Model
1010import software.amazon.smithy.model.shapes.ServiceShape
1111import 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 */
5758class 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}
0 commit comments