Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option<bool> doesn't get required in schema #87

Closed
jakajancar opened this issue Jun 26, 2021 · 2 comments
Closed

Option<bool> doesn't get required in schema #87

jakajancar opened this issue Jun 26, 2021 · 2 comments

Comments

@jakajancar
Copy link

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

@GREsau
Copy link
Owner

GREsau commented Jun 5, 2024

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)

@GREsau
Copy link
Owner

GREsau commented Aug 18, 2024

Closing in favour of #48

@GREsau GREsau closed this as not planned Won't fix, can't repro, duplicate, stale Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants