--http-user-agent arg support in dart generator (#8508)

* add User-Agent header

* set User-Agent header only if httpUserAgent is defined

* add User-Agent header in dart-dio generator

* update samples
This commit is contained in:
SBNTT 2021-01-23 03:39:21 +01:00 committed by GitHub
parent eecd30c2da
commit 96da7aaf9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 82 additions and 80 deletions

View File

@ -33,7 +33,8 @@ class {{classname}} {
final String _path = '{{{path}}}'{{#pathParams}}.replaceAll('{' r'{{baseName}}' '}', {{{paramName}}}.toString()){{/pathParams}};
final queryParams = <String, dynamic>{};
final headerParams = <String, dynamic>{
final headerParams = <String, dynamic>{ {{#httpUserAgent}}
'User-Agent': '{{{.}}}',{{/httpUserAgent}}
if (headers != null) ...headers,
};
dynamic bodyData;

View File

@ -23,6 +23,7 @@ class ApiClient {
_authentications['{{name}}'] = new HttpBasicAuth();{{/isBasic}}{{#isApiKey}}
_authentications['{{name}}'] = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");{{/isApiKey}}{{#isOAuth}}
_authentications['{{name}}'] = new OAuth();{{/isOAuth}}{{/authMethods}}
{{#httpUserAgent}}addDefaultHeader('User-Agent', '{{{.}}}');{{/httpUserAgent}}
}
void addDefaultHeader(String key, String value) {