forked from loafle/openapi-generator-original
[typescript-rxjs] Added support for servers (#7771)
* adding multiple servers support to typescript-rxjs * regenerated typescript-rxjs samples Co-authored-by: Schwartz, Benjamin <benjamin.schwartz@cgi.com>
This commit is contained in:
parent
a5aeb5fdec
commit
9af73d0a0c
@ -91,6 +91,7 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen
|
||||
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 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen
|
||||
this.reservedWords.add("Middleware");
|
||||
this.reservedWords.add("AjaxRequest");
|
||||
this.reservedWords.add("AjaxResponse");
|
||||
this.reservedWords.add("servers");
|
||||
}
|
||||
|
||||
class ExtendedCodegenOperation extends CodegenOperation {
|
||||
|
@ -1,3 +1,4 @@
|
||||
export * from './runtime';
|
||||
export * from './servers';
|
||||
export * from './apis';
|
||||
export * from './models';
|
||||
|
@ -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
|
||||
|
45
modules/openapi-generator/src/main/resources/typescript-rxjs/servers.mustache
vendored
Normal file
45
modules/openapi-generator/src/main/resources/typescript-rxjs/servers.mustache
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
*
|
||||
* 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 }> {
|
||||
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<T>) {
|
||||
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}}];
|
@ -12,4 +12,5 @@ models/Tag.ts
|
||||
models/User.ts
|
||||
models/index.ts
|
||||
runtime.ts
|
||||
servers.ts
|
||||
tsconfig.json
|
||||
|
@ -1,3 +1,4 @@
|
||||
export * from './runtime';
|
||||
export * from './servers';
|
||||
export * from './apis';
|
||||
export * from './models';
|
||||
|
@ -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
|
||||
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
*
|
||||
* 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 }> {
|
||||
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<T>) {
|
||||
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];
|
@ -14,4 +14,5 @@ models/User.ts
|
||||
models/index.ts
|
||||
package.json
|
||||
runtime.ts
|
||||
servers.ts
|
||||
tsconfig.json
|
||||
|
@ -1,3 +1,4 @@
|
||||
export * from './runtime';
|
||||
export * from './servers';
|
||||
export * from './apis';
|
||||
export * from './models';
|
||||
|
@ -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
|
||||
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
*
|
||||
* 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 }> {
|
||||
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<T>) {
|
||||
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];
|
@ -14,4 +14,5 @@ models/User.ts
|
||||
models/index.ts
|
||||
package.json
|
||||
runtime.ts
|
||||
servers.ts
|
||||
tsconfig.json
|
||||
|
@ -1,3 +1,4 @@
|
||||
export * from './runtime';
|
||||
export * from './servers';
|
||||
export * from './apis';
|
||||
export * from './models';
|
||||
|
@ -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
|
||||
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
*
|
||||
* 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 }> {
|
||||
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<T>) {
|
||||
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];
|
@ -12,4 +12,5 @@ models/Tag.ts
|
||||
models/User.ts
|
||||
models/index.ts
|
||||
runtime.ts
|
||||
servers.ts
|
||||
tsconfig.json
|
||||
|
@ -1,3 +1,4 @@
|
||||
export * from './runtime';
|
||||
export * from './servers';
|
||||
export * from './apis';
|
||||
export * from './models';
|
||||
|
@ -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
|
||||
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
*
|
||||
* 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 }> {
|
||||
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<T>) {
|
||||
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];
|
Loading…
x
Reference in New Issue
Block a user