Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.5.1.dev2",
"regenerated": "2021-10-28 15:03:03.917351",
"spec_repo_commit": "f510509"
"regenerated": "2021-10-29 09:17:36.074895",
"spec_repo_commit": "e0d002a"
},
"v2": {
"apigentools_version": "1.5.1.dev2",
"regenerated": "2021-10-28 15:03:03.938056",
"spec_repo_commit": "f510509"
"regenerated": "2021-10-29 09:17:36.104666",
"spec_repo_commit": "e0d002a"
}
}
}
21 changes: 20 additions & 1 deletion .generator/templates/configuration.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function createConfiguration(conf: ConfigurationParameters = {}): Configu
let serverConf = server1.getConfiguration();
server1.setVariables({"site": process.env.DD_SITE} as (typeof serverConf));
for (const op in operationServers) {
(operationServers[op][0] as any).setVariables({ site: process.env.DD_SITE });
operationServers[op][0].setVariables({ site: process.env.DD_SITE });
}
}

Expand Down Expand Up @@ -120,3 +120,22 @@ export function getServer(conf: Configuration, endpoint: string): BaseServerConf
let index = (endpoint in conf.operationServerIndices) ? conf.operationServerIndices[endpoint] : conf.serverIndex;
return (endpoint in operationServers) ? operationServers[endpoint][index] : servers[index];
}

/**
* Sets the server variables.
*
* @param serverVariables key/value object representing the server variables (site, name, protocol, ...)
*/
export function setServerVariables(conf: Configuration, serverVariables: { [key: string]: string }) {
if (conf.baseServer !== undefined) {
conf.baseServer.setVariables(serverVariables);
return ;
}

let index = conf.serverIndex;
servers[index].setVariables(serverVariables);

for (const op in operationServers) {
operationServers[op][0].setVariables(serverVariables);
}
}
23 changes: 13 additions & 10 deletions .generator/templates/http/servers.mustache
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import { RequestContext, HttpMethod } from "./http/http{{extensionForDeno}}";

export interface BaseServerConfiguration {
makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext;
}

/**
*
* Represents the configuration of a server including its
* url template and variable configuration based on the url.
* Represents the configuration of a server
*
*/
export class ServerConfiguration<T extends { [key: string]: string }> implements BaseServerConfiguration {
public constructor(private url: string, private variableConfiguration: T) {}
export class BaseServerConfiguration {
public constructor(private url: string, private variableConfiguration: { [key: string]: string }) {}

/**
* Sets the value of the variables of this server.
*
* @param variableConfiguration a partial variable configuration for the variables contained in the url
*/
public setVariables(variableConfiguration: Partial<T>) {
public setVariables(variableConfiguration: { [key: string]: string }) {
Object.assign(this.variableConfiguration, variableConfiguration);
}

public getConfiguration(): T {
public getConfiguration(): { [key: string]: string } {
return this.variableConfiguration
}

Expand All @@ -48,6 +43,14 @@ export class ServerConfiguration<T extends { [key: string]: string }> implements
}
}

/**
*
* Represents the configuration of a server including its
* url template and variable configuration based on the url.
*
*/
export class ServerConfiguration<T extends { [key: string]: string }> extends BaseServerConfiguration {}

{{#servers}}
export const server{{-index}} = new ServerConfiguration<{ {{#variables}}
"{{name}}": {{#enumValues}}"{{.}}"{{^-last}} | {{/-last}}{{/enumValues}}{{^enumValues}}string{{/enumValues}}{{^-last}},{{/-last}}
Expand Down
2 changes: 2 additions & 0 deletions .generator/templates/index.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export * from "./http/http{{extensionForDeno}}";
export * from "./auth/auth{{extensionForDeno}}";
export { createConfiguration } from "./configuration{{extensionForDeno}}"
export { setServerVariables } from "./configuration{{extensionForDeno}}"

export{{#platforms}}{{#deno}} type{{/deno}}{{/platforms}} { Configuration } from "./configuration{{extensionForDeno}}"
export * from "./apis/exception{{extensionForDeno}}";
export * from "./servers{{extensionForDeno}}";
Expand Down