in api/VsoClient.ts [58:112]
protected autoNegotiateApiVersion(location: ifm.ApiResourceLocation, requestedVersion: string): string {
let negotiatedVersion: string;
let apiVersion: number;
let apiVersionString: string;
if (requestedVersion) {
let apiVersionRegEx = new RegExp('(\\d+(\\.\\d+)?)(-preview(\\.(\\d+))?)?');
// Need to handle 3 types of api versions + invalid apiversion
// '2.1-preview.1' = ["2.1-preview.1", "2.1", ".1", -preview.1", ".1", "1"]
// '2.1-preview' = ["2.1-preview", "2.1", ".1", "-preview", undefined, undefined]
// '2.1' = ["2.1", "2.1", ".1", undefined, undefined, undefined]
let isPreview = false;
let resourceVersion: number;
let regExExecArray = apiVersionRegEx.exec(requestedVersion);
if (regExExecArray) {
if (regExExecArray[1]) {
// we have an api version
apiVersion = +regExExecArray[1];
apiVersionString = regExExecArray[1];
if (regExExecArray[3]) {
// requesting preview
isPreview = true;
if (regExExecArray[5]) {
// we have a resource version
resourceVersion = +regExExecArray[5];
}
}
// compare the location version and requestedversion
if (apiVersion <= +location.releasedVersion
|| (!resourceVersion && apiVersion <= +location.maxVersion && isPreview)
|| (resourceVersion && apiVersion <= +location.maxVersion && resourceVersion <= +location.resourceVersion)) {
negotiatedVersion = requestedVersion;
}
// else fall back to latest version of the resource from location
}
}
}
if (!negotiatedVersion) {
// Use the latest version of the resource if the api version was not specified in the request or if the requested version is higher then the location's supported version
if (apiVersion < +location.maxVersion) {
negotiatedVersion = apiVersionString + "-preview";
}
else if (location.maxVersion === location.releasedVersion) {
negotiatedVersion = location.maxVersion;
}
else {
negotiatedVersion = location.maxVersion + "-preview." + location.resourceVersion;
}
}
return negotiatedVersion;
}