modelina: [BUG] AsyncAPI generator for Java doesn't generate class correctly when there's reference to itself

Describe the bug.

Modelina Async generator fails to generate Java class correctly in certain scenario: there’s self-refence. Example:

{
  "asyncapi": "2.6.0",
  "info": {
    "title": "Case",
    "version": "1.0.0",
    "description": "AsyncAPI schema definition for Case"
  },
  "channels": {},
  "components": {
    "schemas": {
      "CaseSchema": {
        "$id": "CaseSchema",
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "exceptForCase": {
            "type": "array",
            "items": {
              "type": "object",
              "$ref": "./Case.json#/components/schemas/CaseSchema"
            }
          }
        }
      }
    }
  }
}

Expected behavior

Generated Java class should have private List<CaseSchema> exceptForCase;

instead it generates array of Map<String, Object>:

private List<Map<String, Object>> exceptForCase;

Screenshots

Example:

bug1

Generated class:

bug2

How to Reproduce

See screeshots above

🥦 Browser

None

👀 Have you checked for similar open issues?

  • I checked and didn’t find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

No, someone else can work on it

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (10 by maintainers)

Most upvoted comments

Just pinging that I have not forgotten about this, but have to work on some other fixes that I think will fix this along side it.

@xespirit even with next when I use the following AsyncAPI document it works fine (https://65f02a20166dac9eadcc846e--modelina.netlify.app/playground?language=java):

{
  "asyncapi":"2.5.0",
  "info":{
     "title":"Streetlights API",
     "version":"1.0.0",
     "description":"The Smartylighting Streetlights API allows you\nto remotely manage the city lights.\n",
     "license":{
        "name":"Apache 2.0",
        "url":"https://www.apache.org/licenses/LICENSE-2.0"
     }
  },
  "servers":{
     "mosquitto":{
        "url":"mqtt://test.mosquitto.org",
        "protocol":"mqtt"
     }
  },
  "channels":{
     "lightmeasured":{
        "publish":{
           "summary":"Inform about environmental lighting conditions for a particular streetlight.",
           "operationId":"onLightMeasured",
           "message":{
              "name":"LightMeasured",
              "payload":{
                 "$id": "CaseSchema",
                 "type":"object",
                 "properties":{
                    "name":{
                       "type":"string"
                    },
                    "label":{
                       "type":"string"
                    },
                    "exceptForCase":{
                       "type":"array",
                       "items":{
                          "$ref":"#/channels/lightmeasured/publish/message/payload"
                       }
                    }
                 }
              }
           }
        }
     }
  }
}

Might have something to do with your $ref pointing to the file itself 🤔 Is there a more complex setup in place that might cause this?

I’m providing full sets of files to reproduce the issue:

Case.json DirectPolicy.json Insurance.json Policy.json Schemas.json

The generator is being called from Maven plug-in:

generate ./node_modules/.bin/ts-node ./generate.ts com.test.asyncapi.model model/Schemas.json target/generated-sources/asyncapi/com/test/asyncapi/model

I’ve attached pictures of generated files, representing the issue below: generated_files

case_schema_bug

@jonaslagoni could you try to reproduce the bug?

As you can see Modelina generator thinks all files are generated successfuly (without exiting with error). But in fact we have:

@JsonProperty("exceptForCase")
@JsonInclude(JsonInclude.Include.NON_NULL)
private List<Map<String, Object>> exceptForCase;

and exceptForCase shouldn’t be a list of Map<String, Object>. Expected result is a

private List<CaseSchema> exceptForCase;