From 06ea465ab7f02dbd921811597f73824145e42ef7 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Sun, 26 Oct 2025 00:22:55 +0200 Subject: [PATCH 1/3] deps: Update `json-schema-validator` version 2.0.0 Signed-off-by: Frank Viernau --- gradle/libs.versions.toml | 2 +- model/src/test/kotlin/JsonSchemaTest.kt | 13 ++++++++++--- utils/test/src/main/kotlin/Matchers.kt | 6 +++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f0a82e38ad4ba..76f41bc0ac2d8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -36,7 +36,7 @@ jgit = "7.4.0.202509020913-r" jiraRestClient = "7.0.1" jruby = "10.0.2.0" jslt = "0.1.14" -jsonSchemaValidator = "1.5.9" +jsonSchemaValidator = "2.0.0" kaml = "0.102.0" kotest = "6.0.4" kotlinPoet = "2.2.0" diff --git a/model/src/test/kotlin/JsonSchemaTest.kt b/model/src/test/kotlin/JsonSchemaTest.kt index 42a69329830e1..b4085aff1cff7 100644 --- a/model/src/test/kotlin/JsonSchemaTest.kt +++ b/model/src/test/kotlin/JsonSchemaTest.kt @@ -20,8 +20,8 @@ package org.ossreviewtoolkit.model import com.networknt.schema.InputFormat -import com.networknt.schema.JsonSchemaFactory -import com.networknt.schema.SpecVersion +import com.networknt.schema.SchemaRegistry +import com.networknt.schema.SpecificationVersion import io.kotest.core.spec.style.StringSpec import io.kotest.inspectors.forAll @@ -30,6 +30,7 @@ import io.kotest.matchers.should import io.kotest.matchers.shouldNot import java.io.File +import java.net.URI import org.ossreviewtoolkit.model.config.RepositoryConfiguration import org.ossreviewtoolkit.utils.ort.ORT_LICENSE_CLASSIFICATIONS_FILENAME @@ -265,7 +266,11 @@ class JsonSchemaTest : StringSpec({ } }) -private val schemaV7 = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7) +private val schemaV7 = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_7) { builder -> + builder.schemaLoader { schemaLoader -> + schemaLoader.fetchRemoteResources() + } +} private val repositoryConfigurationSchema = File("../integrations/schemas/repository-configuration-schema.json").toURI() @@ -275,3 +280,5 @@ private val repositoryConfigurationAnalyzerConfiguration = private val repositoryConfigurationPackageManagerConfiguration = File("../integrations/schemas/repository-configurations/package-manager-configuration-schema.json").toURI() + +private fun SchemaRegistry.getSchema(uri: URI) = getSchema(uri.toURL().openStream()) diff --git a/utils/test/src/main/kotlin/Matchers.kt b/utils/test/src/main/kotlin/Matchers.kt index c549aaf4cf978..c21ccf4c5dbd4 100644 --- a/utils/test/src/main/kotlin/Matchers.kt +++ b/utils/test/src/main/kotlin/Matchers.kt @@ -23,8 +23,8 @@ import com.github.difflib.DiffUtils import com.github.difflib.UnifiedDiffUtils import com.networknt.schema.InputFormat as NetworkNtInputFormat -import com.networknt.schema.JsonSchemaFactory -import com.networknt.schema.SpecVersion +import com.networknt.schema.SchemaRegistry +import com.networknt.schema.SpecificationVersion import io.kotest.assertions.eq.EqMatcher import io.kotest.matchers.Matcher @@ -135,7 +135,7 @@ enum class InputFormat(internal val networkNtInputformat: NetworkNtInputFormat) fun matchJsonSchema(schemaJson: String, inputFormat: InputFormat = InputFormat.JSON): Matcher = Matcher { actual -> - val schema = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7).getSchema(schemaJson) + val schema = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_7).getSchema(schemaJson) val violations = schema.validate(actual, inputFormat.networkNtInputformat) MatcherResult( From c307b4a30bfc7bdcf81ef2f99bdc6dbe8fed89c1 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Mon, 27 Oct 2025 08:59:58 +0100 Subject: [PATCH 2/3] test(model): Remove some minor code redundancy Signed-off-by: Frank Viernau --- model/src/test/kotlin/JsonSchemaTest.kt | 38 ++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/model/src/test/kotlin/JsonSchemaTest.kt b/model/src/test/kotlin/JsonSchemaTest.kt index b4085aff1cff7..cef159d2f49f0 100644 --- a/model/src/test/kotlin/JsonSchemaTest.kt +++ b/model/src/test/kotlin/JsonSchemaTest.kt @@ -46,7 +46,7 @@ class JsonSchemaTest : StringSpec({ "ORT's own repository configuration file validates successfully" { val repositoryConfiguration = File("../$ORT_REPO_CONFIG_FILENAME").readText() - val errors = schemaV7.getSchema(repositoryConfigurationSchema) + val errors = getSchema(repositoryConfigurationSchema) .validate(repositoryConfiguration, InputFormat.YAML) errors should beEmpty() @@ -58,7 +58,7 @@ class JsonSchemaTest : StringSpec({ examplesDir.walk().filterTo(mutableListOf()) { it.isFile && it.name.endsWith(ORT_REPO_CONFIG_FILENAME) } repositoryConfiguration.forAll { - val errors = schemaV7.getSchema(repositoryConfigurationSchema).validate(it.readText(), InputFormat.YAML) + val errors = getSchema(repositoryConfigurationSchema).validate(it.readText(), InputFormat.YAML) errors should beEmpty() } @@ -69,7 +69,7 @@ class JsonSchemaTest : StringSpec({ "/analyzer-repository-configuration.ort.yml" ).analyzer - val errors = schemaV7.getSchema(repositoryConfigurationAnalyzerConfiguration) + val errors = getSchema(repositoryConfigurationAnalyzerConfiguration) .validate(analyzerConfiguration.toYaml(), InputFormat.YAML) errors should beEmpty() @@ -80,7 +80,7 @@ class JsonSchemaTest : StringSpec({ "/package-manager-repository-configuration.ort.yml" ).analyzer?.packageManagers - val errors = schemaV7.getSchema(repositoryConfigurationPackageManagerConfiguration) + val errors = getSchema(repositoryConfigurationPackageManagerConfiguration) .validate(packageManagerConfiguration.toYaml(), InputFormat.YAML) errors should beEmpty() @@ -90,7 +90,7 @@ class JsonSchemaTest : StringSpec({ val curationsSchema = File("../integrations/schemas/curations-schema.json").toURI() val curationsExample = File("../examples/$ORT_PACKAGE_CURATIONS_FILENAME").readText() - val errors = schemaV7.getSchema(curationsSchema).validate(curationsExample, InputFormat.YAML) + val errors = getSchema(curationsSchema).validate(curationsExample, InputFormat.YAML) errors should beEmpty() } @@ -99,7 +99,7 @@ class JsonSchemaTest : StringSpec({ val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI() val packageConfiguration = File("../examples/$ORT_PACKAGE_CONFIGURATION_FILENAME").readText() - val errors = schemaV7.getSchema(packageConfigurationSchema).validate(packageConfiguration, InputFormat.YAML) + val errors = getSchema(packageConfigurationSchema).validate(packageConfiguration, InputFormat.YAML) errors should beEmpty() } @@ -108,7 +108,7 @@ class JsonSchemaTest : StringSpec({ val resolutionsSchema = File("../integrations/schemas/resolutions-schema.json").toURI() val resolutionsExample = File("../examples/$ORT_RESOLUTIONS_FILENAME").readText() - val errors = schemaV7.getSchema(resolutionsSchema).validate(resolutionsExample, InputFormat.YAML) + val errors = getSchema(resolutionsSchema).validate(resolutionsExample, InputFormat.YAML) errors should beEmpty() } @@ -117,7 +117,7 @@ class JsonSchemaTest : StringSpec({ val ortConfigurationSchema = File("../integrations/schemas/ort-configuration-schema.json").toURI() val referenceConfigFile = File("src/main/resources/$ORT_REFERENCE_CONFIG_FILENAME").readText() - val errors = schemaV7.getSchema(ortConfigurationSchema).validate(referenceConfigFile, InputFormat.YAML) + val errors = getSchema(ortConfigurationSchema).validate(referenceConfigFile, InputFormat.YAML) errors should beEmpty() } @@ -126,7 +126,7 @@ class JsonSchemaTest : StringSpec({ val licenseClassificationsSchema = File("../integrations/schemas/license-classifications-schema.json").toURI() val licenseClassificationsExample = File("../examples/$ORT_LICENSE_CLASSIFICATIONS_FILENAME").readText() - val errors = schemaV7.getSchema(licenseClassificationsSchema) + val errors = getSchema(licenseClassificationsSchema) .validate(licenseClassificationsExample, InputFormat.YAML) errors should beEmpty() @@ -135,7 +135,7 @@ class JsonSchemaTest : StringSpec({ "Snippet choices validate successfully" { val repositoryConfiguration = readResource("/snippet-choices-repository-configuration.ort.yml") - val errors = schemaV7.getSchema(repositoryConfigurationSchema) + val errors = getSchema(repositoryConfigurationSchema) .validate(repositoryConfiguration, InputFormat.YAML) errors should beEmpty() @@ -143,7 +143,7 @@ class JsonSchemaTest : StringSpec({ "Package configuration with no matchers validates successfully" { val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI() - val schema = schemaV7.getSchema(packageConfigurationSchema) + val schema = getSchema(packageConfigurationSchema) val configWithNoMatchers = """ id: "Pip::example-package:0.0.1" @@ -156,7 +156,7 @@ class JsonSchemaTest : StringSpec({ "Package configuration with only vcs validates successfully" { val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI() - val schema = schemaV7.getSchema(packageConfigurationSchema) + val schema = getSchema(packageConfigurationSchema) val configWithVcs = """ id: "Pip::example-package:0.0.1" @@ -172,7 +172,7 @@ class JsonSchemaTest : StringSpec({ "Package configuration with only source_artifact_url validates successfully" { val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI() - val schema = schemaV7.getSchema(packageConfigurationSchema) + val schema = getSchema(packageConfigurationSchema) val configWithSourceArtifact = """ id: "Pip::example-package:0.0.1" @@ -186,7 +186,7 @@ class JsonSchemaTest : StringSpec({ "Package configuration with only source_code_origin validates successfully" { val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI() - val schema = schemaV7.getSchema(packageConfigurationSchema) + val schema = getSchema(packageConfigurationSchema) val configWithSourceCodeOrigin = """ id: "Pip::example-package:0.0.1" @@ -200,7 +200,7 @@ class JsonSchemaTest : StringSpec({ "Package configuration with vcs and source_artifact_url fails validation" { val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI() - val schema = schemaV7.getSchema(packageConfigurationSchema) + val schema = getSchema(packageConfigurationSchema) val configWithVcsAndSourceArtifact = """ id: "Pip::example-package:0.0.1" @@ -217,7 +217,7 @@ class JsonSchemaTest : StringSpec({ "Package configuration with vcs and source_code_origin fails validation" { val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI() - val schema = schemaV7.getSchema(packageConfigurationSchema) + val schema = getSchema(packageConfigurationSchema) val configWithVcsAndSourceCodeOrigin = """ id: "Pip::example-package:0.0.1" @@ -234,7 +234,7 @@ class JsonSchemaTest : StringSpec({ "Package configuration with source_artifact_url and source_code_origin fails validation" { val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI() - val schema = schemaV7.getSchema(packageConfigurationSchema) + val schema = getSchema(packageConfigurationSchema) val configWithSourceArtifactAndSourceCodeOrigin = """ id: "Pip::example-package:0.0.1" @@ -249,7 +249,7 @@ class JsonSchemaTest : StringSpec({ "Package configuration with all three matchers fails validation" { val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI() - val schema = schemaV7.getSchema(packageConfigurationSchema) + val schema = getSchema(packageConfigurationSchema) val configWithAllMatchers = """ id: "Pip::example-package:0.0.1" @@ -281,4 +281,4 @@ private val repositoryConfigurationAnalyzerConfiguration = private val repositoryConfigurationPackageManagerConfiguration = File("../integrations/schemas/repository-configurations/package-manager-configuration-schema.json").toURI() -private fun SchemaRegistry.getSchema(uri: URI) = getSchema(uri.toURL().openStream()) +private fun getSchema(uri: URI) = schemaV7.getSchema(uri.toURL().openStream()) From ed7376ad4026976e3f4148c6afb4a56778e860df Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Mon, 27 Oct 2025 09:01:31 +0100 Subject: [PATCH 3/3] test(model): Use a more speaking name for `schemaV7` While at it, use `lazy` initialization. Signed-off-by: Frank Viernau --- model/src/test/kotlin/JsonSchemaTest.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/model/src/test/kotlin/JsonSchemaTest.kt b/model/src/test/kotlin/JsonSchemaTest.kt index cef159d2f49f0..9f19ade0d2374 100644 --- a/model/src/test/kotlin/JsonSchemaTest.kt +++ b/model/src/test/kotlin/JsonSchemaTest.kt @@ -266,9 +266,11 @@ class JsonSchemaTest : StringSpec({ } }) -private val schemaV7 = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_7) { builder -> - builder.schemaLoader { schemaLoader -> - schemaLoader.fetchRemoteResources() +private val schemaRegistry: SchemaRegistry by lazy { + SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_7) { builder -> + builder.schemaLoader { schemaLoader -> + schemaLoader.fetchRemoteResources() + } } } @@ -281,4 +283,4 @@ private val repositoryConfigurationAnalyzerConfiguration = private val repositoryConfigurationPackageManagerConfiguration = File("../integrations/schemas/repository-configurations/package-manager-configuration-schema.json").toURI() -private fun getSchema(uri: URI) = schemaV7.getSchema(uri.toURL().openStream()) +private fun getSchema(uri: URI) = schemaRegistry.getSchema(uri.toURL().openStream())