Skip to content

Commit 0e5fa6a

Browse files
authored
allow schema to be deprecated (#227)
1 parent e140c73 commit 0e5fa6a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/parser/jsonParser.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,12 @@ function validate(n: ASTNode | undefined, schema: JSONSchema, validationResult:
578578
}
579579

580580
let deprecationMessage = schema.deprecationMessage;
581-
if ((deprecationMessage || schema.deprecated) && node.parent) {
581+
if (deprecationMessage || schema.deprecated) {
582582
deprecationMessage = deprecationMessage || l10n.t('Value is deprecated');
583+
let targetNode = node.parent?.type === 'property' ? node.parent : node;
584+
583585
validationResult.problems.push({
584-
location: { offset: node.parent.offset, length: node.parent.length },
586+
location: { offset: targetNode.offset, length: targetNode.length },
585587
severity: DiagnosticSeverity.Warning,
586588
message: deprecationMessage,
587589
code: ErrorCode.Deprecated

src/test/parser.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,6 +2389,16 @@ suite('JSON Parser', () => {
23892389
assert.strictEqual(semanticErrors!.length, 1);
23902390
}
23912391

2392+
schema = {
2393+
deprecated: true,
2394+
type: 'object'
2395+
};
2396+
{
2397+
const { textDoc, jsonDoc } = toDocument('{"prop": 42}');
2398+
const semanticErrors = validate2(jsonDoc, textDoc, schema);
2399+
assert.strictEqual(semanticErrors!.length, 1);
2400+
}
2401+
23922402
});
23932403

23942404
test('Strings with spaces', function () {

0 commit comments

Comments
 (0)