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:
query[List[String]]("metric")

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

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

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

Thanks,
ben

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.

1 Like

Cats it is then!

Thanks