OpenAPITools / OpenAPITools/openapi-generator
[BUG] [RUST] `std::path::PathBuf` always generated in the docs of endpoints returning a file
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- [*] Have you provided a full/minimal spec to reproduce the issue?
- [*] Have you validated the input using an OpenAPI validator?
- [*] Have you tested with the latest master to confirm the issue still exists?
- [*] Have you searched for related issues/PRs?
- [*] What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Since the implementation of https://github.com/OpenAPITools/openapi-generator/issues/18117, in the reqwest target, endpoints returning a file return the entire response reqwest::Response so callers of the API can handle the file as they want (notice the reqwest::blocking::Response in the return type):
pub fn tests_file_response_get(configuration: &configuration::Configuration, ) -> Result<reqwest::blocking::Response, Error<TestsFileResponseGetError>> {
let uri_str = format!("{}/tests/fileResponse", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(resp)
} else {
let content = resp.text()?;
let entity: Option<TestsFileResponseGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
However, the documentation (which has a single template for all Rust targets) still contains std::path::PathBuf as the return type of the function (which is always wrong I guess):
## tests_file_response_get
> std::path::PathBuf tests_file_response_get()
Returns an image file
### Parameters
This endpoint does not need any parameter.
### Return type
[**std::path::PathBuf**](std::path::PathBuf.md)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: image/jpeg
openapi-generator version
I can see the issue in the samples on main, so I guess it impacts v7.15.0.
OpenAPI declaration file content or url
In the Rust petstore.yaml spec, the endpoint /tests/fileResponse is defined as:
'/tests/fileResponse':
get:
tags:
- testing
summary: Returns an image file
responses:
'200':
description: An image file
content:
image/jpeg:
schema:
type: string
format: binary
Generation Details
./bin/generate-samples.sh ./bin/configs/rust-reqwest-petstore.yaml
Steps to reproduce
Run:
./bin/generate-samples.sh ./bin/configs/rust-reqwest-petstore.yaml
Related issues/PRs
Suggest a fix
The template choosing the return type of the Rust (reqwest) code handles different cases:
{{! ### Response File Support }}
{{#isResponseFile}}
{{#supportAsync}}reqwest::Response{{/supportAsync}}
{{^supportAsync}}reqwest::blocking::Response{{/supportAsync}}
{{/isResponseFile}}
{{! ### Regular Responses }}
{{^isResponseFile}}
{{! ### Multi response support }}
{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}
{{! ### Regular return type }}
{{^supportMultipleResponses}}
{{^returnType}}(){{/returnType}}
{{{returnType}}}
{{/supportMultipleResponses}}
{{/isResponseFile}}
But the template of the documentation is generic for all the Rust targets (reqwest, hyper...) so it doesn't mention target specific types (like reqwest::Response):
{{#returnType}}
{{#returnTypeIsPrimitive}}
**{{{returnType}}}**
{{/returnTypeIsPrimitive}}
{{^returnTypeIsPrimitive}}
[**{{{returnType}}}**]({{{returnBaseType}}}.md)
{{/returnTypeIsPrimitive}}
{{/returnType}}
{{^returnType}}
(empty response body)
{{/returnType}}
Here a few suggestions from someone who's not an expert in the code base:
- Have one template per target
reqwest,hyper... so each one can mention the response type of the corresponding framework. - Wrap the response type in a type common to all frameworks so we can reference it in the docs:
Response tests_file_response_get()
- Check which framework we're generating for in the template of
api_doc.mustache.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with modules/openapi-generator/src/main/resources/rust/api_doc.mustache and compare its return-type handling with rust/reqwest/api.mustache. Run ./bin/generate-samples.sh ./bin/configs/rust-reqwest-petstore.yaml and inspect the generated TestingApi.md for tests_file_response_get. Done means the documentation reports the appropriate file-response type for reqwest without breaking other Rust targets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100