зеркало из https://github.com/Azure/ms-rest-js.git
Code changes to modify encoding step
This commit is contained in:
Родитель
6244e919cf
Коммит
8f0294a4bb
|
@ -245,8 +245,6 @@ export class ServiceClient {
|
|||
queryParameterValue[index] = item == undefined ? "" : item.toString();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
queryParameterValue = queryParameterValue.join(queryParameter.collectionFormat);
|
||||
}
|
||||
}
|
||||
if (!queryParameter.skipEncoding) {
|
||||
|
@ -254,6 +252,9 @@ export class ServiceClient {
|
|||
for (const index in queryParameterValue) {
|
||||
queryParameterValue[index] = encodeURIComponent(queryParameterValue[index]);
|
||||
}
|
||||
if (queryParameter.collectionFormat !== QueryCollectionFormat.Multi) {
|
||||
queryParameterValue = queryParameterValue.join(queryParameter.collectionFormat);
|
||||
}
|
||||
}
|
||||
else {
|
||||
queryParameterValue = encodeURIComponent(queryParameterValue);
|
||||
|
|
|
@ -101,6 +101,56 @@ describe("ServiceClient", function () {
|
|||
assert.strictEqual(JSON.stringify(response), "{}");
|
||||
});
|
||||
|
||||
it("should serialize collection:csv query parameters", async function() {
|
||||
const expected = "?q=1,2,3";
|
||||
|
||||
let request: WebResource;
|
||||
const client = new ServiceClient(undefined, {
|
||||
httpClient: {
|
||||
sendRequest: req => {
|
||||
request = req;
|
||||
return Promise.resolve({ request, status: 200, headers: new HttpHeaders() });
|
||||
},
|
||||
},
|
||||
requestPolicyFactories: () => [],
|
||||
});
|
||||
|
||||
await client.sendOperationRequest(
|
||||
{
|
||||
q: [1, 2, 3]
|
||||
},
|
||||
{
|
||||
httpMethod: "GET",
|
||||
baseUrl: "httpbin.org",
|
||||
serializer: new Serializer(),
|
||||
queryParameters: [
|
||||
{
|
||||
collectionFormat: QueryCollectionFormat.Csv,
|
||||
parameterPath: "q",
|
||||
mapper: {
|
||||
serializedName: "q",
|
||||
type: {
|
||||
name: "Sequence",
|
||||
element: {
|
||||
type: {
|
||||
name: "Number",
|
||||
},
|
||||
serializedName: "q",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
responses: {
|
||||
200: {},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
assert(request!);
|
||||
assert(request!.url.endsWith(expected), `"${request!.url}" does not end with "${expected}"`);
|
||||
});
|
||||
|
||||
it("should serialize collection:multi query parameters", async function () {
|
||||
const expected = "?q=1&q=2&q=3";
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче