Hi, for `http4k-contract` , is it possible to gene...
# http4k
b
Hi, for
http4k-contract
, is it possible to generate array of enum query parameter, e.g.
Copy code
"schema": {
              "type": "array",
              "items":{
                "type": "string",
                "enum": ["foo", "soo", "doo", "coo"]
              }
            }
Context: I was trying to use the following
Copy code
Query.enum<TypeEnum>().multi.defaulted("type", emptyList())
which render into
Copy code
{
  "schema": {
    "type": "array",
    "items": {
      "type": "string"
    }
  },
  "in": "query",
  "name": "type",
  "required": false
}
which lose the information about the enum (request validation still works though, i.e. invalid enum string is rejected) So I was thinking if I can use array of enum string instead, like the one in original question.
a
Based on my quick glance, it appears the openApi specification allows for arrays of enums, and it would appear to me that
multi
is attempting to retain that type data, but I can't say for sure. Maybe an issue with the renderer. Maybe David has a suggestion, but if not, this might be a bug to raise.
b
This is my workaround for now:
Copy code
Query.enum<TypeEnum>().multi.defaulted("type", emptyList(), "Allowed values: ${TypeEnum.values().joinToString()}")
Simply put a description message about the allowed values (enum strings).
Copy code
"parameters": [
          {
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "in": "query",
            "name": "type",
            "required": false,
            "description": "Allowed values: FOO, SOO, DOO, COO"
          }
Not a good solution, but good enough for now, at least client-side developers have some ideas.
d
This will be because of the open api3 rendering. I think it should be possible to do without a lot of rework. Please raise an issue and we can clarify either way.
good news - I've managed to get this working pretty simply, so it will be in the next release