draft 07 polish and added to changelog
This commit is contained in:
Родитель
87e70725b7
Коммит
af23bd88d3
|
@ -1,3 +1,7 @@
|
|||
3.1.5
|
||||
==================
|
||||
- support JSON schema draft-07
|
||||
|
||||
3.1.2 2018-04-13
|
||||
==================
|
||||
* New API `LanguageService.getFoldingRanges`
|
||||
|
@ -5,7 +9,7 @@
|
|||
|
||||
3.1.0 2018-04-09
|
||||
==================
|
||||
* new APIs: `newJSONDocument` to create a JSON Document from a custom AST
|
||||
* new APIs: `newJSONDocument` to create a JSON document from a custom AST
|
||||
* new API types: ObjectASTNode, PropertyASTNode, ArrayASTNode, StringASTNode, NumberASTNode, BooleanASTNode, NullASTNode that allow creating a custom AST
|
||||
|
||||
3.0.9 2018-03-07
|
||||
|
@ -19,7 +23,7 @@
|
|||
|
||||
3.0.0 / 2017-01-11
|
||||
==================
|
||||
* Chaged parameters of API `LanguageService.getColorPresentations` to separate color and range
|
||||
* Changed parameters of API `LanguageService.getColorPresentations` to separate color and range
|
||||
.
|
||||
2.0.19 / 2017-09-21
|
||||
==================
|
||||
|
|
|
@ -470,33 +470,33 @@ function validate(node: ASTNode, schema: JSONSchema, validationResult: Validatio
|
|||
}
|
||||
|
||||
let testBranch = (schema: JSONSchemaRef) => {
|
||||
let subSchema = asSchema(schema);
|
||||
let subValidationResult = new ValidationResult();
|
||||
let subMatchingSchemas = matchingSchemas.newSub();
|
||||
let subSchema = asSchema(schema);
|
||||
let subValidationResult = new ValidationResult();
|
||||
let subMatchingSchemas = matchingSchemas.newSub();
|
||||
|
||||
validate(node, subSchema, subValidationResult, subMatchingSchemas);
|
||||
validate(node, subSchema, subValidationResult, subMatchingSchemas);
|
||||
|
||||
validationResult.merge(subValidationResult);
|
||||
validationResult.propertiesMatches += subValidationResult.propertiesMatches;
|
||||
validationResult.propertiesValueMatches += subValidationResult.propertiesValueMatches;
|
||||
matchingSchemas.merge(subMatchingSchemas);
|
||||
validationResult.merge(subValidationResult);
|
||||
validationResult.propertiesMatches += subValidationResult.propertiesMatches;
|
||||
validationResult.propertiesValueMatches += subValidationResult.propertiesValueMatches;
|
||||
matchingSchemas.merge(subMatchingSchemas);
|
||||
};
|
||||
|
||||
let testCondition = (ifSchema: JSONSchemaRef, thenSchema: JSONSchemaRef, elseSchema: JSONSchemaRef) => {
|
||||
let subSchema = asSchema(ifSchema);
|
||||
let subValidationResult = new ValidationResult();
|
||||
let subMatchingSchemas = matchingSchemas.newSub();
|
||||
let testCondition = (ifSchema: JSONSchemaRef, thenSchema: JSONSchemaRef, elseSchema: JSONSchemaRef) => {
|
||||
let subSchema = asSchema(ifSchema);
|
||||
let subValidationResult = new ValidationResult();
|
||||
let subMatchingSchemas = matchingSchemas.newSub();
|
||||
|
||||
validate(node, subSchema, subValidationResult, subMatchingSchemas);
|
||||
validate(node, subSchema, subValidationResult, subMatchingSchemas);
|
||||
|
||||
if (!subValidationResult.hasProblems()) {
|
||||
if (thenSchema) {
|
||||
testBranch(thenSchema);
|
||||
}
|
||||
} else if (elseSchema) {
|
||||
testBranch(elseSchema);
|
||||
}
|
||||
};
|
||||
if (!subValidationResult.hasProblems()) {
|
||||
if (thenSchema) {
|
||||
testBranch(thenSchema);
|
||||
}
|
||||
} else if (elseSchema) {
|
||||
testBranch(elseSchema);
|
||||
}
|
||||
};
|
||||
|
||||
if (schema.if) {
|
||||
testCondition(schema.if, schema.then, schema.else);
|
||||
|
@ -996,8 +996,8 @@ export function parse(textDocument: TextDocument, config?: JSONDocumentConfig):
|
|||
return false;
|
||||
}
|
||||
|
||||
function _errorAtRange<T extends ASTNode>(message: string, code: ErrorCode, startOffset: number, endOffset: number, severity : DiagnosticSeverity = DiagnosticSeverity.Error): void {
|
||||
|
||||
function _errorAtRange<T extends ASTNode>(message: string, code: ErrorCode, startOffset: number, endOffset: number, severity: DiagnosticSeverity = DiagnosticSeverity.Error): void {
|
||||
|
||||
if (problems.length === 0 || startOffset !== lastProblemOffset) {
|
||||
let range = Range.create(textDocument.positionAt(startOffset), textDocument.positionAt(endOffset));
|
||||
problems.push(Diagnostic.create(range, message, severity, code, textDocument.languageId));
|
||||
|
|
|
@ -460,7 +460,7 @@ export class JSONSchemaService implements IJSONSchemaService {
|
|||
merge(next, parentSchema, parentSchemaURL, segments[1]); // can set next.$ref again
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
collectEntries(<JSONSchema>next.items, <JSONSchema>next.additionalProperties, next.not, next.contains, next.propertyNames, next.if, next.then, next.else);
|
||||
collectMapEntries(next.definitions, next.properties, next.patternProperties, <JSONSchemaMap>next.dependencies);
|
||||
collectArrayEntries(next.anyOf, next.allOf, next.oneOf, <JSONSchema[]>next.items);
|
||||
|
|
|
@ -952,19 +952,19 @@ suite('JSON Parser', () => {
|
|||
|
||||
|
||||
test('if/then/else', function () {
|
||||
let schema: JsonSchema.JSONSchema = {
|
||||
id: 'main',
|
||||
if: {
|
||||
properties: {
|
||||
foo: {
|
||||
const: 'bar'
|
||||
let schema: JsonSchema.JSONSchema = {
|
||||
id: 'main',
|
||||
if: {
|
||||
properties: {
|
||||
foo: {
|
||||
const: 'bar'
|
||||
}
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
abc: {
|
||||
type: 'boolean'
|
||||
properties: {
|
||||
abc: {
|
||||
type: 'boolean'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -975,62 +975,62 @@ suite('JSON Parser', () => {
|
|||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "bar", "abc": true}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 0);
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "bar", "abc": true}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 0);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "bar", "abc": "baz"}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 1);
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "bar", "abc": "baz"}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 1);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "test", "abc": true}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 1);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "test", "abc": "baz"}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 0);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "test", "abc": true}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 1);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "test", "abc": "baz"}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 0);
|
||||
}
|
||||
});
|
||||
|
||||
test('nested if/then/else', function () {
|
||||
let schema: JsonSchema.JSONSchema = {
|
||||
id: 'main',
|
||||
if: {
|
||||
properties: {
|
||||
foo: {
|
||||
const: 'bar'
|
||||
}
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
abc: {
|
||||
type: 'boolean'
|
||||
}
|
||||
}
|
||||
},
|
||||
else: {
|
||||
if: {
|
||||
properties: {
|
||||
foo: {
|
||||
const: 'baz'
|
||||
test('nested if/then/else', function () {
|
||||
let schema: JsonSchema.JSONSchema = {
|
||||
id: 'main',
|
||||
if: {
|
||||
properties: {
|
||||
foo: {
|
||||
const: 'bar'
|
||||
}
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
abc: {
|
||||
type: 'boolean'
|
||||
}
|
||||
}
|
||||
},
|
||||
else: {
|
||||
if: {
|
||||
properties: {
|
||||
foo: {
|
||||
const: 'baz'
|
||||
}
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
abc: {
|
||||
type: 'array'
|
||||
properties: {
|
||||
abc: {
|
||||
type: 'array'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -1041,45 +1041,45 @@ suite('JSON Parser', () => {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "bar", "abc": true}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 0);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "bar", "abc": "baz"}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 1);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "baz", "abc": []}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 0);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "baz", "abc": "baz"}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 1);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "test", "abc": true}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 1);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "test", "abc": "baz"}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "bar", "abc": true}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 0);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "bar", "abc": "baz"}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 1);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "baz", "abc": []}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 0);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "baz", "abc": "baz"}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 1);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "test", "abc": true}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 1);
|
||||
}
|
||||
{
|
||||
let { textDoc, jsonDoc } = toDocument('{"foo": "test", "abc": "baz"}');
|
||||
assert.strictEqual(jsonDoc.syntaxErrors.length, 0);
|
||||
let semanticErrors = jsonDoc.validate(textDoc, schema);
|
||||
assert.strictEqual(semanticErrors.length, 0);
|
||||
}
|
||||
});
|
||||
|
||||
test('minProperties', function () {
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче