openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] [Rust] non-compiling code generated by `reqwest` generator when multipart/form-data in body

Open GeorgeFkd opened this issue 1 year ago • 1 comments

Bug Report Checklist

  • [X] Have you provided a full/minimal spec to reproduce the issue?
  • [X] Have you validated the input using an OpenAPI validator (example)?
  • [X] Have you tested with the latest master to confirm the issue still exists?
  • [X] Have you searched for related issues/PRs?
  • [X] 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))}
        }

    }
}

GeorgeFkd avatar Oct 20 '24 13:10 GeorgeFkd

Problem persists.

NicoPiel avatar Dec 07 '25 13:12 NicoPiel