Found another interesting issue: it looks like when an endpoint/operation has multiple response entries, only one (the last one?) gets included in the endpoint's Response type.
For example, in the generate_full_client.rs example, I added this to "paths"."/todos"."get"."responses" :
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Todo"
}
}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
}
}
}
}
}
}
Before the change it generates:
pub type ListTodosResponse = Vec<Todo>;
And after adding the 400 response, it generates the following rust type:
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListTodosResponse {
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<String>,
}
// No indication of the 200 version anywhere to be seen
The Todo struct for the 200 response is still generated, but there's no Response type containing it. In practice, this leads to a somewhat surprising (de)serialization error when making calls to the API, because the generated client code tries to deserialize the normal response body in the shape of the error response body type (which obviously won't work).
Minor side tangent: What would you think of attaching the raw response body text / headers / whatever else to the client error so it can be inspected? It would be very useful to see what the API responded with when there's a deserialization error like this. Could help determine if there's a problem with the API itself or how I'm calling into it. I was able to get the raw response body text by hacking the generated code a little bit, but I'd rather not do that.
Found another interesting issue: it looks like when an endpoint/operation has multiple response entries, only one (the last one?) gets included in the endpoint's Response type.
For example, in the
generate_full_client.rsexample, I added this to"paths"."/todos"."get"."responses":Before the change it generates:
And after adding the 400 response, it generates the following rust type:
The
Todostruct for the 200 response is still generated, but there's no Response type containing it. In practice, this leads to a somewhat surprising (de)serialization error when making calls to the API, because the generated client code tries to deserialize the normal response body in the shape of the error response body type (which obviously won't work).Minor side tangent: What would you think of attaching the raw response body text / headers / whatever else to the client error so it can be inspected? It would be very useful to see what the API responded with when there's a deserialization error like this. Could help determine if there's a problem with the API itself or how I'm calling into it. I was able to get the raw response body text by hacking the generated code a little bit, but I'd rather not do that.