Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding semantic and model validator to CI #910

Merged
merged 3 commits into from
Feb 6, 2017
Merged

Conversation

amarzavery
Copy link
Contributor

@amarzavery amarzavery commented Feb 5, 2017

  • Refactored common code to util/utils.js
  • Added semantic mode with PR_ONLY false/true
  • Added semantic mode to allowed failures
  • Upgraded the version of node.js to 6.x
  • modified package.json to accurately reflect the devDependencies
  • added support for running CI in custom branch when a PR is sent to that branch

Copy link
Contributor

@vishrutshah vishrutshah left a comment

Choose a reason for hiding this comment

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

Overall, changes looks good. I just left few question to understand it :)

package.json Outdated
"devDependencies": {
"mocha": "*"
"z-schema": "^3.16.1",
"openapi-validation-tools": "amarzavery/openapi-validation-tools#sway4"
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious: Why are we using amarzavery fork of openapi-validation-tools of sway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will update to azure/openapi-validation-tools#master pretty soon.

@@ -31,4 +30,4 @@
"scripts": {
"test": "mocha -t 500000"
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: I am not sure what is the general rule for line ending in JavaScript world?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no rule as such.

}
var _ = require('lodash'),
execSync = require('child_process').execSync,
utils = require('./util/utils');
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. Thanks for refactoring the code into utils 👍

test/semantic.js Outdated
utils = require('./util/utils'),
oav = require('openapi-validation-tools');

describe('Azure swagger semantic validation:', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: (Nit-pick) two spaces between semantic & validation: instead of one.

test/semantic.js Outdated
let swaggersToProcess = utils.getFilesChangedInPR();
_(swaggersToProcess).each(function (swagger) {
it(swagger + ' should be semantically valid.', function (done) {
oav.validateSpec(swagger, false, 'error').catch(function (err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

curious: What is the second parameter in validateSpec function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The second parameter is whether you want a detailed json output or not. I have put this to false as I dont want the CI logs to be lengthy.

test/test.js Outdated
var error = context.validator.getLastErrors();
throw new Error("Schema validation for Composite Swagger failed: " + util.inspect(error, { depth: null }));
}
assert(valid === true);
Copy link
Contributor

Choose a reason for hiding this comment

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

What are the possible values of valid? I am asking because i was thinking whether we can remove this line or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

valid will always be a boolean value. That is returned from validation using z-schema validator package. We would want to fail the CI if swagger spec is not a valid swagger spec. Hence the assert statement.

test/test.js Outdated
done();
describe('Azure x-ms-example schema validation:', function () {
_(utils.examples).each(function (example) {
it('x-ms-examples: ' + example + ' should be a valid x-ms-example.', function (done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

x-ms-examples?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is schema validation for x-ms-examples. This will run only if x-ms-examples is present.

exampleSchema: exampleSchemaBody,
compositeSchema: compositeSchemaBody
};
let validator = new z({ breakOnFirstError: false });
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious: Newbie here :) What is new z?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

z is the z-schema package that we depend on for validating a json document against a given schema.

Top of the file should have a variable named z defined.

@amarzavery amarzavery changed the title Adding semantic validator to CI Adding semantic and model validator to CI Feb 6, 2017
@amarzavery amarzavery dismissed vishrutshah’s stale review February 6, 2017 19:47

have made all the changes

@amarzavery amarzavery removed the request for review from veronicagg February 6, 2017 19:47
Copy link
Contributor Author

@amarzavery amarzavery left a comment

Choose a reason for hiding this comment

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

fixed as per feedback

@amarzavery
Copy link
Contributor Author

@vishrutshah - Please review and merge :).

Copy link
Contributor

@vishrutshah vishrutshah left a comment

Choose a reason for hiding this comment

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

LGTM!

@vishrutshah vishrutshah merged commit 2940a1c into Azure:master Feb 6, 2017
@AutorestCI
Copy link

No modification for Ruby

@AutorestCI
Copy link

No modification for Python

@AutorestCI
Copy link

No modification for NodeJS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants