-
Notifications
You must be signed in to change notification settings - Fork 68
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
Feat extra extractors #102
Conversation
hmmm do I need master branch? Sorry, didn't notice the workflow; I am new to this. I'll make a new PR when ready, but I will keep this up to get your feedback. |
No need, this looks good to me, thank you. I currently have very tight deadlines at work, I'll do a review on the weekened, but please feel free to ping me in case I forget. |
Sorry I know this is long, you can read this later.
I miss understood your comment. Indeed, while testing my work, I was getting schema validation error The problem is: // Incorrect, Value is: `String("024fe6c1-a33e-45a5-8157-2e48f5ff6da9")`
let value: Value = axum::extract::Path::from_request_parts(parts, state)
...
// Correct, but jsonschema doesn't support validating `T` only `serde_json::Value`
let value: T = axum::extract::Path::from_request_parts(parts, state)
... The |
Closing PR. Using validator along with schemars can achieve what I originally wanted. I was hoping jsonschema to do this all by itself to reduce dependencies that do similar things. Below is what I am satisfied with: const REGEX_STR: &'static str = "[A-Z][a-z]+";
lazy_static::lazy_static! {
static ref RE_TWO_CHARS: Regex = Regex::new(REGEX_STR).unwrap();
}
#[derive(Deserialize, JsonSchema, Validate)]
struct TestPath {
#[validate(length(equal = 3))]
input1: String,
#[validate(regex = "RE_TWO_CHARS")]
input2: String,
input3: bool,
} Sorry for the time wasted. Also noticed axum-valid, which supports aide. |
You also have garde which can validate regex from strings and other safer features like explicit opt-out from validation. |
This is not done, but would like to request feedback on this approach.
Also, I got a question; the
axum::Json::from_request
already does deserialize so the code below would never return anErr
(in theory?).aide/crates/axum-jsonschema/src/lib.rs
Lines 96 to 99 in be3b6d7
Maybe do a
trace::error
and do something else? Not sure what, but it feel like the error shouldn't be exposed to crate users.