зеркало из https://github.com/Azure/ms-rest-js.git
Working on failing autorest.typescript tests
This commit is contained in:
Родитель
e9264bf45d
Коммит
1317489974
|
@ -10,7 +10,7 @@ export { HttpPipelineLogger } from "./httpPipelineLogger";
|
|||
export { HttpPipelineLogLevel } from "./httpPipelineLogLevel";
|
||||
export { RestError } from "./restError";
|
||||
export { OperationSpec } from "./operationSpec";
|
||||
export { OperationArguments, createOperationArguments } from "./operationArguments";
|
||||
export { OperationArguments } from "./operationArguments";
|
||||
export { ServiceClient, ServiceClientOptions } from "./serviceClient";
|
||||
export { QueryCollectionFormat } from "./queryCollectionFormat";
|
||||
export { Constants } from "./util/constants";
|
||||
|
|
|
@ -1,51 +1,19 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import { AbortSignalLike, RequestOptionsBase, TransferProgressEvent } from "./webResource";
|
||||
import { RequestOptionsBase } from "./webResource";
|
||||
|
||||
/**
|
||||
* A collection of properties that apply to a single invocation of an operation.
|
||||
*/
|
||||
export interface OperationArguments {
|
||||
/**
|
||||
* The arguments that were passed to the operation method.
|
||||
* The parameters that were passed to the operation method.
|
||||
*/
|
||||
arguments: { [parameterName: string]: any };
|
||||
[parameterName: string]: any;
|
||||
|
||||
/**
|
||||
* Headers that will be applied to this operation's HTTP request after the operation method's
|
||||
* header arguments are added.
|
||||
* The optional arugments that are provided to an operation.
|
||||
*/
|
||||
customHeaders?: { [headerName: string]: string };
|
||||
|
||||
/**
|
||||
* The signal which can be used to abort requests.
|
||||
*/
|
||||
abortSignal?: AbortSignalLike;
|
||||
|
||||
/**
|
||||
* Callback which fires upon upload progress. Only used in the browser.
|
||||
*/
|
||||
onUploadProgress?: (progress: TransferProgressEvent) => void;
|
||||
|
||||
/**
|
||||
* Callback which fires upon download progress. Only used in the browser.
|
||||
*/
|
||||
onDownloadProgress?: (progress: TransferProgressEvent) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns the properties of a RequestOptions object to an OperationArguments object.
|
||||
* @param args the arguments object to use in the OperatonArguments
|
||||
* @param options the RequestOptions to apply
|
||||
* @return an OperationArguments object
|
||||
*/
|
||||
export function createOperationArguments(args: { [parameterName: string]: any }, options?: RequestOptionsBase): OperationArguments {
|
||||
return {
|
||||
arguments: args,
|
||||
customHeaders: options && options.customHeaders,
|
||||
abortSignal: options && options.abortSignal,
|
||||
onUploadProgress: options && options.onUploadProgress,
|
||||
onDownloadProgress: options && options.onDownloadProgress,
|
||||
};
|
||||
}
|
||||
options?: RequestOptionsBase;
|
||||
}
|
|
@ -24,7 +24,7 @@ import { CompositeMapper, DictionaryMapper, Mapper, MapperType, Serializer } fro
|
|||
import { URLBuilder } from "./url";
|
||||
import { Constants } from "./util/constants";
|
||||
import * as utils from "./util/utils";
|
||||
import { RequestPrepareOptions, WebResource } from "./webResource";
|
||||
import { RequestPrepareOptions, WebResource, RequestOptionsBase } from "./webResource";
|
||||
|
||||
/**
|
||||
* Options to be provided while creating the client.
|
||||
|
@ -256,22 +256,25 @@ export class ServiceClient {
|
|||
}
|
||||
}
|
||||
|
||||
if (operationArguments.customHeaders) {
|
||||
for (const customHeaderName in operationArguments.customHeaders) {
|
||||
httpRequest.headers.set(customHeaderName, operationArguments.customHeaders[customHeaderName]);
|
||||
const options: RequestOptionsBase | undefined = operationArguments.options;
|
||||
if (options) {
|
||||
if (options.customHeaders) {
|
||||
for (const customHeaderName in options.customHeaders) {
|
||||
httpRequest.headers.set(customHeaderName, options.customHeaders[customHeaderName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (operationArguments.abortSignal) {
|
||||
httpRequest.abortSignal = operationArguments.abortSignal;
|
||||
}
|
||||
if (options.abortSignal) {
|
||||
httpRequest.abortSignal = options.abortSignal;
|
||||
}
|
||||
|
||||
if (operationArguments.onUploadProgress) {
|
||||
httpRequest.onUploadProgress = operationArguments.onUploadProgress;
|
||||
}
|
||||
if (options.onUploadProgress) {
|
||||
httpRequest.onUploadProgress = options.onUploadProgress;
|
||||
}
|
||||
|
||||
if (operationArguments.onDownloadProgress) {
|
||||
httpRequest.onDownloadProgress = operationArguments.onDownloadProgress;
|
||||
if (options.onDownloadProgress) {
|
||||
httpRequest.onDownloadProgress = options.onDownloadProgress;
|
||||
}
|
||||
}
|
||||
|
||||
httpRequest.withCredentials = this._withCredentials;
|
||||
|
@ -393,33 +396,32 @@ function getOperationArgumentValueFromParameterPath(serviceClient: ServiceClient
|
|||
if (typeof parameterPath === "string") {
|
||||
parameterPath = [parameterPath];
|
||||
}
|
||||
if (operationArguments.arguments) {
|
||||
if (Array.isArray(parameterPath)) {
|
||||
if (parameterPath.length > 0) {
|
||||
let propertySearchResult: PropertySearchResult = getPropertyFromParameterPath(operationArguments.arguments, parameterPath);
|
||||
if (!propertySearchResult.propertyFound) {
|
||||
propertySearchResult = getPropertyFromParameterPath(serviceClient, parameterPath);
|
||||
}
|
||||
value = propertySearchResult.propertyValue;
|
||||
|
||||
// Serialize just for validation purposes.
|
||||
const parameterPathString: string = getPathStringFromParameterPath(parameterPath, parameterMapper);
|
||||
serializer.serialize(parameterMapper, value, parameterPathString);
|
||||
if (Array.isArray(parameterPath)) {
|
||||
if (parameterPath.length > 0) {
|
||||
const parameterInOptions: boolean = parameterPath[0] === "options";
|
||||
let propertySearchResult: PropertySearchResult = getPropertyFromParameterPath(operationArguments, parameterPath);
|
||||
if (!propertySearchResult.propertyFound && parameterInOptions) {
|
||||
propertySearchResult = getPropertyFromParameterPath(serviceClient, parameterPath);
|
||||
}
|
||||
} else {
|
||||
for (const propertyName in parameterPath) {
|
||||
const propertyMapper: Mapper = (parameterMapper as CompositeMapper).type.modelProperties[propertyName];
|
||||
const propertyPath: ParameterPath = parameterPath[propertyName];
|
||||
const propertyValue: any = getOperationArgumentValueFromParameterPath(serviceClient, operationArguments, propertyPath, propertyMapper, serializer);
|
||||
// Serialize just for validation purposes.
|
||||
const propertyPathString: string = getPathStringFromParameterPath(propertyPath, propertyMapper);
|
||||
serializer.serialize(propertyMapper, propertyValue, propertyPathString);
|
||||
if (propertyValue !== undefined) {
|
||||
if (!value) {
|
||||
value = {};
|
||||
}
|
||||
value[propertyName] = propertyValue;
|
||||
value = propertySearchResult.propertyFound ? propertySearchResult.propertyValue : parameterMapper.defaultValue;
|
||||
|
||||
// Serialize just for validation purposes.
|
||||
const parameterPathString: string = getPathStringFromParameterPath(parameterPath, parameterMapper);
|
||||
serializer.serialize(parameterMapper, value, parameterPathString);
|
||||
}
|
||||
} else {
|
||||
for (const propertyName in parameterPath) {
|
||||
const propertyMapper: Mapper = (parameterMapper as CompositeMapper).type.modelProperties[propertyName];
|
||||
const propertyPath: ParameterPath = parameterPath[propertyName];
|
||||
const propertyValue: any = getOperationArgumentValueFromParameterPath(serviceClient, operationArguments, propertyPath, propertyMapper, serializer);
|
||||
// Serialize just for validation purposes.
|
||||
const propertyPathString: string = getPathStringFromParameterPath(propertyPath, propertyMapper);
|
||||
serializer.serialize(propertyMapper, propertyValue, propertyPathString);
|
||||
if (propertyValue !== undefined) {
|
||||
if (!value) {
|
||||
value = {};
|
||||
}
|
||||
value[propertyName] = propertyValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
"autorest",
|
||||
"clientruntime"
|
||||
],
|
||||
"main": "./dist/lib/msRest.js",
|
||||
"main": "./lib/msRest.ts",
|
||||
"types": "./typings/lib/msRest.d.ts",
|
||||
"browser": {
|
||||
"./dist/lib/msRest.js": "./es/lib/msRest.js",
|
||||
|
|
|
@ -24,13 +24,11 @@ describe("ServiceClient", function () {
|
|||
|
||||
await client.sendOperationRequest(
|
||||
{
|
||||
arguments: {
|
||||
metadata: {
|
||||
"alpha": "hello",
|
||||
"beta": "world"
|
||||
},
|
||||
unrelated: 42
|
||||
}
|
||||
metadata: {
|
||||
"alpha": "hello",
|
||||
"beta": "world"
|
||||
},
|
||||
unrelated: 42
|
||||
},
|
||||
{
|
||||
httpMethod: "GET",
|
||||
|
@ -84,9 +82,7 @@ describe("ServiceClient", function () {
|
|||
|
||||
await client.sendOperationRequest(
|
||||
{
|
||||
arguments: {
|
||||
q: [1, 2, 3],
|
||||
},
|
||||
q: [1, 2, 3]
|
||||
},
|
||||
{
|
||||
httpMethod: "GET",
|
||||
|
@ -133,7 +129,8 @@ describe("ServiceClient", function () {
|
|||
httpClient,
|
||||
requestPolicyCreators: []
|
||||
});
|
||||
await client1.sendOperationRequest({ arguments: {} },
|
||||
await client1.sendOperationRequest(
|
||||
{},
|
||||
{
|
||||
serializer: new Serializer(),
|
||||
httpMethod: "GET",
|
||||
|
@ -148,7 +145,8 @@ describe("ServiceClient", function () {
|
|||
requestPolicyCreators: [],
|
||||
withCredentials: true
|
||||
});
|
||||
await client2.sendOperationRequest({ arguments: {} },
|
||||
await client2.sendOperationRequest(
|
||||
{},
|
||||
{
|
||||
serializer: new Serializer(),
|
||||
httpMethod: "GET",
|
||||
|
@ -165,9 +163,7 @@ describe("ServiceClient", function () {
|
|||
new ServiceClient(),
|
||||
httpRequest,
|
||||
{
|
||||
arguments: {
|
||||
bodyArg: "body value"
|
||||
}
|
||||
bodyArg: "body value"
|
||||
},
|
||||
{
|
||||
httpMethod: "POST",
|
||||
|
@ -193,9 +189,7 @@ describe("ServiceClient", function () {
|
|||
new ServiceClient(),
|
||||
httpRequest,
|
||||
{
|
||||
arguments: {
|
||||
bodyArg: stringToByteArray("Javascript")
|
||||
}
|
||||
bodyArg: stringToByteArray("Javascript")
|
||||
},
|
||||
{
|
||||
httpMethod: "POST",
|
||||
|
@ -221,9 +215,7 @@ describe("ServiceClient", function () {
|
|||
new ServiceClient(),
|
||||
httpRequest,
|
||||
{
|
||||
arguments: {
|
||||
bodyArg: "body value"
|
||||
}
|
||||
bodyArg: "body value"
|
||||
},
|
||||
{
|
||||
httpMethod: "POST",
|
||||
|
@ -249,9 +241,7 @@ describe("ServiceClient", function () {
|
|||
new ServiceClient(),
|
||||
httpRequest,
|
||||
{
|
||||
arguments: {
|
||||
bodyArg: "body value"
|
||||
}
|
||||
bodyArg: "body value"
|
||||
},
|
||||
{
|
||||
httpMethod: "POST",
|
||||
|
@ -280,9 +270,7 @@ describe("ServiceClient", function () {
|
|||
new ServiceClient(),
|
||||
httpRequest,
|
||||
{
|
||||
arguments: {
|
||||
bodyArg: stringToByteArray("Javascript")
|
||||
}
|
||||
bodyArg: stringToByteArray("Javascript")
|
||||
},
|
||||
{
|
||||
httpMethod: "POST",
|
||||
|
@ -311,9 +299,7 @@ describe("ServiceClient", function () {
|
|||
new ServiceClient(),
|
||||
httpRequest,
|
||||
{
|
||||
arguments: {
|
||||
bodyArg: "body value"
|
||||
}
|
||||
bodyArg: "body value"
|
||||
},
|
||||
{
|
||||
httpMethod: "POST",
|
||||
|
|
Загрузка…
Ссылка в новой задаче