Skip to content

Commit

Permalink
fix: paginator generator nullability bug caused by documents (#1155)
Browse files Browse the repository at this point in the history
  • Loading branch information
0marperez authored Sep 27, 2024
1 parent 849ceb6 commit 630fbf2
Show file tree
Hide file tree
Showing 4 changed files with 475 additions and 9 deletions.
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

0 comments on commit 630fbf2

Please sign in to comment.