Hi, I've an openapi related question. Are there an...
# http4k
j
Hi, I've an openapi related question. Are there any plans to support the possibility to provide multiple examples when using the http4k contract RouteMetaDsl? For instance:
Copy code
returning(
	status = OK,
    examples = responseLens to mapOf(
	  "english" to Greeting("Hello"),
	  "swedish" to Greeting("Hej"),
	)
)
d
This is "somewhat" supported but there is a limitation. You can for instance call returning twice....
Copy code
returning(OK, toLens to InterfaceHolder(Impl1()), definitionId = "impl1")
                returning(OK, toLens to InterfaceHolder(Impl2()), definitionId = "impl2")
which will result in
Copy code
"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. 🙂
j
Alright. I’ll have a look at it. Thanks for a quick response!