schemars
schemars copied to clipboard
Option<bool> doesn't get required in schema
(cf. Issue #11: Option<bool> gets required in schema)
Type:
pub struct MyType {
my_prop: Option<String>
}
gets written into a schema as not required.
When generating a TypeScript type for this, you (correctly) get:
interface MyType {
myProp: string | null | undefined
// or
myProp?: string | null
}
Either way, the user of my API sees string | null | undefined, which is not the case: my API will always return the property (I do not use #[serde(skip_serializing_if = "Option::is_none")] or similar).
The behavior should be configurable. If you're ingesting stuff, you might want to be loose. But if you're documenting your own API, you might want to be specific (Robustness principle).
This is a special case of #48 - the generated schema currently describes the deserialization contract (where the property may be null or omitted), but you want the serialization contract (where the property will never be omitted)
Closing in favour of https://github.com/GREsau/schemars/issues/48