Skip to content

Commit bd5f2ba

Browse files
bigdazclaude
andauthored
Update json-schema-validator to 2.0.3 and migrate to its new API (#224)
## What Bumps `com.networknt:json-schema-validator` **1.5.9 → 2.0.3** and migrates the test schema-validation helper (`BaseExtractorTest`) to the new 2.x API. This unblocks the Dependabot group update in #223, whose `json-schema-validator` bump was failing to compile (`unable to resolve class JsonSchema` and friends). The other four dependencies in that group are unrelated and can be handled by Dependabot as usual. ## Why the source changes are needed json-schema-validator 2.x is a breaking release that renames the core types out of the old `com.networknt.schema.*` surface: | 1.5.9 | 2.0.3 | | --- | --- | | `JsonSchema` | `Schema` | | `JsonSchemaFactory` | `SchemaRegistry` | | `ValidationMessage` | `Error` | | `JsonSchemaException` | `SchemaException` | | `SpecVersion.VersionFlag.V4` | `SpecificationVersion.DRAFT_4` | | `JsonSchemaFactory.builder(getInstance(...)).build()` | `SchemaRegistry.withDefaultDialect(...)` | | `schema.validate()` → `Set<ValidationMessage>` | `schema.validate()` → `List<Error>` | Imports are now explicit rather than a wildcard, so that the new `com.networknt.schema.Error` correctly shadows `java.lang.Error`. ## Why 2.0.3 and not 3.x The 3.x line requires Jackson 3; this project is on Jackson 2. Dependabot's config already ignores json-schema-validator major v3, so 2.0.3 is the correct Jackson-2-compatible target. ## Verification - `:plugin-test:test` (full integration suite, which exercises the schema validation path) ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent b2464e3 commit bd5f2ba

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ junit-junit4 = { group = "junit", name = "junit", version = "4.13.2" }
1919
junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version = "5.14.3" }
2020

2121
groovy-json = { group = "org.codehaus.groovy", name = "groovy-json", version = "3.0.25" }
22-
json-schema-validator = { group = "com.networknt", name = "json-schema-validator", version = "1.5.9" }
22+
json-schema-validator = { group = "com.networknt", name = "json-schema-validator", version = "2.0.3" }
2323
jetbrains-annotations = { group = "org.jetbrains", name = "annotations", version = "26.1.0" }
2424
google-gson = { group = "com.google.code.gson", name = "gson", version = "2.13.2" }
2525

plugin-test/src/test/groovy/org/gradle/github/dependencygraph/BaseExtractorTest.groovy

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ package org.gradle.github.dependencygraph
22

33
import com.fasterxml.jackson.databind.JsonNode
44
import com.fasterxml.jackson.databind.ObjectMapper
5-
import com.networknt.schema.*
5+
import com.networknt.schema.Error
6+
import com.networknt.schema.Schema
7+
import com.networknt.schema.SchemaException
8+
import com.networknt.schema.SchemaRegistry
9+
import com.networknt.schema.SpecificationVersion
610
import groovy.json.JsonSlurper
711
import groovy.transform.CompileDynamic
812
import groovy.transform.CompileStatic
@@ -251,15 +255,15 @@ abstract class BaseExtractorTest extends Specification {
251255
protected Map jsonRepositorySnapshot() {
252256
def jsonSlurper = new JsonSlurper()
253257
println(dependencyGraphFile.text)
254-
JsonSchema schema = createSchemaValidator()
258+
Schema schema = createSchemaValidator()
255259
ObjectMapper mapper = new ObjectMapper()
256260
JsonNode node = mapper.readTree(dependencyGraphFile)
257261
validateAgainstJsonSchema(schema, node)
258262
return jsonSlurper.parse(dependencyGraphFile) as Map
259263
}
260264

261-
private static void validateAgainstJsonSchema(JsonSchema schema, JsonNode json) {
262-
final Set<ValidationMessage> validationMessages = schema.validate(json)
265+
private static void validateAgainstJsonSchema(Schema schema, JsonNode json) {
266+
final List<Error> validationMessages = schema.validate(json)
263267
if (!validationMessages.isEmpty()) {
264268
final String newline = System.lineSeparator()
265269
final String violationMessage = createViolationMessage(newline, validationMessages)
@@ -270,24 +274,22 @@ abstract class BaseExtractorTest extends Specification {
270274
}
271275

272276
@CompileDynamic
273-
private static String createViolationMessage(String newline, Set<ValidationMessage> validationMessages) {
277+
private static String createViolationMessage(String newline, List<Error> validationMessages) {
274278
return validationMessages
275279
.stream()
276-
.map(ValidationMessage::getMessage)
280+
.map(Error::getMessage)
277281
.collect(Collectors.joining(newline + " - ", " - ", ""))
278282
}
279283

280-
private static JsonSchema createSchemaValidator() {
281-
final JsonSchemaFactory factory =
282-
JsonSchemaFactory
283-
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4))
284-
.build()
284+
private static Schema createSchemaValidator() {
285+
final SchemaRegistry registry =
286+
SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_4)
285287
try {
286-
return factory
288+
return registry
287289
.getSchema(
288290
JsonRepositorySnapshotLoader.class.classLoader.getResourceAsStream(SCHEMA)
289291
)
290-
} catch (JsonSchemaException ex) {
292+
} catch (SchemaException ex) {
291293
throw new RuntimeException(
292294
"Unable to load dependency constraints schema (resource: " + SCHEMA + ")",
293295
ex

0 commit comments

Comments
 (0)