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

Make Option non-required & add required attr #530

Merged
merged 1 commit into from
Mar 19, 2023

Conversation

juhaku
Copy link
Owner

@juhaku juhaku commented Mar 19, 2023

Make Option fields non-required by default. This is the way it used to be originally but was changed due hopes for better client code generation. However since it caused issues with client side generation the behaviour is now changed back on this commit.

The nullability behaviour will still stay to same, so Option will still be considered nullable. These rules are explained in the docs for greater detail.

This commit also adds required attribute that can be used to declare a field of ToSchema and IntoParams as required in order to change the default required status of a field / parameter.

Since Option is by default non-required, this would enforce the name parameter to be required.

 #[derive(IntoParams)]
 #[into_params(parameter_in = Query)]
 struct Params {
     #[param(required)]
     name: Option<String>,
 }

Fixes #529

Make `Option` fields non-required by default. This is the way it used
to be originally but was changed due hopes for better client code
generation. However since it caused issues with client side generation
the behaviour is now changed back on this commit.

The nullability behaviour will still stay to same, so `Option` will
still be considered nullable. These rules are explained in the docs for
greater detail.

This commit also adds `required` attribute that can be used to declare a
field of `ToSchema` and `IntoParams` as required in order to change the
default required status of a field / parameter.

Since `Option` is by default non-required, this would enforce the `name`
parameter to be required.
```rust
 #[derive(IntoParams)]
 #[into_params(parameter_in = Query)]
 struct Params {
     #[param(required)]
     name: Option<String>,
 }
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Released
Development

Successfully merging this pull request may close these issues.

Regression: Option<> fields are labeled as required in the generated OpenAPI spec.
1 participant