-
Notifications
You must be signed in to change notification settings - Fork 202
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
Automatic type recognition for path operation handlers #591
Comments
I think related; it was really surprising (in axum) that |
Yeah, I can take a look at this at the same time. |
Any ideas are welcome to this one #649. Currently not sure at the moment how to proceed with the implementation. The biggest issue is that if I have a handler such as seen below, I can only resolve responses for #[utoipa::path]
#[get("/item")]
async fn get_item() -> Result<Json<Item<'static>>, Error> {
Ok(Json(Item { value: "super" }))
} |
@juhaku thanks! is this in 3.4.3? I seem to be having the same issue still |
Here is some more examples how the path parameter can be recognized: 7cc90b1. It is not fully automatic because the original behavior was reverted as it caused unwanted issues for many users. There is some work to do for make this implementation better but for what comes to the axum path parameters the name of the handler argument must match to the path arguments otherwise they will not be added. // `id` must match to the path argument name.
async fn get_item(id: Path<u32>) {}
// `id and `id2` must match to the path argument name.
async fn get_item(Path((id, id2)): Path<(u32, u32)>) {} |
Description
To streamline further the
utoipa
library and to provide deeper integeration for frameworks likeactix_web
,axum
, androcket
it would be great to be able to automatically recognize necessary types from operation handler and add them to the path schema of OpenAPI doc generated withutoipa
. This will provide more automation and saves the keystrokes the user is ought to take to define#[utoipa::path(...)]
macro content manually.For example, from following handler function we would need to be able to recognize
path
,query
,body
andresponse
. These recognized values, if successful, should be added automatically to the generated OpenAPI spec.This functionality will enforce users to be more strict on what is being returned from the handler functions and what are the args given to the handler functions. Benefit of this is the users are able to declare the OpenAPI spec mostly via code and get compile errors directly to the code of invalid spec.
Tasks
IntoResponses
trait.The text was updated successfully, but these errors were encountered: