Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully support url template in Modular #2884

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
305007d
Update the uri template from http operations
MaryGao Oct 28, 2024
8670310
Refactor the uri template parameters
MaryGao Oct 28, 2024
fad5c86
regen smoke
v-jiaodi Oct 28, 2024
34a1ca2
Update the UTs for testing
MaryGao Oct 28, 2024
825484d
Merge remote-tracking branch 'mary/poc-modular-uri-template-support' …
MaryGao Oct 28, 2024
18687ff
Merge remote-tracking branch 'origin/main' into poc-modular-uri-templ…
MaryGao Oct 29, 2024
a5b4ca0
Refactor the code a little
MaryGao Oct 29, 2024
71e1ca3
Format the codes
MaryGao Oct 29, 2024
0e27f02
regen smoke
v-jiaodi Oct 30, 2024
bbde7ce
fix unit test
v-jiaodi Oct 30, 2024
0adb123
Update to the main to resolve conflicts
MaryGao Nov 22, 2024
265c8b5
Remove the folder first
MaryGao Nov 22, 2024
87b4b9e
Merge remote-tracking branch 'origin/main' into pr/MaryGao/2884
MaryGao Nov 22, 2024
5c8a95e
Merge remote-tracking branch 'origin/main' into poc-modular-uri-templ…
MaryGao Nov 29, 2024
0c90e71
Update the build issue
MaryGao Dec 5, 2024
3f873b8
Update the test cases
MaryGao Dec 10, 2024
91258a5
Add test cases for url template
MaryGao Dec 10, 2024
65ea9db
Update the UTs for url templates
MaryGao Dec 11, 2024
197e60b
Update the lib
MaryGao Dec 12, 2024
61c352c
Update the helper to pass all test cases
MaryGao Dec 17, 2024
ace6c1d
Remove useless codes
MaryGao Dec 17, 2024
c287bec
Update the template with renaming
MaryGao Dec 17, 2024
bddc800
Regen smoke test for batch services
MaryGao Dec 18, 2024
9734181
Merge remote-tracking branch 'origin/main' into pr/MaryGao/2884
MaryGao Dec 18, 2024
b15df11
Support allowReserved option
MaryGao Dec 18, 2024
3caef4a
Merge remote-tracking branch 'origin/main' into poc-modular-uri-templ…
MaryGao Dec 19, 2024
f8ac148
Fix the operation group issues
MaryGao Dec 20, 2024
fac468a
Rename uri to url
MaryGao Dec 20, 2024
c00a804
Add skipUrlEncoding so customers could set method-level skip encoding
MaryGao Dec 20, 2024
89debc7
Remove useless codes
MaryGao Dec 20, 2024
a5b072b
Update the test cases
MaryGao Dec 20, 2024
25817ae
Update the unit test cases
MaryGao Dec 20, 2024
973b316
Refresh the unit test for modular and rlc
MaryGao Dec 20, 2024
3484a89
add routes modular case
v-jiaodi Dec 23, 2024
08aa1c3
Fix the option parameter renaming issue
MaryGao Dec 23, 2024
d63b7a0
fix ci
v-jiaodi Dec 23, 2024
085a0dc
Update the test dependency for ut
MaryGao Dec 23, 2024
51ebe8c
Merge branch 'poc-modular-uri-template-support' of https://github.com…
MaryGao Dec 23, 2024
14e059d
Support the tsv, ssv and pipe format
MaryGao Dec 23, 2024
32848c2
fix ci
v-jiaodi Dec 23, 2024
c30bc15
Update the test cases
MaryGao Dec 23, 2024
81a590d
Merge branch 'poc-modular-uri-template-support' of https://github.com…
MaryGao Dec 23, 2024
111f677
Update the test cases
MaryGao Dec 23, 2024
ab5e380
Refine the helpers
MaryGao Dec 23, 2024
8a0bd79
fix ci
v-jiaodi Dec 24, 2024
82141a3
update
v-jiaodi Dec 24, 2024
a4539a7
Fix the issues
MaryGao Dec 24, 2024
87486ce
revert change
v-jiaodi Dec 24, 2024
598d01d
Fix the issue
MaryGao Dec 24, 2024
9f43cf4
Merge branch 'poc-modular-uri-template-support' of https://github.com…
MaryGao Dec 24, 2024
59a7142
Update the test cases and refine the code a little
MaryGao Dec 24, 2024
760e7cf
regen smoke
v-jiaodi Dec 24, 2024
a9d3dcd
Merge branch 'poc-modular-uri-template-support' of https://github.com…
v-jiaodi Dec 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
PagedAsyncIterableIterator,
buildPagedAsyncIterator,
} from "../../static-helpers/pagingHelpers.js";
import { parseTemplate } from "../../static-helpers/uriTemplate.js";
import {
StreamableMethod,
PathUncheckedResponse,
Expand All @@ -45,8 +46,11 @@ export function _getMultivariateBatchDetectionResultSend(
requestOptions: {},
},
): StreamableMethod {
const path = parseTemplate("/multivariate/detect-batch/{resultId}").expand({
resultId: resultId,
});
return context
.path("/multivariate/detect-batch/{resultId}", resultId)
.path(path)
.get({ ...operationOptionsToRequestParameters(options) });
}

Expand Down Expand Up @@ -132,12 +136,13 @@ export function _listMultivariateModelsSend(
requestOptions: {},
},
): StreamableMethod {
const path = parseTemplate("/multivariate/models{?skip,top}").expand({
skip: options?.skip,
top: options?.top,
});
return context
.path("/multivariate/models")
.get({
...operationOptionsToRequestParameters(options),
queryParameters: { skip: options?.skip, top: options?.top },
});
.path(path)
.get({ ...operationOptionsToRequestParameters(options) });
}

