Added servers

This commit is contained in:
Tino Fuhrmann 2018-08-13 21:18:51 +02:00
parent 1cc6fb0421
commit 276d7d47e5
3 changed files with 24 additions and 6 deletions

View File

@ -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");

View File

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

View File

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