Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function inner(obj,key,state){
if (obj[key] && isRef(obj[key],'$ref')) {
let $ref = obj[key].$ref;
if (!$ref.startsWith('#')) { // is external
let $extra = '';
if (!refs[$ref]) {
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;
}
}
function fixupRefs(obj, key, state) {
let options = state.payload.options;
if (isRef(obj,key)) {
if (obj[key].startsWith('#/components/')) {
// no-op
}
else if (obj[key] === '#/consumes') {
// people are *so* creative
delete obj[key];
state.parent[state.pkey] = clone(options.openapi.consumes);
}
else if (obj[key] === '#/produces') {
// and by creative, I mean devious
delete obj[key];
state.parent[state.pkey] = clone(options.openapi.produces);
}
else if (obj[key].startsWith('#/definitions/')) {
//only the first part of a schema component name must be sanitised
let keys = obj[key].replace('#/definitions/', '').split('/');
recurse(openapi, {identityDetection:true}, function (obj, key, state) {
if (isRef(obj,key)) {
options.context.push(state.path);
should(obj[key]).not.startWith('#/definitions/');
let refUrl = url.parse(obj[key]);
if (!refUrl.protocol && !refUrl.path) {
should(obj[key]+'/%24ref').not.be.equal(state.path,'Circular reference');
should(jptr.jptr(openapi,obj[key])).not.be.exactly(false, 'Cannot resolve reference: ' + obj[key]);
}
options.context.pop();
}
});
recurse(options.openapi,{},function(obj,key,state){
if (isRef(obj, key)) {
if (!options.preserveMiro) delete obj['x-miro'];
}
});
res(options);