Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changes/26842b1e-eda3-4dc5-b306-20cce3a1125d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "26842b1e-eda3-4dc5-b306-20cce3a1125d",
"type": "bugfix",
"description": "Fix schema generation for nullable lists and maps",
"issues": [
"https://github.com/awslabs/aws-sdk-kotlin/issues/1590"
],
"module": "dynamodb-mapper"
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ internal class SchemaRenderer(
val type = Type.from(ksType)

when {
type.nullable -> {
writeInline("#T(", MapperTypes.Values.NullableConverter)
renderValueConverter(ksType.makeNotNullable())
writeInline(")")
}

ksType.isEnum -> writeInline("#T()", MapperTypes.Values.Scalars.enumConverter(type))

// FIXME Handle multi-module codegen rather than assuming nested classes will be in the same [ctx.pkg]
Expand All @@ -201,12 +207,6 @@ internal class SchemaRenderer(

type.isGenericFor(Types.Kotlin.Collections.Set) -> writeInline("#T", ksType.singleArgument().setValueConverter)

type.nullable -> {
writeInline("#T(", MapperTypes.Values.NullableConverter)
renderValueConverter(ksType.makeNotNullable())
writeInline(")")
}

else -> writeInline(
"#T",
when (type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public data class Lists(
var listUShort: List<UShort>,
var listULong: List<ULong>,
var listEnum: List<EnumAnimals>,
var nullableList: List<String>?,
var listNullableElement: List<String?>,
var nullableListNullableElement: List<String?>?,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand All @@ -56,6 +59,9 @@ public data class Lists(
if (listUShort != other.listUShort) return false
if (listULong != other.listULong) return false
if (listEnum != other.listEnum) return false
if (nullableList != other.nullableList) return false
if (listNullableElement != other.listNullableElement) return false
if (nullableListNullableElement != other.nullableListNullableElement) return false

return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ public data class Maps(
var mapStringListString: Map<String, List<String>>,
var mapStringListMapStringString: Map<String, List<Map<String, String>>>,
var mapEnum: Map<String, EnumAnimals>,
var nullableMap: Map<String, String>?,
var mapNullableValue: Map<String, String?>,
var nullableMapNullableValue: Map<String, String?>?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class ListsTest {
listUShort = listOf(UShort.MIN_VALUE, UShort.MAX_VALUE),
listULong = listOf(ULong.MIN_VALUE, ULong.MAX_VALUE),
listEnum = listOf(EnumAnimals.CAT, EnumAnimals.DOG, EnumAnimals.SHEEP),
nullableList = null,
listNullableElement = listOf("foo", null, "baz"),
nullableListNullableElement = null,
)

val item = ListsConverter.convertTo(lists)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class MapsTest {
),
),
mapEnum = mapOf("pet1" to EnumAnimals.CAT, "pet2" to EnumAnimals.DOG, "pet3" to EnumAnimals.SHEEP),
nullableMap = null,
mapNullableValue = mapOf("key1" to "value1", "key2" to null),
nullableMapNullableValue = null,
)

val item = MapsConverter.convertTo(maps)
Expand Down
Loading