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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## 0.1.12 Released on 2018-05-19.

* Added support for readme tags.

## 0.1.11 Released on 2018-05-14

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Options:
-j, --inJson A boolean flag indicating whether output format of the
messages is json. [boolean] [default: true]
-h, --help Show help [boolean]
-o, --oldTagName The tag name for the old specification file. If include it
indicates that the old spec file is a readme file
-n, --newTagName The tag name for the new specification file. If include it
indicates that the new spec file is a readme file
```

## Build dependencies
Expand Down
Empty file modified cli.js
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var utils = require('./lib/util/utils');
// Easy to use methods from validate.js
exports.log = require('./lib/util/logging');
exports.compare = validate.compare;
exports.compareTags = validate.compareTags;

// Classes
exports.OpenApiDiff = require('./lib/validators/openApiDiff');
Expand Down
59 changes: 44 additions & 15 deletions lib/commands/oad.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,67 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

'use strict';
const log = require('../util/logging'),
validate = require('../validate');
"use strict";
const log = require("../util/logging"),
validate = require("../validate");

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

exports.describe = 'Compares old and new open api specification for breaking changes.';
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.',
alias: "inJson",
describe:
"A boolean flag indicating whether output format of the messages is json.",
boolean: true,
default: true
},
o: {
alias: "oldTagName",
describe:
"The tag name for the old specification file. If included it indicates that the old spec file is a readme file"
},
n: {
alias: "newTagName",
describe:
"The tag name for the new specification file. If included it indicates that the new spec file is a readme file"
}
};

exports.handler = function (argv) {
exports.handler = function(argv) {
log.debug(argv);
let oldSpec = argv.oldSpec;
let oldTag = argv.o;
let newSpec = argv.newSpec;
let newTag = argv.n;
let vOptions = {};
vOptions.consoleLogLevel = argv.logLevel;
vOptions.logFilepath = argv.f;
vOptions.json = argv.j;

return validate.compare(oldSpec, newSpec, vOptions).then((result) => {
console.log(result);
}).catch(err => {
console.log(err);
process.exitCode = 1;
});
}
let compareFunc;
if (oldTag && newTag) {
compareFunc = validate.compareTags(
oldSpec,
oldTag,
newSpec,
newTag,
vOptions
);
} else {
compareFunc = validate.compare(oldSpec, newSpec, vOptions);
}

return compareFunc
.then(result => {
console.log(result);
})
.catch(err => {
console.log(err);
process.exitCode = 1;
});
};

exports = module.exports;
30 changes: 29 additions & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exports = module.exports;
* @param {boolean} [options.matchApiVersion] A boolean flag indicating whether to consider api-version while comparing.
*
*/
exports.compare = function compare(oldSwagger, newSwagger, options) {
exports.compare = function (oldSwagger, newSwagger, options) {
if (!options) options = {};

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

return openApiDiff.compare(oldSwagger, newSwagger);
};

/**
* Wrapper method to compares old and new specifications.
*
* @param {string} oldSwagger Path to the old specification file.
*
* @param {string} oldTag Tag name used for autorest with the old specification file.
*
* @param {string} newSwagger Path to the new specification file.
*
* @param {string} newTagName Tag name used for autorest with the new specification file.
*
* @param {object} options The configuration options.
*
* @param {boolean} [options.json] A boolean flag indicating whether output format of the messages is json.
*
* @param {boolean} [options.matchApiVersion] A boolean flag indicating whether to consider api-version while comparing.
*
*/
exports.compareTags = function (oldSwagger, oldTag, newSwagger, newTag, options) {
if (!options) options = {};

log.consoleLogLevel = options.consoleLogLevel || log.consoleLogLevel;
log.filepath = options.logFilepath || log.filepath;
let openApiDiff = new OpenApiDiff(options);

return openApiDiff.compare(oldSwagger, newSwagger, oldTag, newTag);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this will always be a Readme, maybe we can name it something like oldReadme newReadme

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets look at this in a subsequent checkin.

};
18 changes: 13 additions & 5 deletions lib/validators/openApiDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ class OpenApiDiff {
*
* @param {string} newSwagger Path to the new specification file.
*
* @param {string} oldTag Tag name used for autorest with the old specification file.
*
* @param {string} newTag Tag name used for autorest with the new specification file.
*
*/
compare(oldSwagger, newSwagger) {
compare(oldSwagger, newSwagger, oldTag, newTag) {
log.silly(`compare is being called`);

let self = this;
var promise1 = self.processViaAutoRest(oldSwagger, 'old');
var promise2 = self.processViaAutoRest(newSwagger, 'new');
var promise1 = self.processViaAutoRest(oldSwagger, 'old', oldTag);
var promise2 = self.processViaAutoRest(newSwagger, 'new', newTag);

return Promise.all([promise1, promise2]).then(results => {
return self.processViaOpenApiDiff(results[0], results[1]);
Expand Down Expand Up @@ -118,8 +122,10 @@ class OpenApiDiff {
*
* @param {string} outputFileName Name of the output file to which autorest outputs swagger-doc.
*
Copy link

@vladbarosan vladbarosan May 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comment for new param

Copy link
Contributor Author

@alvadb alvadb May 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done #Closed

* @param {string} tagName Name of the tag in the specification file.
*
*/
processViaAutoRest(swaggerPath, outputFileName) {
processViaAutoRest(swaggerPath, outputFileName, tagName) {
log.silly(`processViaAutoRest is being called`);

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public override IEnumerable<ComparisonMessage> Compare(ComparisonContext context
if (previousDefinition == null)
throw new ArgumentException("Comparing a service definition with something else.");

if (Info != null && previousDefinition.Info != null)
if (Info?.Version != null &&
previousDefinition.Info?.Version != null)
{
context.PushProperty("info");
context.PushProperty("version");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oad",
"version": "0.1.11",
"version": "0.1.12",
"author": {
"name": "Microsoft Corporation",
"email": "azsdkteam@microsoft.com",
Expand Down