GREsau / okapi

OpenAPI (AKA Swagger) document generation for Rust projects
MIT License
578 stars 103 forks source link

Form<TempFile<'_>> #110

Closed marirs closed 1 year ago

marirs commented 1 year ago

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

ralpha commented 1 year ago

A type that is used in the data part of #[post("/static", data = "<file>")] need to implement FromData This is done here: https://github.com/GREsau/okapi/blob/5cb59b3fddcf24294b4c6110882d89a68eaf01c1/rocket-okapi/src/request/from_data_impls.rs#L62-L67

But as you can see it is currently waiting on https://github.com/GREsau/schemars/issues/103 Maybe you can solve it with the comment GREsau left here: https://github.com/GREsau/schemars/issues/103#issuecomment-917700888 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.

marirs commented 1 year ago

Thanks so much.

jfroffice commented 5 months ago

Is it still an issue ? @ralpha @marirs thx

ralpha commented 3 months ago

@jfroffice yes, follow the issue by looking at https://github.com/GREsau/schemars/issues/103