Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/languageservice/parser/jsonParser07.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ function validate(
validationResult.problems.push({
location: location,
severity: DiagnosticSeverity.Warning,
message: getWarningMessage(ProblemType.missingRequiredPropWarning, [propertyName]),
message: schema.errorMessage || getWarningMessage(ProblemType.missingRequiredPropWarning, [propertyName]),
source: getSchemaSource(schema, originalSchema),
schemaUri: getSchemaUri(schema, originalSchema),
problemArgs: [propertyName],
Expand Down
40 changes: 40 additions & 0 deletions test/schemaValidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,46 @@ obj:
const result = await parseSetup(content);
expect(result[0].message).to.eq('Missing property "pineapple".');
});
it('should add errorMessage from schema when the property is missing', async () => {
schemaProvider.addSchema(SCHEMA_ID, {
type: 'object',
properties: {
icon: {
type: 'string',
},
},
required: ['title'],
errorMessage: 'Custom message',
});
const content = '';
const result = await parseSetup(content);
expect(result[0].message).to.eq('Custom message');
});
it('should add errorMessage from sub-schema when the property is missing', async () => {
schemaProvider.addSchema(SCHEMA_ID, {
type: 'object',
properties: {
icon: {
type: 'string',
},
title: {
type: 'string',
},
},
anyOf: [
{
required: ['title'],
errorMessage: 'At least one of `title` or `icon` must be defined.',
},
{
required: ['icon'],
},
],
});
const content = '';
const result = await parseSetup(content);
expect(result[0].message).to.eq('At least one of `title` or `icon` must be defined.');
});

describe('filePatternAssociation', () => {
const schema = {
Expand Down