question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request: export org.everit.json.schema.{Visitor, ValidationFailureReporter}

See original GitHub issue

It would be great if org.everit.json.schema.Visitor and org.everit.json.schema.ValidationFailureReporter are made public. This would allow custom schema traversals like:

        CustomFailureReporter reporter = new CustomFailureReporter(schema);
        CustomVisitor visitor = new CustomVisitor(reporter);
        visitor.visit(schema);

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
erosbcommented, Aug 11, 2018

Hello @dmitry-shkolnik !

Is this a blocking issue for you or just nice-to-have? The reason why these classes are currently package-private is that they might change in upcoming releases, and we don’t want to break the backward-compatibility of the public API. They are still fairly new (introduced in last Dec, version 1.8.0), and I simply don’t feel the visitor interface mature enough yet.

Good idea anyway, the visitor pattern aims arbitary processing of the visited classes, so the library should do it too. We just need a bit better visitors for this. Maintaining the backward-compatibility with deprecated but public classes causes enough headache already, I don’t want to increase these troubles.

0reactions
daniloarcidiaconocommented, Oct 24, 2019

Hello @erosb, thanks for your suggestion. I think that if I copy the Visitor class, I also need to simulate the Schema.accept() method with a series of instanceof, like the following:

void accept(org.everit.json.schema.Schema schema, com.example.my.Visitor  visitor) {
    if (schema instanceof ArraySchema) {
        visitor.visitArraySchema(schema);
    } else if (schema instanceof BooleanSchema) {
        // and so on
    }
}

Other than that, I have some doubts about the recursion of the Visitor class, in particular for nested object properties. The method Visitor.visitObjectSchema has an interesting loop

void visitObjectSchema(ObjectSchema objectSchema) {
    //  ... omitted ...
    Map<String, Schema> propertySchemas = objectSchema.getPropertySchemas();
    if (propertySchemas != null) {
        for (Map.Entry<String, Schema> entry : propertySchemas.entrySet()) {
            visitPropertySchema(entry.getKey(), entry.getValue());
        }
     }
}

void visitPropertySchema(String properyName, Schema schema) {
}

I don’t see any further call to Schema.accept() method (for example in ObjectSchemaValidatingVisitor), so how does this algorithm dig down the object hierarchy?

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullPointerException on visitSchemaOnAdditionalItems with ...
Hello, I discovered a strange case when I tried to validate my inputs to Google Json Schema for VOD Contents :
Read more >
org.everit.json.schema.ValidationFailureReporter Maven / Gradle / Ivy
org.everit.json.schema.ValidationFailureReporter maven / gradle build tool code. The class is part of the package ➦ Group: com.github.erosb ➦ Artifact: ...
Read more >
org.everit.json.schema : 1.1.0 - Maven Central
Official search by the maintainers of Maven Central Repository.
Read more >
org.everit.json.schema.ValidatingVisitor java code examples
ValidatingVisitor visitor = new ValidatingVisitor(input, failureReporter, readWriteValidator, validationListener);... visitor.visit(schema);... visitor.
Read more >
Import/export JSON schema for models - DatoCMS community
I noticed that dato uses a json-schema definition for validating the structure of your own API. I also love the ERD export of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found