javajsonschemajsonschema2pojo

JSON Schema references duplicating files instead of using the one passed as reference


I am starting to use the JSON Schema to java pojo in one of the projects I am working on (org.jsonschema2pojo). I have sucessfully referenced one schema inside the other one and I can see the same info is there. However, the json schema where I use the reference instead of referncing the pojo of the original one creates a new file with the exact same information. Example:

Json Schema A:

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema#",
      "$id": "https://example.com/schemas/A",
      "description": "Some Json Schema",
      "type": "object",
      "properties": {
        "genericInfo": {
          "type": "string",
          "description": "Some generic info"
        }
      }
      "required": ["genericInfo"]
    }

Json Schema B :

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema#",
      "$id": "https://example.com/schemas/B",
      "description": "Some Json Schema B",
      "type": "object",
      "properties": {
        "referenceToA": {
          "$ref": "../jsonSchemaA.json"
         }
       }
    }

My POJO of B has the information of A but instead of referencing the same file it creates a new file with the same name + information. Is there a way to stop this from happening? Is this a known Issue? Since I need to reference schemas between them but use common pojos in a lot of them I would need to always cast it to the original one if I can´t solve this issue.

Thanks in advance


Solution

  • I was able to find a workaround to this issue. I was unable to reference the schemas without them being compiled in different directories as I intended. However, by defining different execution phases on the pom.xml I was able to reference the compiled java classes directly inside the schemas that I wanted.

    On each one of the execution phases I specified the dourceDirectory + outputDirectory and generating first the classes to be referenced. Then I reference the path of each java class inside the json schemas I want to ahve a reference to this type by referencing it like this:

    "yourReference" : {
      "type" : "object",
      "javaType" : "location.of.class.Name"
    }
    

    Hope this helps