# Collection is not shown as required in the Open API Documentation

**URL:** <https://softwaremill.community/t/collection-is-not-shown-as-required-in-the-open-api-documentation/449>\
**Category:** tapir\
**Created:** [October 22, 2024, 8:12am UTC](https://softwaremill.community/t/collection-is-not-shown-as-required-in-the-open-api-documentation/449 "2024-10-22T08:12:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pme123](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/pme123/32/211_2.png) [@pme123](https://softwaremill.community/u/pme123)\
**Post date:** [October 22, 2024, 8:12am UTC](https://softwaremill.community/t/collection-is-not-shown-as-required-in-the-open-api-documentation/449/1 "2024-10-22T08:12:05Z")

</div>

I have the following case class:

```auto
case class ProductToOpen(
    newAccounts: Seq[NewAccount] = Seq(NewAccount()),
    someRequired: Boolean = true,
    ....
)

```

This creates me the following documentation:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/softwaremill/original/1X/3897ee048d405f7a691fb19936ef50ba7e824abf.png)  
So it works for objects and simple types but not for the collection.

Is this a bug or is there a way to achieve this?

---

<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:** [October 22, 2024, 10:35am UTC](https://softwaremill.community/t/collection-is-not-shown-as-required-in-the-open-api-documentation/449/2 "2024-10-22T10:35:45Z")

</div>

It’s a feature 😉 Although a pretty contentious one. The rationale is that collections might be empty, which makes them optional. However on the other hand, you might want to differentiate between an empty collection and an absent one. So you might say both that a collection which might be empty is “required” (but has to be there), or not (no elements might be provided, making it an optional field).

There’s some more discussion and background here: [`asIterable` always creates optional properties · Issue #993 · softwaremill/tapir · GitHub](https://github.com/softwaremill/tapir/issues/993) (rationale why this is so and work-arounds are given in this comment: [`asIterable` always creates optional properties · Issue #993 · softwaremill/tapir · GitHub](https://github.com/softwaremill/tapir/issues/993#issuecomment-912588917))

---

<div class="post-metadata">

**Author:** ![pme123](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/pme123/32/211_2.png) [@pme123](https://softwaremill.community/u/pme123)\
**Post date:** [October 22, 2024, 12:14pm UTC](https://softwaremill.community/t/collection-is-not-shown-as-required-in-the-open-api-documentation/449/3 "2024-10-22T12:14:35Z")

</div>

Thanks for the explanation.

I have the problem that a client that calls the service without the collection receives a decoding failure. So I am not a fan of this feature 😉.

I used Iron to indicate that there has to be at least one element and this works as expected:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/softwaremill/original/1X/0aad7c03c2d15cbcf93d61aaaa271939fc78ed52.png)

---

<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:** [October 22, 2024, 12:42pm UTC](https://softwaremill.community/t/collection-is-not-shown-as-required-in-the-open-api-documentation/449/4 "2024-10-22T12:42:14Z")

</div>

Well, I hope the comments on the issue also explain why making an empty collection “required” wouldn’t work well. Maybe that’s simply a shortcoming of Tapir’s design around schemas and codecs - but luckily it’s overridable and there are work-arounds.
