openapi-diff
Version:
A CLI tool to identify differences between Swagger/OpenAPI specs.
39 lines (38 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResultReporter = void 0;
class ResultReporter {
constructor(consoleLogger) {
this.consoleLogger = consoleLogger;
}
static hasDifferences(outcome) {
return outcome.nonBreakingDifferences.length + outcome.unclassifiedDifferences.length > 0;
}
static outcomeToString(outcome) {
return JSON.stringify(outcome, null, 4);
}
reportError(error) {
this.consoleLogger.error(error);
}
reportOutcome(outcome) {
if (outcome.breakingDifferencesFound) {
this.reportFailure(outcome);
}
else if (ResultReporter.hasDifferences(outcome)) {
this.reportSuccessWithDifferences(outcome);
}
else {
this.reportNoChangesFound();
}
}
reportFailure(outcome) {
this.consoleLogger.info(`Breaking changes found between the two specifications:\n${ResultReporter.outcomeToString(outcome)}`);
}
reportSuccessWithDifferences(outcome) {
this.consoleLogger.info(`Non breaking changes found between the two specifications:\n${ResultReporter.outcomeToString(outcome)}`);
}
reportNoChangesFound() {
this.consoleLogger.info('No changes found between the two specifications');
}
}
exports.ResultReporter = ResultReporter;