[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:
BenICE 2020-10-22 13:09:03 +02:00 committed by GitHub
parent a5aeb5fdec
commit 9af73d0a0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 238 additions and 5 deletions

View File

@ -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 {

View File

@ -1,3 +1,4 @@
export * from './runtime';
export * from './servers';
export * from './apis';
export * from './models';

View File

@ -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

View 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}}];

View File

@ -12,4 +12,5 @@ models/Tag.ts
models/User.ts
models/index.ts
runtime.ts
servers.ts
tsconfig.json

View File

@ -1,3 +1,4 @@
export * from './runtime';
export * from './servers';
export * from './apis';
export * from './models';

View File

@ -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

View File

@ -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];

View File

@ -14,4 +14,5 @@ models/User.ts
models/index.ts
package.json
runtime.ts
servers.ts
tsconfig.json

View File

@ -1,3 +1,4 @@
export * from './runtime';
export * from './servers';
export * from './apis';
export * from './models';

View File

@ -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

View File

@ -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];

View File

@ -14,4 +14,5 @@ models/User.ts
models/index.ts
package.json
runtime.ts
servers.ts
tsconfig.json

View File

@ -1,3 +1,4 @@
export * from './runtime';
export * from './servers';
export * from './apis';
export * from './models';

View File

@ -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

View File

@ -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];

View File

@ -12,4 +12,5 @@ models/Tag.ts
models/User.ts
models/index.ts
runtime.ts
servers.ts
tsconfig.json

View File

@ -1,3 +1,4 @@
export * from './runtime';
export * from './servers';
export * from './apis';
export * from './models';

View File

@ -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

View File

@ -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];