[ https://issues.apache.org/jira/browse/JOHNZON-191?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16641605#comment-16641605 ]
Simone Tripodi commented on JOHNZON-191: ---------------------------------------- Thanks a lot for the update [~romain.manni-bucau] and apologise the late reaction, unfortunately I didn't have enough cycles during the WE to give a try. I updated and the re-built the Json Schema and updated the new SNAPSHOT version in my project, re-launched the unit tests and got the stack-trace below on a valid input: {noformat} java.lang.ClassCastException: Cannot cast org.apache.johnzon.core.JsonArrayImpl to javax.json.JsonString at java.lang.Class.cast(Class.java:3369) at org.apache.johnzon.core.JsonObjectImpl.value(JsonObjectImpl.java:41) at org.apache.johnzon.core.JsonObjectImpl.getJsonString(JsonObjectImpl.java:77) at org.apache.johnzon.jsonschema.spi.builtin.TypeValidation.create(TypeValidation.java:39) at org.apache.johnzon.jsonschema.JsonSchemaValidatorFactory.lambda$buildDirectValidations$0(JsonSchemaValidatorFactory.java:155) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) at org.apache.johnzon.jsonschema.JsonSchemaValidatorFactory.buildValidator(JsonSchemaValidatorFactory.java:139) at org.apache.johnzon.jsonschema.JsonSchemaValidatorFactory.lambda$null$10(JsonSchemaValidatorFactory.java:198) at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:267) at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) at java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet.lambda$entryConsumer$0(Collections.java:1575) at java.util.Iterator.forEachRemaining(Iterator.java:116) at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntrySetSpliterator.forEachRemaining(Collections.java:1600) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:270) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) at org.apache.johnzon.jsonschema.JsonSchemaValidator.apply(JsonSchemaValidator.java:41) at org.apache.sling.feature.io.json.FeatureJSONReader.readFeature(FeatureJSONReader.java:105) at org.apache.sling.feature.io.json.FeatureJSONReader.read(FeatureJSONReader.java:75) at org.apache.sling.feature.io.json.U.readFeature(U.java:42) at org.apache.sling.feature.io.json.FeatureJSONReaderTest.testValidatingFeature(FeatureJSONReaderTest.java:80) [...] {noformat} same thing on an invalid input: {noformat} java.lang.ClassCastException: Cannot cast org.apache.johnzon.core.JsonArrayImpl to javax.json.JsonString at java.lang.Class.cast(Class.java:3369) at org.apache.johnzon.core.JsonObjectImpl.value(JsonObjectImpl.java:41) at org.apache.johnzon.core.JsonObjectImpl.getJsonString(JsonObjectImpl.java:77) at org.apache.johnzon.jsonschema.spi.builtin.TypeValidation.create(TypeValidation.java:39) at org.apache.johnzon.jsonschema.JsonSchemaValidatorFactory.lambda$buildDirectValidations$0(JsonSchemaValidatorFactory.java:155) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) at org.apache.johnzon.jsonschema.JsonSchemaValidatorFactory.buildValidator(JsonSchemaValidatorFactory.java:139) at org.apache.johnzon.jsonschema.JsonSchemaValidatorFactory.lambda$null$10(JsonSchemaValidatorFactory.java:198) at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:267) at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) at java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet.lambda$entryConsumer$0(Collections.java:1575) at java.util.Iterator.forEachRemaining(Iterator.java:116) at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntrySetSpliterator.forEachRemaining(Collections.java:1600) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:270) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) at org.apache.johnzon.jsonschema.JsonSchemaValidator.apply(JsonSchemaValidator.java:41) at org.apache.sling.feature.io.json.FeatureJSONReader.readFeature(FeatureJSONReader.java:105) at org.apache.sling.feature.io.json.FeatureJSONReader.read(FeatureJSONReader.java:75) at org.apache.sling.feature.io.json.U.readFeature(U.java:42) at org.apache.sling.feature.io.json.FeatureJSONReaderTest.testInvalidTextInArtifacts(FeatureJSONReaderTest.java:84) [...] {noformat} I've tried to understand what's the root cause of that error, but still got no idea ATM. Many thanks in advance for any hint! > [Schema] "patternProperties" does not correctly handle related property type > ---------------------------------------------------------------------------- > > Key: JOHNZON-191 > URL: https://issues.apache.org/jira/browse/JOHNZON-191 > Project: Johnzon > Issue Type: Bug > Affects Versions: 1.1.10 > Reporter: Simone Tripodi > Priority: Major > Fix For: 1.1.11 > > > In Apache Sling we have been developing a draft-07 compliant schema to define > _Sling Feature files_, which are in JSON format, and of course Johnzon is the > de-facto standard choice to work with JSON structures. > If you want to have a look at the initial draft, have a look at > https://gist.github.com/simonetripodi/c69d2ffebdbd2c4b1355df60568f1ab5 > So, in our _Feature_ we have so called _extensions_ where users can define a > custom data set, _extensions_ keys are defined by {{patternProperties}} which > related type, I noticed, are not correctly handled by the > {{JsonSchemaValidator}}: the expected behaviour is that for an input like the > one below: > {noformat} > { > "id":"test/artifacts-extension/1.0.0", > "my-extension1:TEXT|false":{} > } > {noformat} > an error is detected since type is invalid, _string_ or _array_ is expected > but but got _object_, tested on https://www.jsonschemavalidator.net/, but > {{JsonSchemaValidator}} passes all verifications. > I noticed that this behaviour is even present in Johnzon tests , > i.e.[JsonSchemaValidatorTest.java#L572|https://github.com/apache/johnzon/blob/master/johnzon-jsonschema/src/test/java/org/apache/johnzon/jsonschema/JsonSchemaValidatorTest.java#L572] > where _number_ type is expected for keys identified by _[0-9]+_, but it > succeeds for _string_ type as well. > I think it is a bug, unless I misconfigured something, follows below a > snippet of code where the validator is created: > {noformat} > private final JsonSchemaValidator validator; > private FeatureSchemaValidatorProvider() { > JsonReader reader = null; > JsonSchemaValidatorFactory factory = null; > try (InputStream schemaInput = > FeatureJSONReader.class.getResourceAsStream("/META-INF/feature/Feature-1.0.0.schema.json")) > { > reader = Json.createReader(schemaInput); > JsonObject schema = reader.readObject(); > factory = new JsonSchemaValidatorFactory(); > factory.setRegexFactory(JavaRegex::new); > validator = factory.newInstance(schema); > } catch (IOException ioe) { > // should not happen, /META-INF/feature/Feature-1.0.0.schema.json > is in the classpath > throw new UncheckedIOException(ioe); > } finally { > if (reader != null) { > reader.close(); > } > if (factory != null) { > factory.close(); > } > } > } > {noformat} > Could you kindly help us? Many thanks in advance! -- This message was sent by Atlassian JIRA (v7.6.3#76005)