Skip to content

Get which property failed with seeResponseIsValidOnJsonSchemaString #104

@francislavoie

Description

@francislavoie

When we use $I->seeResponseIsValidOnJsonSchemaString, and the assertion fails, we get an error like this:

 Step  See response is valid on json schema string "{"type":"object","properties":{"error":{"type":"string"},"client":{"type":["string","number","null"]},"state":{"type":"null"},"message":{"type":["string","null"]},"int..."
 Fail  String value found, but a null is required
Failed asserting that false is true.

This is very confusing and hard to debug because it doesn't tell us exactly which property failed the assertion. When we have a giant schema, figuring that out by hand is a real pain.

It would be fantastic if the error message could be improved to mention which property (or path to the property if deeply nested) failed the assertion.

It looks like https://github.com/jsonrainbow/json-schema is being used under the hood, right now the error message is just taking the "message" from the validator:

$outcome = $validator->isValid();
$error = '';
if (!$outcome) {
$errors = $validator->getErrors();
$error = array_shift($errors)["message"];
}

According to the validator package's README, getErrors() also returns the property that failed. It gives an example like this:

    foreach ($validator->getErrors() as $error) {
        printf("[%s] %s\n", $error['property'], $error['message']);
    }

Could we update the error message for this assertion, please?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions