swagger-cli
Advanced tools
Comparing version 2.3.5 to 3.0.0
@@ -145,8 +145,10 @@ #!/usr/bin/env node | ||
*/ | ||
function validate (file, options) { | ||
api.validate(file, options) | ||
.then(() => { | ||
console.log(file, "is valid"); | ||
}) | ||
.catch(errorHandler); | ||
async function validate (file, options) { | ||
try { | ||
await api.validate(file, options); | ||
console.log(file, "is valid"); | ||
} | ||
catch (error) { | ||
errorHandler(error); | ||
} | ||
} | ||
@@ -161,14 +163,17 @@ | ||
*/ | ||
function bundle (file, options) { | ||
api.bundle(file, options) | ||
.then((bundled) => { | ||
if (options.outfile) { | ||
console.log("Created %s from %s", options.outfile, file); | ||
} | ||
else { | ||
// Write the bundled API to stdout | ||
console.log(bundled); | ||
} | ||
}) | ||
.catch(errorHandler); | ||
async function bundle (file, options) { | ||
try { | ||
let bundled = await api.bundle(file, options); | ||
if (options.outfile) { | ||
console.log("Created %s from %s", options.outfile, file); | ||
} | ||
else { | ||
// Write the bundled API to stdout | ||
console.log(bundled); | ||
} | ||
} | ||
catch (error) { | ||
errorHandler(error); | ||
} | ||
} | ||
@@ -175,0 +180,0 @@ |
"use strict"; | ||
const fs = require("fs"); | ||
const { promises: fs } = require("fs"); | ||
const path = require("path"); | ||
const mkdirp = require("mkdirp"); | ||
@@ -12,6 +11,5 @@ /** | ||
* @param {{outfile: string, dereference: boolean, format: number, wrap: number}} options | ||
* @param {function} [cb] | ||
* @returns {Promise} | ||
*/ | ||
module.exports = function bundle (api, options, cb) { | ||
module.exports = async function bundle (api, options) { | ||
// NOTE: lazy-load SwaggerParser, so the CLI can set the env.DEBUG variable first | ||
@@ -30,7 +28,2 @@ var SwaggerParser = require('swagger-parser'); // eslint-disable-line | ||
// Normalize the callback function | ||
if (typeof cb !== "function") { | ||
cb = function () {}; | ||
} | ||
// Throw an error if the API contains circular $refs and we're dereferencing, | ||
@@ -44,32 +37,26 @@ // since the output can't be serialized as JSON | ||
return SwaggerParser[method](api, opts) | ||
.then(bundled => { | ||
let content; | ||
let bundled = await SwaggerParser[method](api, opts); | ||
switch (options.type) { | ||
case "yaml": | ||
// Serialize the bundled/dereferenced API as YAML | ||
content = toYAML(bundled, options.format, options.wrap); | ||
break; | ||
default: | ||
// Serialize the bundled/dereferenced API as JSON | ||
content = toJSON(bundled, options.format); | ||
break; | ||
} | ||
let content; | ||
if (options.outfile) { | ||
// Create the output directory, if necessary | ||
mkdirp.sync(path.dirname(options.outfile)); | ||
switch (options.type) { | ||
case "yaml": | ||
// Serialize the bundled/dereferenced API as YAML | ||
content = toYAML(bundled, options.format, options.wrap); | ||
break; | ||
default: | ||
// Serialize the bundled/dereferenced API as JSON | ||
content = toJSON(bundled, options.format); | ||
break; | ||
} | ||
// Write the result to the output file | ||
fs.writeFileSync(options.outfile, content); | ||
} | ||
if (options.outfile) { | ||
// Create the output directory, if necessary | ||
await fs.mkdir(path.dirname(options.outfile), { recursive: true }); | ||
cb(null, content); | ||
return content; | ||
}) | ||
.catch((err) => { | ||
cb(err, null); | ||
throw err; | ||
}); | ||
// Write the result to the output file | ||
await fs.writeFile(options.outfile, content); | ||
} | ||
return content; | ||
}; | ||
@@ -76,0 +63,0 @@ |
{ | ||
"name": "swagger-cli", | ||
"version": "2.3.5", | ||
"version": "3.0.0", | ||
"description": "Swagger 2.0 and OpenAPI 3.0 command-line tool", | ||
@@ -49,3 +49,3 @@ "keywords": [ | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=10" | ||
}, | ||
@@ -65,7 +65,7 @@ "scripts": { | ||
"eslint-config-modular": "^7.0.1", | ||
"mocha": "^6.2.2", | ||
"mocha": "^7.0.1", | ||
"mockery": "^2.1.0", | ||
"npm-check": "^5.9.0", | ||
"nyc": "^15.0.0", | ||
"rimraf": "^3.0.0", | ||
"rimraf": "^3.0.1", | ||
"spawn-sync": "^2.0.0", | ||
@@ -77,6 +77,5 @@ "version-bump-prompt": "^5.0.7" | ||
"js-yaml": "^3.13.1", | ||
"mkdirp": "^0.5.1", | ||
"swagger-parser": "^8.0.4", | ||
"yargs": "^15.0.2" | ||
"yargs": "^15.1.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
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
19804
4
9
333
- Removedmkdirp@^0.5.1
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
Updatedyargs@^15.1.0