openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][codegen] String enum value NO transforms to FALSE

Open fizzet opened this issue 5 years ago • 4 comments
trafficstars

Bug Report Checklist

  • [X] Have you provided a full/minimal spec to reproduce the issue?
  • [ ] Have you validated the input using an OpenAPI validator (example)?
  • [X] What's the version of OpenAPI Generator used?
  • [X] Have you search for related issues/PRs?
  • [X] What's the actual output vs expected output?
Description

I have a YAML file that contains a string enum type:

    countryCode:
      type: string
      enum:
        - DE
        - FR
        - NO
        ...

In the generated Java code (jaxrs-cxf), this transforms to

public enum CountryCode {
  
  DE("DE"),
  FR("FR"),
  FALSE("false"),
  ...

Obviously, the last entry should be NO("NO") instead.

openapi-generator version

openapi-generator-maven-plugin 4.3.1

OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix

fizzet avatar May 14 '20 09:05 fizzet

Also, enum value OFF transaforms to false too

hleb-albau avatar Jul 01 '20 08:07 hleb-albau

Same here, OFF->false. Is there known fix/workaround?

DmitrySboychakov avatar Jul 13 '22 19:07 DmitrySboychakov

Same here. What could be causing this?

TheAwesomeGem avatar Aug 02 '22 22:08 TheAwesomeGem

That's actual problem with the YAML parser ( even more - not a problem, that's valid behavior), we need to add single or double quotes to the schema to fix that.
For example:

    countryCode:
      type: string
      enum:
        - 'DE'
        - 'FR'
        - 'NO'
        ...

DmitrySboychakov avatar Aug 03 '22 17:08 DmitrySboychakov