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

SpecVersion V4 doesn't accept "id" key

Open DeborahPereira4sh opened this issue 3 years ago • 1 comments

In Draft 4, $id is just id (without the dollar sign) .

But when I give a json file in draft 4 without the dollar sign to build my schema it doesn't work and I have the following error :

urn:OCPP:1.6:2019:12:HeartbeatRequest: null is an invalid segment for URI {2}
com.networknt.schema.JsonSchemaException: urn:OCPP:1.6:2019:12:HeartbeatRequest: null is an invalid segment for URI {2}
	at app//com.networknt.schema.JsonSchema.combineCurrentUriWithIds(JsonSchema.java:111)
	at app//com.networknt.schema.JsonSchema.<init>(JsonSchema.java:86)
	at app//com.networknt.schema.JsonSchema.<init>(JsonSchema.java:72)
	at app//com.networknt.schema.JsonSchema.<init>(JsonSchema.java:67)
	at app//com.networknt.schema.JsonSchemaFactory.newJsonSchema(JsonSchemaFactory.java:274)
	at app//com.networknt.schema.JsonSchemaFactory.getSchema(JsonSchemaFactory.java:316)
	at app//com.networknt.schema.JsonSchemaFactory.getSchema(JsonSchemaFactory.java:324)

And, when I had the $ it works.

DeborahPereira4sh avatar Feb 22 '22 16:02 DeborahPereira4sh

I guess v4 is using the shared code somehow. could you please submit a PR with your test case for both v4 and the newer version? It will help other developers to debug into it to figure out the difference. Also, it would be great if you could debug it, find the root cause and get it fixed. Thanks.

stevehu avatar Feb 22 '22 18:02 stevehu

@DeborahPereira4sh The behavior of the id keyword depends on how you configured the JsonSchemaFactory. If you configured it to anticipate Draft 4, id is a valid keyword. Otherwise, id is just another property.

We have several cross-draft tests that meet the requirements of the JSON Schema Test Suite. This suite tests that a:

  • Draft 2020-12 schema can reference a Draft 2019-9 schema
  • Draft 2019-09 schema can reference a Draft 2020-12 schema
  • Draft 2019-09 schema can reference a Draft 7 schema
  • Draft 7 schema can reference a Draft 2019-09 schema

Attempting to reference a Draft 4 or 6 schema from any of these starting points is undefined (and probably left to the implementation's discretion). Currently, we make a best-effort to comply with the request but cannot vouch for the results.

I'm going to close this issue since we cannot replicate it. Feel free to reopen it if you have additional insights on what we should investigate.

fdutton avatar Jun 06 '23 22:06 fdutton