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

[request] [help] Ranged values #515

Closed
RaulTrombin opened this issue Dec 8, 2023 · 5 comments · Fixed by #524
Closed

[request] [help] Ranged values #515

RaulTrombin opened this issue Dec 8, 2023 · 5 comments · Fixed by #524

Comments

@RaulTrombin
Copy link
Contributor

There is some way/instruction on how to set ranged inputs?
something at the struct field like: [api_v2(min_value = 0)]

For enuns and direct type values it works pretty fine.

@RaulTrombin
Copy link
Contributor Author

Tryed a mix of:

pub maximum: Option<f32>,

and
https://paperclip-rs.github.io/paperclip/actix-security.html

#[derive(Apiv2Schema, Debug, Deserialize, Serialize)]
#[openapi(minimum=0, maximum=255)]
pub struct ApiNeopixel {
    #[openapi(minimum=0, maximum=255)]
    red: u8,
    green: u8,
    blue: u8,
}

no success yet:
image

@RaulTrombin
Copy link
Contributor Author

Maybe we can integrate with validator:

#[derive(Apiv2Schema, Debug, Deserialize, Serialize, Validate)]
pub struct ApiNeopixel {
    #[validate(range(min = 0, max = 255))]
    red: u8,
    #[validate(range(min = 0, max = 255))]
    green: u8,
    #[validate(range(min = 0, max = 255))]
    blue: u8,
}

@RaulTrombin RaulTrombin changed the title Ranged values [requestRanged values Dec 8, 2023
@RaulTrombin RaulTrombin changed the title [requestRanged values [request] [help] Ranged values Dec 8, 2023
@tiagolobocastro
Copy link
Collaborator

Yeah a validator like that seems like a good idea.
Although in general we could also improve things, as with u8 the min and max should also be set?

@RaulTrombin
Copy link
Contributor Author

Yeah a validator like that seems like a good idea. Although in general we could also improve things, as with u8 the min and max should also be set?

I think it could be an optional field, if not set - It will take the minumum and maximum values from integer type.
But if defined you can set your own limits.

@tiagolobocastro
Copy link
Collaborator

Sorry about the long delay in addressing this..
With this I think the min/max are addressed for both your issues, please let me know otherwise.

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

Successfully merging a pull request may close this issue.

2 participants