OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.38k stars 6.47k forks source link

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

Open Zomzog opened 2 years ago

Zomzog commented 2 years ago

Bug Report Checklist

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
Mintas commented 1 year ago

this is actually a bug https://swagger.io/docs/specification/data-models/enums/#:~:text=request%20parameter%20or%20a%20model%20property