Socket
Socket
Sign inDemoInstall

swagger2openapi

Package Overview
Dependencies
Maintainers
1
Versions
156
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger2openapi - npm Package Compare versions

Comparing version 4.0.1 to 5.0.0

41

boast.js

@@ -9,3 +9,3 @@ #!/usr/bin/env node

const yaml = require('js-yaml');
const yaml = require('yaml');
const fetch = require('node-fetch-h2');

@@ -20,2 +20,5 @@ const bae = require('better-ajv-errors');

let argv = require('yargs')
.boolean('all')
.alias('a','all')
.describe('all','show all lint warnings')
.boolean('bae')

@@ -30,2 +33,5 @@ .alias('b','bae')

.alias('s','lintSkip')
.boolean('dumpMeta')
.alias('m','dumpMeta')
.describe('Dump definition metadata')
.count('quiet')

@@ -43,5 +49,7 @@ .alias('q','quiet')

return new Promise(async function(resolve,reject){
const ruleUrls = new Set();
argv.resolve = true;
argv.patch = true;
argv.source = argv._[0];
if (argv.all) argv.lintLimit = Number.MAX_SAFE_INTEGER;
if (argv.bae) {

@@ -51,12 +59,12 @@ argv.validateSchema = 'first';

}
let options;
if (argv.source.startsWith('http')) {
options = await swagger2openapi.convertUrl(argv.source,argv);
}
else {
options = await swagger2openapi.convertFile(argv.source,argv);
}
let options = {};
let result = false;
try {
result = await validator.validateSync(options.openapi,options);
if (argv.source.startsWith('http')) {
options = await swagger2openapi.convertUrl(argv.source,argv);
}
else {
options = await swagger2openapi.convertFile(argv.source,argv);
}
result = await validator.validateSync(options.openapi,options);
}

@@ -77,3 +85,4 @@ catch (ex) {

else {
console.warn(warning.message,warning.pointer);
console.warn(warning.message,warning.pointer,warning.ruleName);
if (warning.rule.url) ruleUrls.add(warning.rule.url+'#'+warning.ruleName);
}

@@ -84,5 +93,15 @@ }

}
if (ruleUrls.size > 0) {
console.warn('For more information, visit:');
for (let url of ruleUrls) {
console.warn(url);
}
}
if (argv.dumpMeta) {
console.warn('\n#Definition metadata:');
console.warn(yaml.stringify(options.metadata,{depth:Math.INFINITY}));
}
if (result) {
if (options.sourceYaml) {
console.log(yaml.safeDump(options.openapi));
console.log(yaml.stringify(options.openapi));
}

@@ -89,0 +108,0 @@ else {

@@ -8,6 +8,5 @@ #!/usr/bin/env node

const path = require('path');
const util = require('util');
const readfiles = require('node-readfiles');
const should = require('should/as-function');
const yaml = require('js-yaml');
const yaml = require('yaml');

@@ -140,3 +139,3 @@ const validator = require('oas-validator');

let outFile = options.file.replace('swagger.yaml', argv.output);
let resultStr = yaml.safeDump(options.openapi, {lineWidth: -1});
let resultStr = yaml.stringify(options.openapi);
fs.writeFileSync(outFile, resultStr, argv.encoding);

@@ -165,3 +164,3 @@ }

}
let resultStr = yaml.dump(result);
let resultStr = yaml.stringify(result);

@@ -171,4 +170,4 @@ if (typeof result !== 'boolean') try {

try {
resultStr = yaml.safeDump(result, { lineWidth: -1 }); // should be representable safely in yaml
let resultStr2 = yaml.safeDump(result, { lineWidth: -1, noRefs: true });
resultStr = yaml.stringify(result); // should be representable safely in yaml
let resultStr2 = yaml.stringify(result); // FIXME dropped 'noRefs:true' here
should(resultStr).not.be.exactly('{}','Result should not be empty');

@@ -182,3 +181,3 @@ should(resultStr).equal(resultStr2,'Result should have no object identity ref_s');

let fix = reref(result);
fs.writeFileSync('./fixed.yaml',yaml.safeDump(fix, { lineWidth: -1 }),'utf8');
fs.writeFileSync('./fixed.yaml',yaml.stringify(fix),'utf8');
}

@@ -233,3 +232,3 @@ should.fail(false,true,'Result cannot be represented safely in YAML');

try {
src = yaml.safeLoad(srcStr, { schema: yaml.JSON_SCHEMA, json: true });
src = yaml.parse(srcStr, { schema: 'core' });
}

@@ -334,3 +333,3 @@ catch (ex) {

readfiles(pathspec, { readContents: false, filenameFormat: readfiles.FULL_PATH }, function (err) {
if (err) console.log(util.inspect(err));
if (err) console.log(yaml.stringify(err));
})

@@ -345,3 +344,2 @@ .then(files => {

.catch(err => {
//console.log(util.inspect(err));
handleResult(err,options);

@@ -348,0 +346,0 @@ });

{
"name": "swagger2openapi",
"version": "4.0.1",
"version": "5.0.0",
"description": "Convert Swagger 2.0 definitions to OpenApi 3.0 and validate",

@@ -9,3 +9,3 @@ "main": "index.js",

"oas-validate": "./oas-validate.js",
"oas-resolve": "./oas-resolve.js",
"oas-resolve": "./node_modules/oas-resolver/resolve.js",
"boast": "./boast.js"

@@ -40,10 +40,10 @@ },

"call-me-maybe": "^1.0.1",
"js-yaml": "^3.12.0",
"node-fetch-h2": "^2.3.0",
"node-readfiles": "^0.2.0",
"oas-kit-common": "^1.0.6",
"oas-resolver": "^1.1.1",
"oas-kit-common": "^1.0.7",
"oas-resolver": "^2.0.0",
"oas-schema-walker": "^1.1.2",
"oas-validator": "^2.0.1",
"reftools": "^1.0.4",
"oas-validator": "^3.0.0",
"reftools": "^1.0.5",
"yaml": "^1.2.0",
"yargs": "^12.0.2"

@@ -64,3 +64,3 @@ },

],
"gitHead": "50a250ff1e68b735925e06e59ba9aed12207216c"
"gitHead": "92ab5dd327dca2f6c64c86606a86e62962c66663"
}

@@ -17,3 +17,3 @@ # swagger2openapi

Currently tracking [v3.0.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md)
Currently tracking [v3.0.x](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md)

@@ -33,19 +33,26 @@ ## Installation:

Options:
--warnProperty Property name to use for warning extensions
[string] [default: "x-s2o-warning"]
--version Show version number [boolean]
-c, --components output information to unresolve a definition [boolean]
-d, --debug enable debug mode, adds specification-extensions [boolean]
-e, --encoding encoding for input/output files [string] [default: "utf8"]
-h, --help Show help [boolean]
-i, --indent JSON indent to use, defaults to 4 spaces [string]
-o, --outfile the output file to write to [string]
-p, --patch fix up small errors in the source definition [boolean]
-r, --resolve resolve external references [boolean]
-t, --targetVersion override default target version of 3.0.0 [string]
-u, --url url of original spec, creates x-origin entry [string]
-v, --verbose increase verbosity [count]
-w, --warnOnly Do not throw on non-patchable errors, add warning extensions
[boolean]
-y, --yaml write YAML, default JSON (overridden by --outfile filepath extension) [boolean]
--refSiblings mode to handle $ref's with sibling properties
[choices: "remove", "preserve", "allOf"]
--warnProperty Property name to use for warning extensions
[string] [default: "x-s2o-warning"]
--version Show version number [boolean]
-c, --components output information to unresolve a definition [boolean]
-d, --debug enable debug mode, adds specification-extensions[boolean]
-e, --encoding encoding for input/output files[string] [default: "utf8"]
-f, --fatal make resolution errors fatal [boolean]
-h, --help Show help [boolean]
-i, --indent JSON indent to use, defaults to 4 spaces [string]
-o, --outfile the output file to write to [string]
-p, --patch fix up small errors in the source definition [boolean]
-r, --resolve resolve external references [boolean]
-t, --targetVersion override default target version of 3.0.0 [string]
-u, --url url of original spec, creates x-origin entry [string]
-v, --verbose increase verbosity [count]
-w, --warnOnly Do not throw on non-patchable errors, add warning
extensions [boolean]
-y, --yaml write YAML, default JSON (overridden by --outfile
filepath extension) [boolean]
-b, --rbname Extension to use to preserve body parameter names in
converted operations ("" == disabled)
[string] [default: ""]
```

@@ -52,0 +59,0 @@

@@ -8,5 +8,4 @@ #!/usr/bin/env node

const url = require('url');
const util = require('util');
const yaml = require('js-yaml');
const yaml = require('yaml');
const converter = require('./index.js');

@@ -40,2 +39,4 @@

.describe('patch', 'fix up small errors in the source definition')
.choices('refSiblings',['remove','preserve','allOf'])
.describe('refSiblings','mode to handle $ref\'s with sibling properties')
.boolean('resolve')

@@ -74,3 +75,3 @@ .alias('r', 'resolve')

delete err.options;
console.warn(util.inspect(err));
console.warn(yaml.stringify(err));
return process.exitCode = 1;

@@ -88,3 +89,3 @@ }

if (options.yaml) {
s = options.debug ? yaml.dump(options.openapi) : yaml.safeDump(options.openapi, {noRefs:true});
s = options.debug ? yaml.stringify(options.openapi) : yaml.stringify(options.openapi, {noRefs:true});
}

@@ -91,0 +92,0 @@ else {

Sorry, the diff of this file is too big to display

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