Skip to content

Commit 6a62de5

Browse files
author
Vlad Barosan
authored
Merge pull request #115 from alvadb/master
Add readme tag support
2 parents 720b650 + a3db030 commit 6a62de5

File tree

9 files changed

+97
-23
lines changed

9 files changed

+97
-23
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
2+
## 0.1.12 Released on 2018-05-19.
3+
4+
* Added support for readme tags.
25

36
## 0.1.11 Released on 2018-05-14
47

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Options:
2323
-j, --inJson A boolean flag indicating whether output format of the
2424
messages is json. [boolean] [default: true]
2525
-h, --help Show help [boolean]
26+
-o, --oldTagName The tag name for the old specification file. If include it
27+
indicates that the old spec file is a readme file
28+
-n, --newTagName The tag name for the new specification file. If include it
29+
indicates that the new spec file is a readme file
2630
```
2731

2832
## Build dependencies

cli.js

100644100755
File mode changed.

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var utils = require('./lib/util/utils');
99
// Easy to use methods from validate.js
1010
exports.log = require('./lib/util/logging');
1111
exports.compare = validate.compare;
12+
exports.compareTags = validate.compareTags;
1213

1314
// Classes
1415
exports.OpenApiDiff = require('./lib/validators/openApiDiff');

lib/commands/oad.js

+44-15
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,67 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
'use strict';
5-
const log = require('../util/logging'),
6-
validate = require('../validate');
4+
"use strict";
5+
const log = require("../util/logging"),
6+
validate = require("../validate");
77

8-
exports.command = 'compare <old-spec> <new-spec>';
8+
exports.command = "compare <old-spec> <new-spec>";
99

10-
exports.describe = 'Compares old and new open api specification for breaking changes.';
10+
exports.describe =
11+
"Compares old and new open api specification for breaking changes.";
1112

1213
exports.builder = {
1314
j: {
14-
alias: 'inJson',
15-
describe: 'A boolean flag indicating whether output format of the messages is json.',
15+
alias: "inJson",
16+
describe:
17+
"A boolean flag indicating whether output format of the messages is json.",
1618
boolean: true,
1719
default: true
20+
},
21+
o: {
22+
alias: "oldTagName",
23+
describe:
24+
"The tag name for the old specification file. If included it indicates that the old spec file is a readme file"
25+
},
26+
n: {
27+
alias: "newTagName",
28+
describe:
29+
"The tag name for the new specification file. If included it indicates that the new spec file is a readme file"
1830
}
1931
};
2032

21-
exports.handler = function (argv) {
33+
exports.handler = function(argv) {
2234
log.debug(argv);
2335
let oldSpec = argv.oldSpec;
36+
let oldTag = argv.o;
2437
let newSpec = argv.newSpec;
38+
let newTag = argv.n;
2539
let vOptions = {};
2640
vOptions.consoleLogLevel = argv.logLevel;
2741
vOptions.logFilepath = argv.f;
2842
vOptions.json = argv.j;
2943

30-
return validate.compare(oldSpec, newSpec, vOptions).then((result) => {
31-
console.log(result);
32-
}).catch(err => {
33-
console.log(err);
34-
process.exitCode = 1;
35-
});
36-
}
44+
let compareFunc;
45+
if (oldTag && newTag) {
46+
compareFunc = validate.compareTags(
47+
oldSpec,
48+
oldTag,
49+
newSpec,
50+
newTag,
51+
vOptions
52+
);
53+
} else {
54+
compareFunc = validate.compare(oldSpec, newSpec, vOptions);
55+
}
56+
57+
return compareFunc
58+
.then(result => {
59+
console.log(result);
60+
})
61+
.catch(err => {
62+
console.log(err);
63+
process.exitCode = 1;
64+
});
65+
};
3766

3867
exports = module.exports;

lib/validate.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ exports = module.exports;
2222
* @param {boolean} [options.matchApiVersion] A boolean flag indicating whether to consider api-version while comparing.
2323
*
2424
*/
25-
exports.compare = function compare(oldSwagger, newSwagger, options) {
25+
exports.compare = function (oldSwagger, newSwagger, options) {
2626
if (!options) options = {};
2727

2828
log.consoleLogLevel = options.consoleLogLevel || log.consoleLogLevel;
@@ -31,3 +31,31 @@ exports.compare = function compare(oldSwagger, newSwagger, options) {
3131

3232
return openApiDiff.compare(oldSwagger, newSwagger);
3333
};
34+
35+
/**
36+
* Wrapper method to compares old and new specifications.
37+
*
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.
51+
*
52+
*/
53+
exports.compareTags = function (oldSwagger, oldTag, newSwagger, newTag, options) {
54+
if (!options) options = {};
55+
56+
log.consoleLogLevel = options.consoleLogLevel || log.consoleLogLevel;
57+
log.filepath = options.logFilepath || log.filepath;
58+
let openApiDiff = new OpenApiDiff(options);
59+
60+
return openApiDiff.compare(oldSwagger, newSwagger, oldTag, newTag);
61+
};

lib/validators/openApiDiff.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,17 @@ class OpenApiDiff {
5151
*
5252
* @param {string} newSwagger Path to the new specification file.
5353
*
54+
* @param {string} oldTag Tag name used for autorest with the old specification file.
55+
*
56+
* @param {string} newTag Tag name used for autorest with the new specification file.
57+
*
5458
*/
55-
compare(oldSwagger, newSwagger) {
59+
compare(oldSwagger, newSwagger, oldTag, newTag) {
5660
log.silly(`compare is being called`);
5761

5862
let self = this;
59-
var promise1 = self.processViaAutoRest(oldSwagger, 'old');
60-
var promise2 = self.processViaAutoRest(newSwagger, 'new');
63+
var promise1 = self.processViaAutoRest(oldSwagger, 'old', oldTag);
64+
var promise2 = self.processViaAutoRest(newSwagger, 'new', newTag);
6165

6266
return Promise.all([promise1, promise2]).then(results => {
6367
return self.processViaOpenApiDiff(results[0], results[1]);
@@ -118,8 +122,10 @@ class OpenApiDiff {
118122
*
119123
* @param {string} outputFileName Name of the output file to which autorest outputs swagger-doc.
120124
*
125+
* @param {string} tagName Name of the tag in the specification file.
126+
*
121127
*/
122-
processViaAutoRest(swaggerPath, outputFileName) {
128+
processViaAutoRest(swaggerPath, outputFileName, tagName) {
123129
log.silly(`processViaAutoRest is being called`);
124130

125131
let self = this;
@@ -141,7 +147,9 @@ class OpenApiDiff {
141147

142148
let outputFolder = os.tmpdir();
143149
let outputFilePath = path.join(outputFolder, `${outputFileName}.json`);
144-
let autoRestCmd = `${self.autoRestPath()} --input-file=${swaggerPath} --output-artifact=swagger-document.json --output-file=${outputFileName} --output-folder=${outputFolder}`;
150+
var autoRestCmd = tagName
151+
? `${self.autoRestPath()} ${swaggerPath} --tag=${tagName} --output-artifact=swagger-document.json --output-file=${outputFileName} --output-folder=${outputFolder}`
152+
: `${self.autoRestPath()} --input-file=${swaggerPath} --output-artifact=swagger-document.json --output-file=${outputFileName} --output-folder=${outputFolder}`;
145153

146154
log.debug(`Executing: "${autoRestCmd}"`);
147155

openapi-diff/src/modeler/AutoRest.Swagger/Model/ServiceDefinition.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ public override IEnumerable<ComparisonMessage> Compare(ComparisonContext context
124124
if (previousDefinition == null)
125125
throw new ArgumentException("Comparing a service definition with something else.");
126126

127-
if (Info != null && previousDefinition.Info != null)
127+
if (Info?.Version != null &&
128+
previousDefinition.Info?.Version != null)
128129
{
129130
context.PushProperty("info");
130131
context.PushProperty("version");

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "oad",
3-
"version": "0.1.11",
3+
"version": "0.1.12",
44
"author": {
55
"name": "Microsoft Corporation",
66
"email": "[email protected]",

0 commit comments

Comments
 (0)