Skip to content

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

Closed
@eliaperantoni

Description

@eliaperantoni

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions