raml-typesystem
Advanced tools
Comparing version 0.0.63 to 0.0.64
@@ -33,4 +33,5 @@ /// <reference path="../../typings/main.d.ts" /> | ||
validate(content: any, alreadyAccepted?: any[]): void; | ||
validateSelf(alreadyAccepted?: any[]): void; | ||
private setupId(json, path); | ||
private acceptErrors(key, errors, throwImmediately?); | ||
private acceptErrors(key, errors, regEntry, throwImmediately?); | ||
contentAsync(reference: any): Promise; | ||
@@ -37,0 +38,0 @@ } |
@@ -289,3 +289,3 @@ /// <reference path="../typings/main.d.ts" /> | ||
if (!missingReferences || missingReferences.length === 0) { | ||
this.acceptErrors(key, validator.getLastErrors(), true); | ||
this.acceptErrors(key, validator.getLastErrors(), typesystem_1.messageRegistry.CONTENT_DOES_NOT_MATCH_THE_SCHEMA, true); | ||
return; | ||
@@ -320,2 +320,48 @@ } | ||
}; | ||
JSONSchemaObject.prototype.validateSelf = function (alreadyAccepted) { | ||
var _this = this; | ||
if (alreadyAccepted === void 0) { alreadyAccepted = []; } | ||
var key = exampleKey("__SCHEMA_VALIDATION__", this.schema, this.provider.contextPath()); | ||
var error = globalCache.getValue(key); | ||
if (error) { | ||
if (error instanceof Error) { | ||
throw error; | ||
} | ||
return; | ||
} | ||
var validator = jsonUtil.getValidator(); | ||
alreadyAccepted.forEach(function (accepted) { return validator.setRemoteReference(accepted.reference, accepted.content); }); | ||
validator.validateSchema(this.jsonSchema); | ||
var missingReferences = validator.getMissingRemoteReferences().filter(function (reference) { return !_.find(alreadyAccepted, function (acceptedReference) { return reference === acceptedReference.reference; }); }); | ||
if (!missingReferences || missingReferences.length === 0) { | ||
this.acceptErrors(key, validator.getLastErrors(), typesystem_1.messageRegistry.INVALID_JSON_SCHEMA_DETAILS, true); | ||
return; | ||
} | ||
var acceptedReferences = []; | ||
missingReferences.forEach(function (reference) { | ||
var remoteSchemeContent; | ||
var result = { reference: reference }; | ||
try { | ||
var api = require('json-schema-compatibility'); | ||
var jsonObject = JSON.parse(_this.provider.content(reference)); | ||
_this.setupId(jsonObject, _this.provider.normalizePath(reference)); | ||
remoteSchemeContent = api.v4(jsonObject); | ||
delete remoteSchemeContent['$schema']; | ||
result.content = remoteSchemeContent; | ||
} | ||
catch (exception) { | ||
result.error = exception; | ||
} | ||
finally { | ||
acceptedReferences.push(result); | ||
} | ||
}); | ||
if (this.provider.hasAsyncRequests()) { | ||
return; | ||
} | ||
acceptedReferences.forEach(function (accepted) { | ||
alreadyAccepted.push(accepted); | ||
}); | ||
this.validateSelf(alreadyAccepted); | ||
}; | ||
JSONSchemaObject.prototype.setupId = function (json, path) { | ||
@@ -338,7 +384,7 @@ if (!path) { | ||
}; | ||
JSONSchemaObject.prototype.acceptErrors = function (key, errors, throwImmediately) { | ||
JSONSchemaObject.prototype.acceptErrors = function (key, errors, regEntry, throwImmediately) { | ||
if (throwImmediately === void 0) { throwImmediately = false; } | ||
if (errors && errors.length > 0) { | ||
var msg = errors.map(function (x) { return x.message + " " + x.params; }).join(", "); | ||
var res = new ts.ValidationError(typesystem_1.messageRegistry.CONTENT_DOES_NOT_MATCH_THE_SCHEMA, { msg: msg }); | ||
var res = new ts.ValidationError(regEntry, { msg: msg }); | ||
res.errors = errors; | ||
@@ -345,0 +391,0 @@ globalCache.setValue(key, res); |
{ | ||
"name": "raml-typesystem", | ||
"version": "0.0.63", | ||
"version": "0.0.64", | ||
"main": "dist/src/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -386,3 +386,4 @@ /// <reference path="../typings/main.d.ts" /> | ||
if(!missingReferences || missingReferences.length === 0) { | ||
this.acceptErrors(key, validator.getLastErrors(), true); | ||
this.acceptErrors(key, validator.getLastErrors(), | ||
messageRegistry.CONTENT_DOES_NOT_MATCH_THE_SCHEMA, true); | ||
@@ -429,2 +430,67 @@ return; | ||
validateSelf(alreadyAccepted: any[] = []): void { | ||
var key = exampleKey("__SCHEMA_VALIDATION__",this.schema,this.provider.contextPath()); | ||
var error = globalCache.getValue(key); | ||
if(error) { | ||
if(error instanceof Error) { | ||
throw error; | ||
} | ||
return; | ||
} | ||
var validator = jsonUtil.getValidator(); | ||
alreadyAccepted.forEach(accepted => validator.setRemoteReference(accepted.reference, accepted.content)); | ||
validator.validateSchema(this.jsonSchema); | ||
var missingReferences = validator.getMissingRemoteReferences().filter((reference: any) => !_.find(alreadyAccepted, (acceptedReference: any) => reference === acceptedReference.reference)); | ||
if(!missingReferences || missingReferences.length === 0) { | ||
this.acceptErrors(key, validator.getLastErrors(), | ||
messageRegistry.INVALID_JSON_SCHEMA_DETAILS, true); | ||
return; | ||
} | ||
var acceptedReferences: any = []; | ||
missingReferences.forEach((reference: any) => { | ||
var remoteSchemeContent: any; | ||
var result: any = {reference: reference}; | ||
try { | ||
var api = require('json-schema-compatibility'); | ||
var jsonObject = JSON.parse(this.provider.content(reference)); | ||
this.setupId(jsonObject, this.provider.normalizePath(reference)); | ||
remoteSchemeContent = api.v4(jsonObject); | ||
delete remoteSchemeContent['$schema']; | ||
result.content = remoteSchemeContent; | ||
} catch(exception){ | ||
result.error = exception; | ||
} finally { | ||
acceptedReferences.push(result); | ||
} | ||
}); | ||
if(this.provider.hasAsyncRequests()) { | ||
return; | ||
} | ||
acceptedReferences.forEach((accepted: any) => { | ||
alreadyAccepted.push(accepted); | ||
}); | ||
this.validateSelf(alreadyAccepted); | ||
} | ||
private setupId(json: any, path: string): any { | ||
@@ -454,6 +520,6 @@ if(!path) { | ||
private acceptErrors(key: any, errors: any[], throwImmediately = false): void { | ||
private acceptErrors(key: any, errors: any[], regEntry:any, throwImmediately = false): void { | ||
if(errors && errors.length>0){ | ||
var msg = errors.map(x=>x.message+" "+x.params).join(", "); | ||
var res= new ts.ValidationError(messageRegistry.CONTENT_DOES_NOT_MATCH_THE_SCHEMA,{msg : msg}); | ||
var res= new ts.ValidationError(regEntry,{msg : msg}); | ||
(<any>res).errors=errors; | ||
@@ -460,0 +526,0 @@ globalCache.setValue(key, res); |
@@ -6,2 +6,3 @@ { | ||
"gitUrl" : "https://github.com/raml-org/raml-js-parser-2.git", | ||
"gitBranch" : "hotfix-for-1.1.15", | ||
"installTypings" : true | ||
@@ -8,0 +9,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2234291
49060