json-schema-validator icon indicating copy to clipboard operation
json-schema-validator copied to clipboard

Incorrect error description (NullPointerException) when using a non-uri value in the id field

Open antonovdmitriy opened this issue 5 years ago • 3 comments

Description

Insufficiently clear description of the error when using a non-uri value in the id field at the root of the schema element. It would be better to show a competent message about incorrect format

Repeating

{
  "id": "JustSomeStringValue",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "field1":{
      "type": "string"
    }
  }
}
    JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4);
    InputStream is = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("test.json");
    JsonSchema node =  factory.getSchema(is);```

output

image

antonovdmitriy avatar Oct 28 '20 20:10 antonovdmitriy

@AntonovDmitriy Thanks for raising it. I am wondering if you could submit a PR to get it fixed.

stevehu avatar Oct 28 '20 22:10 stevehu

Also, $id is not required to be a fully qualified URL. At the Wikimedia Foundation we use relative path URIs for $ids and provide base URIs when resolving them.

I just tried to use this library but realized I can't because our relative path $ids (e.g. "/entity/event/1.0.0") cause a similar exception. I think more recent versions have this NPE caught. The exception I get is:

com.networknt.schema.JsonSchemaException: /test/event/1.0.0: null is an invalid segment for URI {2}

ottomata avatar Dec 24 '22 21:12 ottomata

Not to necrobump this, but I'm running into this exact issue. Our schema still loads, but it's still throwing the error in logs. Any work around?

hscissors avatar Sep 26 '23 17:09 hscissors