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

Schema version no longer validated since version 1.0.83

Open alexruf opened this issue 2 years ago • 4 comments

I noticed that sice the release of version 1.0.83 the behaviour changed, and wrong schema versions do no longer throw an exception.

With version 1.0.82 the following Kotlin example code would have thrown a JsonSchemaException because the schema version doesn't match:

val schemaNode = jacksonObjectMapper().readTree("{\"\$schema\": \"http://json-schema.org/draft-06/schema\", \"properties\": { \"id\": {\"type\": \"number\"}}}")
val factory = com.networknt.schema.JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V202012)
val schema = factory.getSchema(schemaNode) // since 1.0.83 this will no longer throw 'JsonSchemaException' because of wrong schema version

Now, since version 1.0.83 this is no longer the case and regardless what version flag is specified, all schema versions are accepted.

alexruf avatar Jun 20 '23 11:06 alexruf

@alexruf This is intentional (#778) and exists to support Cross-draft validation. This allows a schema written against a newer version to reference a schema written against an older version.

fdutton avatar Jun 20 '23 11:06 fdutton

OK, but since this is a breaking change, is there a way to get back the old behaviour? Since we want to enforce a specific schema version, we were relying on the fact that if the JsonSchemaFactory is initialized with a specific VersionFlag, that this is causing a validation error if the schema doesn't match that version.

Maybe I am misunderstanding something, but for me, the new behaviour doesn't make much sense.

alexruf avatar Jun 20 '23 12:06 alexruf

Let me see what I can do.

fdutton avatar Jun 20 '23 12:06 fdutton

Let me see what I can do.

Thanks!

alexruf avatar Jun 20 '23 12:06 alexruf