Validation

Webtau supports validation of objects against https://json-schema.org/ JSON Schema. It is possible to validate either the entire body or just a specific field with the complyWithSchema matcher as shown in the two examples below: http.get("/weather") { body.should complyWithSchema('valid-schema.json') } http.get("/city/London") { weather.should complyWithSchema('valid-schema.json') } Both examples above validate against the following schema:

Error messages

Using the first example above, an invalid schema will generate an error similar to: invalid schema (examples/scenarios/rest/jsonSchema/validateSchema.groovy) > executing HTTP GET http://localhost:8080/weather X failed expecting body to comply with schema invalid-schema.json : body expected to comply with schema invalid-schema.json [#: required key [anotherField] not found, #/temperature: expected type: Boolean, found: Integer] { "temperature": 88 } The schema used in validation to generate this error is as follows:

Configuration

The path to the schema file specified in complyWithSchema can be relative or absolute. If it's relative, it'll be relative to the jsonSchemasDir specified in configuration and if not specified then relative to working directory. For example: url = "http://localhost:8180" jsonSchemasDir = 'schemas'