Skip to content

Commit

Permalink
Fix handling of default values in schema for complex types. (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
srinivasankavitha authored Jan 17, 2024
1 parent 11a343b commit 1bff1a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class InputTypeGenerator(config: CodeGenConfig, document: Document) : BaseDataTy
}
}.joinToString()
)
is ObjectValue -> CodeBlock.of("new \$L()", typeUtils.findReturnType(it.type))
else -> CodeBlock.of("\$L", defVal)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,32 @@ class CodeGenTest {
assertCompilesJava(enumTypes + dataTypes)
}

@Test
fun generateInputWithDefaultValueForComplexType() {
val schema = """
enum Color {
red
}
input ColorFilter {
color: Color = red
}
input Car {
color: Color = red
make: String
}
input MyCar {
car: Car = {color: red}
}
""".trimIndent()

val (dataTypes, _, enumTypes) = CodeGen(CodeGenConfig(schemas = setOf(schema), packageName = basePackageName)).generate()

assertCompilesJava(enumTypes + dataTypes)
}

@Test
fun generateInputWithDefaultValueForArray() {
val schema = """
Expand Down

0 comments on commit 1bff1a0

Please sign in to comment.