juhaku / utoipa

Simple, Fast, Code first and Compile time generated OpenAPI documentation for Rust
Apache License 2.0
2.01k stars 160 forks source link

Is it possible to accept multiple content-types for requests? #896

Closed rodorgas closed 1 month ago

rodorgas commented 2 months ago

OpenAPI 3 allows describing multiple accepted content-types for a request (first example on this link).

Is it possible using utoipa?

I'd like to make an endpoint accepting both application/json and application/x-www-form-urlencoded. I implemented it in Actix using two handlers and guards, but I don't see how to document it in utoipa.

LockedThread commented 1 month ago

I am also interested in this

juhaku commented 1 month ago

This is a missing feature, that has been implemented for responses but not for request body. This is something that should be added.

LockedThread commented 1 month ago

@rodorgas I was porting over my old Go Gin-based api to Rust using Axum. By default, Gin can accept multipart or json body for all requests.

By any chance, do you have code for Axum that does something similar? I was looking at using a Tower service to handle this but the dev experience overhead would be too high.

juhaku commented 1 month ago

As a matter of fact, I had forgotten about this but there is a PR for the functionality: https://github.com/juhaku/utoipa/pull/876, it just needs some polish and it is done.

xitep commented 6 days ago

hello, many thanks for the fix! i'm referring to the dependency via git="...", rev="..." in my Cargo.toml, but wonder whether you're going to release/publish it as a 4.2.x version. or shall i wait for 5.0?