Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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");
}

/**
Expand Down Expand Up @@ -316,9 +316,12 @@ private static boolean withinExpansionLimits(Path path, String file, List<Config
}
}

private static void validate(JsonSchema schema, JsonNode node, String file, List<ConfigError> errors) {
Set<ValidationMessage> messages = schema.validate(node);
for (ValidationMessage message : messages) {
private static void validate(Schema schema, JsonNode node, String file, List<ConfigError> 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()));
}
}
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
its JUnit Jupiter version to whatever the Quarkus BOM ships. -->
<version.quarkus>3.37.3</version.quarkus>
<version.token-sheriff>0.9.2</version.token-sheriff>
<version.json-schema-validator>1.5.9</version.json-schema-validator>
<version.json-schema-validator>3.0.6</version.json-schema-validator>
<!-- Default empty argLine for JaCoCo compatibility - JaCoCo will override this when active -->
<argLine />
</properties>
Expand Down
Loading