-
Notifications
You must be signed in to change notification settings - Fork 190
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
Utoipa users poll: How do you use responses and how would you like them to work? Answer would help. #1068
Comments
Hi, first of all huge thank you for this crate! To answer your questions. I use dedicated structs and deriving from I find it quite nice and I would not change it. There are two aspects I think would be nice if improved but I am not sure if possible:
|
Great, thanks for a reply.
|
Hey, not really an answer on how I uses it, but I would really like to be able to share responses between routes. For example, in Meilisearch, most routes will return something we call a Going from: /// Get a task
///
/// Get a [task](https://www.meilisearch.com/docs/learn/async/asynchronous_operations)
#[utoipa::path(
post,
path = "/{taskUid}",
tag = "Tasks",
params(("taskUid", format = UInt32, example = 0, description = "The task identifier", nullable = false)),
responses(
(status = 200, description = "Task successfully enqueued", body = SummarizedTaskView, content_type = "application/json", example = json!(
{
"uid": 1,
"indexUid": "movies",
"status": "succeeded",
"type": "documentAdditionOrUpdate",
"canceledBy": null,
"details": {
"receivedDocuments": 79000,
"indexedDocuments": 79000
},
"error": null,
"duration": "PT1S",
"enqueuedAt": "2021-01-01T09:39:00.000000Z",
"startedAt": "2021-01-01T09:39:01.000000Z",
"finishedAt": "2021-01-01T09:39:02.000000Z"
}
))
)
)]
async fn get_task(
... To: /// Get a task
///
/// Get a [task](https://www.meilisearch.com/docs/learn/async/asynchronous_operations)
#[utoipa::path(
post,
path = "/{taskUid}",
tag = "Tasks",
params(("taskUid", format = UInt32, example = 0, description = "The task identifier", nullable = false)),
responses(
(status = 200, description = "Task successfully enqueued", body = SummarizedTaskView, content_type = "application/json", example = task_succeeded())
)
)]
async fn get_task(
... I’m using the latest beta version, let me know if I missed something. |
Responses can be shared if used with struct MyResponse;
impl<'s> ToResponse<'s> for MyResponse {
fn response() -> (&'s str, Response) -> {
// add all the examples here programmatically
("MyResponse", Response::builder().build())
}
}
#[utoipa::path(
post,
path = "/{taskUid}",
tag = "Tasks",
params(("taskUid", format = UInt32, example = 0, description = "The task identifier", nullable = false)),
responses(
(status = 200, response = inline(MyResponse))
)
)]
async fn get_task(} {} You could also derive the
|
Humm, yes, I tried to use it, but it didn’t work, and I don’t really have the time to understand why, It's probably an issue on my side. But in terms of API, I find it strange that the Ideally, in our case, almost every route can have three different errors that share the same error code: If you forget to specify an API key, we don’t understand the format of your API key, or your API key doesn’t give you the right to access this route. #[utoipa::path(
post,
path = "/{taskUid}",
tag = "Tasks",
params(("taskUid", format = UInt32, example = 0, description = "The task identifier", nullable = false)),
responses(
inline(ApiKeyError), // here I can define multiple examples with multiple HTTP status code
inline(SummarizedTaskView), // here I only have one example
(status = BAD_REQUEST, schema = ResponseError, example = json!(...)),
)
)]
async fn get_task(} {} I hope that can help you in your decisions! |
Responses poll
Currently while I am working on refactoring multiple aspects of the
utoipa
lib for the coming release 5.0.0 this is good place to introduce some improvements to current workflow within boundaries set by its users. So here comes the question.How do you currently use the responses with
utoipa
lib?ToResponse
Second question is how would you like the responses work, or is there any aspect you would like to change in order to them to be more user friendly?
The text was updated successfully, but these errors were encountered: