jlalmes / trpc-openapi

OpenAPI support for tRPC 🧩
https://www.npmjs.com/package/trpc-openapi
MIT License
2.18k stars 147 forks source link

Allow coercion when given union of coercible values #427

Open sebinsua opened 9 months ago

sebinsua commented 9 months ago

A value is coercible if it itself is coercible or if it is a union of only coercible values.

This is somewhat related to #255 but only improves upon unions by avoiding the error and supporting coercions. It doesn't add support for discriminated unions, as according to the issue linked to, these lack upstream support within OpenAPI (???).

Note: I originally wrote some code to support intersections in the same way but I've removed this because I don't have a practical example of when it would make sense.