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

Reserved words mappings don't work with enums #100

Open
Colman opened this issue Oct 25, 2024 · 1 comment
Open

Reserved words mappings don't work with enums #100

Colman opened this issue Oct 25, 2024 · 1 comment

Comments

@Colman
Copy link

Colman commented Oct 25, 2024

Describe the bug
When generating an enum that has a value that is a reserved word, the --reserved-words-mappings param is ignored

Expected behavior
The --reserved-words-mappings param should not be ignored for enum values

To Reproduce

{
  "openapi": "3.0.1",
  "info": {
    "title": "Rental v2",
    "description": "Rental related info",
    "version": "v2"
  },
  "paths": {},
  "components": {
    "schemas": {
      "EFoo": {
        "enum": [
          "Late"
        ],
        "type": "string"
      }
    },
    "securitySchemes": {}
  },
  "tags": []
}

Run:

java -cp 'openapi-generator-cli-5.2.1.jar;openapi-dart-generator-5.12.jar' org.openapitools.codegen.OpenAPIGenerator generate -g dart2-api --reserved-words-mappings late=late

Produces the following enum in Dart:

enum EFoo { late_ }

The expected enum in Dart is:

enum EFoo { late }

Versions
openapi-dart-generator-5.12.jar
I believe it still happens in 8.1 since the code still contains the suspected cause

Suspected cause
The toEnumVarName function calls the escapeReservedWord function before calling the toVarName function. This causes the var name to not be found in the reserved words mappings.

Workaround
Use --reserved-words-mappings Late=,Late_=late

@rvowles
Copy link
Member

rvowles commented Oct 27, 2024

Looking at the way this is handled, its actually handed to the Dart generator by the base infrastructure. The AbstractDartCodegen class (which comes from the main project) is what loads these in and the reserved words are predefined there. It looks like late is built in. Perhaps re-log your issue on the main OpenAPIGenerator - feel free to link this ticket as well as I would like to know what they say about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants