Skip to content

Commit 2a13d39

Browse files
committed
feat(codegen): improve service name mapping for DSL constants
- Use same naming logic as service client generation (clientName function) - Apply sanitizeClientName() to remove API/Client/Service suffixes - Apply toPascalCase() for consistent naming - Generated names now match client names: LambdaClient → LambdaOperations - Verified with Lambda, S3, and DynamoDB services Examples: - Lambda service: LambdaOperations (was AwsgirapiserviceOperations) - S3 service: S3Operations (was Amazons3Operations) - DynamoDB service: DynamoDbOperations (was AmazondynamodbOperations) 🤖 Assisted by Amazon Q Developer
1 parent e5163bd commit 2a13d39

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import software.amazon.smithy.kotlin.codegen.core.KotlinWriter
1212
import software.amazon.smithy.kotlin.codegen.core.withBlock
1313
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration
1414
import software.amazon.smithy.kotlin.codegen.model.expectShape
15+
import software.amazon.smithy.kotlin.codegen.utils.toPascalCase
1516
import software.amazon.smithy.model.Model
1617
import software.amazon.smithy.model.knowledge.TopDownIndex
1718
import software.amazon.smithy.model.shapes.OperationShape
@@ -47,7 +48,7 @@ class DslConstantsIntegration : KotlinIntegration {
4748

4849
override fun writeAdditionalFiles(ctx: CodegenContext, delegator: KotlinDelegator) {
4950
val service = ctx.model.expectShape<ServiceShape>(ctx.settings.service)
50-
val serviceName = service.id.name.lowercase()
51+
val serviceName = getServiceName(ctx.settings.sdkId)
5152

5253
// Get all operations for this service
5354
val operations = TopDownIndex
@@ -63,6 +64,22 @@ class DslConstantsIntegration : KotlinIntegration {
6364
generateOperationConstants(ctx, delegator, serviceName, operations)
6465
}
6566

67+
/**
68+
* Generate the service name using the same logic as service client generation.
69+
* This ensures consistency between client names (e.g., "LambdaClient") and
70+
* constants names (e.g., "LambdaOperations").
71+
*/
72+
private fun getServiceName(sdkId: String): String {
73+
return sdkId.sanitizeClientName().toPascalCase()
74+
}
75+
76+
/**
77+
* Sanitize the service name by removing common suffixes, following the same
78+
* logic as the service client naming in KotlinSymbolProvider.
79+
*/
80+
private fun String.sanitizeClientName(): String =
81+
replace(Regex("(API|Client|Service)$", setOf(RegexOption.IGNORE_CASE)), "")
82+
6683
/**
6784
* Generate operation constants for a specific service
6885
*/
@@ -72,7 +89,7 @@ class DslConstantsIntegration : KotlinIntegration {
7289
serviceName: String,
7390
operations: List<OperationShape>
7491
) {
75-
val className = "${serviceName.replaceFirstChar { it.uppercase() }}Operations"
92+
val className = "${serviceName}Operations"
7693
val fileName = "$className.kt"
7794

7895
// Generate the file content

0 commit comments

Comments
 (0)