From d422cf7e6335a88dea7931af3bd361e3da8135a7 Mon Sep 17 00:00:00 2001 From: Dan Schulte Date: Tue, 26 Jun 2018 13:47:00 -0700 Subject: [PATCH 1/2] Make OperationSpec.baseUrl an optional property for moving OperationSpecs into module/file scope --- lib/operationSpec.ts | 5 +++-- lib/serviceClient.ts | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/operationSpec.ts b/lib/operationSpec.ts index b0c599c3812c..07fbbc80f63c 100644 --- a/lib/operationSpec.ts +++ b/lib/operationSpec.ts @@ -22,9 +22,10 @@ export interface OperationSpec { /** * The URL that was provided in the service's specification. This will still have all of the URL - * template variables in it. + * template variables in it. If this is not provided when the OperationSpec is created, then it + * will be populated by a "baseUri" property on the ServiceClient. */ - baseUrl: string; + baseUrl?: string; /** * The fixed path for this operation's URL. This will still have all of the URL template variables diff --git a/lib/serviceClient.ts b/lib/serviceClient.ts index dd47bcad9f00..9ac3911028db 100644 --- a/lib/serviceClient.ts +++ b/lib/serviceClient.ts @@ -177,6 +177,13 @@ export class ServiceClient { let result: Promise; try { + if (operationSpec.baseUrl == undefined) { + operationSpec.baseUrl = (this as any).baseUri; + if (!operationSpec.baseUrl) { + throw new Error("If operationSpec.baseUrl is not specified, then the ServiceClient must have a baseUri string property that contains the base URL to use."); + } + } + httpRequest.method = operationSpec.httpMethod; httpRequest.operationSpec = operationSpec; From 8be6cd370d3075c9c33c878912d2b5d94235acd3 Mon Sep 17 00:00:00 2001 From: Dan Schulte Date: Tue, 26 Jun 2018 14:00:36 -0700 Subject: [PATCH 2/2] Make baseUri an optional parameter on ServiceClient --- lib/serviceClient.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/serviceClient.ts b/lib/serviceClient.ts index 9ac3911028db..e1862a006871 100644 --- a/lib/serviceClient.ts +++ b/lib/serviceClient.ts @@ -75,6 +75,12 @@ export interface ServiceClientOptions { * Initializes a new instance of the ServiceClient. */ export class ServiceClient { + /** + * If specified, this is the base URI that requests will be made against for this ServiceClient. + * If it is not specified, then all OperationSpecs must contain a baseUrl property. + */ + protected baseUri?: string; + /** * The string to be appended to the User-Agent header while sending the request. * This will be applicable only for node.js environment as the fetch library in browser does not allow setting custom UA. @@ -178,7 +184,7 @@ export class ServiceClient { let result: Promise; try { if (operationSpec.baseUrl == undefined) { - operationSpec.baseUrl = (this as any).baseUri; + operationSpec.baseUrl = this.baseUri; if (!operationSpec.baseUrl) { throw new Error("If operationSpec.baseUrl is not specified, then the ServiceClient must have a baseUri string property that contains the base URL to use."); }