Jonas Grönberg
04/03/2023, 9:51 AMreturning(
status = OK,
examples = responseLens to mapOf(
"english" to Greeting("Hello"),
"swedish" to Greeting("Hej"),
)
)
dave
04/03/2023, 10:48 AMreturning(OK, toLens to InterfaceHolder(Impl1()), definitionId = "impl1")
returning(OK, toLens to InterfaceHolder(Impl2()), definitionId = "impl2")
which will result in
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/impl1"
},
{
"$ref": "#/components/schemas/impl2"
}
]
}
}
}
in the response. But you have to give the models different definition ids - the renderer isn't smart enough to merge the 2 definitions into one - it can't determine the "rules" that will apply to the required/not required fields. And nullable fields are not supported (in the examples - you can make them nullable but NOT set the value in the example TO null).
If you need a union-type arrangement then I'm afraid you need to model that with separate classes and a hierarchy for the different response types. This is a limitation of the model, but it's the price you pay for getting the rendering for free. 🙂Jonas Grönberg
04/04/2023, 5:54 PM