Skip to content

[BUG] [Rust] Enums in Query Parameters via $ref Cause Compilation Failure #22280

@winrid

Description

@winrid

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

When enum parameters (referenced via $ref in OpenAPI specs) are used as query parameters, the generated code attempts to call .to_string() on Option. This causes Rust's type inference to fail because it can
t distinguish between primitive types and enums/models.

It's generating code like this:

      if let Some(ref param_value) = time_bucket {
          req_builder = req_builder.query(&[("timeBucket", &param_value.to_string())]);

but it should probably be:

      if let Some(ref param_value) = time_bucket {
          req_builder = req_builder.query(&[("timeBucket", &serde_json::to_string(param_value)?)]);
openapi-generator version

7.11.0

OpenAPI declaration file content or url
      openapi: 3.0.3
      info:
        title: Minimal Enum Query Param Test
        version: 1.0.0
      paths:
        /data:
          get:
            operationId: getData
            parameters:
              - name: timeBucket
                in: query
                required: false
                schema:
                  $ref: '#/components/schemas/TimeBucket'
            responses:
              '200':
                description: OK
      components:
        schemas:
          TimeBucket:
            type: string
            enum:
              - day
              - month
              - year
      EOF)
  ⎿  openapi: 3.0.3                                     
     info:
       title: Minimal Enum Query Param Test
       version: 1.0.0
     paths:
       /data:
         get:
           operationId: getData
           parameters:
             - name: timeBucket
               in: query
               required: false
               schema:
                 $ref: '#/components/schemas/TimeBucket'
           responses:
             '200':
               description: OK
     components:
       schemas:
         TimeBucket:
           type: string
           enum:
             - day
             - month
             - year

I will be creating a PR to propose a fix.

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