List query parameter is not marked required?

Hello, i was wondering if it’s possible in tapir to mark query parameters that accept lists to be required?

I Have a query on my endpoint that looks like:

which works, but the query parameter is not marked as required in the openapi spec…

- name: metric
        in: query
        required: false
          type: array
            type: string

Is this intentional? Is there a way to mark this as required without manipulating the openapi object directly?


Yes, it’s intentional, as if no parameter is provided, the list will be empty.

One possibility is to use a dedicated data type for non-empty lists, such as NonEmptyList from cats-effect. See the cats integration.

Another is to modify the schema attached to the query parameter:

query[List[String]]("metric").schema(_.copy(isOptional = false))

However, this won’t validate that the list is indeed non-empty. For this, you’d need to change the codec as well, for example following the implementation for the above mentioned NonEmptyList.

Cats it is then!