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][Spring][Array][Ref]: Array enum parameters have invalid default value #16223

Closed
5 of 6 tasks
adithyac-spot opened this issue Jul 31, 2023 · 2 comments · Fixed by #17779
Closed
5 of 6 tasks

[BUG][Spring][Array][Ref]: Array enum parameters have invalid default value #16223

adithyac-spot opened this issue Jul 31, 2023 · 2 comments · Fixed by #17779

Comments

@adithyac-spot
Copy link

adithyac-spot commented Jul 31, 2023

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

Default value tags for arrays have square braces([]) surrounded on them, which would fail because of invalid enum values.

Initial state:

openapi.yaml

openapi: 3.0.3
info:
  version: 1.0.0
  title: Bug Report
  description: Spring generator, array enums

paths:
  /test:
    $ref: 'file.yaml#/paths/~1test'

file.yaml

components:
  parameters:
    pets:
      name: pets
      in: query
      schema:
        type: array
        items:
          $ref: '#/components/schemas/Pet'
        default: [DOG, FISH]

  schemas:
    Pet:
      type: string
      enum:
        - DOG
        - CAT
        - FISH

paths:
  /test:
    get:
      description: Returns ad for a given ad ID.
      operationId: getAd
      parameters:
        - $ref: '#/components/parameters/pets'
      responses:
        '200':
          description: OK
          content:
            text/plain:
              schema:
                type: string
                example: pong

Command Run:

openapi-generator generate -i openapi.yaml -g spring

Actual output:

default ResponseEntity<String> getAd(
        @Parameter(name = "pets", description = "", in = ParameterIn.QUERY)  @Valid
        @RequestParam(value = "pets", required = false, defaultValue = "[DOG, FISH]") List<Pet> pets
    )

Expected Output:

default ResponseEntity<String> getAd(
        @Parameter(name = "pets", description = "", in = ParameterIn.QUERY)  @Valid
        @RequestParam(value = "pets", required = false, defaultValue = "DOG, FISH") List<Pet> pets
    )

Actual output makes spring think that [DOG and FISH] are the provided enums and would fail the request processing.

openapi-generator version
openapi-generator-cli 6.6.0
  commit : 7f8b853
  built  : -999999999-01-01T00:00:00+18:00
  source : https://github.com/openapitools/openapi-generator
  docs   : https://openapi-generator.tech/
Debug info

This bug would not occur if the paths are in the main openapi.yaml file instead of being referenced from the file.yaml

@adithyac-spot
Copy link
Author

cc: @wing328

Since you fixed couple of similar issues with array/enums, thought you could help.

@martin-mfg
Copy link
Contributor

Thanks for reporting this issue!
swagger-parser parses the enum default value differently depending on whether it's in a referenced file or not. Which seems strange to me. I opened a bug about this at swagger-api/swagger-parser#1958.

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