Skip to content

Commit da91ddb

Browse files
NouemanKHALtherve
andauthored
generate client for #322 (#339)
Co-authored-by: Thomas Hervé <[email protected]>
1 parent deab709 commit da91ddb

File tree

6 files changed

+86
-30
lines changed

6 files changed

+86
-30
lines changed

packages/datadog-api-client-v1/configuration.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ export function createConfiguration(
8787
const serverConf = server1.getConfiguration();
8888
server1.setVariables({ site: process.env.DD_SITE } as typeof serverConf);
8989
for (const op in operationServers) {
90-
(operationServers[op][0] as any).setVariables({
91-
site: process.env.DD_SITE,
92-
});
90+
operationServers[op][0].setVariables({ site: process.env.DD_SITE });
9391
}
9492
}
9593

@@ -135,3 +133,25 @@ export function getServer(
135133
? operationServers[endpoint][index]
136134
: servers[index];
137135
}
136+
137+
/**
138+
* Sets the server variables.
139+
*
140+
* @param serverVariables key/value object representing the server variables (site, name, protocol, ...)
141+
*/
142+
export function setServerVariables(
143+
conf: Configuration,
144+
serverVariables: { [key: string]: string }
145+
) {
146+
if (conf.baseServer !== undefined) {
147+
conf.baseServer.setVariables(serverVariables);
148+
return;
149+
}
150+
151+
const index = conf.serverIndex;
152+
servers[index].setVariables(serverVariables);
153+
154+
for (const op in operationServers) {
155+
operationServers[op][0].setVariables(serverVariables);
156+
}
157+
}

packages/datadog-api-client-v1/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export * from "./http/http";
22
export * from "./auth/auth";
33
export { createConfiguration } from "./configuration";
4+
export { setServerVariables } from "./configuration";
5+
46
export { Configuration } from "./configuration";
57
export * from "./apis/exception";
68
export * from "./servers";

packages/datadog-api-client-v1/servers.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
import { RequestContext, HttpMethod } from "./http/http";
22

3-
export interface BaseServerConfiguration {
4-
makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext;
5-
}
6-
73
/**
84
*
9-
* Represents the configuration of a server including its
10-
* url template and variable configuration based on the url.
5+
* Represents the configuration of a server
116
*
127
*/
13-
export class ServerConfiguration<T extends { [key: string]: string }>
14-
implements BaseServerConfiguration
15-
{
16-
public constructor(private url: string, private variableConfiguration: T) {}
8+
export class BaseServerConfiguration {
9+
public constructor(
10+
private url: string,
11+
private variableConfiguration: { [key: string]: string }
12+
) {}
1713

1814
/**
1915
* Sets the value of the variables of this server.
2016
*
2117
* @param variableConfiguration a partial variable configuration for the variables contained in the url
2218
*/
23-
public setVariables(variableConfiguration: Partial<T>) {
19+
public setVariables(variableConfiguration: { [key: string]: string }) {
2420
Object.assign(this.variableConfiguration, variableConfiguration);
2521
}
2622

27-
public getConfiguration(): T {
23+
public getConfiguration(): { [key: string]: string } {
2824
return this.variableConfiguration;
2925
}
3026

@@ -53,6 +49,16 @@ export class ServerConfiguration<T extends { [key: string]: string }>
5349
}
5450
}
5551

52+
/**
53+
*
54+
* Represents the configuration of a server including its
55+
* url template and variable configuration based on the url.
56+
*
57+
*/
58+
export class ServerConfiguration<
59+
T extends { [key: string]: string }
60+
> extends BaseServerConfiguration {}
61+
5662
export const server1 = new ServerConfiguration<{
5763
site:
5864
| "datadoghq.com"

packages/datadog-api-client-v2/configuration.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ export function createConfiguration(
8787
const serverConf = server1.getConfiguration();
8888
server1.setVariables({ site: process.env.DD_SITE } as typeof serverConf);
8989
for (const op in operationServers) {
90-
(operationServers[op][0] as any).setVariables({
91-
site: process.env.DD_SITE,
92-
});
90+
operationServers[op][0].setVariables({ site: process.env.DD_SITE });
9391
}
9492
}
9593

@@ -135,3 +133,25 @@ export function getServer(
135133
? operationServers[endpoint][index]
136134
: servers[index];
137135
}
136+
137+
/**
138+
* Sets the server variables.
139+
*
140+
* @param serverVariables key/value object representing the server variables (site, name, protocol, ...)
141+
*/
142+
export function setServerVariables(
143+
conf: Configuration,
144+
serverVariables: { [key: string]: string }
145+
) {
146+
if (conf.baseServer !== undefined) {
147+
conf.baseServer.setVariables(serverVariables);
148+
return;
149+
}
150+
151+
const index = conf.serverIndex;
152+
servers[index].setVariables(serverVariables);
153+
154+
for (const op in operationServers) {
155+
operationServers[op][0].setVariables(serverVariables);
156+
}
157+
}

packages/datadog-api-client-v2/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export * from "./http/http";
22
export * from "./auth/auth";
33
export { createConfiguration } from "./configuration";
4+
export { setServerVariables } from "./configuration";
5+
46
export { Configuration } from "./configuration";
57
export * from "./apis/exception";
68
export * from "./servers";

packages/datadog-api-client-v2/servers.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
import { RequestContext, HttpMethod } from "./http/http";
22

3-
export interface BaseServerConfiguration {
4-
makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext;
5-
}
6-
73
/**
84
*
9-
* Represents the configuration of a server including its
10-
* url template and variable configuration based on the url.
5+
* Represents the configuration of a server
116
*
127
*/
13-
export class ServerConfiguration<T extends { [key: string]: string }>
14-
implements BaseServerConfiguration
15-
{
16-
public constructor(private url: string, private variableConfiguration: T) {}
8+
export class BaseServerConfiguration {
9+
public constructor(
10+
private url: string,
11+
private variableConfiguration: { [key: string]: string }
12+
) {}
1713

1814
/**
1915
* Sets the value of the variables of this server.
2016
*
2117
* @param variableConfiguration a partial variable configuration for the variables contained in the url
2218
*/
23-
public setVariables(variableConfiguration: Partial<T>) {
19+
public setVariables(variableConfiguration: { [key: string]: string }) {
2420
Object.assign(this.variableConfiguration, variableConfiguration);
2521
}
2622

27-
public getConfiguration(): T {
23+
public getConfiguration(): { [key: string]: string } {
2824
return this.variableConfiguration;
2925
}
3026

@@ -53,6 +49,16 @@ export class ServerConfiguration<T extends { [key: string]: string }>
5349
}
5450
}
5551

52+
/**
53+
*
54+
* Represents the configuration of a server including its
55+
* url template and variable configuration based on the url.
56+
*
57+
*/
58+
export class ServerConfiguration<
59+
T extends { [key: string]: string }
60+
> extends BaseServerConfiguration {}
61+
5662
export const server1 = new ServerConfiguration<{
5763
site:
5864
| "datadoghq.com"

0 commit comments

Comments
 (0)