dart-ogurets / dart-openapi-maven

A Maven dependency for use with the OpenAPI swagger Maven plugin
BSD 2-Clause "Simplified" License
27 stars 11 forks source link

Reserved words mappings don't work with enums #100

Open Colman opened 2 weeks ago

Colman commented 2 weeks ago

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 commented 2 weeks ago

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.