paperclip-rs / paperclip

WIP OpenAPI tooling for Rust.
Apache License 2.0
890 stars 117 forks source link

[request] [help] Ranged values #515

Closed RaulTrombin closed 4 months ago

RaulTrombin commented 11 months ago

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 commented 11 months ago

Tryed a mix of: https://github.com/paperclip-rs/paperclip/blob/555a460cdfbc295edb504c3d7f441253a5c681ae/core/src/v2/models.rs#L519 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 commented 11 months ago

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,
}
tiagolobocastro commented 10 months ago

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 commented 10 months ago

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 commented 4 months ago

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.