Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let newRef = url.resolve(base,obj[key]).toString();
if (options.verbose>1) console.warn(common.colour.yellow+'Rewriting external url ref',obj[key],'as',newRef,common.colour.normal);
obj['x-miro'] = obj[key];
obj[key] = newRef;
}
else if (!obj['x-miro']) {
let newRef = url.resolve(base,obj[key]).toString();
if (options.verbose>1) console.warn(common.colour.yellow+'Rewriting external ref',obj[key],'as',newRef,common.colour.normal);
obj['x-miro'] = obj[key]; // we use x-miro as a flag so we don't do this > once
obj[key] = newRef;
}
}
});
}
recurse(obj,{},function(obj,key,state){
if (isRef(obj, key)) {
if (typeof obj.$fixed !== 'undefined') delete obj.$fixed;
}
});
if (options.verbose>1) console.warn('Finished fragment resolution');
return obj;
}
param["x-collectionFormat"] = 'tsv';
}
delete param.collectionFormat;
}
if (param.type && (param.type != 'object') && (param.type != 'body') && (param.in != 'formData')) {
if (param.items && param.schema) {
throwOrWarn('parameter has array,items and schema', param, options);
}
else {
if ((!param.schema) || (typeof param.schema !== 'object')) param.schema = {};
param.schema.type = param.type;
if (param.items) {
param.schema.items = param.items;
delete param.items;
recurse(param.schema.items, null, function (obj, key, state) {
if ((key === 'collectionFormat') && (typeof obj[key] === 'string')) {
if (oldCollectionFormat && obj[key] !== oldCollectionFormat) {
throwOrWarn('Nested collectionFormats are not supported', param, options);
}
delete obj[key]; // not lossless
}
// items in 2.0 was a subset of the JSON-Schema items
// object, it gets fixed up below
});
}
for (let prop of common.parameterTypeProperties) {
if (typeof param[prop] !== 'undefined') param.schema[prop] = param[prop];
delete param[prop];
}
}
}
if (shape.flattened) {
if (!shape.xml) shape.xml = {};
shape.xml.wrapped = (!shape.flattened);
delete shape.flattened;
}
delete shape.exception;
delete shape.fault;
delete shape.error;
delete shape.sensitive;
delete shape.synthetic;
delete shape.wrapper; // xml
delete shape.xmlOrder; // xml
recurse(shape,{},function(obj,key,state){
if (key == 'shape') {
obj["$ref"] = '#/definitions/'+obj[key];
checkDef(openapi,obj[key]);
delete obj[key];
}
if (key == 'documentation') {
obj.description = clean(obj.documentation);
delete obj.documentation;
}
if ((key == 'location') && (obj[key] == 'headers')) {
delete obj[key];
}
if ((key == 'location') && (obj[key] == 'statusCode')) {
delete obj[key]; // should already be pointed to by 'output'
}
if ((key == 'location') && (obj[key] == 'header')) {
let suffix = '';
if (s != sname) {
while (openapi.components.schemas[sname + suffix]) {
// @ts-ignore
suffix = (suffix ? ++suffix : 2);
}
openapi.components.schemas[sname + suffix] = openapi.components.schemas[s];
delete openapi.components.schemas[s];
}
componentNames.schemas[s] = sname + suffix;
fixUpSchema(openapi.components.schemas[sname+suffix],options)
}
// fix all $refs to their new locations (and potentially new names)
options.refmap = {};
recurse(openapi, { payload: { options: options } }, fixupRefs);
dedupeRefs(openapi,options);
for (let p in openapi.components.parameters) {
let sname = common.sanitise(p);
if (p != sname) {
if (openapi.components.parameters[sname]) {
throwError('Duplicate sanitised parameter name ' + sname, options);
}
openapi.components.parameters[sname] = openapi.components.parameters[p];
delete openapi.components.parameters[p];
}
let param = openapi.components.parameters[sname];
processParameter(param, null, null, null, sname, openapi, options);
}
for (let r in openapi.components.responses) {
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);
});
}
result.push(update.value);
}
}
else {
process(result,src,update,options);
}
}
else {
console.warn(update.target,'cannot update immutable type',rtype+' (target parent node instead)');
}
}
catch (ex) {
console.warn(update.target,'cannot be parsed',ex.message);
}
}
recurse(src,{},function(obj,key,state){
if (obj[key] === null) delete obj[key];
});
return reref(src);
}
function strim(obj,maxDepth) {
if (maxDepth <= 0) return obj;
recurse(obj,{identityDetection:true},function(obj,key,state){
if (state.depth >= maxDepth) {
if (Array.isArray(state.parent[state.pkey])) {
state.parent[state.pkey] = [];
}
else if (typeof state.parent[state.pkey] === 'object') {
state.parent[state.pkey] = {};
}
}
});
return obj;
}
}
for (let tag of options.tags) {
if (obj[key] && obj[key][tag]) {
if (options.inverse) {
if (options.strip) {
delete obj[key][tag];
}
jptr(filtered,state.path,clone(obj[key]));
}
filteredpaths.push(state.path);
delete obj[key];
break;
}
}
});
recurse((options.inverse ? filtered : src),{},function(obj,key,state){
if (Array.isArray(obj[key])) {
obj[key] = obj[key].filter(function(e){
return typeof e !== 'undefined';
});
}
});
recurse(src,{},function(obj,key,state){
if (obj.hasOwnProperty('$ref') && filteredpaths.includes(obj['$ref'])) {
if (Array.isArray(state.parent)) {
state.parent.splice(state.pkey, 1);
}
}
});
if (options.inverse && options.valid) {
let info = {};
if (src.info && (!filtered.info || !filtered.info.version || !filtered.info.title)) {