tamasfe/aide

The response for status "200" already exists for the operation

Closed this issue · 3 comments

Since #88 landed, the example-axum project prints the response for status "200" already exists for the operation when launching the application.

This seems to be due to list_todos_docs trying to override the list_todos route with a 200 response status code, but it already exists.

I discovered this in my own project due having a panic! instead of a println! inside aide::gen::on_error.

Not sure if it's a bug in aide, or the example needs to be modified somehow.

It's just an issue with the example. Even if the function is impl IntoApiResponse the response type is automatically derived, but it is also manually added thus the error (which is printed by the on error hook).

What if one wants to specify a custom response type for the 200 status code?
Would they have to change the impl IntoApiResponse with a custom type like Json<TodoList> or something, and not specify response::<200, Json<TodoList>>() for the TransformOperation ?

The custom response is implicitly generated from the response type, so any Json<MyJsonStruct> will be documented as responding MyJsonStruct with code 200 regardless if if the fn returns Json<MyJsonStruct> or impl IntoApiResponse.

Also consider using axum-jsonschema for the Json response as it gives better json parse errors.