GREsau/okapi

Form<TempFile<'_>>

marirs opened this issue · 4 comments

Pardon me if this is a redundant question, I searched the issues, did not find anything in here.

I'm using this:

#[openapi()]
#[post("/static", data = "<file>")]
pub async fn upload(
    userguard: UserGuard,
    file: Form<TempFile<'_>>,
) -> std::result::Result<Json<ResponseData>, (Status, Value)> {

I get this error:

error[E0277]: the trait bound `TempFile<'_>: JsonSchema` is not satisfied
   --> src/controllers/static_analyzer.rs:177:1
    |
177 | #[openapi()]
    | ^^^^^^^^^^^^ the trait `JsonSchema` is not implemented for `TempFile<'_>`
    |
    = note: required because of the requirements on the impl of `OpenApiFromData<'_>` for `rocket::form::Form<TempFile<'_>>`
    = note: this error originates in the attribute macro `openapi` (in Nightly builds, run with -Z macro-backtrace for more info)

However if I use just file: TempFile<_>` it works well.

How to solve this?

Thanks in advance

A type that is used in the data part of #[post("/static", data = "<file>")] need to implement FromData
This is done here:

// Waiting for https://github.com/GREsau/schemars/issues/103
impl<'r> OpenApiFromData<'r> for rocket::fs::TempFile<'r> {
fn request_body(gen: &mut OpenApiGenerator) -> Result {
Vec::<u8>::request_body(gen)
}
}

But as you can see it is currently waiting on GREsau/schemars#103
Maybe you can solve it with the comment GREsau left here: GREsau/schemars#103 (comment)
If that does not solve it for you. There needs to be an implementation of JsonSchema added for TempFile inside schemars or rocket.
Because of trait impl limitations I can not resolve it in okapi.

I'll close the issue here because but feel free to reply and/or comment here or in the linked issue.

Thanks so much.

Is it still an issue ? @ralpha @marirs thx

@jfroffice yes, follow the issue by looking at GREsau/schemars#103