This commit is contained in:
Dan Schulte 2018-05-30 14:23:36 -07:00
Родитель cbf8dad4b4
Коммит 5d750528b7
11 изменённых файлов: 96 добавлений и 212 удалений

Просмотреть файл

@ -10,7 +10,6 @@ export { HttpPipelineLogger } from "./httpPipelineLogger";
export { HttpPipelineLogLevel } from "./httpPipelineLogLevel";
export { RestError } from "./restError";
export { OperationSpec } from "./operationSpec";
export { OperationParameterType } from "./operationParameterType";
export { OperationArguments, createOperationArguments } from "./operationArguments";
export { ServiceClient, ServiceClientOptions } from "./serviceClient";
export { QueryCollectionFormat } from "./queryCollectionFormat";

Просмотреть файл

@ -1,26 +0,0 @@
import { OperationParameterType } from "./operationParameterType";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
/**
* A parameter for an operation that will be added as a property to the operation's formdata request
* body.
*/
export interface OperationFormDataParameter {
/**
* The name of the parameter.
*/
parameterName: string;
/**
* The name of the formdata property. If this is not provided, then the name of the parameter will
* be used as the formdata's property name.
*/
formDataPropertyName?: string;
/**
* The type of value that this parameter contains.
*/
type?: OperationParameterType;
}

Просмотреть файл

@ -1,25 +0,0 @@
import { OperationParameterType } from "./operationParameterType";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
/**
* A parameter for an operation that will be added as a header to the operation's HTTP request.
*/
export interface OperationHeaderParameter {
/**
* The name of the parameter.
*/
parameterName: string;
/**
* The name of the HTTP header. If this is not provided, then the name of the parameter will be
* used as the header's name.
*/
headerName?: string;
/**
* The type of value that this parameter contains.
*/
type?: OperationParameterType;
}

82
lib/operationParameter.ts Normal file
Просмотреть файл

@ -0,0 +1,82 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { Mapper } from "./serializer";
import { QueryCollectionFormat } from "./queryCollectionFormat";
/**
* A common interface that all Operation parameter's extend.
*/
export interface OperationParameter {
/**
* The name of the parameter.
*/
parameterName: string;
/**
* The mapper that defines how to validate and serialize this parameter's value.
*/
mapper: Mapper;
}
/**
* A parameter for an operation that will be substituted into the operation's request URL.
*/
export interface OperationURLParameter extends OperationParameter {
/**
* The name of the parameter that will be replaced in the constructed URL. header. If this is not
* provided, then the name of the parameter will be used as the urlParameterName instead.
*/
urlParameterName?: string;
/**
* Whether or not to skip encoding the URL parameter's value before adding it to the URL.
*/
skipEncoding?: boolean;
}
/**
* A parameter for an operation that will be added as a query parameter to the operation's HTTP
* request.
*/
export interface OperationQueryParameter extends OperationParameter {
/**
* The name of the query parameter that will be added in the constructed URL. header. If this is
* not provided, then the name of the parameter will be used as the query parameter name instead.
*/
queryParameterName?: string;
/**
* Whether or not to skip encoding the query parameter's value before adding it to the URL.
*/
skipEncoding?: boolean;
/**
* If this query parameter's value is a collection, what type of format should the value be
* converted to.
*/
collectionFormat?: QueryCollectionFormat;
}
/**
* A parameter for an operation that will be added as a header to the operation's HTTP request.
*/
export interface OperationHeaderParameter extends OperationParameter {
/**
* The name of the HTTP header. If this is not provided, then the name of the parameter will be
* used as the header's name.
*/
headerName?: string;
}
/**
* A parameter for an operation that will be added as a property to the operation's formdata request
* body.
*/
export interface OperationFormDataParameter extends OperationParameter {
/**
* The name of the formdata property. If this is not provided, then the name of the parameter will
* be used as the formdata's property name.
*/
formDataPropertyName?: string;
}

Просмотреть файл

@ -1,20 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
export enum OperationParameterType {
Int,
Long,
Double,
Decimal,
String,
Stream,
ByteArray,
Date,
DateTime,
DateTimeRfc1123,
TimeSpan,
Boolean,
Uuid,
Base64Url,
UnixTime,
}

Просмотреть файл

@ -1,38 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { OperationParameterType } from "./operationParameterType";
import { QueryCollectionFormat } from "./queryCollectionFormat";
/**
* A parameter for an operation that will be added as a query parameter to the operation's HTTP
* request.
*/
export interface OperationQueryParameter {
/**
* The name of the parameter.
*/
parameterName: string;
/**
* The name of the query parameter that will be added in the constructed URL. header. If this is
* not provided, then the name of the parameter will be used as the query parameter name instead.
*/
queryParameterName?: string;
/**
* Whether or not to skip encoding the query parameter's value before adding it to the URL.
*/
skipEncoding?: boolean;
/**
* If this query parameter's value is a collection, what type of format should the value be
* converted to.
*/
collectionFormat?: QueryCollectionFormat;
/**
* The type of value that this parameter contains.
*/
type?: OperationParameterType;
}

