OpenAPITools / OpenAPITools/openapi-generator

[BUG][Spring] Enum value is ignored for path and query params

Open
#13,350 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

When a path or query param has enum constraint, it is generated as String.
We need to generate it as an enum.

openapi-generator version

Last from master

OpenAPI declaration file content or url
---
openapi: "3.0.1"
info:
  title: "My Little Pony"
  description: "Friendship is magic"
  contact: {}
  version: "1.0.0"
paths:
  /ponies:
    summary: "Everything for ponies"
    get:
      summary: "List"
      operationId: "list"
      parameters:
        - name: "name"
          in: "query"
          required: false
          schema:
            type: "string"
            enum:
              - "Big McIntosh"
              - "Rainbow Dash"
              - "Pinkie Pie"
              - "Rarity"
      responses:
        200:
          description: "Status 200"
          content:
            application/json:
              schema:
                type: "array"
                items:
                  $ref: "#/components/schemas/Pony"
        400:
          description: "Status 400"
components:
  schemas:
    Pony:
      type: "object"
      properties:
        Id:
          type: "string"
Generation Details

Spring generator with spring-boot library
https://github.com/OpenAPITools/openapi-generator/blob/master/bin/configs/spring-boot-delegate.yaml

Steps to reproduce
Related issues/PRs
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Spring spring-boot generator configuration at bin/configs/spring-boot-delegate.yaml and the supplied OpenAPI declaration. Inspect how its path and query parameters are generated, then compare the enum parameter output with the expected enum type; done means enum-constrained parameters are no longer generated as String.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.