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 default_api.rs doesn't import referenced type #16974

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

[BUG][RUST][CLIENT] Generated default_api.rs doesn't import referenced type #16974

eliaperantoni opened this issue Nov 3, 2023 · 1 comment · Fixed by #17968

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 uses the generated Rust enum without importing it first, resulting in a compilation error.

error[E0412]: cannot find type `Color` in this scope
  --> src/apis/default_api.rs:26:82
   |
26 | pub async fn demo_color_get(configuration: &configuration::Configuration, color: Color) -> Result<(), Error<DemoColorGetError>> {
   |                                                                                  ^^^^^ not found in this scope
   |
help: consider importing this enum through its public re-export
   |
12 + use crate::models::Color;

I've found that using the enum in the schema like this:

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

instead of

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

fixes the issue. But still, it should work in both cases.

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
@j-szulc
Copy link
Contributor

j-szulc commented Dec 30, 2023

I have started the work on #17503 . Together with #17504 (fixing linked issue #16975 ) it makes the provided openapi.yml generate a buildable Rust client.

DDtKey added a commit to DDtKey/openapi-generator that referenced this issue Feb 26, 2024
wing328 pushed a commit that referenced this issue Feb 28, 2024
* fix(rust): wrong path to mode used as parameter of api

Closes #16974

* fix: re-build samples
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