Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[typescript-rxjs] Added support for servers #7771

Merged
merged 2 commits into from
Oct 22, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './runtime';
export * from './servers';
export * from './apis';
export * from './models';
Original file line number Diff line number Diff line change
Expand Up @@ -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();
macjohnny marked this conversation as resolved.
Show resolved Hide resolved

export interface ConfigurationParameters {
basePath?: string; // override base path
Expand Down
Original file line number Diff line number Diff line change
@@ -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}}];
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ models/Tag.ts
models/User.ts
models/index.ts
runtime.ts
servers.ts
tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './runtime';
export * from './servers';
export * from './apis';
export * from './models';
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions samples/client/petstore/typescript-rxjs/builds/default/servers.ts
Original file line number Diff line number Diff line change
@@ -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];
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ models/User.ts
models/index.ts
package.json
runtime.ts
servers.ts
tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './runtime';
export * from './servers';
export * from './apis';
export * from './models';
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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];
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ models/User.ts
models/index.ts
package.json
runtime.ts
servers.ts
tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './runtime';
export * from './servers';
export * from './apis';
export * from './models';
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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];
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ models/Tag.ts
models/User.ts
models/index.ts
runtime.ts
servers.ts
tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './runtime';
export * from './servers';
export * from './apis';
export * from './models';
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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];