Skip to content

Commit

Permalink
Updated TS SDK with dynamic base URL
Browse files Browse the repository at this point in the history
  • Loading branch information
tomakehurst committed Sep 24, 2024
1 parent 6d05e81 commit a681542
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 43 deletions.
2 changes: 2 additions & 0 deletions sdks/ts/openapi_sdk_typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ The following parameters are configurable for the API Client:

| Parameter | Type | Description |
| --- | --- | --- |
| `host` | `string` | The fully-qualified hostname of the API<br>*Default*: `'wm-train-travel.wiremockapi.cloud'` |
| `environment` | `Environment` | The API environment. <br> **Default: `Environment.Production`** |
| `timeout` | `number` | Timeout for API calls.<br>*Default*: `0` |
| `httpClientOptions` | `Partial<HttpClientOptions>` | Stable configurable http client options. |
Expand Down Expand Up @@ -141,6 +142,7 @@ const client = new Client({
},
timeout: 0,
environment: Environment.Production,
host: 'wm-train-travel.wiremockapi.cloud',
});
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ const client = new Client({
},
timeout: 0,
environment: Environment.Production,
host: 'wm-train-travel.wiremockapi.cloud',
});

// obtain access token, needed for client to be authorized
Expand Down
2 changes: 2 additions & 0 deletions sdks/ts/openapi_sdk_typescript/doc/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The following parameters are configurable for the API Client:

| Parameter | Type | Description |
| --- | --- | --- |
| `host` | `string` | The fully-qualified hostname of the API<br>*Default*: `'wm-train-travel.wiremockapi.cloud'` |
| `environment` | `Environment` | The API environment. <br> **Default: `Environment.Production`** |
| `timeout` | `number` | Timeout for API calls.<br>*Default*: `0` |
| `httpClientOptions` | `Partial<HttpClientOptions>` | Stable configurable http client options. |
Expand Down Expand Up @@ -47,6 +48,7 @@ const client = new Client({
},
timeout: 0,
environment: Environment.Production,
host: 'wm-train-travel.wiremockapi.cloud',
});
```

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Booking Payment Source

## Class Name

`BookingPaymentSource`

## Cases

| Type |
| --- |
| [`Card`](../../../doc/models/card.md) |
| [`BankAccount`](../../../doc/models/bank-account.md) |

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Bookings Payment Response Source

## Class Name

`BookingsPaymentResponseSource`

## Cases

| Type |
| --- |
| [`Card`](../../../doc/models/card.md) |
| [`BankAccount`](../../../doc/models/bank-account.md) |

78 changes: 39 additions & 39 deletions sdks/ts/openapi_sdk_typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions sdks/ts/openapi_sdk_typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0",
"version": "1.0.5",
"license": "MIT",
"sideEffects": false,
"main": "dist/cjs/index.js",
Expand Down Expand Up @@ -29,7 +29,8 @@
"trailingComma": "es5",
"quoteProps": "preserve"
},
"name": "train-travel-apilib",
"name": "@wiremock-inc/apimatic-sdkgen-demo",
"repository": "github:wiremock-inc/apimatic-sdkgen-demo",
"description": "API for finding and booking train trips across Europe. ## Run in Postman Experiment with this API in Postman, using our Postman Collection. [<img src=\"https://run.pstmn.io/button.svg\" alt=\"Run In Postman\" style=\"width: 128px; height: 32px;\">](https://app.getpostman.com/run-collection/9265903-7a75a0d0-b108-4436-ba54-c6139698dc08?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D9265903-7a75a0d0-b108-4436-ba54-c6139698dc08%26entityType%3Dcollection%26workspaceId%3Df507f69d-9564-419c-89a2-cb8e4c8c7b8f)",
"author": {
"name": "Train Support",
Expand All @@ -50,7 +51,7 @@
"dependencies": {
"@apimatic/authentication-adapters": "^0.5.4",
"@apimatic/axios-client-adapter": "^0.3.4",
"@apimatic/core": "^0.10.13",
"@apimatic/core": "^0.10.14",
"@apimatic/oauth-adapters": "^0.4.6",
"@apimatic/schema": "^0.7.12"
},
Expand Down
3 changes: 2 additions & 1 deletion sdks/ts/openapi_sdk_typescript/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
DEFAULT_RETRY_CONFIG,
} from './defaultConfiguration';
import { ApiError } from './core';
import { pathTemplate, SkipEncode } from './core';
import {
AbortError,
AuthenticatorInterface,
Expand Down Expand Up @@ -105,7 +106,7 @@ function createHttpClientAdapter(client: HttpClient): HttpClientInterface {
function getBaseUri(server: Server = 'default', config: Configuration): string {
if (config.environment === Environment.Production) {
if (server === 'default') {
return 'https://wm-train-travel.wiremockapi.cloud';
return pathTemplate`https://${new SkipEncode(config.host)}`;
}
if (server === 'auth server') {
return 'https://example.com/oauth';
Expand Down
1 change: 1 addition & 0 deletions sdks/ts/openapi_sdk_typescript/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { OAuthToken } from './models/oAuthToken';
export interface Configuration {
timeout: number;
environment: Environment;
host: string;
/** @deprecated use authorizationCodeAuthCredentials field instead */
oAuthClientId?: string;
/** @deprecated use authorizationCodeAuthCredentials field instead */
Expand Down
1 change: 1 addition & 0 deletions sdks/ts/openapi_sdk_typescript/src/defaultConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { RetryConfiguration } from './core';
export const DEFAULT_CONFIGURATION: Configuration = {
timeout: 0,
environment: Environment.Production,
host: 'wm-train-travel.wiremockapi.cloud',
};

/** Default values for retry configuration parameters. */
Expand Down
5 changes: 5 additions & 0 deletions sdks/ts/openapi_sdk_typescript/test/testClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function createConfigurationFromEnvironment(): Partial<Configuration> {
const config: Partial<Configuration> = {};

const environment = process.env.TRAIN_TRAVEL_API_LIB_ENVIRONMENT;
const host = process.env.TRAIN_TRAVEL_API_LIB_HOST;
const timeout = process.env.TRAIN_TRAVEL_API_LIB_TIMEOUT;
const oAuthClientId = process.env.TRAIN_TRAVEL_API_LIB_O_AUTH_CLIENT_ID;
const oAuthClientSecret = process.env.TRAIN_TRAVEL_API_LIB_O_AUTH_CLIENT_SECRET;
Expand All @@ -21,6 +22,10 @@ function createConfigurationFromEnvironment(): Partial<Configuration> {
config.environment = environment as Environment;
}

if (host !== undefined) {
config.host = host;
}

if (timeout !== undefined && timeout !== '') {
config.timeout = parseInt(timeout);
}
Expand Down

0 comments on commit a681542

Please sign in to comment.