Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_.each(composed.properties, function (property, name) {
var oProp = original.properties[name];
// Convert the string values to numerical values
_.each(['maximum', 'minimum'], function (prop) {
if (_.isString(property[prop])) {
property[prop] = parseFloat(property[prop]);
}
});
_.each(JsonRefs.findRefs(oProp, {
includeInvalid: true,
refPreProcessor: swagger1RefPreProcesor
}), function (refDetails, refPtr) {
var dMetadata = documentMetadata.definitions[refDetails.uri];
var path = JsonRefs.pathFromPtr(refPtr);
if (dMetadata.lineage.length > 0) {
traverse(property).set(path, getOrComposeSchema(documentMetadata, refDetails.uri));
} else {
traverse(property).set(path.concat('title'), 'Composed ' + sanitizeRef(documentMetadata.swaggerVersion,
refDetails.uri));
}
});
});
}
var type = swaggerVersion === '1.2' ? 'Model' : 'Definition';
if (iProperties.indexOf(name) === -1 && dProperties.indexOf(name) === -1) {
createErrorOrWarning('MISSING_REQUIRED_' + type.toUpperCase() + '_PROPERTY',
type + ' requires property but it is not defined: ' + name,
defPath.concat(['required', index.toString()]), results.errors);
}
});
});
if (documentMetadata.swaggerVersion === '1.2') {
jsonRefsOptions.refPreProcessor = swagger1RefPreProcesor;
}
// Process local references
_.each(JsonRefs.findRefs(documentMetadata.original, jsonRefsOptions), function (refDetails, refPtr) {
addReference(documentMetadata, refDetails.uri, refPtr, results);
});
// Process invalid references
_.each(documentMetadata.referencesMetadata, function (refDetails, refPtr) {
if (isRemotePtr(refDetails) && refDetails.missing === true) {
results.errors.push({
code: 'UNRESOLVABLE_REFERENCE',
message: 'Reference could not be resolved: ' + sanitizeRef(documentMetadata.swaggerVersion, refDetails.uri),
path: JsonRefs.pathFromPtr(refPtr).concat('$ref')
});
}
});
};
if (!doc) {
doc = self.specInJson;
}
if (!docPath) {
docPath = self.specPath;
docDir = self.specDir;
}
if (!docDir) {
docDir = path.dirname(docPath);
}
if (filterType === 'all') {
delete options.filter;
}
let allRefsRemoteRelative = JsonRefs.findRefs(doc, options);
let promiseFactories = Object.keys(allRefsRemoteRelative).map(function (refName) {
let refDetails = allRefsRemoteRelative[refName];
return function () { return self.resolveRelativeReference(refName, refDetails, doc, docPath); };
});
if (promiseFactories.length) {
return utils.executePromisesSequentially(promiseFactories);
} else {
return Promise.resolve(doc);
}
}
export const findRefs = (
obj: object | ReadonlyArray,
options?: jsonRefs.JsonRefsOptions
): sm.StringMap =>
jsonRefs.findRefs(obj, options) as sm.StringMap
private async resolveExamples(
suppression: Suppression | undefined
): Promise> {
const options = {
relativeBase: this.specDir,
filter: ["relative", "remote"]
}
const allRefsRemoteRelative = JsonRefs.findRefs(this.specInJson as object, options)
const e = entries(allRefsRemoteRelative as StringMap)
const promiseFactories = toArray(
map(e, ([refName, refDetails]) => async () =>
this.resolveRelativeReference(
suppression,
refName,
refDetails,
this.specInJson,
this.specPath
)
)
)
if (promiseFactories.length) {
return utils.executePromisesSequentially(promiseFactories)
} else {
return this.specInJson
methods[method] = spec.paths[path][method]
} catch (error) {
if (error.status !== 403) {
throw error
}
}
}
if (Object.keys(methods).length) {
paths[path] = methods
}
}
const definitions = {}
const refs = jsonRefs.findRefs(paths)
Object.keys(refs).forEach(key => {
const values = jsonRefs.pathFromPtr(refs[key].uri)
const definition = values[1]
definitions[definition] = spec.definitions[definition]
})
spec.paths = paths
spec.definitions = definitions
return spec
}