Skip to content

Commit 77f174d

Browse files
David JöchDavid Joech
authored andcommitted
[typescript-fetch] added global configuration
1 parent dba3b64 commit 77f174d

File tree

13 files changed

+132
-84
lines changed

13 files changed

+132
-84
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
import io.swagger.codegen.CliOption;
44
import io.swagger.codegen.CodegenModel;
5-
import io.swagger.codegen.CodegenProperty;
65
import io.swagger.codegen.SupportingFile;
76
import io.swagger.models.ModelImpl;
87
import io.swagger.models.properties.*;
98

10-
import java.io.File;
119
import java.text.SimpleDateFormat;
12-
import java.util.*;
10+
import java.util.Date;
1311

1412
public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodegen {
1513
private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");
@@ -53,6 +51,7 @@ public void processOpts() {
5351
supportingFiles.add(new SupportingFile("index.mustache", "", "index.ts"));
5452
supportingFiles.add(new SupportingFile("api.mustache", "", "api.ts"));
5553
supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.ts"));
54+
supportingFiles.add(new SupportingFile("globalConfiguration.mustache", "", "globalConfiguration.ts"));
5655
supportingFiles.add(new SupportingFile("custom.d.mustache", "", "custom.d.ts"));
5756
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
5857
supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore"));

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import * as url from "url";
66
import * as portableFetch from "portable-fetch";
77
import { Configuration } from "./configuration";
8-
9-
let BASE_PATH = "{{{basePath}}}".replace(/\/+$/, "");
8+
import { GlobalConfiguration } from "./globalConfiguration";
109

1110
/**
1211
*
@@ -19,10 +18,6 @@ export const COLLECTION_FORMATS = {
1918
pipes: "|",
2019
};
2120

22-
export function setBasePath(basePath: string): void {
23-
BASE_PATH = basePath;
24-
}
25-
2621
/**
2722
*
2823
* @export
@@ -50,7 +45,7 @@ export interface FetchArgs {
5045
export class BaseAPI {
5146
protected configuration: Configuration;
5247
53-
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected fetch: FetchAPI = portableFetch) {
48+
constructor(configuration?: Configuration, protected basePath: string = GlobalConfiguration.basePath, protected fetch: FetchAPI = portableFetch) {
5449
if (configuration) {
5550
this.configuration = configuration;
5651
this.basePath = configuration.basePath || this.basePath;
@@ -266,7 +261,7 @@ export const {{classname}}Fp = function(configuration?: Configuration) {
266261
*/
267262
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): (fetch?: FetchAPI, basePath?: string) => Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Response{{/returnType}}> {
268263
const localVarFetchArgs = {{classname}}FetchParamCreator(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options);
269-
return (fetch: FetchAPI = portableFetch, basePath: string = BASE_PATH) => {
264+
return (fetch: FetchAPI = portableFetch, basePath: string = GlobalConfiguration.basePath) => {
270265
return fetch(basePath + localVarFetchArgs.url, localVarFetchArgs.options).then((response) => {
271266
if (response.status >= 200 && response.status < 300) {
272267
return response{{#returnType}}.json(){{/returnType}};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// tslint:disable
2+
{{>licenseInfo}}
3+
4+
export class GlobalConfiguration {
5+
static basePath: string = "{{{basePath}}}".replace(/\/+$/, "");
6+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
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 & 27 deletions
Large diffs are not rendered by default.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// tslint:disable
2+
/**
3+
* Swagger Petstore
4+
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
5+
*
6+
* OpenAPI spec version: 1.0.0
7+
* Contact: [email protected]
8+
*
9+
* NOTE: This class is auto generated by the swagger code generator program.
10+
* https://github.com/swagger-api/swagger-codegen.git
11+
* Do not edit the class manually.
12+
*/
13+
14+
15+
export class GlobalConfiguration {
16+
static basePath: string = "http://petstore.swagger.io/v2".replace(/\/+$/, "");
17+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
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.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// tslint:disable
2+
/**
3+
* Swagger Petstore
4+
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
5+
*
6+
* OpenAPI spec version: 1.0.0
7+
* Contact: [email protected]
8+
*
9+
* NOTE: This class is auto generated by the swagger code generator program.
10+
* https://github.com/swagger-api/swagger-codegen.git
11+
* Do not edit the class manually.
12+
*/
13+
14+
15+
export class GlobalConfiguration {
16+
static basePath: string = "http://petstore.swagger.io/v2".replace(/\/+$/, "");
17+
}

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

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

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

0 commit comments

Comments
 (0)