Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: paginator generator nullability bug caused by documents #1155

Merged
merged 9 commits into from
Sep 27, 2024
Merged
5 changes: 5 additions & 0 deletions .changes/f71f083b-6e5f-4a3c-9069-464b1f9f6d36.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "f71f083b-6e5f-4a3c-9069-464b1f9f6d36",
"type": "bugfix",
"description": "Fix paginator generator `List<*>` & `Map.Entry<String, *>` nullability"
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class KotlinSymbolProvider(private val model: Model, private val settings: Kotli
val fullyQualifiedKeyType = keyReference.fullName

val valueReference = toSymbol(shape.value)
val valueSuffix = if (valueReference.isNullable) "?" else ""
val valueSuffix = if (valueReference.isNullable || shape.isSparse) "?" else ""
val valueType = "${valueReference.name}$valueSuffix"
val fullyQualifiedValueType = "${valueReference.fullName}$valueSuffix"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,22 @@ private fun getItemDescriptorOrNull(paginationInfo: PaginationInfo, ctx: Codegen
val itemMember = ctx.model.expectShape(itemMemberId)
val isSparse = itemMember.isSparse
val (collectionLiteral, targetMember) = when (itemMember) {
is MapShape ->
ctx.symbolProvider.toSymbol(itemMember)
.expectProperty(SymbolProperty.ENTRY_EXPRESSION) as String to itemMember
is CollectionShape ->
ctx.symbolProvider.toSymbol(ctx.model.expectShape(itemMember.member.target)).name to ctx.model.expectShape(
itemMember.member.target,
)
is MapShape -> {
val symbol = ctx.symbolProvider.toSymbol(itemMember)
val entryExpression = symbol.expectProperty(SymbolProperty.ENTRY_EXPRESSION) as String
entryExpression to itemMember
}
is CollectionShape -> {
val target = ctx.model.expectShape(itemMember.member.target)
val symbol = ctx.symbolProvider.toSymbol(target)
val literal = symbol.name + if (symbol.isNullable || isSparse) "?" else ""
literal to target
}
else -> error("Unexpected shape type ${itemMember.type}")
}

return ItemDescriptor(
collectionLiteral + if (isSparse) "?" else "",
collectionLiteral,
targetMember,
itemLiteral,
itemPathLiteral,
Expand Down
Loading
Loading