diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java index 20bb097eaea..ad1ad80ad1b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java @@ -124,7 +124,7 @@ public class TypeScriptClientCodegen extends DefaultCodegen implements CodegenCo supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.ts")); supportingFiles.add(new SupportingFile("middleware.mustache", "", "middleware.ts")); supportingFiles.add(new SupportingFile("auth" + File.separator + "auth.mustache", "auth", "auth.ts")); - + supportingFiles.add(new SupportingFile("servers.mustache", "servers.ts")); // models this.modelPackage = ""; this.modelTemplateFiles.put("models/models.mustache", ".ts"); diff --git a/modules/openapi-generator/src/main/resources/typescript/configuration.mustache b/modules/openapi-generator/src/main/resources/typescript/configuration.mustache index 2a7e7da234d..59f97141075 100644 --- a/modules/openapi-generator/src/main/resources/typescript/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/configuration.mustache @@ -1,11 +1,10 @@ import {HttpLibrary} from './http/http'; import {Middleware} from './middleware'; import {IsomorphicFetchHttpLibrary} from "./http/isomorphic-fetch"; - -export const BASE_PATH = "{{{basePath}}}".replace(/\/+$/, ""); +import {ServerConfiguration, servers} from './servers'; export interface ConfigurationParameters { - basePath?: string; // override base path + baseServer?: ServerConfiguration; httpApi?: HttpLibrary; // override for fetch implementation middleware?: Middleware[]; // middleware to apply before/after fetch requests username?: string; // parameter for basic security @@ -16,7 +15,7 @@ export interface ConfigurationParameters { export class Configuration { - basePath: string; + baseServer: ServerConfiguration; httpApi: HttpLibrary; middleware: Middleware[]; username?: string; @@ -25,7 +24,7 @@ export class Configuration { accessToken?: (name: string, scopes?: string[]) => string; constructor(conf: ConfigurationParameters = {}) { - this.basePath = conf.basePath !== undefined ? conf.basePath : BASE_PATH; + this.baseServer = conf.baseServer !== undefined ? conf.baseServer : servers[0]; this.httpApi = conf.httpApi || new IsomorphicFetchHttpLibrary(); // TODO: replace with window.fetch? this.middleware = conf.middleware || []; this.username = conf.username; diff --git a/modules/openapi-generator/src/main/resources/typescript/servers.mustache b/modules/openapi-generator/src/main/resources/typescript/servers.mustache new file mode 100644 index 00000000000..6d738c29096 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/typescript/servers.mustache @@ -0,0 +1,19 @@ +import {RequestContext, HttpMethod} from './http/http'; + +export class ServerConfiguration { + + public constructor(private url: string) { + } + + public makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext { + return new RequestContext(this.url + endpoint, httpMethod); + } +} + +{{#openAPI}} +export const servers = [ + {{#servers}} + new ServerConfiguration("{{url}}"){{^last}},{{/last}} + {{/servers}} +] +{{/openAPI}} \ No newline at end of file