in language-service/src/parser/jsonParser.ts [528:596]
public validate(schema: JSONSchema, validationResult: ValidationResult, matchingSchemas: ISchemaCollector): void {
if (!matchingSchemas.include(this)) {
return;
}
if (schema.type === 'string') {
//In YAML, a value like 123 could be a number but it could also be a string. It initially gets
//parsed into a NumberASTNode, but we should also check it against string schema.
this.validateStringValue(schema, '' + this.getValue(), validationResult);
}
else {
// work around type validation in the base class
let typeIsInteger = false;
if (schema.type === 'integer' || (Array.isArray(schema.type) && (<string[]>schema.type).indexOf('integer') !== -1)) {
typeIsInteger = true;
}
if (typeIsInteger && this.isInteger === true) {
this.type = 'integer';
}
super.validate(schema, validationResult, matchingSchemas);
this.type = 'number';
const val = this.getValue();
if (typeof schema.multipleOf === 'number') {
if (val % schema.multipleOf !== 0) {
validationResult.addProblem({
location: { start: this.start, end: this.end },
severity: ProblemSeverity.Warning,
getMessage: () => localize('multipleOfWarning', 'Value is not divisible by {0}.', schema.multipleOf)
});
}
}
if (typeof schema.minimum === 'number') {
if (schema.exclusiveMinimum && val <= schema.minimum) {
validationResult.addProblem({
location: { start: this.start, end: this.end },
severity: ProblemSeverity.Warning,
getMessage: () => localize('exclusiveMinimumWarning', 'Value is below the exclusive minimum of {0}.', schema.minimum)
});
}
if (!schema.exclusiveMinimum && val < schema.minimum) {
validationResult.addProblem({
location: { start: this.start, end: this.end },
severity: ProblemSeverity.Warning,
getMessage: () => localize('minimumWarning', 'Value is below the minimum of {0}.', schema.minimum)
});
}
}
if (typeof schema.maximum === 'number') {
if (schema.exclusiveMaximum && val >= schema.maximum) {
validationResult.addProblem({
location: { start: this.start, end: this.end },
severity: ProblemSeverity.Warning,
getMessage: () => localize('exclusiveMaximumWarning', 'Value is above the exclusive maximum of {0}.', schema.maximum)
});
}
if (!schema.exclusiveMaximum && val > schema.maximum) {
validationResult.addProblem({
location: { start: this.start, end: this.end },
severity: ProblemSeverity.Warning,
getMessage: () => localize('maximumWarning', 'Value is above the maximum of {0}.', schema.maximum)
});
}
}
}
}