Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/commands/oad.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,24 @@
const log = require('../util/logging'),
validate = require('../validate');

exports.command = 'oad <old-spec> <new-spec>';
exports.command = 'compare <old-spec> <new-spec>';

exports.describe = 'Detects breaking changes between old and new open api specification.';
exports.describe = 'Compares old and new open api specification for breaking changes.';

exports.builder = {
j: {
alias: 'inJson',
describe: 'A boolean flag indicating whether output format of the messages is json.',
boolean: true,
default: true
},
m: {
alias: 'matchApiVersion',
describe: 'considers api-version matches while detection.',
boolean: true,
default: false
}
};

exports.handler = function (argv) {
log.debug(argv);
Expand All @@ -16,6 +31,7 @@ exports.handler = function (argv) {
let vOptions = {};
vOptions.consoleLogLevel = argv.logLevel;
vOptions.logFilepath = argv.f;
vOptions.json = argv.j;

return validate.detectChanges(oldSpec, newSpec, vOptions);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ exports.detectChanges = function detectChanges(oldSpec, newSpec, options) {
if (!options) options = {};
log.consoleLogLevel = options.consoleLogLevel || log.consoleLogLevel;
log.filepath = options.logFilepath || log.filepath;
let openApiDiff = new OpenApiDiff();
return openApiDiff.detectChanges(oldSpec, newSpec, options);
let openApiDiff = new OpenApiDiff(options);
return openApiDiff.detectChanges(oldSpec, newSpec);
};
31 changes: 22 additions & 9 deletions lib/validators/openApiDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ const util = require('util'),
*/
class OpenApiDiff {

constructor() {
constructor(options) {
log.silly(`Initializaing OpenApiDiff`);
}
this.options = options;

/**
* Initializes the Open API Diff class.
*/
initialize() {
if (this.options === null || this.options === undefined) {
this.options = {};
this.options.json = true;
this.options.matchApiVersion = false;
}
if (typeof this.options !== 'object') {
throw new Error('options must be of type "object".');
}
}

detectChanges(oldSwagger, newSwagger, options) {
detectChanges(oldSwagger, newSwagger) {
let self = this;
log.debug(`Hello World`);

Expand Down Expand Up @@ -69,6 +73,10 @@ class OpenApiDiff {
return "dotnet";
}

autoRestPath() {
return path.join(__dirname, "..", "..", "node_modules", "autorest", "app.js");
}

openApiDiffDll() {
// try global installation directory
let result = path.join(__dirname, "..", "dlls", "OpenApiDiff.dll");
Expand All @@ -78,6 +86,7 @@ class OpenApiDiff {
}

processViaAutoRest(swaggerPath, outputFileName) {
let self = this;
if (swaggerPath === null || swaggerPath === undefined || typeof swaggerPath.valueOf() !== 'string' || !swaggerPath.trim().length) {
throw new Error('swaggerPath is a required parameter of type "string" and it cannot be an empty string.');
}
Expand All @@ -96,7 +105,7 @@ class OpenApiDiff {

let outputFolder = os.tmpdir();
let outputFilePath = path.join(outputFolder, `${outputFileName}.json`);
let autoRestCmd = `autorest --input-file=${swaggerPath} --output-artifact=swagger-document.json --output-file=${outputFileName} --output-folder=${outputFolder}`;
let autoRestCmd = `node ${self.autoRestPath()} --input-file=${swaggerPath} --output-artifact=swagger-document.json --output-file=${outputFileName} --output-folder=${outputFolder}`;

log.debug(`Executing: "${autoRestCmd}"`);
exec(autoRestCmd, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 64 }, (err, stdout, stderr) => {
Expand Down Expand Up @@ -135,7 +144,11 @@ class OpenApiDiff {
reject(`File "${newSwagger}" not found.`);
}

let cmd = `${self.dotNetPath()} ${self.openApiDiffDll()} -o ${oldSwagger} -n ${newSwagger} -JsonValidationMessages`;
let cmd = `${self.dotNetPath()} ${self.openApiDiffDll()} -o ${oldSwagger} -n ${newSwagger}`;
if (self.options.json)
{
cmd = `${cmd} -JsonValidationMessages`;
}

log.debug(`Executing: "${cmd}"`);
exec(cmd, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 64 }, (err, stdout, stderr) => {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"bin": { "oad": "./cli.js" },
"scripts": {
"jshint": "jshint index.js --reporter=jslint",
"test": "npm -s run-script jshint && mocha -t 50000",
"postinstall": "node ./lib/scripts/postInstall.js"
"test": "npm -s run-script jshint && mocha -t 50000"
}
}