Skip to content

Commit

Permalink
fix: oneOfs is ignored in Builder's
Browse files Browse the repository at this point in the history
  • Loading branch information
y9vad9 committed Mar 3, 2024
1 parent bf9feb7 commit 6c43eb0
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ internal object MessageBuilderTransformer {
declaredFields: List<Pair<PropertySpec, Field>>,
oneOfs: List<PropertySpec>,
): TypeSpec {
val returnParametersSet = (declaredFields.map { it.first.name } + oneOfs.map { it.name })
.joinToString(", ")

return TypeSpec.classBuilder("Builder")
.addProperties(declaredFields.map { (spec, type) ->
spec.toBuilder().initializer(TypeDefaultValueTransformer.transform(type)).mutable(true).also {
Expand All @@ -22,7 +25,7 @@ internal object MessageBuilderTransformer {
.addProperties(oneOfs.map { it.toBuilder().apply { annotations.clear()}.mutable(true).initializer("null").build() })
.addFunction(
FunSpec.builder("build")
.addCode("return ${name}(${declaredFields.joinToString(", ") { it.first.name }})")
.addCode("return ${name}(${returnParametersSet})")
.returns(ClassName("", name))
.build()
)
Expand Down

0 comments on commit 6c43eb0

Please sign in to comment.