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

[BUG] dart generator creates invalid code

Open just-doit opened this issue 1 year ago • 0 comments

Description

The attached example demonstrates the problem.

It contains two classes (Obj1 and Obj2). Both have the same mode property.

In the class Obj1 this results in the property

Set<Obj1ModeEnum> mode;

while in the class Obj2 the property looks like this:

Set<ModeEnum> mode;

Here I would expect Set<Obj2ModeEnum> mode;.

In the file obj1.dart the associated type is

class Obj2ModeEnum {
  /// Instantiate a new enum with the provided [value].
  const Obj2ModeEnum._(this.value);
  ...

Here I would expect Obj1ModeEnum.

In the file obj2.dart the corresponding type is correct (but duplicate, since it's in obj1.dart already):

class Obj2ModeEnum {
  /// Instantiate a new enum with the provided [value].
  const Obj2ModeEnum._(this.value);
  ...
openapi-generator version
openapi-generator-cli 7.6.0
  commit : ab7d0cb
  built  : -999999999-01-01T00:00:00+18:00
  source : https://github.com/openapitools/openapi-generator
  docs   : https://openapi-generator.tech/
OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "info": {
    "title": "api_test",
    "version": "1.0.0"
  },
  "paths": {},
  "components": {
    "schemas": {
      "Obj1": {
        "type": "object",
        "properties": {
          "mode": {
            "uniqueItems": true,
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "mode1",
                "mode2",
                "mode3"
              ]
            }
          }
        }
      },
      "Obj2": {
        "type": "object",
        "properties": {
          "mode": {
            "uniqueItems": true,
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "mode1",
                "mode2",
                "mode3"
              ]
            }
          }
        }
      }
    }
  }
}
Generation Details

I'm using the following command:

openapi-generator generate -g dart -i spapi.json -o "$(pwd)/spapi" --additional-properties=pubName=spapi
Steps to reproduce

Use provided sample json and command.

just-doit avatar Jun 27 '24 08:06 just-doit