# How to add a Schema derivation of a Union Type

**URL:** <https://softwaremill.community/t/how-to-add-a-schema-derivation-of-a-union-type/322>\
**Category:** tapir\
**Created:** [November 16, 2023, 2:17pm UTC](https://softwaremill.community/t/how-to-add-a-schema-derivation-of-a-union-type/322 "2023-11-16T14:17:19Z")\
**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:** [November 16, 2023, 2:17pm UTC](https://softwaremill.community/t/how-to-add-a-schema-derivation-of-a-union-type/322/1 "2023-11-16T14:17:19Z")

</div>

Hi  
I have a union type of 2 Scala 3 Enums, like

```auto
case class In(
      subStatusKey: SubStatusKeyDocuments | SubStatusKeyGeneral = SubStatusKeyDocuments.`documents-prepared`,
     )
object In:
    given Schema[In] = Schema.derived
    given CirceCodec[In] = deriveCodec
end In

enum SubStatusKeyGeneral derives ConfiguredEnumCodec:
  case canceled
  case finished

object SubStatusKeyGeneral:
  given Schema[SubStatusKeyGeneral] = Schema.derived
end SubStatusKeyGeneral
...

```

This does not work - is there a working example or are union types not supported?  
I use Circe for Json Marshalling.

---

<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:** [December 9, 2023, 10:30am UTC](https://softwaremill.community/t/how-to-add-a-schema-derivation-of-a-union-type/322/2 "2023-12-09T10:30:51Z")

</div>

I am the only one that uses Union Types with Tapir? 😢

---

<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:** [December 13, 2023, 8:27pm UTC](https://softwaremill.community/t/how-to-add-a-schema-derivation-of-a-union-type/322/3 "2023-12-13T20:27:25Z")

</div>

Sorry for the late reply 🙂

Indeed that’s something that we should definitely support. Can you create an issue on GH to track this?

Also, I suspect you’d expect a coproduct (`oneOf` schema) to be generated? Would this match your JSON format?

---

<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:** [December 19, 2023, 6:42am UTC](https://softwaremill.community/t/how-to-add-a-schema-derivation-of-a-union-type/322/4 "2023-12-19T06:42:41Z")

</div>

Thanks, here the issue on Github: [Support Union Types in Tapir · Issue #3412 · softwaremill/tapir · GitHub](https://github.com/softwaremill/tapir/issues/3412)
