diff --git a/README.md b/README.md index bf05d37..ceefb51 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,26 @@ Options: I created this schema generator to validate JSON responses from APIs. As the JSON API is enhanced and nodes are added or removed from the response, the schema is regenerated and validated against the newly deployed API. ### Tests -Install [mocha](https://github.com/mochajs/mocha) globally (as cli) and run `npm test`. +To run tests, including fetching documents via HTTP, we've added [node-stubby-server-cli](https://github.com/krg7880/node-stubby-server-cli) to help with serving mock data. The ports for the stub server is defined under *test/helpers/stubby-cli*, in the event the default port is in use, you can change them there. + +```bash +npm install -g stubby +``` + +Install [mocha](https://github.com/mochajs/mocha) globally (as cli) and run + +```bash +npm test +``` ### Validating Documents JSON documents can be validated against schemas using [chai-json-schema](http://chaijs.com/plugins/chai-json-schema). See the tests under [test](https://github.com/krg7880/json-schema-generator/tree/master/test) for example usage. + +### Contributors +Thanks to those who have contributed. These kind folks are listed below: + +* [nickyout](https://github.com/nickyout) +* [Edward Silverton](https://github.com/edsilv) +* [Tschef](https://github.com/Tschef) + + diff --git a/bin/cli.js b/bin/cli.js index 2ed716d..726eb7f 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,4 +1,7 @@ #!/usr/bin/env node + +console.log('Node'); + var url = require('url'), path = require('path'), cliConsole = require('../lib/cli/console'), @@ -166,6 +169,7 @@ handleInput(config.src, function(jsonString) { handleOutput(config.dest, jsonSchemaString); }) .catch(function(e) { + console.log(e); errorHandler(e.toString('utf8')); }); }); diff --git a/doc/README.md b/doc/README.md index ccb035d..3680d68 100644 --- a/doc/README.md +++ b/doc/README.md @@ -40,7 +40,7 @@ equal. * **Object** -## buildPrimative(tree, node) +## buildPrimitive(tree, node) Inspect primitatives and apply the correct type and mark as required if the element contains a value. @@ -52,7 +52,7 @@ and mark as required if the element contains a value. ### Return: -* **void** +* void ## buildObject(tree, node) @@ -87,7 +87,7 @@ given JSON document. ### Return: -* **void** +* void @@ -113,7 +113,7 @@ Generates a JSON schema based on the provided AST tree. ### Return: -* **void** +* void ## compile(tree) @@ -126,7 +126,7 @@ JSON schema. ### Return: -* **void** +* void @@ -135,96 +135,6 @@ JSON schema. -## jsondir - -Specify a directory where a remote -JSON will be stored after downloading -the resource. - -CLI Flag ---jsondir - -## schemadir - -Specify a directory where the generated -schema will be stored. - -CLI Flag ---schemadir - -## file - -Specify a local JSON document that is -used to generate the schema. - -CLI Flag ---file - -## url - -Specfiy a remote JSON document to fetch -and generate it's schema. - -CLI Flag ---url - -## fetchResource(url) - -Fetches a remote JSON document and generate -the schema based on the contents of the remote -resource. If an output directory is specified, -the document will be saved locally. - -### Params: - -* **String** *url* The location of the remote resource - -### Return: - -* **void** - -## readFile(filepath) - -Reads the specified JSON file from the -filesystem which is used to generate -the schema. - -### Params: - -* **String** *filepath* Path to JSON document to load. - -### Return: - -* **void** - -## writeFile(contents, file) - -Writes the given data to the specified -file location. - -### Params: - -* **String** *contents* The data to write to the FS -* **String** *file* The file to write the data to - -### Return: - -* **void** - -## getName(str) - -Get the name of the JSON resource so the schema -matches the source. The .json extension is added -if it's missing from the filename. - -### Params: - -* **String** *str* File name - -### Return: - -* **String** The name of the file only. - diff --git a/gulpfile.js b/gulpfile.js index 1e51480..fea6345 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,6 +1,45 @@ var markdox = require("gulp-markdox"); var gulp = require('gulp'); +var mocha = require('gulp-mocha'); var concat = require("gulp-concat"); +var Stubby = require('node-stubby-server-cli').CLI; +var Events = Stubby.Events; +var path = require('path'); +var stubbyHelper = require(path.normalize(__dirname + '/test/helpers/stubby-cli')); + + + +gulp.task('start:stubby', function(next) { + var cli = new Stubby(); + cli.admin(stubbyHelper.ports.admin) + .stubs(stubbyHelper.ports.stubs) + .tls(stubbyHelper.ports.tls) + .data(path.normalize(__dirname + '/test/fixtures/stubby/routes.json')) + .unmute() + + cli.once('LISTENING', function() { + next(); + }).start(); +}); + + +gulp.task('test', ['start:stubby'], function() { + return gulp.src('test/**/*-test.js') + .pipe(mocha({reporter: 'nyan'})) + .once('error', function(e) { + process.exit(1); + }) + .once('end', function() { + process.exit(0) + }); +}); + + +gulp.task('stop:stubby', ['test'], function(next) { + cli.kill(); + next(); +}); + gulp.task("doc", function(){ gulp.src("./lib/*.js") @@ -9,4 +48,11 @@ gulp.task("doc", function(){ .pipe(gulp.dest("./doc")); }); -gulp.task('default', ['doc']); \ No newline at end of file + +// Default tasks to run +gulp.task('default', [ + 'start:stubby', + 'test', + 'stop:stubby', + 'doc' +]); \ No newline at end of file diff --git a/index.js b/index.js index dddd052..144ec7f 100644 --- a/index.js +++ b/index.js @@ -1 +1 @@ -require('./lib/index'); \ No newline at end of file +module.exports = require('./lib/index'); \ No newline at end of file diff --git a/lib/ast.js b/lib/ast.js index ea83ff1..4ce1dfa 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -34,7 +34,7 @@ AST.prototype.generateHash = function(value) { if (utils.isObject(value)) { var keys = Object.keys(value); return crypto.createHash("md5").update(JSON.stringify(keys)).digest("hex"); - } else if (utils.Array(value)) { + } else if (utils.isArray(value)) { return crypto.createHash("md5").update(JSON.stringify(value)).digest("hex"); } else { return crypto.createHash("md5").update(value).digest("hex"); @@ -152,7 +152,7 @@ AST.prototype.buildArrayTree = function(tree, node) { if (node[i].length > 0) { tree.children[i].required = true; } - tree.buildArrayTree(tree.children[i], node[i]); + this.buildArrayTree(tree.children[i], node[i]); } else { if (tree.type === 'object') { tree.children[i] = {}; @@ -177,4 +177,4 @@ AST.prototype.build = function(json) { } }; -module.exports = AST; \ No newline at end of file +module.exports = AST; diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index b2e8b6d..15340f5 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,240 +1,314 @@ { "name": "json-schema-generator", - "version": "1.1.16", + "version": "2.0.3", "dependencies": { + "ajv": { + "version": "5.2.3", + "from": "ajv@>=5.1.0 <6.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/ajv/-/ajv-5.2.3.tgz" + }, + "asn1": { + "version": "0.2.3", + "from": "asn1@>=0.2.3 <0.3.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/asn1/-/asn1-0.2.3.tgz" + }, + "assert-plus": { + "version": "1.0.0", + "from": "assert-plus@>=1.0.0 <2.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/assert-plus/-/assert-plus-1.0.0.tgz" + }, + "asynckit": { + "version": "0.4.0", + "from": "asynckit@>=0.4.0 <0.5.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/asynckit/-/asynckit-0.4.0.tgz" + }, + "aws-sign2": { + "version": "0.7.0", + "from": "aws-sign2@>=0.7.0 <0.8.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/aws-sign2/-/aws-sign2-0.7.0.tgz" + }, + "aws4": { + "version": "1.6.0", + "from": "aws4@>=1.6.0 <2.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/aws4/-/aws4-1.6.0.tgz" + }, + "bcrypt-pbkdf": { + "version": "1.0.1", + "from": "bcrypt-pbkdf@>=1.0.0 <2.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", + "optional": true + }, + "boom": { + "version": "4.3.1", + "from": "boom@>=4.0.0 <5.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/boom/-/boom-4.3.1.tgz" + }, + "caseless": { + "version": "0.12.0", + "from": "caseless@>=0.12.0 <0.13.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/caseless/-/caseless-0.12.0.tgz" + }, + "co": { + "version": "4.6.0", + "from": "co@>=4.6.0 <5.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/co/-/co-4.6.0.tgz" + }, + "combined-stream": { + "version": "1.0.5", + "from": "combined-stream@>=1.0.5 <1.1.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/combined-stream/-/combined-stream-1.0.5.tgz" + }, + "core-util-is": { + "version": "1.0.2", + "from": "core-util-is@1.0.2", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/core-util-is/-/core-util-is-1.0.2.tgz" + }, + "cryptiles": { + "version": "3.1.2", + "from": "cryptiles@>=3.0.0 <4.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/cryptiles/-/cryptiles-3.1.2.tgz", + "dependencies": { + "boom": { + "version": "5.2.0", + "from": "boom@>=5.0.0 <6.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/boom/-/boom-5.2.0.tgz" + } + } + }, + "dashdash": { + "version": "1.14.1", + "from": "dashdash@>=1.12.0 <2.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/dashdash/-/dashdash-1.14.1.tgz" + }, + "delayed-stream": { + "version": "1.0.0", + "from": "delayed-stream@>=1.0.0 <1.1.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/delayed-stream/-/delayed-stream-1.0.0.tgz" + }, + "ecc-jsbn": { + "version": "0.1.1", + "from": "ecc-jsbn@>=0.1.1 <0.2.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", + "optional": true + }, + "extend": { + "version": "3.0.1", + "from": "extend@>=3.0.1 <3.1.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/extend/-/extend-3.0.1.tgz" + }, + "extsprintf": { + "version": "1.3.0", + "from": "extsprintf@1.3.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/extsprintf/-/extsprintf-1.3.0.tgz" + }, + "fast-deep-equal": { + "version": "1.0.0", + "from": "fast-deep-equal@>=1.0.0 <2.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz" + }, + "forever-agent": { + "version": "0.6.1", + "from": "forever-agent@>=0.6.1 <0.7.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/forever-agent/-/forever-agent-0.6.1.tgz" + }, + "form-data": { + "version": "2.3.1", + "from": "form-data@>=2.3.1 <2.4.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/form-data/-/form-data-2.3.1.tgz" + }, + "getpass": { + "version": "0.1.7", + "from": "getpass@>=0.1.1 <0.2.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/getpass/-/getpass-0.1.7.tgz" + }, + "har-schema": { + "version": "2.0.0", + "from": "har-schema@>=2.0.0 <3.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/har-schema/-/har-schema-2.0.0.tgz" + }, + "har-validator": { + "version": "5.0.3", + "from": "har-validator@>=5.0.3 <5.1.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/har-validator/-/har-validator-5.0.3.tgz" + }, + "hawk": { + "version": "6.0.2", + "from": "hawk@>=6.0.2 <6.1.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/hawk/-/hawk-6.0.2.tgz" + }, + "hoek": { + "version": "4.2.0", + "from": "hoek@>=4.0.0 <5.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/hoek/-/hoek-4.2.0.tgz" + }, + "http-signature": { + "version": "1.2.0", + "from": "http-signature@>=1.2.0 <1.3.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/http-signature/-/http-signature-1.2.0.tgz" + }, + "is-typedarray": { + "version": "1.0.0", + "from": "is-typedarray@>=1.0.0 <1.1.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/is-typedarray/-/is-typedarray-1.0.0.tgz" + }, + "isstream": { + "version": "0.1.2", + "from": "isstream@>=0.1.2 <0.2.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/isstream/-/isstream-0.1.2.tgz" + }, + "jsbn": { + "version": "0.1.1", + "from": "jsbn@>=0.1.0 <0.2.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/jsbn/-/jsbn-0.1.1.tgz", + "optional": true + }, "json-promise": { "version": "1.1.8", - "from": "http://registry.npmjs.org/json-promise/-/json-promise-1.1.8.tgz", + "from": "json-promise@>=1.1.8 <2.0.0", "resolved": "http://registry.npmjs.org/json-promise/-/json-promise-1.1.8.tgz", "dependencies": { "bluebird": { "version": "2.2.2", - "from": "http://registry.npmjs.org/bluebird/-/bluebird-2.2.2.tgz", + "from": "bluebird@2.2.2", "resolved": "http://registry.npmjs.org/bluebird/-/bluebird-2.2.2.tgz" } } }, + "json-schema": { + "version": "0.2.3", + "from": "json-schema@0.2.3", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/json-schema/-/json-schema-0.2.3.tgz" + }, + "json-schema-traverse": { + "version": "0.3.1", + "from": "json-schema-traverse@>=0.3.0 <0.4.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz" + }, + "json-stable-stringify": { + "version": "1.0.1", + "from": "json-stable-stringify@>=1.0.1 <2.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz" + }, + "json-stringify-safe": { + "version": "5.0.1", + "from": "json-stringify-safe@>=5.0.1 <5.1.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz" + }, + "jsonify": { + "version": "0.0.0", + "from": "jsonify@>=0.0.0 <0.1.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/jsonify/-/jsonify-0.0.0.tgz" + }, + "jsprim": { + "version": "1.4.1", + "from": "jsprim@>=1.2.2 <2.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/jsprim/-/jsprim-1.4.1.tgz" + }, + "mime-db": { + "version": "1.30.0", + "from": "mime-db@>=1.30.0 <1.31.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/mime-db/-/mime-db-1.30.0.tgz" + }, + "mime-types": { + "version": "2.1.17", + "from": "mime-types@>=2.1.17 <2.2.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/mime-types/-/mime-types-2.1.17.tgz" + }, + "minimist": { + "version": "0.0.8", + "from": "minimist@0.0.8", + "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz" + }, "mkdirp": { - "version": "0.5.0", - "from": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz", - "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz", - "dependencies": { - "minimist": { - "version": "0.0.8", - "from": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz" - } - } + "version": "0.5.1", + "from": "mkdirp@>=0.5.0 <0.6.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/mkdirp/-/mkdirp-0.5.1.tgz" + }, + "oauth-sign": { + "version": "0.8.2", + "from": "oauth-sign@>=0.8.2 <0.9.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/oauth-sign/-/oauth-sign-0.8.2.tgz" }, "optimist": { "version": "0.6.1", - "from": "http://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", - "resolved": "http://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", - "dependencies": { - "wordwrap": { - "version": "0.0.2", - "from": "http://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz", - "resolved": "http://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz" - }, - "minimist": { - "version": "0.0.10", - "from": "http://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz" - } - } + "from": "optimist@>=0.6.1 <0.7.0", + "resolved": "http://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz" + }, + "performance-now": { + "version": "2.1.0", + "from": "performance-now@>=2.1.0 <3.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/performance-now/-/performance-now-2.1.0.tgz" }, "pretty-data": { "version": "0.40.0", - "from": "pretty-data@*", + "from": "pretty-data@>=0.40.0 <0.41.0", "resolved": "https://registry.npmjs.org/pretty-data/-/pretty-data-0.40.0.tgz" }, + "punycode": { + "version": "1.4.1", + "from": "punycode@>=1.4.1 <2.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/punycode/-/punycode-1.4.1.tgz" + }, + "qs": { + "version": "6.5.1", + "from": "qs@>=6.5.1 <6.6.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/qs/-/qs-6.5.1.tgz" + }, "request": { - "version": "2.51.0", - "from": "http://registry.npmjs.org/request/-/request-2.51.0.tgz", - "resolved": "http://registry.npmjs.org/request/-/request-2.51.0.tgz", - "dependencies": { - "bl": { - "version": "0.9.4", - "from": "http://registry.npmjs.org/bl/-/bl-0.9.4.tgz", - "resolved": "http://registry.npmjs.org/bl/-/bl-0.9.4.tgz", - "dependencies": { - "readable-stream": { - "version": "1.0.33", - "from": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.0.33.tgz", - "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.0.33.tgz", - "dependencies": { - "core-util-is": { - "version": "1.0.1", - "from": "http://registry.npmjs.org/core-util-is/-/core-util-is-1.0.1.tgz", - "resolved": "http://registry.npmjs.org/core-util-is/-/core-util-is-1.0.1.tgz" - }, - "isarray": { - "version": "0.0.1", - "from": "http://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "resolved": "http://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz" - }, - "string_decoder": { - "version": "0.10.31", - "from": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz" - }, - "inherits": { - "version": "2.0.1", - "from": "http://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz", - "resolved": "http://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz" - } - } - } - } - }, - "caseless": { - "version": "0.8.0", - "from": "http://registry.npmjs.org/caseless/-/caseless-0.8.0.tgz", - "resolved": "http://registry.npmjs.org/caseless/-/caseless-0.8.0.tgz" - }, - "forever-agent": { - "version": "0.5.2", - "from": "http://registry.npmjs.org/forever-agent/-/forever-agent-0.5.2.tgz", - "resolved": "http://registry.npmjs.org/forever-agent/-/forever-agent-0.5.2.tgz" - }, - "form-data": { - "version": "0.2.0", - "from": "http://registry.npmjs.org/form-data/-/form-data-0.2.0.tgz", - "resolved": "http://registry.npmjs.org/form-data/-/form-data-0.2.0.tgz", - "dependencies": { - "async": { - "version": "0.9.0", - "from": "http://registry.npmjs.org/async/-/async-0.9.0.tgz", - "resolved": "http://registry.npmjs.org/async/-/async-0.9.0.tgz" - }, - "mime-types": { - "version": "2.0.7", - "from": "http://registry.npmjs.org/mime-types/-/mime-types-2.0.7.tgz", - "resolved": "http://registry.npmjs.org/mime-types/-/mime-types-2.0.7.tgz", - "dependencies": { - "mime-db": { - "version": "1.5.0", - "from": "http://registry.npmjs.org/mime-db/-/mime-db-1.5.0.tgz", - "resolved": "http://registry.npmjs.org/mime-db/-/mime-db-1.5.0.tgz" - } - } - } - } - }, - "json-stringify-safe": { - "version": "5.0.0", - "from": "http://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.0.tgz", - "resolved": "http://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.0.tgz" - }, - "mime-types": { - "version": "1.0.2", - "from": "http://registry.npmjs.org/mime-types/-/mime-types-1.0.2.tgz", - "resolved": "http://registry.npmjs.org/mime-types/-/mime-types-1.0.2.tgz" - }, - "node-uuid": { - "version": "1.4.2", - "from": "http://registry.npmjs.org/node-uuid/-/node-uuid-1.4.2.tgz", - "resolved": "http://registry.npmjs.org/node-uuid/-/node-uuid-1.4.2.tgz" - }, - "qs": { - "version": "2.3.3", - "from": "http://registry.npmjs.org/qs/-/qs-2.3.3.tgz", - "resolved": "http://registry.npmjs.org/qs/-/qs-2.3.3.tgz" - }, - "tunnel-agent": { - "version": "0.4.0", - "from": "http://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.4.0.tgz", - "resolved": "http://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.4.0.tgz" - }, - "tough-cookie": { - "version": "0.12.1", - "from": "http://registry.npmjs.org/tough-cookie/-/tough-cookie-0.12.1.tgz", - "resolved": "http://registry.npmjs.org/tough-cookie/-/tough-cookie-0.12.1.tgz", - "dependencies": { - "punycode": { - "version": "1.3.2", - "from": "http://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz", - "resolved": "http://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz" - } - } - }, - "http-signature": { - "version": "0.10.1", - "from": "http://registry.npmjs.org/http-signature/-/http-signature-0.10.1.tgz", - "resolved": "http://registry.npmjs.org/http-signature/-/http-signature-0.10.1.tgz", - "dependencies": { - "assert-plus": { - "version": "0.1.5", - "from": "http://registry.npmjs.org/assert-plus/-/assert-plus-0.1.5.tgz", - "resolved": "http://registry.npmjs.org/assert-plus/-/assert-plus-0.1.5.tgz" - }, - "asn1": { - "version": "0.1.11", - "from": "http://registry.npmjs.org/asn1/-/asn1-0.1.11.tgz", - "resolved": "http://registry.npmjs.org/asn1/-/asn1-0.1.11.tgz" - }, - "ctype": { - "version": "0.5.3", - "from": "http://registry.npmjs.org/ctype/-/ctype-0.5.3.tgz", - "resolved": "http://registry.npmjs.org/ctype/-/ctype-0.5.3.tgz" - } - } - }, - "oauth-sign": { - "version": "0.5.0", - "from": "http://registry.npmjs.org/oauth-sign/-/oauth-sign-0.5.0.tgz", - "resolved": "http://registry.npmjs.org/oauth-sign/-/oauth-sign-0.5.0.tgz" - }, - "hawk": { - "version": "1.1.1", - "from": "http://registry.npmjs.org/hawk/-/hawk-1.1.1.tgz", - "resolved": "http://registry.npmjs.org/hawk/-/hawk-1.1.1.tgz", - "dependencies": { - "hoek": { - "version": "0.9.1", - "from": "http://registry.npmjs.org/hoek/-/hoek-0.9.1.tgz", - "resolved": "http://registry.npmjs.org/hoek/-/hoek-0.9.1.tgz" - }, - "boom": { - "version": "0.4.2", - "from": "http://registry.npmjs.org/boom/-/boom-0.4.2.tgz", - "resolved": "http://registry.npmjs.org/boom/-/boom-0.4.2.tgz" - }, - "cryptiles": { - "version": "0.2.2", - "from": "http://registry.npmjs.org/cryptiles/-/cryptiles-0.2.2.tgz", - "resolved": "http://registry.npmjs.org/cryptiles/-/cryptiles-0.2.2.tgz" - }, - "sntp": { - "version": "0.2.4", - "from": "http://registry.npmjs.org/sntp/-/sntp-0.2.4.tgz", - "resolved": "http://registry.npmjs.org/sntp/-/sntp-0.2.4.tgz" - } - } - }, - "aws-sign2": { - "version": "0.5.0", - "from": "http://registry.npmjs.org/aws-sign2/-/aws-sign2-0.5.0.tgz", - "resolved": "http://registry.npmjs.org/aws-sign2/-/aws-sign2-0.5.0.tgz" - }, - "stringstream": { - "version": "0.0.4", - "from": "http://registry.npmjs.org/stringstream/-/stringstream-0.0.4.tgz", - "resolved": "http://registry.npmjs.org/stringstream/-/stringstream-0.0.4.tgz" - }, - "combined-stream": { - "version": "0.0.7", - "from": "http://registry.npmjs.org/combined-stream/-/combined-stream-0.0.7.tgz", - "resolved": "http://registry.npmjs.org/combined-stream/-/combined-stream-0.0.7.tgz", - "dependencies": { - "delayed-stream": { - "version": "0.0.5", - "from": "http://registry.npmjs.org/delayed-stream/-/delayed-stream-0.0.5.tgz", - "resolved": "http://registry.npmjs.org/delayed-stream/-/delayed-stream-0.0.5.tgz" - } - } - } - } + "version": "2.83.0", + "from": "request@>=2.81.0 <3.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/request/-/request-2.83.0.tgz" + }, + "safe-buffer": { + "version": "5.1.1", + "from": "safe-buffer@>=5.1.1 <6.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/safe-buffer/-/safe-buffer-5.1.1.tgz" + }, + "sntp": { + "version": "2.0.2", + "from": "sntp@>=2.0.0 <3.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/sntp/-/sntp-2.0.2.tgz" + }, + "sshpk": { + "version": "1.13.1", + "from": "sshpk@>=1.7.0 <2.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/sshpk/-/sshpk-1.13.1.tgz" + }, + "stringstream": { + "version": "0.0.5", + "from": "stringstream@>=0.0.5 <0.1.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/stringstream/-/stringstream-0.0.5.tgz" + }, + "tough-cookie": { + "version": "2.3.3", + "from": "tough-cookie@>=2.3.3 <2.4.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/tough-cookie/-/tough-cookie-2.3.3.tgz" + }, + "tunnel-agent": { + "version": "0.6.0", + "from": "tunnel-agent@>=0.6.0 <0.7.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/tunnel-agent/-/tunnel-agent-0.6.0.tgz" + }, + "tweetnacl": { + "version": "0.14.5", + "from": "tweetnacl@>=0.14.0 <0.15.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/tweetnacl/-/tweetnacl-0.14.5.tgz", + "optional": true + }, + "uuid": { + "version": "3.1.0", + "from": "uuid@>=3.1.0 <4.0.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/uuid/-/uuid-3.1.0.tgz" + }, + "verror": { + "version": "1.10.0", + "from": "verror@1.10.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/verror/-/verror-1.10.0.tgz" + }, + "wordwrap": { + "version": "0.0.3", + "from": "wordwrap@>=0.0.2 <0.1.0", + "resolved": "http://apim-ci1.rtp.raleigh.ibm.com:8080/wordwrap/-/wordwrap-0.0.3.tgz" } } } diff --git a/package.json b/package.json index 1e8ba4c..8a2f0da 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,15 @@ { "name": "json-schema-generator", - "version": "1.1.16", + "version": "2.0.3", "description": "JSON schema generator based on draft-v4.", "main": "./index.js", "directories": { "test": "test" }, + "repository": { + "type": "git", + "url": "https://github.com/krg7880/json-schema-generator.git" + }, "bin": { "json-schema-generator": "./bin/cli.js" }, @@ -19,7 +23,7 @@ "mkdirp": "^0.5.0", "optimist": "^0.6.1", "pretty-data": "^0.40.0", - "request": "^2.47.0" + "request": "^2.81.0" }, "devDependencies": { "chai": "^1.9.2", @@ -28,10 +32,12 @@ "gulp": "^3.8.9", "gulp-concat": "^2.4.1", "gulp-markdox": "^0.1.0", - "mocha": "^1.21.4" + "gulp-mocha": "^2.2.0", + "mocha": "^1.21.4", + "node-stubby-server-cli": "^1.0.0" }, "scripts": { - "test": "./node_modules/.bin/_mocha" + "test": "gulp" }, "keywords": [ "json schema", diff --git a/test/cli-test.js b/test/cli-test.js index f084d75..5b012be 100644 --- a/test/cli-test.js +++ b/test/cli-test.js @@ -1,10 +1,12 @@ 'use strict'; +var path = require('path'); var child_process = require('child_process'); var fs = require('fs'); var chai = require('chai'); chai.use(require('chai-json-schema')); var expect = chai.expect; +var stubbyHelper = require(path.normalize(__dirname + '/helpers/stubby-cli')); /** * Use the command line interface. @@ -26,8 +28,9 @@ function runCli(args, stdin) { return [response.stdout.toString('utf8'), response.stderr.toString('utf8')]; } -var inputLocalPath ='./test/fixtures/json/valid.json', - inputRemotePath = 'https://raw.githubusercontent.com/krg7880/json-schema-generator/master/test/fixtures/json/valid.json', +var inputLocalPath = __dirname + '/fixtures/json/valid.json', + inputRemotePath = 'http://localhost:' + stubbyHelper.ports.stubs + '/valid/', + //'https://raw.githubusercontent.com/krg7880/json-schema-generator/master/test/fixtures/json/valid.json', inputJSONString = fs.readFileSync(inputLocalPath, 'utf8'), inputJSON = JSON.parse(inputJSONString); @@ -35,17 +38,19 @@ var schemaJSON, copyJSON; describe('Cli', function() { it('Should be able to read a local file', function() { - schemaJSON = JSON.parse(runCli(inputLocalPath)[0]); + var json = runCli(inputLocalPath); + console.log(typeof json); + schemaJSON = runCli(inputLocalPath); expect(inputJSON).to.be.jsonSchema(schemaJSON); }); it('Should be able to read a remote file', function() { - schemaJSON = JSON.parse(runCli(inputRemotePath)[0]); + this.timeout(5000); + schemaJSON = runCli(inputRemotePath); expect(inputJSON).to.be.jsonSchema(schemaJSON); - // Use it only once, github is not supposed to be used this way. inputRemotePath = null; }); it('Should be able to read stdin', function() { - schemaJSON = JSON.parse(runCli([], inputJSONString)[0]); + schemaJSON = runCli([], inputJSONString); expect(inputJSON).to.be.jsonSchema(schemaJSON); }); it('Should be able to write to a file', function() { diff --git a/test/fixtures/stubby/routes.json b/test/fixtures/stubby/routes.json new file mode 100644 index 0000000..84ae862 --- /dev/null +++ b/test/fixtures/stubby/routes.json @@ -0,0 +1,14 @@ +[{ + "request": { + "url": "^/valid/", + "method": "GET", + "body": "" + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/json" + }, + "file": "./../json/valid.json" + } + }] \ No newline at end of file diff --git a/test/helpers/stubby-cli.js b/test/helpers/stubby-cli.js new file mode 100644 index 0000000..4b9eef7 --- /dev/null +++ b/test/helpers/stubby-cli.js @@ -0,0 +1,7 @@ +module.exports = { + ports: { + admin: 9000, + stubs: 9001, + tls: 9002 + } +}; \ No newline at end of file