jsonschemafriend icon indicating copy to clipboard operation
jsonschemafriend copied to clipboard

Support $refs with implicit url base

Open tyilo opened this issue 4 years ago • 5 comments

When loading the following schema I get a warning:

Aug 06, 2021 12:31:26 PM net.jimblackler.jsonschemafriend.Schema <init>
WARNING: No match for #/$defs/reference
{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "$id": "urn:defs-test",
  "title": "TEST",
  "type": "object",
  "properties": {
    "testReference": {
      "$ref": "#/$defs/reference",
    }
  },
  "$defs": {
    "reference": {
      "type": "string"
    }
  }
}

tyilo avatar Aug 06 '21 10:08 tyilo

Hmm, actually the problem seems to be that #/$defs/reference is not mapped to urn:defs-test#/$defs/reference

tyilo avatar Aug 06 '21 10:08 tyilo

Thanks for the report and apologies for the delay investigating. There's been a problem with the scheme 'urn'. It seems it doesn't play nice with the constructor for java.net.URI, which I use throughout. I pushed enough to fix the precise issue above (thanks for the test case) but will need to do more digging to make sure it works throughout.

jimblackler avatar Sep 24 '21 22:09 jimblackler

When I use urn: with $dynamicRef/$dynamicAnchor I get same error.

olegshtch avatar Oct 14 '21 11:10 olegshtch

Sorry to read that; could you confirm that you are using 0.11.2.

If you are, could you paste an example of a failed case here? You can check it in advance on https://tryjsonschematypes.appspot.com/#validate

jimblackler avatar Oct 14 '21 12:10 jimblackler

I got java.lang.IllegalStateException: java.net.URISyntaxException: Expected scheme-specific part at index 4: urn:

for

{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"$id": "urn:java:common.proto.Message",
	"title": "Message itself",
	"type": "object",
	"properties": {
		"head": {
			"type": "object"
		},
		"body": {
			"$dynamicRef": "#body"
		}
	},
	"required": ["head", "body"],
	"additionalProperties": false,
	"$defs": {
	    "body": {
	        "$dynamicAnchor": "body",
	        "type": "object"
	    }
	}
}

olegshtch avatar Oct 14 '21 12:10 olegshtch