Skip to content

Commit

Permalink
Show unevaluated property name in error msg (stoplightio#2441)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleung authored and ilanashapiro committed Aug 22, 2024
1 parent 1910bba commit 01c7636
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 16 additions & 0 deletions packages/http/src/validator/validators/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ describe('convertAjvErrors()', () => {
).toHaveProperty('message', 'Request parameter a.b ');
});
});

describe('has unevaluated property', () => {
it('converts properly', () => {
expect(
convertAjvErrors(
[Object.assign({}, errorObjectFixture, {
params: { unevaluatedProperty: 'd' },
keyword: 'unevaluatedProperties',
message: 'must NOT have unevaluated propertes',
})],
DiagnosticSeverity.Error,
ValidationContext.Input
)[0]
).toHaveProperty('message', "Request parameter a.b must NOT have unevaluated propertes: 'd'");
});
});
});

describe('validateAgainstSchema()', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/http/src/validator/validators/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export const convertAjvErrors = (
const allowedParameters = 'allowedValues' in error.params ? `: ${error.params.allowedValues.join(', ')}` : '';
const detectedAdditionalProperties =
'additionalProperty' in error.params ? `; found '${error.params.additionalProperty}'` : '';
const unevaluatedProperty =
'unevaluatedProperty' in error.params ? `: '${error.params.unevaluatedProperty}'` : '';
const errorPath = error.instancePath.split('/').filter(segment => segment !== '');
const path = prefix ? [prefix, ...errorPath] : errorPath;
const errorPathType = errorPath.length > 0 ? (prefix == 'body' ? 'property ' : 'parameter ') : '';
Expand All @@ -96,7 +98,7 @@ export const convertAjvErrors = (
return {
path,
code: error.keyword || '',
message: `${errorSourceDescription}${error.message || ''}${allowedParameters}${detectedAdditionalProperties}`,
message: `${errorSourceDescription}${error.message || ''}${allowedParameters}${detectedAdditionalProperties}${unevaluatedProperty}`,
severity,
};
})
Expand Down

0 comments on commit 01c7636

Please sign in to comment.