From 66d910c61348ed01f9e38563086e18ff864948ee Mon Sep 17 00:00:00 2001 From: Hector Ventura Date: Sun, 30 Aug 2026 22:06:30 -0500 Subject: [PATCH] fix(build): resolve the JSON schema library from Maven Central (#2811) A clone with a cold ~/.m2 cannot build. Apicurio's schema-util-json asks for the JSON schema library under its JitPack coordinate, com.github.everit-org.json-schema:org.everit.json.schema, which has never been published to Maven Central. The project declares no repositories, so Maven only ever consults Central, where that artifact returns 404. Builds that work are resolving it from a warm local cache, CI included via its restored Maven cache, which is why this stayed hidden. Replaced with com.github.erosb:everit-json-schema, the same project rehomed by its author to a Central-published coordinate. Both jars carry the same 174 classes under org.everit.json.schema, so apicurio's JsonSchemaCompatibilityChecker and JsonSchemaContentValidator load unchanged, and the Central version is newer (1.14.6 against 1.14.4). Adds the JSON cases that prove it. SchemaCompatibilityCheckerTest covered only AVRO and PROTOBUF, neither of which touches the library, so the whole JSON branch of checkerFor/validatorFor was untested and a missing dependency would only have surfaced at runtime. Dropping the replacement now fails those three with NoClassDefFoundError on org.everit.json.schema.loader.SchemaLoader. One expectation is asserted as observed rather than assumed: apicurio treats adding an optional JSON property as narrowing, the opposite of the AVRO case, because data carrying that key with another type validated before. --- pom.xml | 18 +++++++ .../SchemaCompatibilityCheckerTest.java | 50 +++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/pom.xml b/pom.xml index a6f37a9bf1..e881de3dd8 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,7 @@ 3.37.4 2.22.1 2.6.13.Final + 1.14.6 6.4.5 @@ -257,8 +258,25 @@ io.apicurio apicurio-common-app-components-logging + + + com.github.everit-org.json-schema + org.everit.json.schema + + + + com.github.erosb + everit-json-schema + ${everit.json.schema.version} + io.apicurio apicurio-registry-schema-util-protobuf diff --git a/src/test/java/io/github/hectorvent/floci/services/glue/schemaregistry/SchemaCompatibilityCheckerTest.java b/src/test/java/io/github/hectorvent/floci/services/glue/schemaregistry/SchemaCompatibilityCheckerTest.java index c16454c661..0dd577746c 100644 --- a/src/test/java/io/github/hectorvent/floci/services/glue/schemaregistry/SchemaCompatibilityCheckerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/glue/schemaregistry/SchemaCompatibilityCheckerTest.java @@ -59,6 +59,20 @@ class SchemaCompatibilityCheckerTest { + " required string phone = 3;\n" + "}\n"; + private static final String JSON_V1 = + "{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\"," + + "\"properties\":{\"id\":{\"type\":\"integer\"}},\"required\":[\"id\"]}"; + + private static final String JSON_ADD_OPTIONAL = + "{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\"," + + "\"properties\":{\"id\":{\"type\":\"integer\"}," + + "\"email\":{\"type\":\"string\"}},\"required\":[\"id\"]}"; + + private static final String JSON_ADD_REQUIRED = + "{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\"," + + "\"properties\":{\"id\":{\"type\":\"integer\"}," + + "\"email\":{\"type\":\"string\"}},\"required\":[\"id\",\"email\"]}"; + @Test void noneAlwaysCompatible() { var r = SchemaCompatibilityChecker.check("NONE", List.of(AVRO_V1), AVRO_ADD_REQUIRED, "AVRO"); @@ -158,4 +172,40 @@ class SchemaCompatibilityCheckerTest { String error = SchemaCompatibilityChecker.validateDefinition("{garbage", "AVRO"); assertNotNull(error); } + + // JSON goes through apicurio's JsonSchemaCompatibilityChecker and JsonSchemaContentValidator, + // which are backed by the org.everit.json.schema library. These cases are what prove that + // library actually loads: the AVRO and PROTOBUF paths never touch it, so before this the JSON + // branch of checkerFor/validatorFor was entirely uncovered. + + @Test + void jsonBackwardAcceptsAnUnchangedSchema() { + var r = SchemaCompatibilityChecker.check("BACKWARD", List.of(JSON_V1), JSON_V1, "JSON"); + assertTrue(r.compatible(), () -> "expected compatible, got: " + r.reason()); + } + + /** + * Apicurio treats adding even an optional property as narrowing, because data that carried that + * key with another type validated before and no longer does. Asserted as observed rather than + * assumed: it is the opposite of the AVRO case above. + */ + @Test + void jsonBackwardTreatsANewOptionalPropertyAsNarrowing() { + var r = SchemaCompatibilityChecker.check("BACKWARD", List.of(JSON_V1), JSON_ADD_OPTIONAL, "JSON"); + assertFalse(r.compatible()); + assertNotNull(r.reason()); + } + + @Test + void jsonBackwardRejectsAddingARequiredProperty() { + var r = SchemaCompatibilityChecker.check("BACKWARD", List.of(JSON_V1), JSON_ADD_REQUIRED, "JSON"); + assertFalse(r.compatible()); + assertNotNull(r.reason()); + } + + @Test + void jsonFirstVersionIsCompatible() { + var r = SchemaCompatibilityChecker.check("BACKWARD", List.of(), JSON_V1, "JSON"); + assertTrue(r.compatible(), () -> "expected compatible, got: " + r.reason()); + } }