forked from loafle/openapi-generator-original
feat dart: mv basePath to ApiClient
Changing the basePath is pretty annoying otherwise, because you would need to set the basePath for every Api.
This commit is contained in:
parent
999ef42e81
commit
0d0d353b9d
@ -4,7 +4,6 @@ part of api;
|
|||||||
|
|
||||||
|
|
||||||
class {{classname}} {
|
class {{classname}} {
|
||||||
String basePath = "{{basePath}}";
|
|
||||||
final ApiClient apiClient;
|
final ApiClient apiClient;
|
||||||
|
|
||||||
{{classname}}([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient;
|
{{classname}}([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient;
|
||||||
@ -73,8 +72,7 @@ class {{classname}} {
|
|||||||
{{/formParams}}
|
{{/formParams}}
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = await apiClient.invokeAPI(basePath,
|
var response = await apiClient.invokeAPI(path,
|
||||||
path,
|
|
||||||
'{{httpMethod}}',
|
'{{httpMethod}}',
|
||||||
queryParams,
|
queryParams,
|
||||||
postBody,
|
postBody,
|
||||||
|
@ -9,6 +9,7 @@ class QueryParam {
|
|||||||
|
|
||||||
class ApiClient {
|
class ApiClient {
|
||||||
|
|
||||||
|
String basePath;
|
||||||
var client = new {{#browserClient}}Browser{{/browserClient}}Client();
|
var client = new {{#browserClient}}Browser{{/browserClient}}Client();
|
||||||
|
|
||||||
Map<String, String> _defaultHeaderMap = {};
|
Map<String, String> _defaultHeaderMap = {};
|
||||||
@ -20,7 +21,7 @@ class ApiClient {
|
|||||||
final _RegList = new RegExp(r'^List<(.*)>$');
|
final _RegList = new RegExp(r'^List<(.*)>$');
|
||||||
final _RegMap = new RegExp(r'^Map<String,(.*)>$');
|
final _RegMap = new RegExp(r'^Map<String,(.*)>$');
|
||||||
|
|
||||||
ApiClient() {
|
ApiClient({this.basePath: "{{{basePath}}}"}) {
|
||||||
// Setup authentications (key: authentication name, value: authentication).{{#authMethods}}{{#isBasic}}
|
// Setup authentications (key: authentication name, value: authentication).{{#authMethods}}{{#isBasic}}
|
||||||
_authentications['{{name}}'] = new HttpBasicAuth();{{/isBasic}}{{#isApiKey}}
|
_authentications['{{name}}'] = new HttpBasicAuth();{{/isBasic}}{{#isApiKey}}
|
||||||
_authentications['{{name}}'] = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");{{/isApiKey}}{{#isOAuth}}
|
_authentications['{{name}}'] = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");{{/isApiKey}}{{#isOAuth}}
|
||||||
@ -113,8 +114,7 @@ class ApiClient {
|
|||||||
|
|
||||||
// We don't use a Map<String, String> for queryParams.
|
// We don't use a Map<String, String> for queryParams.
|
||||||
// If collectionFormat is 'multi' a key might appear multiple times.
|
// If collectionFormat is 'multi' a key might appear multiple times.
|
||||||
Future<Response> invokeAPI(String host,
|
Future<Response> invokeAPI(String path,
|
||||||
String path,
|
|
||||||
String method,
|
String method,
|
||||||
List<QueryParam> queryParams,
|
List<QueryParam> queryParams,
|
||||||
Object body,
|
Object body,
|
||||||
@ -130,7 +130,7 @@ class ApiClient {
|
|||||||
'?' + ps.join('&') :
|
'?' + ps.join('&') :
|
||||||
'';
|
'';
|
||||||
|
|
||||||
String url = host + path + queryString;
|
String url = basePath + path + queryString;
|
||||||
|
|
||||||
headerParams.addAll(_defaultHeaderMap);
|
headerParams.addAll(_defaultHeaderMap);
|
||||||
headerParams['Content-Type'] = contentType;
|
headerParams['Content-Type'] = contentType;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user