Skip to content

Commit

Permalink
fix: Don't supply a default value when reading a non-optional value (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins authored Oct 16, 2024
1 parent 6793bc4 commit 051904a
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ open class MemberShapeDecodeGenerator(
else -> renderMemberExp(member, isPayload)
}
val memberName = ctx.symbolProvider.toMemberName(member)
if (shapeContainingMembers.isUnionShape) {
if (decodingUnion) {
writer.write("return .\$L(\$L)", memberName, readExp)
} else if (shapeContainingMembers.isError) {
writer.write("value.properties.\$L = \$L", memberName, readExp)
Expand Down Expand Up @@ -148,7 +148,7 @@ open class MemberShapeDecodeGenerator(
}

private fun readMethodName(baseName: String): String {
val extension = "".takeIf { shapeContainingMembers.isUnionShape } ?: "IfPresent"
val extension = "".takeIf { decodingUnion } ?: "IfPresent"
return writer.format("\$L\$L", baseName, extension)
}

Expand All @@ -158,6 +158,9 @@ open class MemberShapeDecodeGenerator(
}

private fun default(memberShape: MemberShape): String {
// If decoding the member of a union, then no default is needed.
if (decodingUnion) { return "" }

val targetShape = ctx.model.expectShape(memberShape.target)
val defaultTrait = memberShape.getTrait<DefaultTrait>() ?: targetShape.getTrait<DefaultTrait>()
val requiredTrait = memberShape.getTrait<RequiredTrait>()
Expand Down Expand Up @@ -290,4 +293,6 @@ open class MemberShapeDecodeGenerator(
)
}
}

private var decodingUnion: Boolean = shapeContainingMembers.isUnionShape
}

0 comments on commit 051904a

Please sign in to comment.