Issue with `S.optionalWith()` and OpenAPI Spec Examples

Hi everyone, I'm using S.optionalWith() in a nested schema prop of a POST request body schema. I then generate an OpenAPI spec with examples, descriptions, and serve my api with HttpApi. I'm facing this issue with the examples annotation.

Property 'someOptionalField' is missing in type '{ someRequiredField: string; }' but required in type '{ readonly someOptionalField: string; readonly someRequiredField: string; }'.


I'd expect someOptionalField to be optional in the examples array element, but it's not. I think I understand why : I guess it's because examples array elements are decoded instances of my schema. But still, practically I have a hard time finding a good workaround.

Is there a way to define examples as encoded instances? (which I believe would make more sense for this use case as examples are examples of what the user of my API should send, and ultimately are encoded strings in my api spec/docs?).

Or any workaround I did not think of?

Link to repro : https://effect.website/play/#7d2dc1e7a310
CleanShot_2025-06-19_at_15.10.372x.png
Was this page helpful?