ZenWave360/json-schema-ref-parser-jvm

Multiple occurrences of the same reference replaces all other properties

Closed this issue · 1 comments

I have a schema that has multiple properties with the same reference. Those properties have additional information like title, which are different for each property.

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "myDummySchema",
  "properties": {
    "lorem": {
      "title": "lorem",
      "$ref": "https://json.schemastore.org/base.json#/definitions/nullable-boolean"
    },
    "ipsum": {
      "title": "ipsum",
      "$ref": "https://json.schemastore.org/base.json#/definitions/nullable-boolean"
    }
  }
}

When I was trying to read the schema, my additional properties "merged" and were the same for all my referenced properties.

Reading of the schema:

$RefParser refParser = new $RefParser(file.toFile());
refParser.withOptions(new $RefParserOptions().withOnCircular($RefParserOptions.OnCircular.SKIP));
$Refs refs = refParser.parse().dereference().getRefs();

System.out.println(refs.schema());

Output

{$schema=http://json-schema.org/draft-07/schema#, $id=myDummySchema, properties={lorem={type=[boolean, null], title=ipsum}, ipsum={type=[boolean, null], title=ipsum}}}

As you can see, the title of lorem is read wrong, because it is now the title of ipsum

Expected output: the title of lorem should still be lorem, even after dereferencing.

MRE project: https://github.com/rH4rtinger/mre-refs-in-schemas

Thanks @rH4rtinger for taking the time to report this and for providing a minimal runnable test project

This fix is being released now as v0.9.2

Happy coding!!