rest-assured / rest-assured

Java DSL for easy testing of REST services
Apache License 2.0
6.85k stars 1.88k forks source link

using schema-validator with format attribute in schema #970

Open willia58 opened 6 years ago

willia58 commented 6 years ago

When we do this we don't seem to get a validation failure when data doesn't match the format type chosen.

e.g.

{
  "type": "object",
  "definitions": {},
  "$schema": "http://json-schema.org/draft-04/schema#",
  "properties": {
    "self_url": {
      "$id": "/properties/self_url",
      "type": "string",
      "format": "uri",
      "title": "The Self_url Schema",
      "description": "Url to collect a submission status.",
      "default": "",
      "examples": [
        "http://localhost:8080/api/"
      ]
    }
  },
  "required": ["self_url"]
}

with data of:

{
    "self_url": "jkhfdkjgfkjdsgfkj"
}

the validation passes when we hoped it would fail. We set the test up like this:

 @Test
    public void shouldReturnSelfUrlToACreateSubmissionsRequest() {
        given()
            .multiPart("field1", "data")
        .when()
            .post("/api")
        .then()
            .assertThat().body(matchesJsonSchemaInClasspath("schema/example.json"));
    }
nikhilgupta1789 commented 6 years ago

Hi, @willia58 exactly I too faced the same issue, this is a big bug from Rest Assured and need to be fixed on a priority basis because changes in values(existing JSON) don't match with the actual JSON response from the Rest API output. Do you have any idea what another way you are trying to verify exact JSON schema? @johanhaleby could you please look into this issue and let us know another best approach for asserting exact schema validation