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

Support for non-required tuple type path parameters #479

Closed
sondrelg opened this issue Feb 12, 2023 · 7 comments
Closed

Support for non-required tuple type path parameters #479

sondrelg opened this issue Feb 12, 2023 · 7 comments

Comments

@sondrelg
Copy link

Hi!

First of all, thanks for maintain this great library! Super useful 🙇

I see that it is possible to generate non-required parameters by using the Option type, when defining parameters like this:

#[derive(IntoParams)]
pub struct Params {
    foo: Option<u8>,
}

However, it does not seem to work for manually documented parameters. I have a macro invocation that looks like this:

#[utoipa::path(
    get,
    path = "...",
    responses((status = 200, description = "...", body = Body)),
    params(
        ("foo" = String, Path, description = "..."),
        ("bar" = Option<String>, Path, description = "..."),
    ),
    tag="..."
)]

At least in my generated UI bar remains required 🙂

Am I missing something? Couldn't find anything in the docs about this, so thought it might just be something that still needs implementing?

@juhaku
Copy link
Owner

juhaku commented Mar 14, 2023

Hey,

Great that you have enjoyed. It should work, but there might be a bug that it behaves differently. I need to check this from the code and see what is actually going on to be sure. I'll get back to this when I have time.

@juhaku juhaku changed the title Support for non-required non-derived parameters Support for non-required tuple type path parameters Mar 14, 2023
@juhaku
Copy link
Owner

juhaku commented Mar 17, 2023

As of these PRs (#525, #498) the definition of required changes to strictly according to how serde serializes types. This means that Option is nullable, but always required if it has not

  • serde's skip_serializing_if
  • and serde's with double option
  • and field does not have default value

This implies that manual tuple style path parameters are always required without an option to change it. Non-required parameters can only achieved with IntoParams derive macro.

@sondrelg
Copy link
Author

Ok I see, thanks for looking into it 👍

@juhaku
Copy link
Owner

juhaku commented Mar 19, 2023

@sondrelg As of some issues that have arised mentioned here #529, the Option field will from now on will be considered non-required as before, but can be optionally enforced to be required by using newly introduced required attribute #530.

@sondrelg
Copy link
Author

So if I'm understanding you correctly, it will be possible to define optional variables using the both the path macro, and using the IntoParams macro after all?

@juhaku
Copy link
Owner

juhaku commented Mar 20, 2023

So if I'm understanding you correctly, it will be possible to define optional variables using the both the path macro, and using the IntoParams macro after all?

Yes, currently with the latest master and with next release when released.

@sondrelg
Copy link
Author

Cool, thanks!

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

No branches or pull requests

2 participants