Skip to content

Commit 38ceb2d

Browse files
committed
Moved tags to method call and out of options.
1 parent 932c74d commit 38ceb2d

File tree

4 files changed

+65
-24
lines changed

4 files changed

+65
-24
lines changed

cli.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ yargs
2828
describe: `Set the log file path. It must be an absolute filepath. ` +
2929
`By default the logs will stored in a timestamp based log file at "${defaultLogDir}".`
3030
})
31-
.option('o', {
32-
alias: 'oldTagName',
33-
describe: `The tag name for the old specification file. If include it ` +
34-
`indicates that the old spec file is a readme file`
35-
})
36-
.option('n', {
37-
alias: 'newTagName',
38-
describe: `The tag name for the new specification file. If include it ` +
39-
`indicates that the new spec file is a readme file`
40-
})
4131
.global(['h', 'l', 'f'])
4232
.help()
4333
.argv;

lib/commands/oad.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,22 @@ exports.builder = {
2929
exports.handler = function (argv) {
3030
log.debug(argv);
3131
let oldSpec = argv.oldSpec;
32+
let oldTag = argv.o;
3233
let newSpec = argv.newSpec;
34+
let newTag = argv.n;
3335
let vOptions = {};
3436
vOptions.consoleLogLevel = argv.logLevel;
3537
vOptions.logFilepath = argv.f;
3638
vOptions.json = argv.j;
37-
vOptions.oldTagName = argv.o;
38-
vOptions.newTagName = argv.n;
39-
40-
return validate.compare(oldSpec, newSpec, vOptions).then((result) => {
39+
40+
let compareFunc;
41+
if(oldTag && newTag) {
42+
compareFunc = validate.compareTags(oldSpec, oldTag, oldSpec, newTag, vOptions);
43+
}else {
44+
compareFunc = validate.compare(oldSpec, newSpec, vOptions);
45+
}
46+
47+
return compareFunc.then((result) => {
4148
console.log(result);
4249
}).catch(err => {
4350
console.log(err);

lib/validate.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,41 @@ exports = module.exports;
2121
*
2222
* @param {boolean} [options.matchApiVersion] A boolean flag indicating whether to consider api-version while comparing.
2323
*
24-
* @param {string} [options.oldTagName] Tag name used for autorest with the old specification file.
24+
*/
25+
exports.compare = function (oldSwagger, newSwagger, options) {
26+
if (!options) options = {};
27+
28+
log.consoleLogLevel = options.consoleLogLevel || log.consoleLogLevel;
29+
log.filepath = options.logFilepath || log.filepath;
30+
let openApiDiff = new OpenApiDiff(options);
31+
32+
return openApiDiff.compare(oldSwagger, newSwagger);
33+
};
34+
35+
/**
36+
* Wrapper method to compares old and new specifications.
2537
*
26-
* @param {string} [options.newTagName] Tag name used for autorest with the new specification file.
38+
* @param {string} oldSwagger Path to the old specification file.
39+
*
40+
* @param {string} oldTag Tag name used for autorest with the old specification file.
41+
*
42+
* @param {string} newSwagger Path to the new specification file.
43+
*
44+
* @param {string} newTagName Tag name used for autorest with the new specification file.
45+
*
46+
* @param {object} options The configuration options.
47+
*
48+
* @param {boolean} [options.json] A boolean flag indicating whether output format of the messages is json.
49+
*
50+
* @param {boolean} [options.matchApiVersion] A boolean flag indicating whether to consider api-version while comparing.
2751
*
2852
*/
29-
exports.compare = function compare(oldSwagger, newSwagger, options) {
53+
exports.compareTags = function (oldSwagger, oldTag, newSwagger, newTag, options) {
3054
if (!options) options = {};
3155

3256
log.consoleLogLevel = options.consoleLogLevel || log.consoleLogLevel;
3357
log.filepath = options.logFilepath || log.filepath;
3458
let openApiDiff = new OpenApiDiff(options);
3559

36-
return openApiDiff.compare(oldSwagger, newSwagger);
60+
return openApiDiff.compareTags(oldSwagger, oldTag, newSwagger, newTag);
3761
};

lib/validators/openApiDiff.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ class OpenApiDiff {
2727
*
2828
* @param {boolean} [options.matchApiVersion] A boolean flag indicating whether to consider api-version while comparing.
2929
*
30-
* @param {string} [options.oldTagName] Tag name used for autorest with the old specification file.
31-
*
32-
* @param {string} [options.newTagName] Tag name used for autorest with the new specification file.
33-
*
3430
* @returns {object} OpenApiDiff Returns the configured OpenApiDiff object.
3531
*/
3632
constructor(options) {
@@ -60,8 +56,32 @@ class OpenApiDiff {
6056
log.silly(`compare is being called`);
6157

6258
let self = this;
63-
var promise1 = self.processViaAutoRest(oldSwagger, 'old', self.options.oldTagName);
64-
var promise2 = self.processViaAutoRest(newSwagger, 'new', self.options.newTagName);
59+
var promise1 = self.processViaAutoRest(oldSwagger, 'old');
60+
var promise2 = self.processViaAutoRest(newSwagger, 'new');
61+
62+
return Promise.all([promise1, promise2]).then(results => {
63+
return self.processViaOpenApiDiff(results[0], results[1]);
64+
});
65+
}
66+
67+
/**
68+
* Compares old and new specifications.
69+
*
70+
* @param {string} oldSwagger Path to the old specification file.
71+
*
72+
* @param {string} [oldTag] Tag name used for autorest with the old specification file.
73+
*
74+
* @param {string} newSwagger Path to the new specification file.
75+
*
76+
* @param {string} [newTag] Tag name used for autorest with the new specification file.
77+
*
78+
*/
79+
compareTags(oldSwagger, oldTag, newSwagger, newTag) {
80+
log.silly(`compare is being called`);
81+
82+
let self = this;
83+
var promise1 = self.processViaAutoRest(oldSwagger, 'old', oldTag);
84+
var promise2 = self.processViaAutoRest(newSwagger, 'new', newTag);
6585

6686
return Promise.all([promise1, promise2]).then(results => {
6787
return self.processViaOpenApiDiff(results[0], results[1]);

0 commit comments

Comments
 (0)