export async function _listMultivariateModelsDeserialize(
Expand Down Expand Up @@ -174,8 +179,11 @@ export function _deleteMultivariateModelSend(
requestOptions: {},
},
): StreamableMethod {
const path = parseTemplate("/multivariate/models/{modelId}").expand({
modelId: modelId,
});
return context
.path("/multivariate/models/{modelId}", modelId)
.path(path)
.delete({ ...operationOptionsToRequestParameters(options) });
}

Expand Down Expand Up @@ -209,8 +217,11 @@ export function _getMultivariateModelSend(
requestOptions: {},
},
): StreamableMethod {
const path = parseTemplate("/multivariate/models/{modelId}").expand({
modelId: modelId,
});
return context
.path("/multivariate/models/{modelId}", modelId)
.path(path)
.get({ ...operationOptionsToRequestParameters(options) });
}

Expand Down Expand Up @@ -248,8 +259,13 @@ export function _detectMultivariateBatchAnomalySend(
requestOptions: {},
},
): StreamableMethod {
const path = parseTemplate(
"/multivariate/models/{modelId}:detect-batch",
).expand({
modelId: modelId,
});
return context
.path("/multivariate/models/{modelId}:detect-batch", modelId)
.path(path)
.post({
...operationOptionsToRequestParameters(optionalParams),
body: multivariateMultivariateBatchDetectionOptionsSerializer(options),
Expand Down Expand Up @@ -300,8 +316,13 @@ export function _detectMultivariateLastAnomalySend(
requestOptions: {},
},
): StreamableMethod {
const path = parseTemplate(
"/multivariate/models/{modelId}:detect-last",
).expand({
modelId: modelId,
});
return context
.path("/multivariate/models/{modelId}:detect-last", modelId)
.path(path)
.post({
...operationOptionsToRequestParameters(optionalParams),
body: multivariateMultivariateLastDetectionOptionsSerializer(options),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
function encodeReserved(str: any) {
return str
.split(/(%[0-9A-Fa-f]{2})/g)
.map(function (part: any) {
if (!/%[0-9A-Fa-f]/.test(part)) {
part = encodeURI(part).replace(/%5B/g, "[").replace(/%5D/g, "]");
}
return part;
})
.join("");
}

function encodeUnreserved(str: any) {
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
return "%" + c.charCodeAt(0).toString(16).toUpperCase();
});
}

function encodeValue(operator: any, value: any, key?: any | null) {
value =
operator === "+" || operator === "#"
? encodeReserved(value)
: encodeUnreserved(value);

if (key) {
return encodeUnreserved(key) + "=" + value;
} else {
return value;
}
}

function isDefined(value: any) {
return value !== undefined && value !== null;
}

function isKeyOperator(operator: string): boolean {
return operator === ";" || operator === "&" || operator === "?";
}

function getValues(
context: any,
operator: any,
key: any | null,
modifier: any | null,
) {
var value = context[key],
result: any[] = [];

if (isDefined(value) && value !== "") {
if (
typeof value === "string" ||
typeof value === "number" ||
typeof value === "boolean"
) {
value = value.toString();

if (modifier && modifier !== "*") {
value = value.substring(0, parseInt(modifier, 10));
}
result.push(
encodeValue(operator, value, isKeyOperator(operator) ? key : null),
);
} else {
if (modifier === "*") {
if (Array.isArray(value)) {
value.filter(isDefined).forEach(function (value) {
result.push(
encodeValue(
operator,
value,
isKeyOperator(operator) ? key : null,
),
);
});
} else {
Object.keys(value).forEach(function (k) {
if (isDefined(value[k])) {
result.push(encodeValue(operator, value[k], k));
}
});
}
} else {
var tmp: any[] = [];

if (Array.isArray(value)) {
value.filter(isDefined).forEach(function (value) {
tmp.push(encodeValue(operator, value));
});
} else {
Object.keys(value).forEach(function (k) {
if (isDefined(value[k])) {
tmp.push(encodeUnreserved(k));
tmp.push(encodeValue(operator, value[k].toString()));
}
});
}

if (isKeyOperator(operator)) {
result.push(encodeUnreserved(key) + "=" + tmp.join(","));
} else if (tmp.length !== 0) {
result.push(tmp.join(","));
}
}
}
} else {
if (operator === ";") {
if (isDefined(value)) {
result.push(encodeUnreserved(key));
}
} else if (value === "" && (operator === "&" || operator === "?")) {
result.push(encodeUnreserved(key) + "=");
} else if (value === "") {
result.push("");
}
}
return result;
}

export function parseTemplate(template: any) {
var operators = ["+", "#", ".", "/", ";", "?", "&"];

return {
expand: function (context: any) {
return template.replace(
/\{([^\{\}]+)\}|([^\{\}]+)/g,
function (_: any, expression: any, literal: any) {
if (expression) {
var operator: any = null,
values: any[] = [];

if (operators.indexOf(expression.charAt(0)) !== -1) {
operator = expression.charAt(0);
expression = expression.substr(1);
}

expression.split(/,/g).forEach(function (variable: any) {
var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable);
if (!!tmp) {
values.push.apply(
values,
getValues(context, operator, tmp[1], tmp[2] || tmp[3]),
);
}
});

if (operator && operator !== "+") {
var separator = ",";

if (operator === "?") {
separator = "&";
} else if (operator !== "#") {
separator = operator;
}
return (
(values.length !== 0 ? operator : "") + values.join(separator)
);
} else {
return values.join(",");
}
} else {
return encodeReserved(literal);
}
},
);
},
};
}
Loading
Loading