jimblackler / jsonschemafriend

A JSON Schema loader and validator, delivered as a Java library.
Apache License 2.0
49 stars 23 forks source link

Support $refs with implicit url base #5

Open tyilo opened 3 years ago

tyilo commented 3 years ago

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 commented 3 years ago

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

jimblackler commented 2 years ago

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.

olegshtch commented 2 years ago

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

jimblackler commented 2 years ago

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

olegshtch commented 2 years ago

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"
        }
    }
}