Просмотреть файл

@ -1,13 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { OperationHeaderParameter } from "./operationHeaderParameter";
import { OperationQueryParameter } from "./operationQueryParameter";
import { OperationURLParameter } from "./operationURLParameter";
import { Mapper } from "./serializer";
import { HttpMethods } from "./webResource";
import { OperationFormDataParameter } from "./operationFormDataParameter";
import { OperationParameterType } from "./msRest";
import { OperationURLParameter, OperationQueryParameter, OperationHeaderParameter, OperationFormDataParameter } from "./operationParameter";
/**
* A specification that defines an operation.
@ -51,12 +47,6 @@ export interface OperationSpec {
*/
requestBodyName?: string;
/**
* The type of the request body. If this is not specified, then it is a composite or sequence
* type.
*/
requestBodyType?: OperationParameterType;
/**
* Whether or not this operation uses XML request and response bodies.
*/

Просмотреть файл

@ -1,30 +0,0 @@
import { OperationParameterType } from "./operationParameterType";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
/**
* A parameter for an operation that will be substituted into the operation's request URL.
*/
export interface OperationURLParameter {
/**
* The name of the parameter.
*/
parameterName: string;
/**
* The name of the parameter that will be replaced in the constructed URL. header. If this is not
* provided, then the name of the parameter will be used as the urlParameterName instead.
*/
urlParameterName?: string;
/**
* The type of value that this parameter contains.
*/
type?: OperationParameterType;
/**
* Whether or not to skip encoding the URL parameter's value before adding it to the URL.
*/
skipEncoding?: boolean;
}

Просмотреть файл

@ -2,11 +2,11 @@
// Licensed under the MIT License. See License.txt in the project root for license information.
import { HttpOperationResponse } from "../httpOperationResponse";
import { WebResource } from "../webResource";
import { BaseRequestPolicy, RequestPolicyCreator, RequestPolicy, RequestPolicyOptions } from "./requestPolicy";
import { Serializer, Mapper } from "../serializer";
import { OperationSpec, OperationParameterType } from "../msRest";
import { OperationSpec } from "../operationSpec";
import { Mapper, MapperType, Serializer } from "../serializer";
import * as utils from "../util/utils";
import { WebResource } from "../webResource";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyCreator, RequestPolicyOptions } from "./requestPolicy";
/**
* Create a new serialization RequestPolicyCreator that will serialized HTTP request bodies as they
@ -51,13 +51,13 @@ export class SerializationPolicy extends BaseRequestPolicy {
if (request.body != undefined && operationSpec.requestBodyName) {
request.body = this._serializer.serialize(bodyMapper, request.body, operationSpec.requestBodyName);
if (operationSpec.isXML) {
if (bodyMapper.type.name === "Sequence") {
if (bodyMapper.type.name === MapperType.Sequence) {
request.body = utils.stringifyXML(utils.prepareXMLRootList(request.body, bodyMapper.xmlElementName || bodyMapper.xmlName || bodyMapper.serializedName), { rootName: bodyMapper.xmlName || bodyMapper.serializedName });
}
else {
request.body = utils.stringifyXML(request.body, { rootName: bodyMapper.xmlName || bodyMapper.serializedName });
}
} else if (operationSpec.requestBodyType !== OperationParameterType.Stream) {
} else if (bodyMapper.type.name !== MapperType.Stream) {
request.body = JSON.stringify(request.body);
}
}

Просмотреть файл

@ -7,7 +7,6 @@ import { HttpClient } from "./httpClient";
import { HttpOperationResponse } from "./httpOperationResponse";
import { HttpPipelineLogger } from "./httpPipelineLogger";
import { OperationArguments } from "./operationArguments";
import { OperationParameterType } from "./operationParameterType";
import { OperationSpec } from "./operationSpec";
import { exponentialRetryPolicy } from "./policies/exponentialRetryPolicy";
import { generateClientRequestIdPolicy } from "./policies/generateClientRequestIdPolicy";
@ -18,7 +17,7 @@ import { rpRegistrationPolicy } from "./policies/rpRegistrationPolicy";
import { serializationPolicy } from "./policies/serializationPolicy";
import { signingPolicy } from "./policies/signingPolicy";
import { systemErrorRetryPolicy } from "./policies/systemErrorRetryPolicy";
import { Serializer, serializeObject } from "./serializer";
import { Serializer } from "./serializer";
import { Constants } from "./util/constants";
import * as utils from "./util/utils";
import { RequestPrepareOptions, WebResource } from "./webResource";
@ -198,9 +197,7 @@ export class ServiceClient {
if (operationSpec.urlParameters && operationSpec.urlParameters.length > 0) {
for (const urlParameter of operationSpec.urlParameters) {
let urlParameterValue: string = operationArguments.arguments[urlParameter.parameterName];
if (urlParameter.type != undefined) {
urlParameterValue = serializeParameterValue(urlParameterValue, urlParameter.type, this._serializer, urlParameter.parameterName);
}
urlParameterValue = this._serializer.serialize(urlParameter.mapper, urlParameterValue, urlParameter.parameterName);
if (!urlParameter.skipEncoding) {
urlParameterValue = encodeURIComponent(urlParameterValue);
}
@ -211,9 +208,7 @@ export class ServiceClient {
for (const queryParameter of operationSpec.queryParameters) {
let queryParameterValue: any = operationArguments.arguments[queryParameter.parameterName];
if (queryParameterValue != undefined) {
if (queryParameter.type != undefined) {
queryParameterValue = serializeParameterValue(queryParameterValue, queryParameter.type, this._serializer, queryParameter.parameterName);
}
queryParameterValue = this._serializer.serialize(queryParameter.mapper, queryParameterValue, queryParameter.parameterName);
if (queryParameter.collectionFormat != undefined) {
if (queryParameter.collectionFormat === QueryCollectionFormat.Multi) {
if (queryParameterValue.length === 0) {
@ -239,12 +234,9 @@ export class ServiceClient {
if (operationSpec.headerParameters) {
for (const headerParameter of operationSpec.headerParameters) {
const parameterType: OperationParameterType | undefined = headerParameter.type;
let headerValue: any = operationArguments.arguments[headerParameter.parameterName];
if (headerValue != undefined) {
if (parameterType != undefined) {
headerValue = serializeParameterValue(headerValue, parameterType, this._serializer, headerParameter.parameterName);
}
headerValue = this._serializer.serialize(headerParameter.mapper, headerValue, headerParameter.parameterName);
httpRequest.headers.set(headerParameter.headerName || headerParameter.parameterName, headerValue);
}
}
@ -280,7 +272,7 @@ export class ServiceClient {
const formDataParameterValue: any = operationArguments.arguments[formDataParameter.parameterName];
if (formDataParameterValue != undefined) {
const formDataParameterPropertyName: string = formDataParameter.formDataPropertyName || formDataParameter.parameterName;
httpRequest.formData[formDataParameterPropertyName] = serializeParameterValue(formDataParameterValue, formDataParameter.type, this._serializer, formDataParameter.parameterName);
httpRequest.formData[formDataParameterPropertyName] = this._serializer.serialize(formDataParameter.mapper, formDataParameterValue, formDataParameter.parameterName);
}
}
}
@ -289,46 +281,6 @@ export class ServiceClient {
}
}
function serializeParameterValue(value: any, parameterType: OperationParameterType | undefined, serializer: Serializer, parameterName: string): any {
if (value != undefined) {
if (parameterType != undefined) {
switch (parameterType) {
case OperationParameterType.Date:
value = serializeObject(value).replace(/[Tt].*[Zz]/, "");
break;
case OperationParameterType.DateTimeRfc1123:
if (value instanceof Date) {
value = value.toUTCString();
}
break;
case OperationParameterType.DateTime:
case OperationParameterType.ByteArray:
value = serializeObject(value);
break;
case OperationParameterType.Base64Url:
value = serializer.serialize({ required: true, serializedName: parameterName, type: { name: "Base64Url" } }, value, parameterName);
break;
case OperationParameterType.UnixTime:
value = serializer.serialize({ required: true, serializedName: parameterName, type: { name: "UnixTime" } }, value, parameterName);
break;
case OperationParameterType.Stream:
value = serializer.serialize({ required: true, serializedName: parameterName, type: { name: "Stream" } }, value, parameterName);
break;
default:
value = value.toString();
break;
}
}
return value;
}
}
function createDefaultRequestPolicyCreators(credentials: ServiceClientCredentials | undefined, options: ServiceClientOptions, userAgentInfo: string[]): RequestPolicyCreator[] {
const defaultRequestPolicyCreators: RequestPolicyCreator[] = [];

Просмотреть файл

@ -25,7 +25,7 @@
"autorest",
"clientruntime"
],
"main": "./dist/lib/msRest.js",
"main": "./lib/msRest.ts",
"types": "./typings/lib/msRest.d.ts",
"license": "MIT",
"dependencies": {
@ -93,4 +93,4 @@
"preview": "node ./.scripts/preview.js",
"latest": "node ./.scripts/latest.js"
}
}
}