Skip to content

Commit 15df5a1

Browse files
committed
Correct partition key and sort key name
1 parent c4e64a5 commit 15df5a1

File tree

1 file changed

+11
-4
lines changed
  • hll/dynamodb-mapper/dynamodb-mapper-schema-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering

1 file changed

+11
-4
lines changed

hll/dynamodb-mapper/dynamodb-mapper-schema-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.google.devtools.ksp.symbol.*
2323
* @param classDeclaration the [KSClassDeclaration] of the class
2424
* @param ctx the [RenderContext] of the renderer
2525
*/
26+
@OptIn(KspExperimental::class)
2627
internal class SchemaRenderer(
2728
private val classDeclaration: KSClassDeclaration,
2829
private val ctx: RenderContext,
@@ -34,7 +35,6 @@ internal class SchemaRenderer(
3435
private val converterName = "${className}Converter"
3536
private val schemaName = "${className}Schema"
3637

37-
@OptIn(KspExperimental::class)
3838
private val dynamoDbItemAnnotation = classDeclaration.getAnnotationsByType(DynamoDbItem::class).single()
3939

4040
private val itemConverter: Type = dynamoDbItemAnnotation
@@ -46,7 +46,6 @@ internal class SchemaRenderer(
4646
TypeRef(pkg, shortName)
4747
} ?: TypeRef(ctx.pkg, converterName)
4848

49-
@OptIn(KspExperimental::class)
5049
private val properties = classDeclaration
5150
.getAllProperties()
5251
.filterNot { it.modifiers.contains(Modifier.PRIVATE) || it.isAnnotationPresent(DynamoDbIgnore::class) }
@@ -61,7 +60,15 @@ internal class SchemaRenderer(
6160
}
6261

6362
private val partitionKeyProp = properties.single { it.isPk }
63+
private val partitionKeyName: String = partitionKeyProp
64+
.getAnnotationsByType(DynamoDbAttribute::class)
65+
.singleOrNull()?.name ?: partitionKeyProp.name
66+
6467
private val sortKeyProp = properties.singleOrNull { it.isSk }
68+
private val sortKeyName: String? = sortKeyProp
69+
?.getAnnotationsByType(DynamoDbAttribute::class)
70+
?.singleOrNull()?.name ?: sortKeyProp?.name
71+
6572

6673
/**
6774
* Skip rendering a class builder if:
@@ -286,9 +293,9 @@ internal class SchemaRenderer(
286293
write("@#T", Types.Smithy.ExperimentalApi)
287294
withBlock("#Lobject #L : #T {", "}", ctx.attributes.visibility, schemaName, schemaType) {
288295
write("override val converter : #1T = #1T", itemConverter)
289-
write("override val partitionKey: #T = #T(#S)", MapperTypes.Items.keySpec(partitionKeyProp.keySpec), partitionKeyProp.keySpecType, partitionKeyProp.name)
296+
write("override val partitionKey: #T = #T(#S)", MapperTypes.Items.keySpec(partitionKeyProp.keySpec), partitionKeyProp.keySpecType, partitionKeyName)
290297
if (sortKeyProp != null) {
291-
write("override val sortKey: #T = #T(#S)", MapperTypes.Items.keySpec(sortKeyProp.keySpec), sortKeyProp.keySpecType, sortKeyProp.name)
298+
write("override val sortKey: #T = #T(#S)", MapperTypes.Items.keySpec(sortKeyProp.keySpec), sortKeyProp.keySpecType, sortKeyName!!)
292299
}
293300
}
294301
blankLine()

0 commit comments

Comments
 (0)