# List query parameter is not marked required?

**URL:** <https://softwaremill.community/t/list-query-parameter-is-not-marked-required/265>\
**Category:** tapir\
**Created:** [August 14, 2023, 4:23pm UTC](https://softwaremill.community/t/list-query-parameter-is-not-marked-required/265 "2023-08-14T16:23:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bclouser](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/bclouser/32/108_2.png) [@bclouser](https://softwaremill.community/u/bclouser)\
**Post date:** [August 14, 2023, 4:23pm UTC](https://softwaremill.community/t/list-query-parameter-is-not-marked-required/265/1 "2023-08-14T16:23:42Z")

</div>

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…

```auto
- 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

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [August 16, 2023, 8:15am UTC](https://softwaremill.community/t/list-query-parameter-is-not-marked-required/265/2 "2023-08-16T08:15:47Z")

</div>

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](https://tapir.softwaremill.com/en/latest/endpoint/integrations.html#cats-datatypes-integration).

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

```plaintext
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](https://github.com/softwaremill/tapir/blob/17f0d913b4ba189e0a060c78b416e808ef6a0ecf/integrations/cats/src/main/scala/sttp/tapir/integ/cats/TapirCodecCats.scala#L27-L30).

---

<div class="post-metadata">

**Author:** ![bclouser](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/bclouser/32/108_2.png) [@bclouser](https://softwaremill.community/u/bclouser)\
**Post date:** [August 16, 2023, 4:31pm UTC](https://softwaremill.community/t/list-query-parameter-is-not-marked-required/265/3 "2023-08-16T16:31:15Z")

</div>

Cats it is then!

Thanks
