Updated code to be more readable as suggested in comment

This commit is contained in:
Vishal Shingala
2021-08-05 12:26:00 +05:30
parent 3cbbf4f320
commit 25b2ee0831

View File

@@ -176,14 +176,17 @@ module.exports = {
return { value: 'reference ' + schema.$ref + ' not found in the OpenAPI spec' };
}
/**
* use cached schema if it was resolved at level lower or equal then at current stack level or
* cached schema is resolved fully (it does not contain ERR_TOO_MANY_LEVELS value in sub schema)
*/
if (_.get(schemaResolutionCache, [refKey, 'schema']) &&
(_.get(schemaResolutionCache, [refKey, 'maxStack'], 0) < stackLimit ||
_.get(schemaResolutionCache, [refKey, 'resLevel'], stackLimit) <= stack)) {
return schemaResolutionCache[refKey].schema;
if (_.get(schemaResolutionCache, [refKey, 'schema'])) {
let maxStack = _.get(schemaResolutionCache, [refKey, 'maxStack'], 0),
resLevel = _.get(schemaResolutionCache, [refKey, 'resLevel'], stackLimit);
/**
* use cached schema if it was resolved at level lower or equal then at current stack level or
* if cached schema is resolved fully (it does not contain ERR_TOO_MANY_LEVELS value in sub schema)
*/
if (resLevel <= stack || maxStack < stackLimit) {
return schemaResolutionCache[refKey].schema;
}
}
// something like #/components/schemas/PaginationEnvelope/properties/page
// will be resolved - we don't care about anything after the components part