It is important that contracts among consumer of the API ensure that the data expected are always correct. With this JSON Schema comparison, we can add assertion on the response data if it conforms to expected schema. We can store the schema to a file and use that as expected schema.
In the above Schema, it expects that max_page should be required and must be with the response, however the example of our response does not contain it, so we expect that this will be reported on our test. Aside from that, in the schema it also described that id in the items are string but we will be receiving number instead hence this should also be reported.
@schemachecks
Feature: Bad Schema Feature Example
As Autokin tester
I want to verify that all API contracts are correct
Scenario: Perform check on bad schema
Given that a secure endpoint is up at reqres.in
Given I set Content-Type header to application/json
When I GET /api/users?page=2
Then response status code should be 200
Then I expect response data schema complies to "{schemaBasePath}/resreq-users-schema.json"
The last line of our test is a check for Schema compliance. Here Autokin will validate if the response does conforms with our expected schema, if not it should report all errors. Below is an example, where exact error will be presented along with the line numbers if available, so that it will be easier for us to debug and identify the problem.