Closed gengteng closed 1 year ago
Hi, at the moment I am a bit busy, I will take a look during the weekend and update you.
But technically yes, we could either have the field public or provide a new function that populates the error field with the default implementation like you are doing, I want to take a deeper look though to see if we can come up with a better pattern. Can I see how this would be used in a handler? Just to make sure I understand your objective.
Thank you for your reply. I introduced an extractor called Validified
, and here is an example of using Validified
combined with BaseMultipart
in a handler (using with other extractors like Json
, WithRejection
would be similar):
async fn handler(Validified(BaseMultipart { data, .. }): Validified<BaseMultipart<Data, Rejection>>) {
// data has been constructed, modified and validated using validify
}
#[derive(TryFromMultipart, Validify)]
pub struct Data {
v0: String,
}
Here the Data
needs to derive the Validify
trait. The validify library will generate an associated type DataPayload
for it. My implementation in FromRequest
/ FromRequestParts
needs to extract a BaseMultipart<DataPayload, Rejection>
from the request, then take out the DataPayload
, call the modification and validation functions provided by validify to construct a Data
instance, and then reconstruct a BaseMultipart<Data, Rejection> with it.
Thank you again for your attention to this issue. Please let me know if any additional information is needed.
I reviewed validify's implementation again and realized Validified
cannot directly support axum_typed_multipart currently, since validify requires the payload to implement Deserialize
. However, constructing data without relying on the payload is still possible. I greatly appreciate your response to my issue.
And I still believe making the rejection
pub
, similar to axum-extra's WithRejection
, would improve the crate's ergonomics without breaking changes.
Hi, I'm working on axum-valid and trying to integrate
axum
withvalidify
. I need to extract the data from aBaseMultipart
initially parsed from the request as the payload. Then validate this payload, construct the actual data using the validated payload, and repackage it into a newBaseMultipart
.I would like to request making the rejection field in the
BaseMultipart
structpub
. Having it aspub
would allow me to do this more easily. Here is a minimal reproduction of what I'm trying to do:Please let me know if this change would break any existing interfaces or backwards compatibility. If so, I'm happy to discuss potential solutions. I'm open to your feedback and can amend this request accordingly.
Thanks for your consideration! Let me know if you would like any clarification or have any other questions.