本文整理匯總了TypeScript中@maxxton/microdocs-core/helpers.ProblemReporter類的典型用法代碼示例。如果您正苦於以下問題:TypeScript ProblemReporter類的具體用法?TypeScript ProblemReporter怎麽用?TypeScript ProblemReporter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ProblemReporter類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: ProblemReporter
clientViews.forEach(clientView => {
let reporter = new ProblemReporter(problemReport.getRootObject());
problemReporters.push(reporter);
let producerProperties = producerView.properties;
let clientProperties = clientView.properties;
// Check each producer properties
if (producerProperties) {
for (let key in producerProperties) {
// Find client Property by name
let producerProperty = producerProperties[key];
if (!isProducerIgnored(producerProperty)) {
let propertyName = getProducerPropertyMappingName(key, producerProperty);
let clientProperty = findClientPropertyByName(propertyName, clientProperties);
checkSchema(endpoint, clientProperty, producerProperty, clientProject, producerProject, reporter, path + (path == '' ? '' : '.') + key, placing);
}
}
}
// Check unknown client properties
if (clientProperties) {
for (let key in clientProperties) {
let clientProperty = clientProperties[key];
if (!isClientIgnored(clientProperty)) {
let name = getClientPropertyMappingName(key, clientProperty);
let producerProperty:Schema = null;
if(producerProperties) {
producerProperty = findProducerPropertyByName(name, producerProperties);
}
if (!producerProperty) {
let keyPath = path + (path ? '.' : '') + key;
reporter.report(ProblemLevels.WARNING, `Unknown property '${keyPath}' in ${placing} body`, endpoint.controller, endpoint.method);
}
}
}
}
// Decorate problems with view info
if(producerViews.length > 1 || clientViews.length > 1) {
reporter.getRawProblems().forEach(problem => {
problem.message = "[" + clientView.name + " > " + producerView.name + "] " + problem.message;
});
}
});
示例2: checkPathParameters
export function checkPathParameters(clientEndpoint: Path, producerEndpoint: Path, clientProject: Project, producerProject: Project, problemReport: ProblemReporter): void {
// match via wildcards in regexp
var expression = '^' + producerEndpoint.path.replace(new RegExp("\/", 'g'), '\/').replace(new RegExp("\\{.*?\\}", 'g'), '(.+)') + '$';
var clientExp = new RegExp(expression);
var producerExp = new RegExp("\\{.*?\\}", 'g');
var clientMatches: string[] = clientEndpoint.path.match(clientExp);
var producerMatches: string[] = producerEndpoint.path.match(producerExp);
if (clientMatches && producerMatches && clientMatches.length == producerMatches.length + 1 && clientMatches.length >= 1) {
for (let i = 1; i < clientMatches.length; i++) {
let producerParamName = producerMatches[i - 1].substr(1, producerMatches[i - 1].length - 2);
let producerParam = getPathVariable(producerParamName, producerEndpoint);
if (producerParam == null) {
problemReport.report(ProblemLevels.ERROR, "path variable '" + producerParamName + "' is missing on the controller", clientEndpoint.controller, clientEndpoint.method);
} else {
let clientParamName = clientMatches[i];
if (clientParamName.match(/^\{.*?\}$/)) {
var clientParam = getPathVariable(clientParamName.substr(1, clientParamName.length - 2), clientEndpoint);
if (clientParam == null) {
problemReport.report(ProblemLevels.ERROR, "path variable '" + clientParamName.substr(1, clientParamName.length - 2) + "' is missing", clientEndpoint.controller, clientEndpoint.method);
}
if (clientParam != null && producerParam != null) {
if (!matchType(producerParam, clientParam)) {
problemReport.report(ProblemLevels.WARNING, "Type mismatches path variable '" + clientParamName.substr(1, clientParamName.length - 2) + "', expected: " + producerParam.type + ", found: " + clientParam.type, clientEndpoint.controller, clientEndpoint.method);
}
}
} else {
var value = clientParamName;
switch (producerParam.type.toLowerCase()) {
case SchemaTypes.NUMBER:
case SchemaTypes.INTEGER:
if (!parseInt(value)) {
problemReport.report(ProblemLevels.WARNING, "Type mismatches path variable '" + producerParamName + "' is not a number', expected: " + producerParam.type + ", found: number", clientEndpoint.controller, clientEndpoint.method);
}
break;
}
}
}
}
}
}
示例3: checkResponseBody
export function checkResponseBody(clientEndpoint: Path, producerEndpoint: Path, clientProject: Project, producerProject: Project, problemReport: ProblemReporter): void {
if (clientEndpoint.responses != undefined && clientEndpoint.responses != null &&
clientEndpoint.responses['default'] != undefined && clientEndpoint.responses['default'] != null &&
clientEndpoint.responses['default'].schema != undefined && clientEndpoint.responses['default'].schema != null) {
if (producerEndpoint.responses != undefined && producerEndpoint.responses != null &&
producerEndpoint.responses['default'] != undefined && producerEndpoint.responses['default'] != null &&
producerEndpoint.responses['default'].schema != undefined && producerEndpoint.responses['default'].schema != null) {
// let producerSchema = SchemaHelper.collect(producerEndpoint.responses['default'].schema, [], producerProject);
// let clientSchema = SchemaHelper.collect(clientEndpoint.responses['default'].schema, [], clientProject);
// checkSchema(clientEndpoint, clientSchema, producerSchema, clientProject, producerProject, problemReport, '', 'response');
} else {
problemReport.report(ProblemLevels.ERROR, "There is no response body", clientEndpoint.controller, clientEndpoint.method);
}
}
}
示例4: checkSchema
function checkSchema(endpoint: Path, clientSchema: Schema, producerSchema: Schema, clientProject: Project, producerProject: Project, problemReport: ProblemReporter, path: string, placing: 'request'|'response'): void {
if (producerSchema != null && producerSchema != undefined) {
if (clientSchema != null && clientSchema != undefined) {
if (!matchType(clientSchema, producerSchema)) {
let position = "";
if (path != '') {
position = ' at ' + path;
}
problemReport.report(ProblemLevels.WARNING, "Type mismatches in " + placing + " body" + position + ", expected: " + producerSchema.type + ", found: " + clientSchema.type, endpoint.controller, endpoint.method);
} else {
if (producerSchema.type == SchemaTypes.OBJECT) {
let producerViews = collectViews(producerSchema);
let clientViews = collectViews(clientSchema);
// Check each view for problems
let problemReporters: ProblemReporter[] = [];
producerViews.forEach(producerView => {
clientViews.forEach(clientView => {
let reporter = new ProblemReporter(problemReport.getRootObject());
problemReporters.push(reporter);
let producerProperties = producerView.properties;
let clientProperties = clientView.properties;
// Check each producer properties
if (producerProperties) {
for (let key in producerProperties) {
// Find client Property by name
let producerProperty = producerProperties[key];
if (!isProducerIgnored(producerProperty)) {
let propertyName = getProducerPropertyMappingName(key, producerProperty);
let clientProperty = findClientPropertyByName(propertyName, clientProperties);
checkSchema(endpoint, clientProperty, producerProperty, clientProject, producerProject, reporter, path + (path == '' ? '' : '.') + key, placing);
}
}
}
// Check unknown client properties
if (clientProperties) {
for (let key in clientProperties) {
let clientProperty = clientProperties[key];
if (!isClientIgnored(clientProperty)) {
let name = getClientPropertyMappingName(key, clientProperty);
let producerProperty:Schema = null;
if(producerProperties) {
producerProperty = findProducerPropertyByName(name, producerProperties);
}
if (!producerProperty) {
let keyPath = path + (path ? '.' : '') + key;
reporter.report(ProblemLevels.WARNING, `Unknown property '${keyPath}' in ${placing} body`, endpoint.controller, endpoint.method);
}
}
}
}
// Decorate problems with view info
if(producerViews.length > 1 || clientViews.length > 1) {
reporter.getRawProblems().forEach(problem => {
problem.message = "[" + clientView.name + " > " + producerView.name + "] " + problem.message;
});
}
});
});
if (problemReporters.filter(reporter => !reporter.hasProblems()).length == 0) {
// No matching view
if (problemReporters.length > 1) {
let position = "";
if (path != '') {
position = ' at ' + path;
}
problemReport.report(ProblemLevels.ERROR, `No matching view in ${placing} body${position}`, endpoint.controller, endpoint.method);
}
problemReporters.forEach(r => {
r.getRawProblems().forEach(problem => {
problemReport.getRawProblems().push(problem);
});
});
}
} else if (producerSchema.type == SchemaTypes.ARRAY) {
let producerItems = producerSchema.items;
let clientItems = clientSchema.items;
checkSchema(endpoint, clientItems, producerItems, clientProject, producerProject, problemReport, path + (path == '' ? '' : '.') + "0", placing);
}
}
} else {
if (producerSchema.required) {
problemReport.report(ProblemLevels.ERROR, `Missing required property '${path}' in ${placing} body`, endpoint.controller, endpoint.method);
}
}
}
}
示例5:
clientParams.forEach(clientParam => {
if (producerParam.name == clientParam.name && producerParam.in == clientParam.in) {
exists = true;
if (!matchType(producerParam, clientParam)) {
problemReport.report(ProblemLevels.WARNING, "Type mismatches query parameter '" + producerParam.name + "', expected: '" + producerParam.type + "', found: '" + clientParam.type + "'", clientEndpoint.controller, clientEndpoint.method);
}
return true;
}
return false;
});