swagger-cli
Advanced tools
Comparing version 1.0.0-beta.2 to 1.0.0
'use strict'; | ||
var fs = require('fs'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const mkdirp = require('mkdirp'); | ||
@@ -13,24 +15,29 @@ /** | ||
*/ | ||
module.exports = function bundle(api, options, cb) { | ||
module.exports = function bundle (api, options, cb) { | ||
// NOTE: lazy-load SwaggerParser, so the CLI can set the env.DEBUG variable first | ||
var SwaggerParser = require('swagger-parser'); | ||
var SwaggerParser = require('swagger-parser'); // eslint-disable-line | ||
// Determine which Swagger Parser method to use | ||
var method = options.dereference ? 'dereference' : 'bundle'; | ||
let method = options.dereference ? 'dereference' : 'bundle'; | ||
// If the API contains circular $refs, then ignore them. | ||
// Otherwise, JSON serialization will fail | ||
var opts = {$refs: {circular: 'ignore'}}; | ||
// Throw an error if the API contains circular $refs and we're dereferencing, | ||
// since the output can't be serialized as JSON | ||
let opts = { | ||
dereference: !options.dereference, | ||
}; | ||
// Normalize the callback function | ||
if (typeof(cb) !== 'function') { | ||
cb = function() {}; | ||
if (typeof cb !== 'function') { | ||
cb = function () {}; | ||
} | ||
return SwaggerParser[method](api, opts) | ||
.then(function(api) { | ||
.then(bundled => { | ||
// Serialize the bundled/dereferenced API as JSON | ||
var json = toJSON(api, options.format); | ||
let json = toJSON(bundled, options.format); | ||
if (options.outfile) { | ||
// Create the output directory, if necessary | ||
mkdirp.sync(path.dirname(options.outfile)); | ||
// Write the JSON to the output file | ||
@@ -43,3 +50,3 @@ fs.writeFileSync(options.outfile, json); | ||
}) | ||
.catch(function(err) { | ||
.catch((err) => { | ||
cb(err, null); | ||
@@ -56,5 +63,5 @@ throw err; | ||
*/ | ||
function toJSON(api, spaces) { | ||
var strSpaces = spaces; | ||
var numSpaces = parseInt(spaces); | ||
function toJSON (api, spaces) { | ||
let strSpaces = spaces; | ||
let numSpaces = parseInt(spaces); | ||
if (isNaN(numSpaces)) { | ||
@@ -67,3 +74,3 @@ spaces = strSpaces || 2; | ||
return JSON.stringify(api, null, spaces); | ||
return JSON.stringify(api, null, spaces) + '\n'; | ||
} |
@@ -5,2 +5,1 @@ 'use strict'; | ||
exports.bundle = require('./bundle'); | ||
exports.serve = require('./serve'); |
@@ -11,3 +11,3 @@ 'use strict'; | ||
*/ | ||
module.exports = function validate(api, options, cb) { | ||
module.exports = function validate (api, options, cb) { | ||
// Convert the Swagger CLI options into Swagger Parser options | ||
@@ -23,4 +23,6 @@ options = options || {}; | ||
// NOTE: lazy-load SwaggerParser, so the CLI can set the env.DEBUG variable first | ||
var SwaggerParser = require('swagger-parser'); | ||
var SwaggerParser = require('swagger-parser'); // eslint-disable-line | ||
// Validate the API and return it | ||
return SwaggerParser.validate(api, options, cb); | ||
}; |
{ | ||
"name": "swagger-cli", | ||
"version": "1.0.0-beta.2", | ||
"version": "1.0.0", | ||
"description": "Swagger 2.0 command-line tool", | ||
"keywords": [ | ||
"swagger", | ||
"cli", | ||
"rest", | ||
@@ -15,4 +16,2 @@ "api", | ||
"validation", | ||
"serve", | ||
"server", | ||
"host" | ||
@@ -24,39 +23,2 @@ ], | ||
}, | ||
"license": "MIT", | ||
"homepage": "https://github.com/BigstickCarpet/swagger-cli", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"lint": "jshint . --verbose && jscs . --verbose", | ||
"build": "npm run lint", | ||
"mocha": "mocha --bail --recursive tests/fixtures tests/specs", | ||
"istanbul": "istanbul cover _mocha --dir coverage/node -- --bail --recursive tests/fixtures tests/specs", | ||
"test": "echo work-in-progress", | ||
"upgrade": "ncu --upgradeAll && npm update", | ||
"bump": "bump --prompt --tag --push --all", | ||
"release": "npm run upgrade && npm run build && npm test && npm run bump && npm publish" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/BigstickCarpet/swagger-cli.git" | ||
}, | ||
"devDependencies": { | ||
"istanbul": "^0.3.21", | ||
"coveralls": "^2.11.4", | ||
"mocha": "^2.3.3", | ||
"chai": "^3.3.0", | ||
"sinon": "^1.17.1", | ||
"jscs": "^2.2.1", | ||
"jshint": "^2.8.0", | ||
"npm-check-updates": "^2.2.4", | ||
"version-bump-prompt": "^1.5.2", | ||
"mockery": "^1.4.0" | ||
}, | ||
"dependencies": { | ||
"chalk": "^1.1.1", | ||
"commander": "^2.8.1", | ||
"es6-promise": "^3.0.2", | ||
"lodash": "^3.10.1", | ||
"swagger-parser": "^3.1.0", | ||
"swagger-server": "^1.0.0-alpha.18" | ||
}, | ||
"contributors": [ | ||
@@ -72,5 +34,43 @@ { | ||
], | ||
"homepage": "http://bigstickcarpet.com/swagger-parser", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/BigstickCarpet/swagger-cli.git" | ||
}, | ||
"main": "lib/index.js", | ||
"bin": { | ||
"swagger": "bin/swagger.js" | ||
"swagger-cli": "bin/swagger-cli.js" | ||
}, | ||
"files": [ | ||
"bin", | ||
"lib" | ||
], | ||
"scripts": { | ||
"lint": "eslint bin lib test --fix", | ||
"test": "mocha && npm run lint", | ||
"upgrade": "npm-check -u", | ||
"bump": "bump --prompt --tag --push --all", | ||
"release": "npm run upgrade && npm test && npm run bump && npm publish" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"eslint": "^4.10.0", | ||
"eslint-config-modular": "^4.1.0", | ||
"mocha": "^4.0.1", | ||
"mockery": "^2.1.0", | ||
"npm-check": "^5.5.1", | ||
"rimraf": "^2.4.3", | ||
"spawn-sync": "^1.0.13", | ||
"version-bump-prompt": "^3.1.2" | ||
}, | ||
"dependencies": { | ||
"chalk": "^2.3.0", | ||
"mkdirp": "^0.5.1", | ||
"swagger-parser": "^4.0.1", | ||
"yargs": "^10.0.3" | ||
}, | ||
"engines": { | ||
"node": ">=4.0.0" | ||
} | ||
} |
Swagger 2.0 CLI | ||
============================ | ||
[![Build Status](https://api.travis-ci.org/BigstickCarpet/swagger-cli.svg)](https://travis-ci.org/BigstickCarpet/swagger-cli) | ||
[![Build Status](https://api.travis-ci.org/BigstickCarpet/swagger-cli.svg?branch=master)](https://travis-ci.org/BigstickCarpet/swagger-cli) | ||
[![Dependencies](https://david-dm.org/BigstickCarpet/swagger-cli.svg)](https://david-dm.org/BigstickCarpet/swagger-cli) | ||
[![Coverage Status](https://coveralls.io/repos/BigstickCarpet/swagger-cli/badge.svg?branch=master&service=github)](https://coveralls.io/r/BigstickCarpet/swagger-cli) | ||
[![Code Climate Score](https://codeclimate.com/github/BigstickCarpet/swagger-cli/badges/gpa.svg)](https://codeclimate.com/github/BigstickCarpet/swagger-cli) | ||
[![Codacy Score](https://www.codacy.com/project/badge/b20026f43c2d4a149088ba0ad2ab6355)](https://www.codacy.com/public/jamesmessinger/swagger-cli) | ||
@@ -20,5 +18,11 @@ [![Inline docs](http://inch-ci.org/github/BigstickCarpet/swagger-cli.svg?branch=master&style=shields)](http://inch-ci.org/github/BigstickCarpet/swagger-cli) | ||
- Bundle multiple Swagger files into one combined Swagger file | ||
- Built-in **HTTP server** to serve your REST API — great for testing! | ||
Related Projects | ||
-------------------------- | ||
- [Swagger Parser](https://github.com/BigstickCarpet/swagger-parser) | ||
- [Swagger Express Middleware](https://github.com/BigstickCarpet/swagger-express-middleware) | ||
- [Swagger Server](https://github.com/BigstickCarpet/swagger-server) | ||
Installation | ||
@@ -37,15 +41,13 @@ -------------------------- | ||
```bash | ||
swagger <command> [options] <filename> | ||
swagger-cli <command> [options] <file> | ||
Commands: | ||
validate Validates a Swagger API against the Swagger 2.0 schema and spec | ||
validate Validates a Swagger API against the Swagger 2.0 schema and spec | ||
bundle Bundles a multi-file Swagger API into a single file | ||
bundle Bundles a multi-file Swagger API into a single file | ||
serve Serves a Swagger API via the built-in HTTP REST server | ||
Options: | ||
-h, --help Show help for any command | ||
-V, --version Output the CLI version number | ||
-d, --debug [filter] Show debug output, optionally filtered (e.g. "*", "swagger:*", etc.) | ||
-h, --help Show help for any command | ||
-v, --version Output the CLI version number | ||
-d, --debug [filter] Show debug output, optionally filtered (e.g. "*", "swagger:*", etc.) | ||
``` | ||
@@ -56,11 +58,11 @@ | ||
The `swagger validate` command will validate your Swagger API against the [Swagger 2.0 schema](https://github.com/reverb/swagger-spec/blob/master/schemas/v2.0/schema.json) _and_ the [Swagger 2.0 spec](https://github.com/reverb/swagger-spec/blob/master/versions/2.0.md) to make sure it is fully compliant. The command will exit with a non-zero code if the API is invalid. | ||
The `swagger-cli validate` command will validate your Swagger API against the [Swagger 2.0 schema](https://github.com/reverb/swagger-spec/blob/master/schemas/v2.0/schema.json) _and_ the [Swagger 2.0 spec](https://github.com/reverb/swagger-spec/blob/master/versions/2.0.md) to make sure it is fully compliant. The command will exit with a non-zero code if the API is invalid. | ||
```bash | ||
swagger validate [options] <filename> | ||
swagger-cli validate [options] <file> | ||
Options: | ||
--no-schema Do NOT validate against the Swagger 2.0 schema | ||
--no-schema Do NOT validate against the Swagger 2.0 JSON schema | ||
--no-spec Do NOT validate against the Swagger 2.0 spec | ||
--no-spec Do NOT validate against the Swagger 2.0 specification | ||
``` | ||
@@ -71,5 +73,5 @@ | ||
The Swagger 2.0 spec allows you to split your API across multiple files using [`$ref` pointers](https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#reference-object) to reference each file. You can use the `swagger bundle` command to combine all of those referenced files into a single file, which is useful for distribution or interoperation with other tools. | ||
The Swagger 2.0 spec allows you to split your API across multiple files using [`$ref` pointers](https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#reference-object) to reference each file. You can use the `swagger-cli bundle` command to combine all of those referenced files into a single file, which is useful for distribution or interoperation with other tools. | ||
By default, the `swagger bundle` command tries to keep the output file size as small as possible, by only embedding each referenced file _once_. If the same file is referenced multiple times, then any subsequent references are simply modified to point to the _single_ inlined copy of the file. If you want to produce a bundled file without _any_ `$ref` pointers, then add the `--dereference` option. This will result in a larger file size, since multiple references to the same file will result in that file being embedded multiple times. | ||
By default, the `swagger-cli bundle` command tries to keep the output file size as small as possible, by only embedding each referenced file _once_. If the same file is referenced multiple times, then any subsequent references are simply modified to point to the _single_ inlined copy of the file. If you want to produce a bundled file without _any_ `$ref` pointers, then add the `--dereference` option. This will result in a larger file size, since multiple references to the same file will result in that file being embedded multiple times. | ||
@@ -79,32 +81,14 @@ If you don't specify the `--output-file` option, then the bundled API will be written to stdout, which means you can pipe it to other commands. | ||
```bash | ||
swagger bundle [options] <filename> | ||
swagger-cli bundle [options] <file> | ||
Options: | ||
-o, --outfile <filename> The output file | ||
-o, --outfile <file> The output file | ||
-r, --dereference Fully dereference all $ref pointers | ||
-r, --dereference Fully dereference all $ref pointers | ||
-f, --format <spaces> Formats the JSON output using the given number of spaces | ||
(the default is 2 spaces) | ||
-f, --format <spaces> Formats the JSON output using the given number of spaces | ||
(the default is 2 spaces) | ||
``` | ||
### HTTP REST Server | ||
The `swagger serve` command serves your REST API via the built-in HTTP server — [Swagger Server](https://github.com/BigstickCarpet/swagger-server). Swagger Server automatically provides mock implementations for every operation defined in your Swagger API. You can replace or supplement the mock implementations via [Express middleware](http://expressjs.com/guide/using-middleware.html). | ||
By default, Swagger Server uses an [in-memory data store](https://github.com/BigstickCarpet/swagger-express-middleware/blob/master/docs/exports/MemoryDataStore.md), which means no data will be persisted after the server shuts down. This is great for testing and CI purposes, but if you want to maintain data across sessions, then use the `--json` option, which will persist the REST resources as [JSON files](https://github.com/BigstickCarpet/swagger-express-middleware/blob/master/docs/exports/FileDataStore.md). | ||
> NOTE: Swagger Server is still in development, so some functionality is not fully complete yet. | ||
```bash | ||
swagger serve [options] <filename> | ||
Options: | ||
-p, --port <port> The server port number or socket name | ||
-j, --json <basedir> Store REST resources as JSON files under the given directory | ||
``` | ||
Contributing | ||
@@ -126,5 +110,4 @@ -------------------------- | ||
4. **Run the unit tests**<br> | ||
`npm run mocha` (just the tests)<br> | ||
`npm test` (tests + code coverage) | ||
4. **Run the tests**<br> | ||
`npm test` | ||
@@ -131,0 +114,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
15931
4
9
295
0
8
112
3
+ Addedmkdirp@^0.5.1
+ Addedyargs@^10.0.3
+ Addedansi-regex@3.0.1(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedcamelcase@4.1.0(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcliui@4.1.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcross-spawn@5.1.0(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedexeca@0.7.0(transitive)
+ Addedfind-up@2.1.0(transitive)
+ Addedget-caller-file@1.0.3(transitive)
+ Addedget-stream@3.0.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedinvert-kv@1.0.0(transitive)
+ Addedis-fullwidth-code-point@1.0.02.0.0(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjson-schema-ref-parser@5.1.3(transitive)
+ Addedlcid@1.0.0(transitive)
+ Addedlocate-path@2.0.0(transitive)
+ Addedlru-cache@4.1.5(transitive)
+ Addedmem@1.1.0(transitive)
+ Addedmimic-fn@1.2.0(transitive)
+ Addednpm-run-path@2.0.2(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedos-locale@2.1.0(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedp-limit@1.3.0(transitive)
+ Addedp-locate@2.0.0(transitive)
+ Addedp-try@1.0.0(transitive)
+ Addedpath-exists@3.0.0(transitive)
+ Addedpath-key@2.0.1(transitive)
+ Addedpseudomap@1.0.2(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@1.0.1(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstring-width@1.0.22.1.1(transitive)
+ Addedstrip-ansi@4.0.0(transitive)
+ Addedstrip-eof@1.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedswagger-parser@4.1.0(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwrap-ansi@2.1.0(transitive)
+ Addedy18n@3.2.2(transitive)
+ Addedyallist@2.1.2(transitive)
+ Addedyargs@10.1.2(transitive)
+ Addedyargs-parser@8.1.0(transitive)
- Removedcommander@^2.8.1
- Removedes6-promise@^3.0.2
- Removedlodash@^3.10.1
- Removedswagger-server@^1.0.0-alpha.18
- Removed@apidevtools/json-schema-ref-parser@9.0.6(transitive)
- Removed@apidevtools/openapi-schemas@2.1.0(transitive)
- Removed@apidevtools/swagger-express-middleware@4.0.2(transitive)
- Removed@apidevtools/swagger-methods@3.0.2(transitive)
- Removed@apidevtools/swagger-parser@10.1.0(transitive)
- Removed@jsdevtools/ono@7.1.3(transitive)
- Removedaccepts@1.3.8(transitive)
- Removedajv@8.17.1(transitive)
- Removedajv-draft-04@1.0.0(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedappend-field@1.0.0(transitive)
- Removedarray-flatten@1.1.1(transitive)
- Removedbody-parser@1.20.3(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedbusboy@0.2.14(transitive)
- Removedbytes@3.1.2(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedchalk@1.1.3(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedcontent-disposition@0.5.4(transitive)
- Removedcontent-type@1.0.5(transitive)
- Removedcookie@0.7.10.7.2(transitive)
- Removedcookie-parser@1.4.7(transitive)
- Removedcookie-signature@1.0.6(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddebug@2.6.94.3.7(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddepd@2.0.0(transitive)
- Removeddestroy@1.2.0(transitive)
- Removeddicer@0.2.5(transitive)
- Removeddirectory-search@0.0.32(transitive)
- Removedee-first@1.1.1(transitive)
- Removedencodeurl@1.0.22.0.0(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes6-promise@3.3.14.2.8(transitive)
- Removedescape-html@1.0.3(transitive)
- Removedetag@1.8.1(transitive)
- Removedexpress@4.21.1(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-uri@3.0.3(transitive)
- Removedfinalhandler@1.3.1(transitive)
- Removedforwarded@0.2.0(transitive)
- Removedfresh@0.5.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhttp-errors@2.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedinherits@2.0.4(transitive)
- Removedipaddr.js@1.9.1(transitive)
- Removedisarray@0.0.11.0.0(transitive)
- Removedjson-schema-ref-parser@1.4.1(transitive)
- Removedjson-schema-traverse@1.0.0(transitive)
- Removedlodash@3.10.14.17.21(transitive)
- Removedmedia-typer@0.3.0(transitive)
- Removedmerge-descriptors@1.0.3(transitive)
- Removedmethods@1.1.2(transitive)
- Removedmime@1.6.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedms@2.0.0(transitive)
- Removedmulter@1.4.4(transitive)
- Removednegotiator@0.6.3(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedon-finished@2.4.1(transitive)
- Removedono@2.2.5(transitive)
- Removedopenapi-types@12.1.3(transitive)
- Removedparseurl@1.3.3(transitive)
- Removedpath-to-regexp@0.1.10(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedproxy-addr@2.0.7(transitive)
- Removedqs@6.13.0(transitive)
- Removedrange-parser@1.2.1(transitive)
- Removedraw-body@2.5.2(transitive)
- Removedreadable-stream@1.1.142.3.8(transitive)
- Removedrequire-from-string@2.0.2(transitive)
- Removedsafe-buffer@5.1.25.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsend@0.19.0(transitive)
- Removedserve-static@1.16.2(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedsetprototypeof@1.2.0(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedstatuses@2.0.1(transitive)
- Removedstreamsearch@0.1.2(transitive)
- Removedstring_decoder@0.10.311.1.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedswagger-express-middleware@4.0.2(transitive)
- Removedswagger-parser@3.4.2(transitive)
- Removedswagger-server@1.0.0-alpha.19(transitive)
- Removedtmp@0.2.3(transitive)
- Removedtoidentifier@1.0.1(transitive)
- Removedtv4@1.3.0(transitive)
- Removedtype-is@1.6.18(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedunpipe@1.0.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedutils-merge@1.0.1(transitive)
- Removedvary@1.1.2(transitive)
- Removedxtend@4.0.2(transitive)
Updatedchalk@^2.3.0
Updatedswagger-parser@^4.0.1