Skip to content

Commit

Permalink
Merge pull request Azure#153 from Azure/daschult/MoveOperationSpecs
Browse files Browse the repository at this point in the history
Make OperationSpec.baseUrl an optional property for moving OperationSpecs into module/file scope
  • Loading branch information
Dan Schulte authored Jun 26, 2018
2 parents 5547c64 + 8be6cd3 commit 2d75303
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/operationSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions lib/serviceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -177,6 +183,13 @@ export class ServiceClient {

let result: Promise<HttpOperationResponse>;
try {
if (operationSpec.baseUrl == undefined) {
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.");
}
}

httpRequest.method = operationSpec.httpMethod;
httpRequest.operationSpec = operationSpec;

Expand Down

0 comments on commit 2d75303

Please sign in to comment.