diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java index 9d397611d286..b4e0e3aa29b2 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java @@ -91,6 +91,7 @@ public void processOpts() { super.processOpts(); supportingFiles.add(new SupportingFile("index.mustache", "", "index.ts")); supportingFiles.add(new SupportingFile("runtime.mustache", "", "runtime.ts")); + supportingFiles.add(new SupportingFile("servers.mustache", "", "servers.ts")); supportingFiles.add(new SupportingFile("apis.index.mustache", apiPackage().replace('.', File.separatorChar), "index.ts")); supportingFiles.add(new SupportingFile("models.index.mustache", modelPackage().replace('.', File.separatorChar), "index.ts")); supportingFiles.add(new SupportingFile("tsconfig.mustache", "", "tsconfig.json")); @@ -344,6 +345,7 @@ private void addExtraReservedWords() { this.reservedWords.add("Middleware"); this.reservedWords.add("AjaxRequest"); this.reservedWords.add("AjaxResponse"); + this.reservedWords.add("servers"); } class ExtendedCodegenOperation extends CodegenOperation { diff --git a/modules/openapi-generator/src/main/resources/typescript-rxjs/index.mustache b/modules/openapi-generator/src/main/resources/typescript-rxjs/index.mustache index 848ecfa4d100..b9e2f3ca3b7e 100644 --- a/modules/openapi-generator/src/main/resources/typescript-rxjs/index.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-rxjs/index.mustache @@ -1,3 +1,4 @@ export * from './runtime'; +export * from './servers'; export * from './apis'; export * from './models'; diff --git a/modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache b/modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache index 611797ab47a0..cb89d5cedbf0 100644 --- a/modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache @@ -3,8 +3,9 @@ import { Observable, of{{#withProgressSubscriber}}, Subscriber{{/withProgressSubscriber}} } from 'rxjs'; import { ajax, AjaxRequest, AjaxResponse } from 'rxjs/ajax'; import { map, concatMap } from 'rxjs/operators'; +import { servers } from './servers'; -export const BASE_PATH = '{{{basePath}}}'.replace(/\/+$/, ''); +export const BASE_PATH = servers[0].getUrl(); export interface ConfigurationParameters { basePath?: string; // override base path diff --git a/modules/openapi-generator/src/main/resources/typescript-rxjs/servers.mustache b/modules/openapi-generator/src/main/resources/typescript-rxjs/servers.mustache new file mode 100644 index 000000000000..497695af6934 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/typescript-rxjs/servers.mustache @@ -0,0 +1,45 @@ +/** + * + * Represents the configuration of a server including its + * url template and variable configuration based on the url. + * + */ +export class ServerConfiguration { + public constructor(private url: string, private variableConfiguration: T, private description: 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) { + Object.assign(this.variableConfiguration, variableConfiguration); + } + + public getConfiguration(): T { + return this.variableConfiguration + } + + public getDescription(): string { + return this.description + } + + /** + * Constructions the URL this server using the url with variables + * replaced with their respective values + */ + public getUrl(): string { + let replacedUrl = this.url; + for (const key in this.variableConfiguration) { + var re = new RegExp("{" + key + "}","g"); + replacedUrl = replacedUrl.replace(re, this.variableConfiguration[key]); + } + return replacedUrl + } +} + +{{#servers}} +const server{{-index}} = new ServerConfiguration<{ {{#variables}} "{{name}}": {{#enumValues}}"{{.}}"{{^-last}} | {{/-last}}{{/enumValues}}{{^enumValues}}string{{/enumValues}}{{^-last}},{{/-last}} {{/variables}} }>("{{url}}", { {{#variables}} "{{name}}": "{{defaultValue}}" {{^-last}},{{/-last}}{{/variables}} }, "{{description}}") +{{/servers}} + +export const servers = [{{#servers}}server{{-index}}{{^-last}}, {{/-last}}{{/servers}}]; diff --git a/samples/client/petstore/typescript-rxjs/builds/default/.openapi-generator/FILES b/samples/client/petstore/typescript-rxjs/builds/default/.openapi-generator/FILES index 687ab35b18db..9f25cbf794c1 100644 --- a/samples/client/petstore/typescript-rxjs/builds/default/.openapi-generator/FILES +++ b/samples/client/petstore/typescript-rxjs/builds/default/.openapi-generator/FILES @@ -12,4 +12,5 @@ models/Tag.ts models/User.ts models/index.ts runtime.ts +servers.ts tsconfig.json diff --git a/samples/client/petstore/typescript-rxjs/builds/default/index.ts b/samples/client/petstore/typescript-rxjs/builds/default/index.ts index 848ecfa4d100..b9e2f3ca3b7e 100644 --- a/samples/client/petstore/typescript-rxjs/builds/default/index.ts +++ b/samples/client/petstore/typescript-rxjs/builds/default/index.ts @@ -1,3 +1,4 @@ export * from './runtime'; +export * from './servers'; export * from './apis'; export * from './models'; diff --git a/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts b/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts index b417f8b45947..cc22d83bfd91 100644 --- a/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts @@ -14,8 +14,9 @@ import { Observable, of } from 'rxjs'; import { ajax, AjaxRequest, AjaxResponse } from 'rxjs/ajax'; import { map, concatMap } from 'rxjs/operators'; +import { servers } from './servers'; -export const BASE_PATH = 'http://petstore.swagger.io/v2'.replace(/\/+$/, ''); +export const BASE_PATH = servers[0].getUrl(); export interface ConfigurationParameters { basePath?: string; // override base path diff --git a/samples/client/petstore/typescript-rxjs/builds/default/servers.ts b/samples/client/petstore/typescript-rxjs/builds/default/servers.ts new file mode 100644 index 000000000000..6d9b253596e6 --- /dev/null +++ b/samples/client/petstore/typescript-rxjs/builds/default/servers.ts @@ -0,0 +1,43 @@ +/** + * + * Represents the configuration of a server including its + * url template and variable configuration based on the url. + * + */ +export class ServerConfiguration { + public constructor(private url: string, private variableConfiguration: T, private description: 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) { + Object.assign(this.variableConfiguration, variableConfiguration); + } + + public getConfiguration(): T { + return this.variableConfiguration + } + + public getDescription(): string { + return this.description + } + + /** + * Constructions the URL this server using the url with variables + * replaced with their respective values + */ + public getUrl(): string { + let replacedUrl = this.url; + for (const key in this.variableConfiguration) { + var re = new RegExp("{" + key + "}","g"); + replacedUrl = replacedUrl.replace(re, this.variableConfiguration[key]); + } + return replacedUrl + } +} + +const server1 = new ServerConfiguration<{ }>("http://petstore.swagger.io/v2", { }, "") + +export const servers = [server1]; diff --git a/samples/client/petstore/typescript-rxjs/builds/es6-target/.openapi-generator/FILES b/samples/client/petstore/typescript-rxjs/builds/es6-target/.openapi-generator/FILES index f2edf3edf868..3b574b7ab7c5 100644 --- a/samples/client/petstore/typescript-rxjs/builds/es6-target/.openapi-generator/FILES +++ b/samples/client/petstore/typescript-rxjs/builds/es6-target/.openapi-generator/FILES @@ -14,4 +14,5 @@ models/User.ts models/index.ts package.json runtime.ts +servers.ts tsconfig.json diff --git a/samples/client/petstore/typescript-rxjs/builds/es6-target/index.ts b/samples/client/petstore/typescript-rxjs/builds/es6-target/index.ts index 848ecfa4d100..b9e2f3ca3b7e 100644 --- a/samples/client/petstore/typescript-rxjs/builds/es6-target/index.ts +++ b/samples/client/petstore/typescript-rxjs/builds/es6-target/index.ts @@ -1,3 +1,4 @@ export * from './runtime'; +export * from './servers'; export * from './apis'; export * from './models'; diff --git a/samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts b/samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts index b417f8b45947..cc22d83bfd91 100644 --- a/samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts @@ -14,8 +14,9 @@ import { Observable, of } from 'rxjs'; import { ajax, AjaxRequest, AjaxResponse } from 'rxjs/ajax'; import { map, concatMap } from 'rxjs/operators'; +import { servers } from './servers'; -export const BASE_PATH = 'http://petstore.swagger.io/v2'.replace(/\/+$/, ''); +export const BASE_PATH = servers[0].getUrl(); export interface ConfigurationParameters { basePath?: string; // override base path diff --git a/samples/client/petstore/typescript-rxjs/builds/es6-target/servers.ts b/samples/client/petstore/typescript-rxjs/builds/es6-target/servers.ts new file mode 100644 index 000000000000..6d9b253596e6 --- /dev/null +++ b/samples/client/petstore/typescript-rxjs/builds/es6-target/servers.ts @@ -0,0 +1,43 @@ +/** + * + * Represents the configuration of a server including its + * url template and variable configuration based on the url. + * + */ +export class ServerConfiguration { + public constructor(private url: string, private variableConfiguration: T, private description: 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) { + Object.assign(this.variableConfiguration, variableConfiguration); + } + + public getConfiguration(): T { + return this.variableConfiguration + } + + public getDescription(): string { + return this.description + } + + /** + * Constructions the URL this server using the url with variables + * replaced with their respective values + */ + public getUrl(): string { + let replacedUrl = this.url; + for (const key in this.variableConfiguration) { + var re = new RegExp("{" + key + "}","g"); + replacedUrl = replacedUrl.replace(re, this.variableConfiguration[key]); + } + return replacedUrl + } +} + +const server1 = new ServerConfiguration<{ }>("http://petstore.swagger.io/v2", { }, "") + +export const servers = [server1]; diff --git a/samples/client/petstore/typescript-rxjs/builds/with-npm-version/.openapi-generator/FILES b/samples/client/petstore/typescript-rxjs/builds/with-npm-version/.openapi-generator/FILES index f2edf3edf868..3b574b7ab7c5 100644 --- a/samples/client/petstore/typescript-rxjs/builds/with-npm-version/.openapi-generator/FILES +++ b/samples/client/petstore/typescript-rxjs/builds/with-npm-version/.openapi-generator/FILES @@ -14,4 +14,5 @@ models/User.ts models/index.ts package.json runtime.ts +servers.ts tsconfig.json diff --git a/samples/client/petstore/typescript-rxjs/builds/with-npm-version/index.ts b/samples/client/petstore/typescript-rxjs/builds/with-npm-version/index.ts index 848ecfa4d100..b9e2f3ca3b7e 100644 --- a/samples/client/petstore/typescript-rxjs/builds/with-npm-version/index.ts +++ b/samples/client/petstore/typescript-rxjs/builds/with-npm-version/index.ts @@ -1,3 +1,4 @@ export * from './runtime'; +export * from './servers'; export * from './apis'; export * from './models'; diff --git a/samples/client/petstore/typescript-rxjs/builds/with-npm-version/runtime.ts b/samples/client/petstore/typescript-rxjs/builds/with-npm-version/runtime.ts index b417f8b45947..cc22d83bfd91 100644 --- a/samples/client/petstore/typescript-rxjs/builds/with-npm-version/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/with-npm-version/runtime.ts @@ -14,8 +14,9 @@ import { Observable, of } from 'rxjs'; import { ajax, AjaxRequest, AjaxResponse } from 'rxjs/ajax'; import { map, concatMap } from 'rxjs/operators'; +import { servers } from './servers'; -export const BASE_PATH = 'http://petstore.swagger.io/v2'.replace(/\/+$/, ''); +export const BASE_PATH = servers[0].getUrl(); export interface ConfigurationParameters { basePath?: string; // override base path diff --git a/samples/client/petstore/typescript-rxjs/builds/with-npm-version/servers.ts b/samples/client/petstore/typescript-rxjs/builds/with-npm-version/servers.ts new file mode 100644 index 000000000000..6d9b253596e6 --- /dev/null +++ b/samples/client/petstore/typescript-rxjs/builds/with-npm-version/servers.ts @@ -0,0 +1,43 @@ +/** + * + * Represents the configuration of a server including its + * url template and variable configuration based on the url. + * + */ +export class ServerConfiguration { + public constructor(private url: string, private variableConfiguration: T, private description: 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) { + Object.assign(this.variableConfiguration, variableConfiguration); + } + + public getConfiguration(): T { + return this.variableConfiguration + } + + public getDescription(): string { + return this.description + } + + /** + * Constructions the URL this server using the url with variables + * replaced with their respective values + */ + public getUrl(): string { + let replacedUrl = this.url; + for (const key in this.variableConfiguration) { + var re = new RegExp("{" + key + "}","g"); + replacedUrl = replacedUrl.replace(re, this.variableConfiguration[key]); + } + return replacedUrl + } +} + +const server1 = new ServerConfiguration<{ }>("http://petstore.swagger.io/v2", { }, "") + +export const servers = [server1]; diff --git a/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/.openapi-generator/FILES b/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/.openapi-generator/FILES index 687ab35b18db..9f25cbf794c1 100644 --- a/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/.openapi-generator/FILES +++ b/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/.openapi-generator/FILES @@ -12,4 +12,5 @@ models/Tag.ts models/User.ts models/index.ts runtime.ts +servers.ts tsconfig.json diff --git a/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/index.ts b/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/index.ts index 848ecfa4d100..b9e2f3ca3b7e 100644 --- a/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/index.ts +++ b/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/index.ts @@ -1,3 +1,4 @@ export * from './runtime'; +export * from './servers'; export * from './apis'; export * from './models'; diff --git a/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/runtime.ts b/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/runtime.ts index 2fb0ef154ab6..8705c9e95465 100644 --- a/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/runtime.ts @@ -14,8 +14,9 @@ import { Observable, of, Subscriber } from 'rxjs'; import { ajax, AjaxRequest, AjaxResponse } from 'rxjs/ajax'; import { map, concatMap } from 'rxjs/operators'; +import { servers } from './servers'; -export const BASE_PATH = 'http://petstore.swagger.io/v2'.replace(/\/+$/, ''); +export const BASE_PATH = servers[0].getUrl(); export interface ConfigurationParameters { basePath?: string; // override base path diff --git a/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/servers.ts b/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/servers.ts new file mode 100644 index 000000000000..6d9b253596e6 --- /dev/null +++ b/samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber/servers.ts @@ -0,0 +1,43 @@ +/** + * + * Represents the configuration of a server including its + * url template and variable configuration based on the url. + * + */ +export class ServerConfiguration { + public constructor(private url: string, private variableConfiguration: T, private description: 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) { + Object.assign(this.variableConfiguration, variableConfiguration); + } + + public getConfiguration(): T { + return this.variableConfiguration + } + + public getDescription(): string { + return this.description + } + + /** + * Constructions the URL this server using the url with variables + * replaced with their respective values + */ + public getUrl(): string { + let replacedUrl = this.url; + for (const key in this.variableConfiguration) { + var re = new RegExp("{" + key + "}","g"); + replacedUrl = replacedUrl.replace(re, this.variableConfiguration[key]); + } + return replacedUrl + } +} + +const server1 = new ServerConfiguration<{ }>("http://petstore.swagger.io/v2", { }, "") + +export const servers = [server1];