sahaya / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

JsonSchemaValidator fails to load relative schemas even if provided an URI #346

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Line 215 of JsonSchemaValidator has:

    JsonSchema jsonSchema = instanceSettings.jsonSchemaFactory().getJsonSchema(schema);

where schema is a pre-loaded JsonNode.

This prevent resolving relative $ref in the parent schema because the validator 
does not know what is the base URI of the parent schema.

It would be nice if matchesJsonSchema(URL url) and matchesJsonSchema(URI uri) 
could carry this URI down to the matchesSafely method instead of using 
JsonLoader.fromURL (thus losing the base URI).

I've confirmed the suggested approach works with the following test case:

    String json = expect().statusCode(200)
            .contentType(JSON)
            .when()
            .get("/nodes")
            .extract()
            .asString();

    jsonSchemaFactory.getJsonSchema(schemaURI).validate(JsonLoader.fromString(json));

Original issue reported on code.google.com by ddos...@gmail.com on 16 Aug 2014 at 10:48

GoogleCodeExporter commented 9 years ago
Is this something that you always want to do when you use a URI or URL? Are 
there cases when you want to disable it? (i.e. should we make it configurable?)

Original comment by johan.ha...@gmail.com on 29 Aug 2014 at 6:39

GoogleCodeExporter commented 9 years ago
I've made it configurable from the JsonSchemaValidatorSettings but URI's and 
URL's are parsed according to your suggestions by default now.

Original comment by johan.ha...@gmail.com on 29 Aug 2014 at 9:08

GoogleCodeExporter commented 9 years ago
Thanks much!

Also I can't think of any reason why I would not want this behaviour when 
providing a URL/URI but that's just me :) So it's good you've made this 
configurable!

Original comment by ddos...@gmail.com on 29 Aug 2014 at 2:52