Skip to content
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

[BUG][RUST][CLIENT] Generated enum type used with format! but it doesn't impl Display #16975

Closed
5 of 6 tasks
eliaperantoni opened this issue Nov 3, 2023 · 1 comment · Fixed by #17968
Closed
5 of 6 tasks

Comments

@eliaperantoni
Copy link

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

If an endpoint uses an enum as the path parameter, and the enum is defined in components rather than inline, then the generated default_api.rs creates the URL with the format! macro but the generated Rust enum doesn't implement Display (it does implement ToString instead).

error[E0277]: `Color` doesn't implement `std::fmt::Display`
  --> src/apis/default_api.rs:31:97
   |
31 |     let local_var_uri_str = format!("{}/demo/{color}", local_var_configuration.base_path, color=color);
   |                                                                                                 ^^^^^ `Color` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `Color`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: this error originates in the macro `$crate::__export::format_args` which comes from the expansion of the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)

NOTE: You need to reference the enum like:

schema:
  allOf:
    - $ref: "#/components/schemas/Color"

otherwise you're going to run into issue #16974 first.

openapi-generator version

I'm using the Docker openapitools/openapi-generator-cli:latest image. openapi-generator-cli version prints 7.1.0-SNAPSHOT.

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Demo
  version: 0.0.0
paths:
  /demo/{color}:
    get:
      parameters:
        - name: color
          required: true
          in: path
          schema:
            $ref: "#/components/schemas/Color"
      responses:
        200:
          description: OK
components:
  schemas:
    Color:
      type: string
      enum:
        - RED
        - GREEN
        - BLUE
Generation Details
$ openapi-generator generate -i openapi.yaml -g rust -o demo
@wing328
Copy link
Member

wing328 commented Jan 24, 2024

NOTE: You need to reference the enum like:

I've filed #17694 to fix the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants