Is there a way how to assert that API response contains values which are NOT in JSON schema? (e.g.: "name": "Nick")
API response example (name is not specified in schema below):
{
"id": "390",
"name": "Nick",
"data": {
"leagueId": 35,
"homeTeam": "Norway",
"visitingTeam": "England",
}
}
JSON schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
"leagueId": {
"type": "integer"
},
"homeTeam": {
"type": "string"
},
"visitingTeam": {
"type": "string"
}
},
"required": [
"leagueId",
"homeTeam",
"visitingTeam"
]
}
},
"required": [
"id",
"data"
]
}
Comparison code example:
@Test
public void givenUrl_whenValidatesResponseWithInstanceSettings_thenCorrect() {
JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.newBuilder()
.setValidationConfiguration(
ValidationConfiguration.newBuilder()
.setDefaultVersion(SchemaVersion.DRAFTV4).freeze())
.freeze();
get("/events?id=390").then().assertThat()
.body(matchesJsonSchemaInClasspath("event_0.json")
.using(jsonSchemaFactory));
}