0

I am trying to validate a schema using RestAssured.

I have a response

{
"a" : 1,
"b" : 1,
"c" : 1
}

and I have a schema like shown below

{
"type" : "object",
"properties" : {
    "a" : {
        "type" : "string"
    },
    "b" : {
        "type" : "string"
    }
},
"required" : ["a", "b"],
"additionalProperties" : false
}

And I test it using RestAssured like shown below

public static void test01() {
    
    given().log().all()
    .when().get("http://localhost:8080/aaa")
    .then().assertThat().statusCode(200)
    .and().body(matchesJsonSchemaInClasspath("static/test.json"));
}

When I ran the test, the error is only about the unwanted key c. But based on my test, it should also fail for keys a and b as the response is of an integer type and my schema is checking for string.

My question is, is there a way to return all the errors?

Error is shown below

FAILED: test01 java.lang.AssertionError: 1 expectation failed.

Response body doesn't match expectation.

Expected: The content to match the given JSON schema.

error: object instance has properties which are not allowed by the schema: ["c"] level: "error" schema: {"loadingURI":"file:/C:/Users/allen/eclipse-workspace/tsrv/target/test-classes/static/test.json#","pointer":""} instance: {"pointer":""} domain: "validation" keyword: "additionalProperties" unwanted: ["c"]

Actual: { "a" : 1, "b" : 1, "c" : 1 }

mdl1999
  • 35
  • 3
  • The backend should return all the errors. Is the backend API returning all errors ? – Deepak Patankar Jan 15 '21 at 07:20
  • Hi Deepak, backend API meaning the json-schema-validator library that is being used by RestAssured? I dont know how to check that. But this is the library. https://github.com/java-json-tools/json-schema-validator – mdl1999 Jan 15 '21 at 07:38

0 Answers0