Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get which property failed with seeResponseIsValidOnJsonSchemaString #104

Open
francislavoie opened this issue Jun 25, 2024 · 0 comments · May be fixed by #105
Open

Get which property failed with seeResponseIsValidOnJsonSchemaString #104

francislavoie opened this issue Jun 25, 2024 · 0 comments · May be fixed by #105

Comments

@francislavoie
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant