OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Rust] non-compiling code generated by `reqwest` generator when multipart/form-data in body
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 (example)?
- 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
There is a missing trait implemented for the form object.
It is straightforward (file src/models/test_form_object_multipart_request_marker.rs):
local_var_form = local_var_form.text("marker", marker.to_string());
We are calling the .to_string() fn without having implemented the required trait(ToString or Display).
openapi-generator version
7.9.0-SNAPSHOT
OpenAPI declaration file content or url
Minimum reproducible example (only the problematic path included from echo_api example:
openapi: 3.1.0
info:
title: Title
description: Title
version: 1.0.0
servers:
- url: 'https'
paths:
/form/object/multipart:
post:
tags:
- form
summary: Test form parameter(s) for multipart schema
description: Test form parameter(s) for multipart schema
operationId: test/form/object/multipart
requestBody:
content:
multipart/form-data:
schema:
required:
- marker
properties:
marker:
type: object
properties:
name:
type: string
responses:
'200':
description: Successful operation
content:
text/plain:
schema:
type: string
Generation Details
The arguments to the CLI are the following
generate -i {yaml-filepath-shown-above} -g rust --library reqwest -o {output_dir}
Steps to reproduce
Use the resources above and run the example
Related issues/PRs
#19632 with PR in #19922 also captures problem 1
EDIT: But does not fix it as it seems. For normal models it works, but in this specific case it does not function properly.
Suggest a fix
A simple impl Display block is needed(which is something that would be usefull in general), a quick solution looks like this.
impl Display for TestFormObjectMultipartRequestMarker {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
match &self.name {
None => {fmt.write_str("<none>")}
Some(val) => {fmt.write_str(&format!("Data: {}",val))}
}
}
}
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 by reproducing the issue with the supplied OpenAPI declaration and the generate -i ... -g rust --library reqwest command. Inspect how src/models/test_form_object_multipart_request_marker.rs is generated and verify the multipart request code compiles when the marker object is used. Done means the generated Rust code no longer calls to_string() without the required formatting trait.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100