diff --git a/api-sheriff/src/main/java/de/cuioss/sheriff/gateway/config/load/ConfigLoader.java b/api-sheriff/src/main/java/de/cuioss/sheriff/gateway/config/load/ConfigLoader.java index aba44bc..496ec5d 100644 --- a/api-sheriff/src/main/java/de/cuioss/sheriff/gateway/config/load/ConfigLoader.java +++ b/api-sheriff/src/main/java/de/cuioss/sheriff/gateway/config/load/ConfigLoader.java @@ -26,7 +26,6 @@ import java.util.Iterator; import java.util.List; import java.util.Objects; -import java.util.Set; import java.util.function.Consumer; import java.util.regex.Pattern; import java.util.stream.Stream; @@ -55,10 +54,11 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; -import com.networknt.schema.JsonSchema; -import com.networknt.schema.JsonSchemaFactory; -import com.networknt.schema.SpecVersion; -import com.networknt.schema.ValidationMessage; +import com.networknt.schema.Error; +import com.networknt.schema.InputFormat; +import com.networknt.schema.Schema; +import com.networknt.schema.SchemaRegistry; +import com.networknt.schema.SpecificationVersion; import org.jspecify.annotations.Nullable; import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; @@ -110,8 +110,8 @@ public final class ConfigLoader { private final Path configDir; private final EnvSecretResolver secretResolver; private final ObjectMapper mapper; - private final JsonSchema gatewaySchema; - private final JsonSchema endpointSchema; + private final Schema gatewaySchema; + private final Schema endpointSchema; /** * Creates a loader for the given configuration directory. @@ -125,9 +125,9 @@ public ConfigLoader(Path configDir, EnvSecretResolver secretResolver) { this.configDir = Objects.requireNonNull(configDir, "configDir"); this.secretResolver = Objects.requireNonNull(secretResolver, "secretResolver"); this.mapper = buildMapper(); - JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V202012); - this.gatewaySchema = loadSchema(factory, "/schema/gateway.schema.json"); - this.endpointSchema = loadSchema(factory, "/schema/endpoint.schema.json"); + SchemaRegistry registry = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12); + this.gatewaySchema = loadSchema(registry, "/schema/gateway.schema.json"); + this.endpointSchema = loadSchema(registry, "/schema/endpoint.schema.json"); } /** @@ -316,9 +316,12 @@ private static boolean withinExpansionLimits(Path path, String file, List errors) { - Set messages = schema.validate(node); - for (ValidationMessage message : messages) { + private static void validate(Schema schema, JsonNode node, String file, List errors) { + // json-schema-validator 3.x exposes its node API on Jackson 3 (tools.jackson); this loader is + // built on Jackson 2 (com.fasterxml.jackson). Bridge the already-parsed Jackson 2 tree through its + // own JSON rendering (JsonNode.toString() is total — no checked exception) so the validator + // re-parses it with its own mapper; Jackson 3 never enters this code. + for (Error message : schema.validate(node.toString(), InputFormat.JSON)) { errors.add(new ConfigError(file, message.getInstanceLocation().toString(), message.getMessage())); } } @@ -464,12 +467,12 @@ private static YAMLFactory hardenedYamlFactory() { .build(); } - private static JsonSchema loadSchema(JsonSchemaFactory factory, String resource) { + private static Schema loadSchema(SchemaRegistry registry, String resource) { try (InputStream stream = ConfigLoader.class.getResourceAsStream(resource)) { if (stream == null) { throw new IllegalStateException("Missing bundled schema resource: " + resource); } - return factory.getSchema(stream); + return registry.getSchema(stream); } catch (IOException e) { throw new IllegalStateException("Cannot read bundled schema resource: " + resource, e); } diff --git a/pom.xml b/pom.xml index cd4850c..7d5f9aa 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ its JUnit Jupiter version to whatever the Quarkus BOM ships. --> 3.37.3 0.9.2 - 1.5.9 + 3.0.6