From a8e07f30490854305213398c1c4e4a01276584ee Mon Sep 17 00:00:00 2001 From: Jose Manuel Heredia Hidalgo Date: Fri, 31 Jan 2020 12:52:58 -0800 Subject: [PATCH] Multiple clean up fixes for JSDoc and parameter handling (#557) * Multiple clean up fixes for JSDoc and parameter handling * Add comment * Address PR Comments --- src/generators/clientContextFileGenerator.ts | 87 +++-------- src/generators/clientFileGenerator.ts | 40 ++--- src/generators/operationGenerator.ts | 20 +-- src/generators/parametersGenerator.ts | 16 +- src/generators/utils/parameterUtils.ts | 29 +--- src/generators/utils/stringUtils.ts | 37 +++++ src/models/parameterDetails.ts | 4 +- src/transforms/parameterTransforms.ts | 35 ++++- src/transforms/transforms.ts | 5 +- .../src/bodyComplexClientContext.ts | 17 +- .../bodyComplex/src/operations/array.ts | 6 +- .../bodyComplex/src/operations/dictionary.ts | 6 +- .../bodyComplex/src/operations/inheritance.ts | 4 +- .../src/operations/polymorphicrecursive.ts | 64 ++++---- .../src/operations/polymorphism.ts | 145 +++++++++--------- .../bodyComplex/src/operations/primitive.ts | 3 +- .../bodyString/src/bodyStringClientContext.ts | 12 +- .../bodyString/src/operations/string.ts | 6 +- .../customUrl/src/customUrlClientContext.ts | 13 +- .../generated/url/src/operations/pathItems.ts | 16 +- .../generated/url/src/operations/paths.ts | 9 +- .../generated/url/src/operations/queries.ts | 12 +- .../generated/url/src/urlClient.ts | 1 + .../generated/url/src/urlClientContext.ts | 19 +-- 24 files changed, 305 insertions(+), 301 deletions(-) create mode 100644 src/generators/utils/stringUtils.ts diff --git a/src/generators/clientContextFileGenerator.ts b/src/generators/clientContextFileGenerator.ts index aed7e94c6c..2f1975630e 100644 --- a/src/generators/clientContextFileGenerator.ts +++ b/src/generators/clientContextFileGenerator.ts @@ -14,11 +14,8 @@ import { ClientDetails } from "../models/clientDetails"; import { PackageDetails } from "../models/packageDetails"; import { ParameterDetails } from "../models/parameterDetails"; import { ImplementationLocation, SchemaType } from "@azure-tools/codemodel"; -import { - getCredentialsCheck, - getCredentialsParameter -} from "./utils/parameterUtils"; import { BaseUrlDetails } from "../transforms/urlTransforms"; +import { formatJsDocParam } from "./utils/parameterUtils"; export function generateClientContext( clientDetails: ClientDetails, @@ -29,7 +26,6 @@ export function generateClientContext( param => param.implementationLocation === ImplementationLocation.Client ); const requiredParams = getRequiredParameters(clientParams); - const hasCredentials = !!clientDetails.options.addCredentials; const clientContextClassName = `${clientDetails.className}Context`; const clientContextFileName = normalizeName( clientContextClassName, @@ -52,20 +48,17 @@ export function generateClientContext( const classConstructor = buildConstructor(contextClass, { clientContextClassName, - hasCredentials, requiredParams }); writeConstructorBody(classConstructor, { clientParams, - hasCredentials, clientDetails, requiredPaams: requiredParams }); } interface WriteConstructorBodyParameters { - hasCredentials: boolean; requiredPaams: ParameterDetails[]; clientParams: ParameterDetails[]; clientDetails: ClientDetails; @@ -84,8 +77,8 @@ function writePackageInfo( ) { sourceFile.addStatements([ `\n\n`, - `const packageName = "${packageDetails.name}";`, - `const packageVersion = "${packageDetails.version}";` + `const packageName = "${packageDetails.name || ""}";`, + `const packageVersion = "${packageDetails.version || ""}";` ]); } @@ -106,33 +99,23 @@ function writeClassProperties( function writeConstructorBody( classConstructor: ConstructorDeclaration, - { - clientParams, - hasCredentials, - requiredPaams, - clientDetails - }: WriteConstructorBodyParameters + { clientParams, requiredPaams, clientDetails }: WriteConstructorBodyParameters ) { - const optionalParams = getOptionalParameters(clientParams); const addBlankLine = true; const requiredParameters = getRequiredParamAssignments(requiredPaams); const constantParameters = getConstantClientParamAssignments(clientParams); - const optionalParameters = getOptionalParameterAssignments(optionalParams); classConstructor.addStatements([ - writeStatement(getCredentialsCheck(hasCredentials)), writeStatements(getRequiredParamChecks(requiredPaams), addBlankLine), - writeStatement(writeDefaultOptions(hasCredentials)), + writeStatement( + writeDefaultOptions(clientParams.some(p => p.name === "credentials")) + ), + writeStatement(getBaseUriStatement(clientDetails.baseUrl), addBlankLine), requiredParameters.length ? "// Parameter assignments" : "", writeStatements(getRequiredParamAssignments(requiredPaams), addBlankLine), constantParameters.length ? "// Assigning values to Constant parameters" : "", - writeStatements(constantParameters, addBlankLine), - writeStatement(getBaseUriStatement(clientDetails.baseUrl), addBlankLine), - optionalParameters.length - ? "// Replacing parameter defaults with user-provided parameters." - : "", - writeStatements(optionalParameters) + writeStatements(constantParameters, addBlankLine) ]); } @@ -180,25 +163,24 @@ function buildClass(sourceFile: SourceFile, clientContextClassName: string) { interface BuildContructorParams { clientContextClassName: string; - hasCredentials: boolean; requiredParams: ParameterDetails[]; } function buildConstructor( contextClass: ClassDeclaration, - { - clientContextClassName, - hasCredentials, - requiredParams - }: BuildContructorParams + { clientContextClassName, requiredParams }: BuildContructorParams ) { + const docs = [ + `Initializes a new instance of the ${clientContextClassName} class.`, + ...formatJsDocParam(requiredParams), + `@param options The parameter options` + ] + .filter(d => !!d) + .join("\n"); + return contextClass.addConstructor({ - docs: [ - `Initializes a new instance of the ${clientContextClassName} class.\n -@param options The parameter options` - ], + docs: [docs], parameters: [ - ...getCredentialsParameter(hasCredentials), ...requiredParams.map(p => ({ name: p.name, type: p.typeDetails.typeName @@ -212,16 +194,6 @@ function buildConstructor( }); } -function getOptionalParameters(parameters: ParameterDetails[]) { - /** - * Getting parameters that are not marked as required, and the ones that are not marked as required - * but are constants or have a defaultValue - */ - return parameters.filter( - p => !p.required || p.defaultValue || p.schemaType === SchemaType.Constant - ); -} - function getRequiredParameters(parameters: ParameterDetails[]) { /** * Getting parameters that are marked as required, and also don't have a defaultValue. @@ -234,9 +206,7 @@ function getRequiredParameters(parameters: ParameterDetails[]) { function getBaseUriStatement(baseUrl: BaseUrlDetails) { const uri = baseUrl.baseUrl; - return `this.baseUri = options.baseUri || this.baseUri ${ - uri ? ` || "${uri}"` : "" - };`; + return `this.baseUri = options.baseUri ${uri ? ` || "${uri}"` : ""};`; } function getConstantClientParamAssignments( @@ -244,7 +214,10 @@ function getConstantClientParamAssignments( ) { return clientParameters .filter(p => !!p.defaultValue || p.schemaType === SchemaType.Constant) - .map(({ name, defaultValue }) => `this.${name} = ${defaultValue}`); + .map( + ({ name, defaultValue }) => + `this.${name} = options.${name} || ${defaultValue}` + ); } function getRequiredParamChecks(requiredParameters: ParameterDetails[]) { @@ -255,18 +228,6 @@ function getRequiredParamChecks(requiredParameters: ParameterDetails[]) { ); } -function getOptionalParameterAssignments( - optionalParameters: ParameterDetails[] -) { - return optionalParameters.map( - ({ - name - }) => `if(options.${name} !== null && options.${name} !== undefined) { - this.${name} = options.${name}; - }` - ); -} - function getRequiredParamAssignments(requiredParameters: ParameterDetails[]) { return requiredParameters.map(({ name }) => `this.${name} = ${name};`); } diff --git a/src/generators/clientFileGenerator.ts b/src/generators/clientFileGenerator.ts index 5599a131a4..2ab2e19ac6 100644 --- a/src/generators/clientFileGenerator.ts +++ b/src/generators/clientFileGenerator.ts @@ -15,10 +15,9 @@ import { normalizeName, NameType } from "../utils/nameUtils"; -import { ParameterDetails } from "../models/parameterDetails"; import { ImplementationLocation, SchemaType } from "@azure-tools/codemodel"; -import { getCredentialsParameter } from "./utils/parameterUtils"; import { OperationGroupDetails } from "../models/operationDetails"; +import { formatJsDocParam } from "./utils/parameterUtils"; type OperationDeclarationDetails = { name: string; typeName: string }; @@ -78,7 +77,7 @@ export function generateClient(clientDetails: ClientDetails, project: Project) { extends: clientContextClassName }); - writeConstructor(clientDetails, clientClass, hasCredentials); + writeConstructor(clientDetails, clientClass); writeClientOperations(clientFile, clientClass, clientDetails); clientFile.addExportDeclaration({ @@ -100,8 +99,7 @@ export function generateClient(clientDetails: ClientDetails, project: Project) { function writeConstructor( clientDetails: ClientDetails, - classDeclaration: ClassDeclaration, - hasCredentials: boolean + classDeclaration: ClassDeclaration ) { const requiredParams = clientDetails.parameters.filter( param => @@ -111,13 +109,17 @@ function writeConstructor( param.schemaType !== SchemaType.Constant ); + const docs = [ + `Initializes a new instance of the ${clientDetails.className} class.`, + ...formatJsDocParam(requiredParams), + `@param options The parameter options` + ] + .filter(d => !!d) + .join("\n"); + const clientConstructor = classDeclaration.addConstructor({ - docs: [ - `Initializes a new instance of the ${clientDetails.className} class. -@param options The parameter options` - ], + docs: [docs], parameters: [ - ...getCredentialsParameter(hasCredentials), ...requiredParams.map(p => ({ name: p.name, hasQuestionToken: !p.required, @@ -132,7 +134,7 @@ function writeConstructor( }); clientConstructor.addStatements([ - `super(${getSuperParams(requiredParams, hasCredentials)});` + `super(${[...requiredParams.map(p => p.name), "options"].join()});` ]); const operationDeclarationDetails: OperationDeclarationDetails[] = getOperationGroupsDeclarationDetails( @@ -190,19 +192,3 @@ function writeClientOperations( }) ); } - -function getSuperParams( - requiredParams: ParameterDetails[], - hasCredentials: boolean -) { - let allParams = ["options"]; - requiredParams.forEach(p => { - allParams = [p.name, ...allParams]; - }); - - if (hasCredentials) { - allParams.unshift("credentials"); - } - - return allParams.join(); -} diff --git a/src/generators/operationGenerator.ts b/src/generators/operationGenerator.ts index 07a9a51be8..84f7b9f559 100644 --- a/src/generators/operationGenerator.ts +++ b/src/generators/operationGenerator.ts @@ -22,8 +22,12 @@ import { } from "../models/operationDetails"; import { isString } from "util"; import { ParameterDetails } from "../models/parameterDetails"; -import { filterOperationParameters } from "./utils/parameterUtils"; +import { + filterOperationParameters, + formatJsDocParam +} from "./utils/parameterUtils"; import { PropertyKind } from "../models/modelDetails"; +import { wrapString } from "./utils/stringUtils"; /** * Function that writes the code for all the operations. @@ -308,15 +312,11 @@ function generateOperationJSDoc( description: string = "" ): string { const paramJSDoc = - !params || !params.length - ? "" - : params - .map(param => { - return `@param ${param.name} ${param.description}`; - }) - .join("\n"); - - return `${description ? description + "\n" : description}${paramJSDoc}`; + !params || !params.length ? "" : formatJsDocParam(params).join("\n"); + + return `${ + description ? wrapString(description) + "\n" : description + }${paramJSDoc}`; } /** diff --git a/src/generators/parametersGenerator.ts b/src/generators/parametersGenerator.ts index 8c823c33ad..9230e3901e 100644 --- a/src/generators/parametersGenerator.ts +++ b/src/generators/parametersGenerator.ts @@ -29,14 +29,16 @@ export function generateParameters( moduleSpecifier: "../models/mappers" }); - clientDetails.parameters.forEach(param => { - parametersFile.addVariableStatement({ - isExported: true, - declarations: [buildParameterInitializer(param)], - declarationKind: VariableDeclarationKind.Const, - leadingTrivia: writer => writer.blankLine() + clientDetails.parameters + .filter(p => !p.isSynthetic) + .forEach(param => { + parametersFile.addVariableStatement({ + isExported: true, + declarations: [buildParameterInitializer(param)], + declarationKind: VariableDeclarationKind.Const, + leadingTrivia: writer => writer.blankLine() + }); }); - }); } function buildParameterInitializer(parameter: ParameterDetails) { diff --git a/src/generators/utils/parameterUtils.ts b/src/generators/utils/parameterUtils.ts index f867c168f9..fe40f91bbb 100644 --- a/src/generators/utils/parameterUtils.ts +++ b/src/generators/utils/parameterUtils.ts @@ -4,7 +4,7 @@ import { ParameterDetails } from "../../models/parameterDetails"; import { OperationDetails } from "../../models/operationDetails"; import { ImplementationLocation, SchemaType } from "@azure-tools/codemodel"; -import { StructureKind, ParameterDeclarationStructure } from "ts-morph"; +import { wrapString, IndentationType } from "./stringUtils"; interface ParameterFilterOptions { includeOptional?: boolean; @@ -59,24 +59,11 @@ export function filterOperationParameters( ); } -export function getCredentialsParameter( - hasCredentials: boolean -): ParameterDeclarationStructure[] { - return hasCredentials - ? [ - { - name: "credentials", - type: `coreHttp.TokenCredential | coreHttp.ServiceClientCredentials`, - kind: StructureKind.Parameter - } - ] - : []; -} - -export function getCredentialsCheck(hasCredentials: boolean): string { - return hasCredentials - ? `if (credentials == undefined) { - throw new Error("'credentials' cannot be null."); - }` - : ``; +export function formatJsDocParam(parameters: Partial[]) { + return parameters.map(p => + wrapString(`@param ${p.name} ${p.description}`, { + indentationType: IndentationType.JSDocParam, + paramNameLength: p.name?.length + }) + ); } diff --git a/src/generators/utils/stringUtils.ts b/src/generators/utils/stringUtils.ts new file mode 100644 index 0000000000..2af545e9bd --- /dev/null +++ b/src/generators/utils/stringUtils.ts @@ -0,0 +1,37 @@ +export enum IndentationType { + None, + JSDocParam +} + +export interface WrapStringOptions { + indentationType?: IndentationType; + paramNameLength?: number; + width?: number; +} + +export const wrapString = ( + string: string, + { + width = 100, + indentationType = IndentationType.None, + paramNameLength = 0 + }: WrapStringOptions = {} +) => { + const indentation = getIndentation(indentationType, paramNameLength); + return string.replace( + new RegExp(`(?![^\\n]{1,${width}}$)([^\\n]{1,${width}})\\s`, "g"), + `$1\n${indentation}` + ); +}; + +const getIndentation = ( + indentationType: IndentationType, + paramNameLength: number +) => { + switch (indentationType) { + case IndentationType.JSDocParam: + return " ".repeat(" @param ".length + paramNameLength); + default: + return ""; + } +}; diff --git a/src/models/parameterDetails.ts b/src/models/parameterDetails.ts index 34a9e03465..82ac0949cb 100644 --- a/src/models/parameterDetails.ts +++ b/src/models/parameterDetails.ts @@ -5,8 +5,7 @@ import { Parameter, ParameterLocation, AllSchemaTypes, - ImplementationLocation, - SchemaType + ImplementationLocation } from "@azure-tools/codemodel"; import { Mapper } from "@azure/core-http"; import { TypeDetails } from "./modelDetails"; @@ -29,4 +28,5 @@ export interface ParameterDetails { implementationLocation?: ImplementationLocation; typeDetails: TypeDetails; skipEncoding?: boolean; + isSynthetic?: boolean; } diff --git a/src/transforms/parameterTransforms.ts b/src/transforms/parameterTransforms.ts index 98d6966d43..19c3e46243 100644 --- a/src/transforms/parameterTransforms.ts +++ b/src/transforms/parameterTransforms.ts @@ -24,18 +24,51 @@ import { isEqual, isNil } from "lodash"; import { getTypeForSchema } from "../utils/schemaHelpers"; import { getStringForValue } from "../utils/valueHelpers"; import { TOPLEVEL_OPERATIONGROUP } from "./constants"; +import { ClientOptions } from "../models/clientDetails"; +import { PropertyKind } from "../models/modelDetails"; interface OperationParameterDetails { parameter: Parameter; operationName: string; } -export function transformParameters(codeModel: CodeModel): ParameterDetails[] { +const buildCredentialsParameter = (): ParameterDetails => ({ + nameRef: "credentials", + description: + "Subscription credentials which uniquely identify client subscription.", + name: "credentials", + serializedName: "credentials", + location: ParameterLocation.None, + required: true, + parameterPath: "credentials", + mapper: "any", + isGlobal: true, + parameter: {} as Parameter, + implementationLocation: ImplementationLocation.Client, + typeDetails: { + typeName: "coreHttp.TokenCredential | coreHttp.ServiceClientCredentials", + kind: PropertyKind.Primitive + }, + isSynthetic: true, + schemaType: SchemaType.Object +}); + +export function transformParameters( + codeModel: CodeModel, + options: ClientOptions = {} +): ParameterDetails[] { let parameters: ParameterDetails[] = []; extractOperationParameters(codeModel).forEach(p => populateOperationParameters(p.parameter, parameters, p.operationName) ); + // Adding credentials parameter as a Synthetic parameter, this is to treat this as any another parameter + // during generation and remove the need of special handling it. + if (options.addCredentials) { + const creds = buildCredentialsParameter(); + parameters.unshift(creds); + } + return parameters; } diff --git a/src/transforms/transforms.ts b/src/transforms/transforms.ts index eca49165a9..c089ae306d 100644 --- a/src/transforms/transforms.ts +++ b/src/transforms/transforms.ts @@ -56,6 +56,7 @@ export async function transformCodeModel( ): Promise { const className = normalizeName(codeModel.info.title, NameType.Class); const uberParents = await getUberParents(codeModel); + const options = await transformOptions(host); const [ objects, @@ -63,15 +64,13 @@ export async function transformCodeModel( unions, operationGroups, parameters, - options, baseUrl ] = await Promise.all([ transformObjects(codeModel, uberParents), transformMappers(codeModel), transformChoices(codeModel), transformOperationGroups(codeModel), - transformParameters(codeModel), - transformOptions(host), + transformParameters(codeModel, options), transformBaseUrl(codeModel) ]); diff --git a/test/integration/generated/bodyComplex/src/bodyComplexClientContext.ts b/test/integration/generated/bodyComplex/src/bodyComplexClientContext.ts index 8987b57f44..d3d31d5b87 100644 --- a/test/integration/generated/bodyComplex/src/bodyComplexClientContext.ts +++ b/test/integration/generated/bodyComplex/src/bodyComplexClientContext.ts @@ -17,7 +17,6 @@ export class BodyComplexClientContext extends coreHttp.ServiceClient { /** * Initializes a new instance of the BodyComplexClientContext class. - * * @param options The parameter options */ constructor(options?: any) { @@ -35,18 +34,10 @@ export class BodyComplexClientContext extends coreHttp.ServiceClient { this.requestContentType = "application/json; charset=utf-8"; - // Assigning values to Constant parameters - this.$host = "http://localhost:3000"; - this.apiVersion = "2016-02-29"; - - this.baseUri = options.baseUri || this.baseUri || "{$host}"; + this.baseUri = options.baseUri || "{$host}"; - // Replacing parameter defaults with user-provided parameters. - if (options.$host !== null && options.$host !== undefined) { - this.$host = options.$host; - } - if (options.apiVersion !== null && options.apiVersion !== undefined) { - this.apiVersion = options.apiVersion; - } + // Assigning values to Constant parameters + this.$host = options.$host || "http://localhost:3000"; + this.apiVersion = options.apiVersion || "2016-02-29"; } } diff --git a/test/integration/generated/bodyComplex/src/operations/array.ts b/test/integration/generated/bodyComplex/src/operations/array.ts index 1a5131848d..51f606d82c 100644 --- a/test/integration/generated/bodyComplex/src/operations/array.ts +++ b/test/integration/generated/bodyComplex/src/operations/array.ts @@ -41,7 +41,8 @@ export class Array { /** * Put complex types with array property - * @param complexBody Please put an array with 4 items: "1, 2, 3, 4", "", null, "&S#$(*Y", "The quick brown fox jumps over the lazy dog" + * @param complexBody Please put an array with 4 items: "1, 2, 3, 4", "", null, "&S#$(*Y", "The quick + * brown fox jumps over the lazy dog" * @param options The options parameters. */ putValid( @@ -69,7 +70,8 @@ export class Array { /** * Put complex types with array property which is empty - * @param complexBody Please put an array with 4 items: "1, 2, 3, 4", "", null, "&S#$(*Y", "The quick brown fox jumps over the lazy dog" + * @param complexBody Please put an array with 4 items: "1, 2, 3, 4", "", null, "&S#$(*Y", "The quick + * brown fox jumps over the lazy dog" * @param options The options parameters. */ putEmpty( diff --git a/test/integration/generated/bodyComplex/src/operations/dictionary.ts b/test/integration/generated/bodyComplex/src/operations/dictionary.ts index f5c3494ec8..461bdcabcf 100644 --- a/test/integration/generated/bodyComplex/src/operations/dictionary.ts +++ b/test/integration/generated/bodyComplex/src/operations/dictionary.ts @@ -41,7 +41,8 @@ export class Dictionary { /** * Put complex types with dictionary property - * @param complexBody Please put a dictionary with 5 key-value pairs: "txt":"notepad", "bmp":"mspaint", "xls":"excel", "exe":"", "":null + * @param complexBody Please put a dictionary with 5 key-value pairs: "txt":"notepad", "bmp":"mspaint", + * "xls":"excel", "exe":"", "":null * @param options The options parameters. */ putValid( @@ -69,7 +70,8 @@ export class Dictionary { /** * Put complex types with dictionary property which is empty - * @param complexBody Please put a dictionary with 5 key-value pairs: "txt":"notepad", "bmp":"mspaint", "xls":"excel", "exe":"", "":null + * @param complexBody Please put a dictionary with 5 key-value pairs: "txt":"notepad", "bmp":"mspaint", + * "xls":"excel", "exe":"", "":null * @param options The options parameters. */ putEmpty( diff --git a/test/integration/generated/bodyComplex/src/operations/inheritance.ts b/test/integration/generated/bodyComplex/src/operations/inheritance.ts index 581de28404..688ec8749f 100644 --- a/test/integration/generated/bodyComplex/src/operations/inheritance.ts +++ b/test/integration/generated/bodyComplex/src/operations/inheritance.ts @@ -41,7 +41,9 @@ export class Inheritance { /** * Put complex types that extend others - * @param complexBody Please put a siamese with id=2, name="Siameee", color=green, breed=persion, which hates 2 dogs, the 1st one named "Potato" with id=1 and food="tomato", and the 2nd one named "Tomato" with id=-1 and food="french fries". + * @param complexBody Please put a siamese with id=2, name="Siameee", color=green, breed=persion, which + * hates 2 dogs, the 1st one named "Potato" with id=1 and food="tomato", and the 2nd one named "Tomato" + * with id=-1 and food="french fries". * @param options The options parameters. */ putValid( diff --git a/test/integration/generated/bodyComplex/src/operations/polymorphicrecursive.ts b/test/integration/generated/bodyComplex/src/operations/polymorphicrecursive.ts index 57ac44ea75..a6e174e77c 100644 --- a/test/integration/generated/bodyComplex/src/operations/polymorphicrecursive.ts +++ b/test/integration/generated/bodyComplex/src/operations/polymorphicrecursive.ts @@ -42,38 +42,38 @@ export class Polymorphicrecursive { /** * Put complex types that are polymorphic and have recursive references * @param complexBody Please put a salmon that looks like this: - * { - * 'fishtype':'Salmon', - * 'location':'alaska', - * 'iswild':true, - * 'species':'king', - * 'length':1.0, - * 'siblings':[ - * { - * 'fishtype':'Shark', - * 'age':6, - * 'birthday': '2012-01-05T01:00:00Z', - * 'length':20.0, - * 'species':'predator', - * }, - * { - * 'fishtype':'Sawshark', - * 'age':105, - * 'birthday': '1900-01-05T01:00:00Z', - * 'length':10.0, - * 'picture': new Buffer([255, 255, 255, 255, 254]).toString('base64'), - * 'species':'dangerous', - * }, - * { - * 'fishtype': 'goblin', - * 'age': 1, - * 'birthday': '2015-08-08T00:00:00Z', - * 'length': 30.0, - * 'species': 'scary', - * 'jawsize': 5 - * } - * ] - * }; + * { + * 'fishtype':'Salmon', + * 'location':'alaska', + * 'iswild':true, + * 'species':'king', + * 'length':1.0, + * 'siblings':[ + * { + * 'fishtype':'Shark', + * 'age':6, + * 'birthday': '2012-01-05T01:00:00Z', + * 'length':20.0, + * 'species':'predator', + * }, + * { + * 'fishtype':'Sawshark', + * 'age':105, + * 'birthday': '1900-01-05T01:00:00Z', + * 'length':10.0, + * 'picture': new Buffer([255, 255, 255, 255, 254]).toString('base64'), + * 'species':'dangerous', + * }, + * { + * 'fishtype': 'goblin', + * 'age': 1, + * 'birthday': '2015-08-08T00:00:00Z', + * 'length': 30.0, + * 'species': 'scary', + * 'jawsize': 5 + * } + * ] + * }; * @param options The options parameters. */ putValid( diff --git a/test/integration/generated/bodyComplex/src/operations/polymorphism.ts b/test/integration/generated/bodyComplex/src/operations/polymorphism.ts index 27c6841f2c..664bbae61e 100644 --- a/test/integration/generated/bodyComplex/src/operations/polymorphism.ts +++ b/test/integration/generated/bodyComplex/src/operations/polymorphism.ts @@ -42,38 +42,38 @@ export class Polymorphism { /** * Put complex types that are polymorphic * @param complexBody Please put a salmon that looks like this: - * { - * 'fishtype':'Salmon', - * 'location':'alaska', - * 'iswild':true, - * 'species':'king', - * 'length':1.0, - * 'siblings':[ - * { - * 'fishtype':'Shark', - * 'age':6, - * 'birthday': '2012-01-05T01:00:00Z', - * 'length':20.0, - * 'species':'predator', - * }, - * { - * 'fishtype':'Sawshark', - * 'age':105, - * 'birthday': '1900-01-05T01:00:00Z', - * 'length':10.0, - * 'picture': new Buffer([255, 255, 255, 255, 254]).toString('base64'), - * 'species':'dangerous', - * }, - * { - * 'fishtype': 'goblin', - * 'age': 1, - * 'birthday': '2015-08-08T00:00:00Z', - * 'length': 30.0, - * 'species': 'scary', - * 'jawsize': 5 - * } - * ] - * }; + * { + * 'fishtype':'Salmon', + * 'location':'alaska', + * 'iswild':true, + * 'species':'king', + * 'length':1.0, + * 'siblings':[ + * { + * 'fishtype':'Shark', + * 'age':6, + * 'birthday': '2012-01-05T01:00:00Z', + * 'length':20.0, + * 'species':'predator', + * }, + * { + * 'fishtype':'Sawshark', + * 'age':105, + * 'birthday': '1900-01-05T01:00:00Z', + * 'length':10.0, + * 'picture': new Buffer([255, 255, 255, 255, 254]).toString('base64'), + * 'species':'dangerous', + * }, + * { + * 'fishtype': 'goblin', + * 'age': 1, + * 'birthday': '2015-08-08T00:00:00Z', + * 'length': 30.0, + * 'species': 'scary', + * 'jawsize': 5 + * } + * ] + * }; * @param options The options parameters. */ putValid( @@ -100,7 +100,9 @@ export class Polymorphism { } /** - * Get complex object composing a polymorphic scalar property and array property with polymorphic element type, with discriminator specified. Deserialization must NOT fail and use the discriminator type specified on the wire. + * Get complex object composing a polymorphic scalar property and array property with polymorphic + * element type, with discriminator specified. Deserialization must NOT fail and use the discriminator + * type specified on the wire. * @param options The options parameters. */ getComposedWithDiscriminator( @@ -113,7 +115,9 @@ export class Polymorphism { } /** - * Get complex object composing a polymorphic scalar property and array property with polymorphic element type, without discriminator specified on wire. Deserialization must NOT fail and use the explicit type of the property. + * Get complex object composing a polymorphic scalar property and array property with polymorphic + * element type, without discriminator specified on wire. Deserialization must NOT fail and use the + * explicit type of the property. * @param options The options parameters. */ getComposedWithoutDiscriminator( @@ -126,7 +130,8 @@ export class Polymorphism { } /** - * Get complex types that are polymorphic, but not at the root of the hierarchy; also have additional properties + * Get complex types that are polymorphic, but not at the root of the hierarchy; also have additional + * properties * @param options The options parameters. */ getComplicated( @@ -139,7 +144,8 @@ export class Polymorphism { } /** - * Put complex types that are polymorphic, but not at the root of the hierarchy; also have additional properties + * Put complex types that are polymorphic, but not at the root of the hierarchy; also have additional + * properties * @param complexBody * @param options The options parameters. */ @@ -169,40 +175,41 @@ export class Polymorphism { } /** - * Put complex types that are polymorphic, attempting to omit required 'birthday' field - the request should not be allowed from the client + * Put complex types that are polymorphic, attempting to omit required 'birthday' field - the request + * should not be allowed from the client * @param complexBody Please put a salmon that looks like this: - * { - * 'fishtype':'Salmon', - * 'location':'alaska', - * 'iswild':true, - * 'species':'king', - * 'length':1.0, - * 'siblings':[ - * { - * 'fishtype':'Shark', - * 'age':6, - * 'birthday': '2012-01-05T01:00:00Z', - * 'length':20.0, - * 'species':'predator', - * }, - * { - * 'fishtype':'Sawshark', - * 'age':105, - * 'birthday': '1900-01-05T01:00:00Z', - * 'length':10.0, - * 'picture': new Buffer([255, 255, 255, 255, 254]).toString('base64'), - * 'species':'dangerous', - * }, - * { - * 'fishtype': 'goblin', - * 'age': 1, - * 'birthday': '2015-08-08T00:00:00Z', - * 'length': 30.0, - * 'species': 'scary', - * 'jawsize': 5 - * } - * ] - * }; + * { + * 'fishtype':'Salmon', + * 'location':'alaska', + * 'iswild':true, + * 'species':'king', + * 'length':1.0, + * 'siblings':[ + * { + * 'fishtype':'Shark', + * 'age':6, + * 'birthday': '2012-01-05T01:00:00Z', + * 'length':20.0, + * 'species':'predator', + * }, + * { + * 'fishtype':'Sawshark', + * 'age':105, + * 'birthday': '1900-01-05T01:00:00Z', + * 'length':10.0, + * 'picture': new Buffer([255, 255, 255, 255, 254]).toString('base64'), + * 'species':'dangerous', + * }, + * { + * 'fishtype': 'goblin', + * 'age': 1, + * 'birthday': '2015-08-08T00:00:00Z', + * 'length': 30.0, + * 'species': 'scary', + * 'jawsize': 5 + * } + * ] + * }; * @param options The options parameters. */ putValidMissingRequired( diff --git a/test/integration/generated/bodyComplex/src/operations/primitive.ts b/test/integration/generated/bodyComplex/src/operations/primitive.ts index 4e7fe6697b..9323b39e97 100644 --- a/test/integration/generated/bodyComplex/src/operations/primitive.ts +++ b/test/integration/generated/bodyComplex/src/operations/primitive.ts @@ -125,7 +125,8 @@ export class Primitive { /** * Put complex types with double properties - * @param complexBody Please put 3e-100 and -0.000000000000000000000000000000000000000000000000000000005 + * @param complexBody Please put 3e-100 and + * -0.000000000000000000000000000000000000000000000000000000005 * @param options The options parameters. */ putDouble( diff --git a/test/integration/generated/bodyString/src/bodyStringClientContext.ts b/test/integration/generated/bodyString/src/bodyStringClientContext.ts index c9ab45be3f..a887d63a80 100644 --- a/test/integration/generated/bodyString/src/bodyStringClientContext.ts +++ b/test/integration/generated/bodyString/src/bodyStringClientContext.ts @@ -16,7 +16,6 @@ export class BodyStringClientContext extends coreHttp.ServiceClient { /** * Initializes a new instance of the BodyStringClientContext class. - * * @param options The parameter options */ constructor(options?: any) { @@ -34,14 +33,9 @@ export class BodyStringClientContext extends coreHttp.ServiceClient { this.requestContentType = "application/json; charset=utf-8"; - // Assigning values to Constant parameters - this.$host = "http://localhost:3000"; - - this.baseUri = options.baseUri || this.baseUri || "{$host}"; + this.baseUri = options.baseUri || "{$host}"; - // Replacing parameter defaults with user-provided parameters. - if (options.$host !== null && options.$host !== undefined) { - this.$host = options.$host; - } + // Assigning values to Constant parameters + this.$host = options.$host || "http://localhost:3000"; } } diff --git a/test/integration/generated/bodyString/src/operations/string.ts b/test/integration/generated/bodyString/src/operations/string.ts index f0228e3fc4..1bf5cb6fcd 100644 --- a/test/integration/generated/bodyString/src/operations/string.ts +++ b/test/integration/generated/bodyString/src/operations/string.ts @@ -105,7 +105,8 @@ export class String { } /** - * Get string value with leading and trailing whitespace 'Now is the time for all good men to come to the aid of their country' + * Get string value with leading and trailing whitespace 'Now is the time for all + * good men to come to the aid of their country' * @param options The options parameters. */ getWhitespace( @@ -118,7 +119,8 @@ export class String { } /** - * Set String value with leading and trailing whitespace 'Now is the time for all good men to come to the aid of their country' + * Set String value with leading and trailing whitespace 'Now is the time for all + * good men to come to the aid of their country' * @param options The options parameters. */ putWhitespace( diff --git a/test/integration/generated/customUrl/src/customUrlClientContext.ts b/test/integration/generated/customUrl/src/customUrlClientContext.ts index 277094be92..87062581dd 100644 --- a/test/integration/generated/customUrl/src/customUrlClientContext.ts +++ b/test/integration/generated/customUrl/src/customUrlClientContext.ts @@ -16,7 +16,6 @@ export class CustomUrlClientContext extends coreHttp.ServiceClient { /** * Initializes a new instance of the CustomUrlClientContext class. - * * @param options The parameter options */ constructor(options?: any) { @@ -34,15 +33,9 @@ export class CustomUrlClientContext extends coreHttp.ServiceClient { this.requestContentType = "application/json; charset=utf-8"; - // Assigning values to Constant parameters - this.host = "host"; - - this.baseUri = - options.baseUri || this.baseUri || "http://{accountName}{host}"; + this.baseUri = options.baseUri || "http://{accountName}{host}"; - // Replacing parameter defaults with user-provided parameters. - if (options.host !== null && options.host !== undefined) { - this.host = options.host; - } + // Assigning values to Constant parameters + this.host = options.host || "host"; } } diff --git a/test/integration/generated/url/src/operations/pathItems.ts b/test/integration/generated/url/src/operations/pathItems.ts index 14ad8d23cf..805df09a6a 100644 --- a/test/integration/generated/url/src/operations/pathItems.ts +++ b/test/integration/generated/url/src/operations/pathItems.ts @@ -27,7 +27,9 @@ export class PathItems { } /** - * send globalStringPath='globalStringPath', pathItemStringPath='pathItemStringPath', localStringPath='localStringPath', globalStringQuery='globalStringQuery', pathItemStringQuery='pathItemStringQuery', localStringQuery='localStringQuery' + * send globalStringPath='globalStringPath', pathItemStringPath='pathItemStringPath', + * localStringPath='localStringPath', globalStringQuery='globalStringQuery', + * pathItemStringQuery='pathItemStringQuery', localStringQuery='localStringQuery' * @param pathItemStringPath A string value 'pathItemStringPath' that appears in the path * @param localStringPath should contain value 'localStringPath' * @param options The options parameters. @@ -44,7 +46,9 @@ export class PathItems { } /** - * send globalStringPath='globalStringPath', pathItemStringPath='pathItemStringPath', localStringPath='localStringPath', globalStringQuery=null, pathItemStringQuery='pathItemStringQuery', localStringQuery='localStringQuery' + * send globalStringPath='globalStringPath', pathItemStringPath='pathItemStringPath', + * localStringPath='localStringPath', globalStringQuery=null, + * pathItemStringQuery='pathItemStringQuery', localStringQuery='localStringQuery' * @param pathItemStringPath A string value 'pathItemStringPath' that appears in the path * @param localStringPath should contain value 'localStringPath' * @param options The options parameters. @@ -61,7 +65,9 @@ export class PathItems { } /** - * send globalStringPath=globalStringPath, pathItemStringPath='pathItemStringPath', localStringPath='localStringPath', globalStringQuery=null, pathItemStringQuery='pathItemStringQuery', localStringQuery=null + * send globalStringPath=globalStringPath, pathItemStringPath='pathItemStringPath', + * localStringPath='localStringPath', globalStringQuery=null, + * pathItemStringQuery='pathItemStringQuery', localStringQuery=null * @param pathItemStringPath A string value 'pathItemStringPath' that appears in the path * @param localStringPath should contain value 'localStringPath' * @param options The options parameters. @@ -78,7 +84,9 @@ export class PathItems { } /** - * send globalStringPath='globalStringPath', pathItemStringPath='pathItemStringPath', localStringPath='localStringPath', globalStringQuery='globalStringQuery', pathItemStringQuery=null, localStringQuery=null + * send globalStringPath='globalStringPath', pathItemStringPath='pathItemStringPath', + * localStringPath='localStringPath', globalStringQuery='globalStringQuery', pathItemStringQuery=null, + * localStringQuery=null * @param pathItemStringPath A string value 'pathItemStringPath' that appears in the path * @param localStringPath should contain value 'localStringPath' * @param options The options parameters. diff --git a/test/integration/generated/url/src/operations/paths.ts b/test/integration/generated/url/src/operations/paths.ts index e5417436fe..f694483a90 100644 --- a/test/integration/generated/url/src/operations/paths.ts +++ b/test/integration/generated/url/src/operations/paths.ts @@ -310,7 +310,8 @@ export class Paths { } /** - * Get null as date - this should throw or be unusable on the client side, depending on date representation + * Get null as date - this should throw or be unusable on the client side, depending on date + * representation * @param datePath null as date (should throw) * @param options The options parameters. */ @@ -368,8 +369,10 @@ export class Paths { } /** - * Get an array of string ['ArrayPath1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the csv-array format - * @param arrayPath an array of string ['ArrayPath1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the csv-array format + * Get an array of string ['ArrayPath1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the csv-array + * format + * @param arrayPath an array of string ['ArrayPath1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using + * the csv-array format * @param options The options parameters. */ arrayCsvInPath( diff --git a/test/integration/generated/url/src/operations/queries.ts b/test/integration/generated/url/src/operations/queries.ts index b8fc259113..f5c6e3de4a 100644 --- a/test/integration/generated/url/src/operations/queries.ts +++ b/test/integration/generated/url/src/operations/queries.ts @@ -391,7 +391,8 @@ export class Queries { } /** - * Get an array of string ['ArrayQuery1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the csv-array format + * Get an array of string ['ArrayQuery1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the csv-array + * format * @param options The options parameters. */ arrayStringCsvValid( @@ -430,7 +431,8 @@ export class Queries { } /** - * Get an array of string ['ArrayQuery1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the ssv-array format + * Get an array of string ['ArrayQuery1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the ssv-array + * format * @param options The options parameters. */ arrayStringSsvValid( @@ -443,7 +445,8 @@ export class Queries { } /** - * Get an array of string ['ArrayQuery1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the tsv-array format + * Get an array of string ['ArrayQuery1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the tsv-array + * format * @param options The options parameters. */ arrayStringTsvValid( @@ -456,7 +459,8 @@ export class Queries { } /** - * Get an array of string ['ArrayQuery1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the pipes-array format + * Get an array of string ['ArrayQuery1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the + * pipes-array format * @param options The options parameters. */ arrayStringPipesValid( diff --git a/test/integration/generated/url/src/urlClient.ts b/test/integration/generated/url/src/urlClient.ts index 3e7fe31775..93bf2a2510 100644 --- a/test/integration/generated/url/src/urlClient.ts +++ b/test/integration/generated/url/src/urlClient.ts @@ -14,6 +14,7 @@ import { UrlClientContext } from "./urlClientContext"; class UrlClient extends UrlClientContext { /** * Initializes a new instance of the UrlClient class. + * @param globalStringPath A string value 'globalItemStringPath' that appears in the path * @param options The parameter options */ constructor(globalStringPath: string, options?: any) { diff --git a/test/integration/generated/url/src/urlClientContext.ts b/test/integration/generated/url/src/urlClientContext.ts index 9b92b2212f..26f8339be1 100644 --- a/test/integration/generated/url/src/urlClientContext.ts +++ b/test/integration/generated/url/src/urlClientContext.ts @@ -18,7 +18,7 @@ export class UrlClientContext extends coreHttp.ServiceClient { /** * Initializes a new instance of the UrlClientContext class. - * + * @param globalStringPath A string value 'globalItemStringPath' that appears in the path * @param options The parameter options */ constructor(globalStringPath: string, options?: any) { @@ -40,23 +40,12 @@ export class UrlClientContext extends coreHttp.ServiceClient { this.requestContentType = "application/json; charset=utf-8"; + this.baseUri = options.baseUri || "{$host}"; + // Parameter assignments this.globalStringPath = globalStringPath; // Assigning values to Constant parameters - this.$host = "http://localhost:3000"; - - this.baseUri = options.baseUri || this.baseUri || "{$host}"; - - // Replacing parameter defaults with user-provided parameters. - if (options.$host !== null && options.$host !== undefined) { - this.$host = options.$host; - } - if ( - options.globalStringQuery !== null && - options.globalStringQuery !== undefined - ) { - this.globalStringQuery = options.globalStringQuery; - } + this.$host = options.$host || "http://localhost:3000"; } }