support 'deprecated'
This commit is contained in:
Родитель
6ce1f2e271
Коммит
f1ab4a8b65
|
@ -58,6 +58,7 @@ export interface JSONSchema {
|
|||
unevaluatedItems?: boolean | JSONSchemaRef;
|
||||
minContains?: number;
|
||||
maxContains?: number;
|
||||
deprecated?: boolean;
|
||||
|
||||
// schema 2020-12
|
||||
prefixItems?: JSONSchemaRef[];
|
||||
|
|
|
@ -554,11 +554,13 @@ function validate(n: ASTNode | undefined, schema: JSONSchema, validationResult:
|
|||
validationResult.enumValues = [schema.const];
|
||||
}
|
||||
|
||||
if (schema.deprecationMessage && node.parent) {
|
||||
let deprecationMessage = schema.deprecationMessage;
|
||||
if ((deprecationMessage || schema.deprecated) && node.parent) {
|
||||
deprecationMessage = deprecationMessage || localize('deprecated', 'Value is deprecated');
|
||||
validationResult.problems.push({
|
||||
location: { offset: node.parent.offset, length: node.parent.length },
|
||||
severity: DiagnosticSeverity.Warning,
|
||||
message: schema.deprecationMessage,
|
||||
message: deprecationMessage,
|
||||
code: ErrorCode.Deprecated
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2269,9 +2269,7 @@ suite('JSON Parser', () => {
|
|||
|
||||
test('deprecated', function () {
|
||||
|
||||
const { textDoc, jsonDoc } = toDocument('{"prop": 42}');
|
||||
|
||||
const schema: JSONSchema = {
|
||||
let schema: JSONSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
'prop': {
|
||||
|
@ -2279,10 +2277,26 @@ suite('JSON Parser', () => {
|
|||
}
|
||||
}
|
||||
};
|
||||
{
|
||||
const { textDoc, jsonDoc } = toDocument('{"prop": 42}');
|
||||
const semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors!.length, 1);
|
||||
}
|
||||
|
||||
const semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
'prop': {
|
||||
deprecated: true
|
||||
}
|
||||
}
|
||||
};
|
||||
{
|
||||
const { textDoc, jsonDoc } = toDocument('{"prop": 42}');
|
||||
const semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors!.length, 1);
|
||||
}
|
||||
|
||||
assert.strictEqual(semanticErrors!.length, 1);
|
||||
});
|
||||
|
||||
test('Strings with spaces', function () {
|
||||
|
|
Загрузка…
Ссылка в новой задаче