rmannibucau commented on PR #77: URL: https://github.com/apache/johnzon/pull/77#issuecomment-1323818292
Hi @radu-almasan , I took time to check this case and as suspected it is still a bug but here what I meant for the fix (`validable` is the one to handle, root is just a particular case and if it has multiple validations we should ensure the extractor works as fast as possible to avoiding the chaining from `root` is likely sane so it is mainly about rewriting provider): ```diff index 14103bc..d62752f 100644 --- a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/JsonSchemaValidatorFactory.java +++ b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/JsonSchemaValidatorFactory.java @@ -197,17 +197,20 @@ public class JsonSchemaValidatorFactory implements AutoCloseable { final Predicate<CharSequence> pattern = regexFactory.get().apply(obj.getKey()); final JsonObject currentSchema = obj.getValue().asJsonObject(); // no cache cause otherwise it could be in properties - return (Function<JsonValue, Stream<ValidationResult.ValidationError>>) validable -> { + return (Function<JsonValue, Stream<ValidationResult.ValidationError>>) root -> { + final JsonValue validable = Optional.ofNullable(valueProvider) + .map(provider -> provider.apply(root)) + .orElse(root); if (validable.getValueType() != JsonValue.ValueType.OBJECT) { return Stream.empty(); } return validable.asJsonObject().entrySet().stream() .filter(e -> pattern.test(e.getKey())) - .flatMap(e -> { - final String[] subPath = Stream.concat(Stream.of(path), Stream.of(e.getKey())).toArray(String[]::new); - final Function<JsonValue, JsonValue> provider = new ChainedValueAccessor(valueProvider, e.getKey()); - return buildValidator(subPath, currentSchema, provider).apply(validable); - }); + .flatMap(e -> buildValidator( + Stream.concat(Stream.of(path), Stream.of(e.getKey())).toArray(String[]::new), + currentSchema, + o -> o.asJsonObject().get(e.getKey())) + .apply(validable)); }; }) .collect(toList())) ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@johnzon.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org