-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Azure/fix/resources
Add Swagger validation and travis support and fix Resource references
- Loading branch information
Showing
8 changed files
with
116 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,3 +58,5 @@ Icon | |
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- "0.12" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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://raw.githubusercontent.com/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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |