зеркало из https://github.com/Azure/ms-rest-js.git
Working on refactoring mapper generation
This commit is contained in:
Родитель
e88c6929d8
Коммит
cc1145cb3b
|
@ -23,12 +23,6 @@ export interface OperationParameter {
|
|||
* 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.
|
||||
*/
|
||||
|
@ -40,12 +34,6 @@ export interface OperationURLParameter extends OperationParameter {
|
|||
* 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.
|
||||
*/
|
||||
|
@ -56,27 +44,4 @@ export interface OperationQueryParameter extends OperationParameter {
|
|||
* 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;
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import { Mapper } from "./serializer";
|
||||
import { HttpMethods } from "./webResource";
|
||||
import { OperationURLParameter, OperationQueryParameter, OperationHeaderParameter, OperationFormDataParameter } from "./operationParameter";
|
||||
import { OperationURLParameter, OperationQueryParameter, OperationParameter } from "./operationParameter";
|
||||
|
||||
/**
|
||||
* A specification that defines an operation.
|
||||
|
@ -66,11 +66,11 @@ export interface OperationSpec {
|
|||
* The parameters to the operation method that will be converted to headers on the operation's
|
||||
* HTTP request.
|
||||
*/
|
||||
headerParameters?: OperationHeaderParameter[];
|
||||
headerParameters?: OperationParameter[];
|
||||
|
||||
/**
|
||||
* The parameters to the operation method that will be used to create a formdata body for the
|
||||
* operation's HTTP request.
|
||||
*/
|
||||
formDataParameters?: OperationFormDataParameter[];
|
||||
formDataParameters?: OperationParameter[];
|
||||
}
|
|
@ -47,12 +47,14 @@ export class Serializer {
|
|||
throw new Error(`${objectName}" with value "${value}" should satify the constraint "MinLength": ${((mapper.constraints as MapperConstraints).MinLength as number)}.`);
|
||||
}
|
||||
} else if (constraintType.match(/^MultipleOf$/ig) !== null) {
|
||||
if (value.length % ((mapper.constraints as MapperConstraints).MultipleOf as number) !== 0) {
|
||||
if (value % ((mapper.constraints as MapperConstraints).MultipleOf as number) !== 0) {
|
||||
throw new Error(`${objectName}" with value "${value}" should satify the constraint "MultipleOf": ${((mapper.constraints as MapperConstraints).MultipleOf as number)}.`);
|
||||
}
|
||||
} else if (constraintType.match(/^Pattern$/ig) !== null) {
|
||||
if (value.match(((mapper.constraints as MapperConstraints).Pattern as string).split("/").join("\/")) === null) {
|
||||
throw new Error(`${objectName}" with value "${value}" should satify the constraint "Pattern": ${((mapper.constraints as MapperConstraints).Pattern as string)}.`);
|
||||
const regexp: RegExp = (mapper.constraints as MapperConstraints).Pattern!;
|
||||
const match: any = value.match(regexp);
|
||||
if (match === null) {
|
||||
throw new Error(`${objectName}" with value "${value}" should satify the constraint "Pattern": ${regexp}.`);
|
||||
}
|
||||
} else if (constraintType.match(/^UniqueItems/ig) !== null) {
|
||||
if (((mapper.constraints as MapperConstraints).UniqueItems as boolean)) {
|
||||
|
@ -156,10 +158,10 @@ export class Serializer {
|
|||
} else if (typeName.match(/^Stream$/ig) !== null) {
|
||||
const objectType = typeof value;
|
||||
if (objectType !== "string" &&
|
||||
objectType !== "function" &&
|
||||
!(value instanceof ArrayBuffer) &&
|
||||
!ArrayBuffer.isView(value) &&
|
||||
!(typeof Blob === "function" && value instanceof Blob)) {
|
||||
objectType !== "function" &&
|
||||
!(value instanceof ArrayBuffer) &&
|
||||
!ArrayBuffer.isView(value) &&
|
||||
!(typeof Blob === "function" && value instanceof Blob)) {
|
||||
throw new Error(`${objectName} must be a string, Blob, ArrayBuffer, ArrayBufferView, or a function returning NodeJS.ReadableStream.`);
|
||||
}
|
||||
}
|
||||
|
@ -710,7 +712,7 @@ export interface MapperConstraints {
|
|||
ExclusiveMinimum?: number;
|
||||
MaxLength?: number;
|
||||
MinLength?: number;
|
||||
Pattern?: string;
|
||||
Pattern?: RegExp;
|
||||
MaxItems?: number;
|
||||
MinItems?: number;
|
||||
UniqueItems?: true;
|
||||
|
@ -729,7 +731,7 @@ export interface Mapper {
|
|||
xmlIsWrapped?: boolean;
|
||||
readOnly?: boolean;
|
||||
isConstant?: boolean;
|
||||
required: boolean;
|
||||
required?: boolean;
|
||||
serializedName: string;
|
||||
type: BaseMapperType;
|
||||
defaultValue?: any;
|
||||
|
@ -806,7 +808,7 @@ export function serializeObject(toSerialize: any): any {
|
|||
/**
|
||||
* Utility function to create a K:V from a list of strings
|
||||
*/
|
||||
function strEnum<T extends string>(o: Array<T>): {[K in T]: K} {
|
||||
function strEnum<T extends string>(o: Array<T>): { [K in T]: K } {
|
||||
const result: any = {};
|
||||
for (const key of o) {
|
||||
result[key] = key;
|
||||
|
|
|
@ -201,7 +201,7 @@ export class ServiceClient {
|
|||
if (!urlParameter.skipEncoding) {
|
||||
urlParameterValue = encodeURIComponent(urlParameterValue);
|
||||
}
|
||||
requestUrl.replaceAll(`{${urlParameter.urlParameterName || urlParameter.parameterName}}`, urlParameterValue);
|
||||
requestUrl.replaceAll(`{${urlParameter.mapper.serializedName || urlParameter.parameterName}}`, urlParameterValue);
|
||||
}
|
||||
}
|
||||
if (operationSpec.queryParameters && operationSpec.queryParameters.length > 0) {
|
||||
|
@ -226,7 +226,7 @@ export class ServiceClient {
|
|||
if (!queryParameter.skipEncoding) {
|
||||
queryParameterValue = encodeURIComponent(queryParameterValue);
|
||||
}
|
||||
requestUrl.setQueryParameter(queryParameter.queryParameterName || queryParameter.parameterName, queryParameterValue);
|
||||
requestUrl.setQueryParameter(queryParameter.mapper.serializedName || queryParameter.parameterName, queryParameterValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ export class ServiceClient {
|
|||
let headerValue: any = operationArguments.arguments[headerParameter.parameterName];
|
||||
if (headerValue != undefined) {
|
||||
headerValue = this._serializer.serialize(headerParameter.mapper, headerValue, headerParameter.parameterName);
|
||||
httpRequest.headers.set(headerParameter.headerName || headerParameter.parameterName, headerValue);
|
||||
httpRequest.headers.set(headerParameter.mapper.serializedName || headerParameter.parameterName, headerValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ export class ServiceClient {
|
|||
for (const formDataParameter of operationSpec.formDataParameters) {
|
||||
const formDataParameterValue: any = operationArguments.arguments[formDataParameter.parameterName];
|
||||
if (formDataParameterValue != undefined) {
|
||||
const formDataParameterPropertyName: string = formDataParameter.formDataPropertyName || formDataParameter.parameterName;
|
||||
const formDataParameterPropertyName: string = formDataParameter.mapper.serializedName || formDataParameter.parameterName;
|
||||
httpRequest.formData[formDataParameterPropertyName] = this._serializer.serialize(formDataParameter.mapper, formDataParameterValue, formDataParameter.parameterName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"email": "azsdkteam@microsoft.com",
|
||||
"url": "https://github.com/Azure/ms-rest-js"
|
||||
},
|
||||
"version": "0.7.0",
|
||||
"version": "0.8.0",
|
||||
"description": "Isomorphic client Runtime for Typescript/node.js/browser javascript client libraries generated using AutoRest",
|
||||
"tags": [
|
||||
"isomorphic",
|
||||
|
|
Загрузка…
Ссылка в новой задаче