Skip to content

Commit 54c8990

Browse files
author
David
committed
[typescript-fetch] global configuration
1 parent 77f174d commit 54c8990

File tree

19 files changed

+111
-159
lines changed

19 files changed

+111
-159
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptFetchClientCodegen.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public void processOpts() {
5151
supportingFiles.add(new SupportingFile("index.mustache", "", "index.ts"));
5252
supportingFiles.add(new SupportingFile("api.mustache", "", "api.ts"));
5353
supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.ts"));
54-
supportingFiles.add(new SupportingFile("globalConfiguration.mustache", "", "globalConfiguration.ts"));
5554
supportingFiles.add(new SupportingFile("custom.d.mustache", "", "custom.d.ts"));
5655
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
5756
supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore"));

modules/swagger-codegen/src/main/resources/typescript-fetch/api.mustache

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import * as url from "url";
66
import * as portableFetch from "portable-fetch";
77
import { Configuration } from "./configuration";
8-
import { GlobalConfiguration } from "./globalConfiguration";
98

109
/**
1110
*
@@ -45,10 +44,10 @@ export interface FetchArgs {
4544
export class BaseAPI {
4645
protected configuration: Configuration;
4746
48-
constructor(configuration?: Configuration, protected basePath: string = GlobalConfiguration.basePath, protected fetch: FetchAPI = portableFetch) {
47+
constructor(configuration: Configuration = Configuration.DEFAULT_INSTANCE, protected basePath: string = Configuration.DEFAULT_INSTANCE.basePath, protected fetch: FetchAPI = portableFetch) {
4948
if (configuration) {
5049
this.configuration = configuration;
51-
this.basePath = configuration.basePath || this.basePath;
50+
this.basePath = configuration.basePath || this.basePath || '';
5251
}
5352
}
5453
};
@@ -261,7 +260,7 @@ export const {{classname}}Fp = function(configuration?: Configuration) {
261260
*/
262261
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): (fetch?: FetchAPI, basePath?: string) => Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Response{{/returnType}}> {
263262
const localVarFetchArgs = {{classname}}FetchParamCreator(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options);
264-
return (fetch: FetchAPI = portableFetch, basePath: string = GlobalConfiguration.basePath) => {
263+
return (fetch: FetchAPI = portableFetch, basePath: string = Configuration.DEFAULT_INSTANCE.basePath) => {
265264
return fetch(basePath + localVarFetchArgs.url, localVarFetchArgs.options).then((response) => {
266265
if (response.status >= 200 && response.status < 300) {
267266
return response{{#returnType}}.json(){{/returnType}};

modules/swagger-codegen/src/main/resources/typescript-fetch/configuration.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export interface ConfigurationParameters {
1010
}
1111

1212
export class Configuration {
13+
/**
14+
* object for default configurations
15+
*/
16+
static DEFAULT_INSTANCE = new Configuration({basePath: "{{{basePath}}}".replace(/\/+$/, "")});
1317
/**
1418
* parameter for apiKey security
1519
* @param name security name

modules/swagger-codegen/src/main/resources/typescript-fetch/globalConfiguration.mustache

Lines changed: 0 additions & 6 deletions
This file was deleted.

modules/swagger-codegen/src/main/resources/typescript-fetch/index.mustache

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33

44
export * from "./api";
55
export * from "./configuration";
6-
export * from "./globalConfiguration";

samples/client/petstore/typescript-fetch/builds/default/api.ts

Lines changed: 22 additions & 23 deletions
Large diffs are not rendered by default.

samples/client/petstore/typescript-fetch/builds/default/configuration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export interface ConfigurationParameters {
2121
}
2222

2323
export class Configuration {
24+
/**
25+
* object for default configurations
26+
*/
27+
static DEFAULT_INSTANCE = new Configuration({basePath: "http://petstore.swagger.io/v2".replace(/\/+$/, "")});
2428
/**
2529
* parameter for apiKey security
2630
* @param name security name

samples/client/petstore/typescript-fetch/builds/default/globalConfiguration.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

samples/client/petstore/typescript-fetch/builds/default/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@
1414

1515
export * from "./api";
1616
export * from "./configuration";
17-
export * from "./globalConfiguration";

samples/client/petstore/typescript-fetch/builds/es6-target/api.ts

Lines changed: 22 additions & 23 deletions
Large diffs are not rendered by default.

samples/client/petstore/typescript-fetch/builds/es6-target/configuration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export interface ConfigurationParameters {
2121
}
2222

2323
export class Configuration {
24+
/**
25+
* object for default configurations
26+
*/
27+
static DEFAULT_INSTANCE = new Configuration({basePath: "http://petstore.swagger.io/v2".replace(/\/+$/, "")});
2428
/**
2529
* parameter for apiKey security
2630
* @param name security name

samples/client/petstore/typescript-fetch/builds/es6-target/globalConfiguration.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

samples/client/petstore/typescript-fetch/builds/es6-target/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@
1414

1515
export * from "./api";
1616
export * from "./configuration";
17-
export * from "./globalConfiguration";

0 commit comments

Comments
 (0)