Skip to content

Commit 0d0d353

Browse files
committed
feat dart: mv basePath to ApiClient
Changing the basePath is pretty annoying otherwise, because you would need to set the basePath for every Api.
1 parent 999ef42 commit 0d0d353

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

modules/swagger-codegen/src/main/resources/dart/api.mustache

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ part of api;
44

55

66
class {{classname}} {
7-
String basePath = "{{basePath}}";
87
final ApiClient apiClient;
98
109
{{classname}}([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient;
@@ -73,8 +72,7 @@ class {{classname}} {
7372
{{/formParams}}
7473
}
7574

76-
var response = await apiClient.invokeAPI(basePath,
77-
path,
75+
var response = await apiClient.invokeAPI(path,
7876
'{{httpMethod}}',
7977
queryParams,
8078
postBody,

modules/swagger-codegen/src/main/resources/dart/api_client.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class QueryParam {
99

1010
class ApiClient {
1111
12+
String basePath;
1213
var client = new {{#browserClient}}Browser{{/browserClient}}Client();
1314

1415
Map<String, String> _defaultHeaderMap = {};
@@ -20,7 +21,7 @@ class ApiClient {
2021
final _RegList = new RegExp(r'^List<(.*)>$');
2122
final _RegMap = new RegExp(r'^Map<String,(.*)>$');
2223

23-
ApiClient() {
24+
ApiClient({this.basePath: "{{{basePath}}}"}) {
2425
// Setup authentications (key: authentication name, value: authentication).{{#authMethods}}{{#isBasic}}
2526
_authentications['{{name}}'] = new HttpBasicAuth();{{/isBasic}}{{#isApiKey}}
2627
_authentications['{{name}}'] = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");{{/isApiKey}}{{#isOAuth}}
@@ -113,8 +114,7 @@ class ApiClient {
113114

114115
// We don't use a Map<String, String> for queryParams.
115116
// If collectionFormat is 'multi' a key might appear multiple times.
116-
Future<Response> invokeAPI(String host,
117-
String path,
117+
Future<Response> invokeAPI(String path,
118118
String method,
119119
List<QueryParam> queryParams,
120120
Object body,
@@ -130,7 +130,7 @@ class ApiClient {
130130
'?' + ps.join('&') :
131131
'';
132132
133-
String url = host + path + queryString;
133+
String url = basePath + path + queryString;
134134
135135
headerParams.addAll(_defaultHeaderMap);
136136
headerParams['Content-Type'] = contentType;

0 commit comments

Comments
 (0)