Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$ref loop detection after second call of 'validate' method #4

Closed
lazdmx opened this issue Jan 29, 2012 · 8 comments
Closed

$ref loop detection after second call of 'validate' method #4

lazdmx opened this issue Jan 29, 2012 · 8 comments
Labels

Comments

@lazdmx
Copy link

lazdmx commented Jan 29, 2012

Hi!

I found that if I try to validate json-instance against a schema by specified path (validator.validate("#/schema/in", json)), validation pass for first time, but second third and so on calls will report an "$ref loop" error. It seems strange since I try to revalidate same json-instance.

@fge
Copy link
Collaborator

fge commented Feb 1, 2012

Can you post your schema and sample data?

@fge
Copy link
Collaborator

fge commented Feb 3, 2012

Any input? I'm at a loss on reproducing this issue. Also, what version are you using? Is this 0.4, master?

@lazdmx
Copy link
Author

lazdmx commented Feb 4, 2012

Ok, for example

Schemas:

{
  "search": {
    "in": {
      "type": "object",
      "properties": {
        "filter": {
          "type": "string",
          "required": true
        },
        "max": {
          "type": "integer",
          "minimum": 1,
          "required": true
        }
      },
      "additionalProperties": false
    },
    "out": {
      "type": "object",
      "properties": {
        "status": {
          "type":"number"
        },
        "subjects":{
          "type": "array",
          "items":{
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "passport": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}

Json instance :

{
  "status":0,
  "subjects":[{
    "name": "User",
    "passport": "12345679"
  }]
}

Code:

public class App {

  private static final Logger logger = Logger.getLogger(App.class.getName());

  public static void main(String[] args) {

    try {
      File schemaFile =
              new File(new File(System.getProperty("user.dir")),
              "target/classes/schemas/all.json");
      File jsonFile =
              new File(new File(System.getProperty("user.dir")),
              "target/classes/in.json");
      final JsonNode schemas = JsonLoader.fromFile(schemaFile);
      final JsonNode js = JsonLoader.fromFile(jsonFile);

      final JsonValidator validator = new JsonValidator(schemas);

      for (int i = 0; i < 2; ++i) {
        ValidationReport report = validator.validate("#/search/out", js);
        if (report.isSuccess()) {
          logger.info("Success");
        } else {
          logger.info("Error:");
          for (String mes : report.getMessages()) {
            logger.info(mes);
          }

        }
      }

    } catch (JsonValidationFailureException ex) {
      logger.log(Level.WARNING, "Validation Failure", ex);
    } catch (IOException ex) {
      logger.log(Level.SEVERE, "Unable to read JSON schemas", ex);
    }
  }
}

@fge
Copy link
Collaborator

fge commented Feb 4, 2012

OK, I can reproduce it, looking it up...

@fge
Copy link
Collaborator

fge commented Feb 5, 2012

43cb1f2 <-- this fixes it. Nice catch!

I prepare for release 0.4.1.

@fge
Copy link
Collaborator

fge commented Feb 5, 2012

OK, 0.4.1 is in the pipe. Let me know when you have downloaded it!

@fge
Copy link
Collaborator

fge commented Feb 28, 2012

I take it that "no news, good news".

@fge fge closed this as completed Feb 28, 2012
@lazdmx
Copy link
Author

lazdmx commented Feb 29, 2012

All seams to be workable now, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants