Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swagger-cli

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-cli - npm Package Compare versions

Comparing version 1.0.0-beta.2 to 1.0.0

bin/help-text.json

39

lib/bundle.js
'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 &mdash; [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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc