Socket
Socket
Sign inDemoInstall

oas-resolver

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oas-resolver - npm Package Compare versions

Comparing version 1.0.12 to 1.1.0

in/openapi.yaml

54

index.js

@@ -8,3 +8,3 @@ 'use strict';

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

@@ -264,16 +264,25 @@

return new Promise(function (res, rej) {
let refs = options.externalRefs;
if ((options.resolver.depth>0) && (options.source === options.resolver.base)) {
// we only need to do any of this when called directly on pass #1
return res(refs);
}
recurse(options.openapi, {identityDetection: true}, function (obj, key, state) {
function inner(obj,key,state){
if (obj[key] && isRef(obj[key],'$ref')) {
let $ref = obj[key].$ref;
if (!$ref.startsWith('#')) {
if (!$ref.startsWith('#')) { // is external
let $extra = '';
if (!refs[$ref]) {
refs[$ref] = { resolved: false, paths: [], description: obj[key].description };
let potential = Object.keys(refs).find(function(e,i,a){
return $ref.startsWith(e+'/');
});
if (potential) {
if (options.verbose) console.warn('Found potential subschema at',potential);
$extra = '/'+($ref.split('#')[1]||'').replace(potential.split('#')[1]||'');
$extra = $extra.split('/undefined').join(''); // FIXME
$ref = potential;
}
}
if (!refs[$ref]) {
refs[$ref] = { resolved: false, paths: [], extras:{}, description: obj[key].description };
}
if (refs[$ref].resolved) {

@@ -285,3 +294,3 @@ if (options.rewriteRefs) {

obj[key]['x-miro'] = $ref;
obj[key].$ref = newRef; // resolutionCase:C (new string)
obj[key].$ref = newRef+$extra; // resolutionCase:C (new string)
}

@@ -294,7 +303,19 @@ else {

refs[$ref].paths.push(state.path);
refs[$ref].extras[state.path] = $extra;
}
}
}
});
}
let refs = options.externalRefs;
if ((options.resolver.depth>0) && (options.source === options.resolver.base)) {
// we only need to do any of this when called directly on pass #1
return res(refs);
}
recurse(options.openapi.definitions, {identityDetection: true, path: '#/definitions'}, inner);
recurse(options.openapi.components, {identityDetection: true, path: '#/components'}, inner);
recurse(options.openapi, {identityDetection: true}, inner);
res(refs);

@@ -338,2 +359,9 @@ });

let pointers = unique(refs[ref].paths);
pointers = pointers.sort(function(a,b){
const aComp = (a.startsWith('#/components/') || a.startsWith('#/definitions/'));
const bComp = (b.startsWith('#/components/') || b.startsWith('#/definitions/'));
if (aComp && !bComp) return -1;
if (bComp && !aComp) return +1;
return 0;
});

@@ -344,3 +372,3 @@ for (let ptr of pointers) {

if (options.verbose>1) console.log('Creating pointer to data at', ptr);
jptr(options.openapi, ptr, { $ref: refs[ref].resolvedAt, 'x-miro': ref }); // resolutionCase:E (new object)
jptr(options.openapi, ptr, { $ref: refs[ref].resolvedAt+refs[ref].extras[ptr], 'x-miro': ref+refs[ref].extras[ptr] }); // resolutionCase:E (new object)
}

@@ -347,0 +375,0 @@ else {

{
"name": "oas-resolver",
"version": "1.0.12",
"version": "1.1.0",
"description": "Resolve external $refs in OpenAPI (swagger) 2.0 / 3.x definitions",

@@ -23,8 +23,15 @@ "main": "index.js",

"js-yaml": "^3.12.0",
"node-fetch": "^2.3.0",
"oas-kit-common": "^1.0.4",
"reftools": "^1.0.3",
"node-fetch-h2": "^2.3.0",
"oas-kit-common": "^1.0.5",
"reftools": "^1.0.4",
"yargs": "^12.0.2"
},
"gitHead": "4862e159745d6ca06044bc3ebabe57a2ad8b7152"
"repository": {
"type": "git",
"url": "https://github.com/Mermade/oas-kit.git"
},
"bugs": {
"url": "https://github.com/mermade/oas-kit/issues"
},
"gitHead": "81067168e0cc0c151de4fd25bf24cfc23bc7bf8b"
}

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

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

@@ -37,2 +39,5 @@ const resolver = require('./index.js');

if (filespec.startsWith('https')) options.agent = new https.Agent({ keepAlive: true, keepAliveMsecs: 1500 })
else if (filespec.startsWith('http')) options.agent = new http.Agent({ keepAlive: true });
function main(str,source,options){

@@ -42,6 +47,13 @@ let input = yaml.safeLoad(str,{json:true});

.then(function(options){
if (options.agent) {
options.agent.destroy();
}
fs.writeFileSync(argv.output,yaml.safeDump(options.openapi,{lineWidth:-1}),'utf8');
//console.log(util.inspect(process._getActiveRequests()));
//console.log(util.inspect(process._getActiveHandles()));
//process.exit(0); // ensure we exit even if http2-client sitting about
})
.catch(function(err){
console.warn(err);
process.exit(1); // ensure we exit even if http2-client sitting about
});

@@ -48,0 +60,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