GREsau/schemars

Option<bool> doesn't get required in schema

jakajancar opened this issue · 0 comments

(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).