New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

swagger-cli

Package Overview
Dependencies
Maintainers
3
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 2.1.3 to 2.2.0

3

bin/help-text.json

@@ -53,4 +53,7 @@ {

" (the default is JSON)",
"",
" -w, --wrap <column> Set the line length for YAML strings",
" (the default is no wrapping)",
""
]
}

86

bin/swagger-cli.js
#!/usr/bin/env node
'use strict';
"use strict";
const yargs = require('yargs');
const chalk = require('chalk');
const api = require('../');
const helpText = require('./help-text.json');
const yargs = require("yargs");
const chalk = require("chalk");
const api = require("../");
const helpText = require("./help-text.json");
const validTypeOptions = ['json', 'yaml'];
const validTypeOptions = ["json", "yaml"];

@@ -19,3 +19,3 @@ (function main () {

// Enable debug output
process.env.DEBUG = 'swagger:*,json-schema-ref-parser';
process.env.DEBUG = "swagger:*,json-schema-ref-parser";
}

@@ -25,3 +25,3 @@

if (validTypeOptions.indexOf(options.type) === -1) {
const validValues = validTypeOptions.join(', ');
const validValues = validTypeOptions.join(", ");
console.error('Error: type value "' + options.type + '" is invalid. Valid values: ' + validValues);

@@ -36,7 +36,7 @@ process.exit(2);

}
else if (command === 'validate' && file) {
else if (command === "validate" && file) {
// Validate an API
validate(file, options);
}
else if (command === 'bundle' && file) {
else if (command === "bundle" && file) {
// Bundle a multi-file API

@@ -47,3 +47,3 @@ bundle(file, options);

// Invalid args. Show help text and exit with non-zero
console.error('Error: Invalid arguments\n');
console.error("Error: Invalid arguments\n");
console.error(getHelpText(command));

@@ -63,37 +63,42 @@ process.exit(1);

yargs
.option('schema', {
type: 'boolean',
.option("schema", {
type: "boolean",
default: true,
})
.option('spec', {
type: 'boolean',
.option("spec", {
type: "boolean",
default: true,
})
.option('o', {
alias: 'outfile',
type: 'string',
.option("o", {
alias: "outfile",
type: "string",
normalize: true,
})
.option('r', {
alias: 'dereference',
type: 'boolean',
.option("r", {
alias: "dereference",
type: "boolean",
})
.option('f', {
alias: 'format',
type: 'number',
.option("t", {
alias: "type",
type: "string",
normalize: true,
default: "json",
})
.option("f", {
alias: "format",
type: "number",
default: 2,
})
.option('t', {
alias: 'type',
type: 'string',
normalize: true,
default: 'json',
.option("w", {
alias: "wrap",
type: "number",
default: Infinity,
})
.option('d', {
alias: 'debug',
type: 'boolean',
.option("d", {
alias: "debug",
type: "boolean",
})
.option('h', {
alias: 'help',
type: 'boolean',
.option("h", {
alias: "help",
type: "boolean",
});

@@ -104,3 +109,3 @@

.version()
.alias('v', 'version');
.alias("v", "version");

@@ -123,3 +128,4 @@ // Disable the default "--help" behavior

format: args.format || 2,
type: args.type || 'json',
type: args.type || "json",
wrap: args.wrap || Infinity,
debug: args.debug,

@@ -149,3 +155,3 @@ help: args.help,

.then(() => {
console.log(file, 'is valid');
console.log(file, "is valid");
})

@@ -166,3 +172,3 @@ .catch(errorHandler);

if (options.outfile) {
console.log('Created %s from %s', options.outfile, file);
console.log("Created %s from %s", options.outfile, file);
}

@@ -186,3 +192,3 @@ else {

let lines = helpText[commandName] || helpText.default;
return lines.join('\n');
return lines.join("\n");
}

@@ -189,0 +195,0 @@

@@ -1,6 +0,6 @@

'use strict';
"use strict";
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
const fs = require("fs");
const path = require("path");
const mkdirp = require("mkdirp");

@@ -11,3 +11,3 @@ /**

* @param {string} api - The path of the Swagger/OpenAPI file
* @param {{outfile: string, dereference: boolean, format: number}} options
* @param {{outfile: string, dereference: boolean, format: number, wrap: number}} options
* @param {function} [cb]

@@ -21,15 +21,24 @@ * @returns {Promise}

// Determine which Swagger Parser method to use
let method = options.dereference ? 'dereference' : 'bundle';
let method = options.dereference ? "dereference" : "bundle";
// The "format" option can be a number of characters or the string to use as the indent
let numSpaces = parseInt(options.format);
options.format = numSpaces || options.format || 2;
// The "wrap" option can only be a number
options.wrap = parseInt(options.wrap) || Infinity;
// Normalize the callback function
if (typeof cb !== "function") {
cb = function () {};
}
// 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,
dereference: {
circular: !options.dereference,
}
};
// Normalize the callback function
if (typeof cb !== 'function') {
cb = function () {};
}
return SwaggerParser[method](api, opts)

@@ -40,5 +49,5 @@ .then(bundled => {

switch (options.type) {
case 'yaml':
case "yaml":
// Serialize the bundled/dereferenced API as YAML
content = toYAML(bundled, options.format);
content = toYAML(bundled, options.format, options.wrap);
break;

@@ -75,12 +84,3 @@ default:

function toJSON (api, spaces) {
let strSpaces = spaces;
let numSpaces = parseInt(spaces);
if (isNaN(numSpaces)) {
spaces = strSpaces || 2;
}
else {
spaces = numSpaces;
}
return JSON.stringify(api, null, spaces) + '\n';
return JSON.stringify(api, null, spaces) + "\n";
}

@@ -93,19 +93,12 @@

* @param {string|number} spaces number of spaces to ident
* @param {number} wrap the column to word-wrap at
*/
function toYAML (api, spaces) {
const jsYaml = require('js-yaml');
function toYAML (api, spaces, wrap) {
const jsYaml = require("js-yaml");
let strSpaces = spaces;
let numSpaces = parseInt(spaces);
if (isNaN(numSpaces)) {
spaces = strSpaces || 2;
}
else {
spaces = numSpaces;
}
return jsYaml.dump(api, {
indent: spaces,
lineWidth: wrap,
noRefs: true
});
}

@@ -1,4 +0,4 @@

'use strict';
"use strict";
exports.validate = require('./validate');
exports.bundle = require('./bundle');
exports.validate = require("./validate");
exports.bundle = require("./bundle");

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -3,0 +3,0 @@ /**

{
"name": "swagger-cli",
"version": "2.1.3",
"version": "2.2.0",
"description": "Swagger 2.0 and OpenAPI 3.0 command-line tool",

@@ -52,3 +52,3 @@ "keywords": [

"scripts": {
"lint": "eslint bin lib test --fix",
"lint": "eslint bin lib test",
"test": "mocha && npm run lint",

@@ -62,10 +62,10 @@ "coverage": "nyc --reporter=text --reporter=lcov mocha",

"chai": "^4.2.0",
"codacy-coverage": "^3.1.0",
"codacy-coverage": "^3.2.0",
"coveralls": "^3.0.2",
"eslint": "^5.6.1",
"eslint-config-modular": "^4.2.2",
"eslint": "^5.8.0",
"eslint-config-modular": "^5.0.0",
"mocha": "^5.2.0",
"mockery": "^2.1.0",
"npm-check": "^5.9.0",
"nyc": "^13.0.1",
"nyc": "^13.1.0",
"rimraf": "^2.4.3",

@@ -79,5 +79,5 @@ "spawn-sync": "^2.0.0",

"mkdirp": "^0.5.1",
"swagger-parser": "^6.0.0",
"swagger-parser": "^6.0.1",
"yargs": "^12.0.2"
}
}
Swagger/OpenAPI CLI
============================
[![Cross-Platform Compatibility](https://apidevtools.org/img/os-badges.svg)](https://travis-ci.org/APIDevTools/swagger-cli)
[![Build Status](https://api.travis-ci.org/APIDevTools/swagger-cli.svg?branch=master)](https://travis-ci.org/APIDevTools/swagger-cli)
[![Coverage Status](https://coveralls.io/repos/github/APIDevTools/swagger-cli/badge.svg?branch=master)](https://coveralls.io/github/APIDevTools/swagger-cli?branch=master)

@@ -88,3 +90,3 @@ [![Dependencies](https://david-dm.org/APIDevTools/swagger-cli.svg)](https://david-dm.org/APIDevTools/swagger-cli)

-f, --format <spaces> Formats the JSON output using the given number of spaces
-f, --format <spaces> Formats the output using the given number of spaces
(the default is 2 spaces)

@@ -94,2 +96,5 @@

(the default is JSON)
-w, --wrap <column> Set the line length for YAML strings
(the default is no wrapping)
```

@@ -96,0 +101,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