in lib/liveValidation/operationSearcher.ts [139:219]
public search(info: ValidationRequest): {
operationMatch: OperationMatch;
apiVersion: string;
} {
const startTime = Date.now();
const requestInfo = { ...info };
const searchOperation = () => {
const operations = this.getPotentialOperations(requestInfo);
if (operations.reason !== undefined) {
this.logging(
`${operations.reason.message} with requestUrl ${requestInfo.requestUrl}`,
LiveValidatorLoggingLevels.info,
LiveValidatorLoggingTypes.trace,
"Oav.OperationSearcher.search.getPotentialOperations",
undefined,
requestInfo
);
}
return operations;
};
let potentialOperations = searchOperation();
const firstReason = potentialOperations.reason;
if (potentialOperations!.matches.length === 0) {
this.logging(
`Fallback to ${unknownResourceProvider} -> ${unknownApiVersion}`,
LiveValidatorLoggingLevels.info,
LiveValidatorLoggingTypes.trace,
"Oav.OperationSearcher.search",
undefined,
requestInfo
);
//requestInfo.apiVersion = unknownApiVersion;
potentialOperations = searchOperation();
}
if (potentialOperations.matches.length === 0) {
throw firstReason ?? potentialOperations.reason;
}
if (potentialOperations.matches.length > 1) {
const operationInfos: Array<{ id: string; path: string; specPath: string }> = [];
potentialOperations.matches.forEach(({ operation }) => {
const specPath = operation._path._spec._filePath;
operationInfos.push({
id: operation.operationId!,
path: operation._path._pathTemplate,
specPath,
});
});
const msg =
`Found multiple matching operations ` +
`for request url "${requestInfo.requestUrl}" with HTTP Method "${requestInfo.requestMethod}".` +
`Operation Information: ${JSON.stringify(operationInfos)}`;
this.logging(
msg,
LiveValidatorLoggingLevels.info,
LiveValidatorLoggingTypes.trace,
"Oav.OperationSearcher.Search",
undefined,
requestInfo
);
const e = new LiveValidationError(ErrorCodes.MultipleOperationsFound.name, msg);
throw e;
}
this.logging(
"Complete operation search",
LiveValidatorLoggingLevels.info,
LiveValidatorLoggingTypes.perfTrace,
"Oav.OperationSearcher.Search",
Date.now() - startTime,
requestInfo
);
return {
operationMatch: potentialOperations.matches[0],
apiVersion: potentialOperations.apiVersion,
};
}