diff --git a/modules/openapi-generator/src/main/resources/dart2/api.mustache b/modules/openapi-generator/src/main/resources/dart2/api.mustache index 2ce04e81f0eb..e40ebac39408 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api.mustache @@ -86,7 +86,6 @@ class {{{classname}}} { {{/headerParams}} {{/hasHeaderParams}} - const authNames = [{{#authMethods}}'{{{name}}}'{{^-last}}, {{/-last}}{{/authMethods}}]; const contentTypes = [{{#prioritizedContentTypes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/prioritizedContentTypes}}]; {{#isMultipart}} @@ -129,7 +128,6 @@ class {{{classname}}} { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } diff --git a/modules/openapi-generator/src/main/resources/dart2/api_client.mustache b/modules/openapi-generator/src/main/resources/dart2/api_client.mustache index 92846fc4b910..8eae959e3e5d 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api_client.mustache @@ -1,27 +1,7 @@ {{>header}} {{>part_of}} class ApiClient { - ApiClient({this.basePath = '{{{basePath}}}'}) { - {{#hasAuthMethods}} - // Setup authentications (key: authentication name, value: authentication). - {{#authMethods}} - {{#isBasic}} - {{#isBasicBasic}} - _authentications[r'{{{name}}}'] = HttpBasicAuth(); - {{/isBasicBasic}} - {{#isBasicBearer}} - _authentications[r'{{{name}}}'] = HttpBearerAuth(); - {{/isBasicBearer}} - {{/isBasic}} - {{#isApiKey}} - _authentications[r'{{{name}}}'] = ApiKeyAuth({{#isKeyInCookie}}'cookie'{{/isKeyInCookie}}{{^isKeyInCookie}}{{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{^isKeyInHeader}}'query'{{/isKeyInHeader}}{{/isKeyInCookie}}, '{{{keyParamName}}}'); - {{/isApiKey}} - {{#isOAuth}} - _authentications[r'{{{name}}}'] = OAuth(); - {{/isOAuth}} - {{/authMethods}} - {{/hasAuthMethods}} - } + ApiClient({this.basePath = '{{{basePath}}}', this.authentication}); final String basePath; @@ -38,7 +18,7 @@ class ApiClient { } final _defaultHeaderMap = {}; - final _authentications = {}; + final Authentication? authentication; void addDefaultHeader(String key, String value) { _defaultHeaderMap[key] = value; @@ -46,15 +26,6 @@ class ApiClient { Map get defaultHeaderMap => _defaultHeaderMap; - /// Returns an unmodifiable [Map] of the authentications, since none should be added - /// or deleted. - Map get authentications => Map.unmodifiable(_authentications); - - T? getAuthentication(String name) { - final authentication = _authentications[name]; - return authentication is T ? authentication : null; - } - // We don't use a Map for queryParams. // If collectionFormat is 'multi', a key might appear multiple times. Future invokeAPI( @@ -65,9 +36,8 @@ class ApiClient { Map headerParams, Map formParams, String? contentType, - List authNames, ) async { - _updateParamsForAuth(authNames, queryParams, headerParams); + _updateParamsForAuth(queryParams, headerParams); headerParams.addAll(_defaultHeaderMap); if (contentType != null) { @@ -188,18 +158,12 @@ class ApiClient { String serialize(Object? value) => value == null ? '' : json.encode(value); /// Update query and header parameters based on authentication settings. - /// @param authNames The authentications to apply void _updateParamsForAuth( - List authNames, List queryParams, Map headerParams, ) { - for(final authName in authNames) { - final auth = _authentications[authName]; - if (auth == null) { - throw ArgumentError('Authentication undefined: $authName'); - } - auth.applyToParams(queryParams, headerParams); + if (authentication != null) { + authentication!.applyToParams(queryParams, headerParams); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart index 22858e953afa..d0354de38dbb 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart @@ -37,7 +37,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - const authNames = ['petstore_auth']; const contentTypes = ['application/json', 'application/xml']; @@ -49,7 +48,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -104,7 +102,6 @@ class PetApi { headerParams[r'api_key'] = parameterToString(apiKey); } - const authNames = ['petstore_auth']; const contentTypes = []; @@ -116,7 +113,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -160,7 +156,6 @@ class PetApi { queryParams.addAll(_queryParams('csv', 'status', status)); - const authNames = ['petstore_auth']; const contentTypes = []; @@ -172,7 +167,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -225,7 +219,6 @@ class PetApi { queryParams.addAll(_queryParams('csv', 'tags', tags)); - const authNames = ['petstore_auth']; const contentTypes = []; @@ -237,7 +230,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -289,7 +281,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - const authNames = ['api_key']; const contentTypes = []; @@ -301,7 +292,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -349,7 +339,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - const authNames = ['petstore_auth']; const contentTypes = ['application/json', 'application/xml']; @@ -361,7 +350,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -416,7 +404,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - const authNames = ['petstore_auth']; const contentTypes = ['application/x-www-form-urlencoded']; if (name != null) { @@ -434,7 +421,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -487,7 +473,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - const authNames = ['petstore_auth']; const contentTypes = ['multipart/form-data']; bool hasFields = false; @@ -513,7 +498,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart index 51b4b81fb0f5..db1ac1f010bf 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart @@ -38,7 +38,6 @@ class StoreApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = []; @@ -50,7 +49,6 @@ class StoreApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -85,7 +83,6 @@ class StoreApi { final headerParams = {}; final formParams = {}; - const authNames = ['api_key']; const contentTypes = []; @@ -97,7 +94,6 @@ class StoreApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -141,7 +137,6 @@ class StoreApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = []; @@ -153,7 +148,6 @@ class StoreApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -201,7 +195,6 @@ class StoreApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -213,7 +206,6 @@ class StoreApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart index 46eef79d505a..a44252a6130b 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart @@ -37,7 +37,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - const authNames = ['api_key']; const contentTypes = ['application/json']; @@ -49,7 +48,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -89,7 +87,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - const authNames = ['api_key']; const contentTypes = ['application/json']; @@ -101,7 +98,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -141,7 +137,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - const authNames = ['api_key']; const contentTypes = ['application/json']; @@ -153,7 +148,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -194,7 +188,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - const authNames = ['api_key']; const contentTypes = []; @@ -206,7 +199,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -247,7 +239,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = []; @@ -259,7 +250,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -313,7 +303,6 @@ class UserApi { queryParams.addAll(_queryParams('', 'username', username)); queryParams.addAll(_queryParams('', 'password', password)); - const authNames = []; const contentTypes = []; @@ -325,7 +314,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -371,7 +359,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - const authNames = ['api_key']; const contentTypes = []; @@ -383,7 +370,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -422,7 +408,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - const authNames = ['api_key']; const contentTypes = ['application/json']; @@ -434,7 +419,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api_client.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api_client.dart index 3efae0775a54..79977d854b68 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api_client.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api_client.dart @@ -11,11 +11,7 @@ part of openapi.api; class ApiClient { - ApiClient({this.basePath = 'http://petstore.swagger.io/v2'}) { - // Setup authentications (key: authentication name, value: authentication). - _authentications[r'api_key'] = ApiKeyAuth('header', 'api_key'); - _authentications[r'petstore_auth'] = OAuth(); - } + ApiClient({this.basePath = 'http://petstore.swagger.io/v2', this.authentication}); final String basePath; @@ -32,7 +28,7 @@ class ApiClient { } final _defaultHeaderMap = {}; - final _authentications = {}; + final Authentication? authentication; void addDefaultHeader(String key, String value) { _defaultHeaderMap[key] = value; @@ -40,15 +36,6 @@ class ApiClient { Map get defaultHeaderMap => _defaultHeaderMap; - /// Returns an unmodifiable [Map] of the authentications, since none should be added - /// or deleted. - Map get authentications => Map.unmodifiable(_authentications); - - T? getAuthentication(String name) { - final authentication = _authentications[name]; - return authentication is T ? authentication : null; - } - // We don't use a Map for queryParams. // If collectionFormat is 'multi', a key might appear multiple times. Future invokeAPI( @@ -59,9 +46,8 @@ class ApiClient { Map headerParams, Map formParams, String? contentType, - List authNames, ) async { - _updateParamsForAuth(authNames, queryParams, headerParams); + _updateParamsForAuth(queryParams, headerParams); headerParams.addAll(_defaultHeaderMap); if (contentType != null) { @@ -180,18 +166,12 @@ class ApiClient { String serialize(Object? value) => value == null ? '' : json.encode(value); /// Update query and header parameters based on authentication settings. - /// @param authNames The authentications to apply void _updateParamsForAuth( - List authNames, List queryParams, Map headerParams, ) { - for(final authName in authNames) { - final auth = _authentications[authName]; - if (auth == null) { - throw ArgumentError('Authentication undefined: $authName'); - } - auth.applyToParams(queryParams, headerParams); + if (authentication != null) { + authentication!.applyToParams(queryParams, headerParams); } } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/another_fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/another_fake_api.dart index f03350c4dfff..689eafbd8ed7 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/another_fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/another_fake_api.dart @@ -37,7 +37,6 @@ class AnotherFakeApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -49,7 +48,6 @@ class AnotherFakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/default_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/default_api.dart index 02c22bfa2d9f..23798028b943 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/default_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/default_api.dart @@ -28,7 +28,6 @@ class DefaultApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = []; @@ -40,7 +39,6 @@ class DefaultApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart index d4bd12ec939b..6cfbfb4e6c93 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart @@ -30,7 +30,6 @@ class FakeApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = []; @@ -42,7 +41,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -95,7 +93,6 @@ class FakeApi { headerParams[r'header_1'] = parameterToString(header1); } - const authNames = ['http_signature_test']; const contentTypes = ['application/json', 'application/xml']; @@ -107,7 +104,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -149,7 +145,6 @@ class FakeApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -161,7 +156,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -205,7 +199,6 @@ class FakeApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -217,7 +210,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -261,7 +253,6 @@ class FakeApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -273,7 +264,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -317,7 +307,6 @@ class FakeApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -329,7 +318,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -373,7 +361,6 @@ class FakeApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -385,7 +372,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -429,7 +415,6 @@ class FakeApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['image/png']; @@ -441,7 +426,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -476,7 +460,6 @@ class FakeApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -488,7 +471,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -523,7 +505,6 @@ class FakeApi { queryParams.addAll(_queryParams('', 'query', query)); - const authNames = []; const contentTypes = ['application/json']; @@ -535,7 +516,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -572,7 +552,6 @@ class FakeApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -584,7 +563,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -671,7 +649,6 @@ class FakeApi { final headerParams = {}; final formParams = {}; - const authNames = ['http_basic_test']; const contentTypes = ['application/x-www-form-urlencoded']; if (integer != null) { @@ -722,7 +699,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -847,7 +823,6 @@ class FakeApi { headerParams[r'enum_header_string'] = parameterToString(enumHeaderString); } - const authNames = []; const contentTypes = ['application/x-www-form-urlencoded']; if (enumFormStringArray != null) { @@ -865,7 +840,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -957,7 +931,6 @@ class FakeApi { headerParams[r'boolean_group'] = parameterToString(booleanGroup); } - const authNames = ['bearer_test']; const contentTypes = []; @@ -969,7 +942,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -1024,7 +996,6 @@ class FakeApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -1036,7 +1007,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -1079,7 +1049,6 @@ class FakeApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/x-www-form-urlencoded']; if (param != null) { @@ -1097,7 +1066,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -1159,7 +1127,6 @@ class FakeApi { } queryParams.addAll(_queryParams('', 'allowEmpty', allowEmpty)); - const authNames = []; const contentTypes = []; @@ -1171,7 +1138,6 @@ class FakeApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_classname_tags123_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_classname_tags123_api.dart index 158c127195bf..2782357efb9b 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_classname_tags123_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_classname_tags123_api.dart @@ -37,7 +37,6 @@ class FakeClassnameTags123Api { final headerParams = {}; final formParams = {}; - const authNames = ['api_key_query']; const contentTypes = ['application/json']; @@ -49,7 +48,6 @@ class FakeClassnameTags123Api { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart index 74d8ab2b059d..371afa625cfc 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/pet_api.dart @@ -37,7 +37,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - const authNames = ['petstore_auth']; const contentTypes = ['application/json', 'application/xml']; @@ -49,7 +48,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -96,7 +94,6 @@ class PetApi { headerParams[r'api_key'] = parameterToString(apiKey); } - const authNames = ['petstore_auth']; const contentTypes = []; @@ -108,7 +105,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -152,7 +148,6 @@ class PetApi { queryParams.addAll(_queryParams('csv', 'status', status)); - const authNames = ['petstore_auth']; const contentTypes = []; @@ -164,7 +159,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -217,7 +211,6 @@ class PetApi { queryParams.addAll(_queryParams('csv', 'tags', tags)); - const authNames = ['petstore_auth']; const contentTypes = []; @@ -229,7 +222,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -281,7 +273,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - const authNames = ['api_key']; const contentTypes = []; @@ -293,7 +284,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -341,7 +331,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - const authNames = ['petstore_auth']; const contentTypes = ['application/json', 'application/xml']; @@ -353,7 +342,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -400,7 +388,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - const authNames = ['petstore_auth']; const contentTypes = ['application/x-www-form-urlencoded']; if (name != null) { @@ -418,7 +405,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -471,7 +457,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - const authNames = ['petstore_auth']; const contentTypes = ['multipart/form-data']; bool hasFields = false; @@ -497,7 +482,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -558,7 +542,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - const authNames = ['petstore_auth']; const contentTypes = ['multipart/form-data']; bool hasFields = false; @@ -584,7 +567,6 @@ class PetApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/store_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/store_api.dart index ee1756bea39b..68c1c9fdccb9 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/store_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/store_api.dart @@ -38,7 +38,6 @@ class StoreApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = []; @@ -50,7 +49,6 @@ class StoreApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -85,7 +83,6 @@ class StoreApi { final headerParams = {}; final formParams = {}; - const authNames = ['api_key']; const contentTypes = []; @@ -97,7 +94,6 @@ class StoreApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -141,7 +137,6 @@ class StoreApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = []; @@ -153,7 +148,6 @@ class StoreApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -201,7 +195,6 @@ class StoreApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -213,7 +206,6 @@ class StoreApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart index dec46b87bd84..a44252a6130b 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/user_api.dart @@ -37,7 +37,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -49,7 +48,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -89,7 +87,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -101,7 +98,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -141,7 +137,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -153,7 +148,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -194,7 +188,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = []; @@ -206,7 +199,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -247,7 +239,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = []; @@ -259,7 +250,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -313,7 +303,6 @@ class UserApi { queryParams.addAll(_queryParams('', 'username', username)); queryParams.addAll(_queryParams('', 'password', password)); - const authNames = []; const contentTypes = []; @@ -325,7 +314,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -371,7 +359,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = []; @@ -383,7 +370,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } @@ -422,7 +408,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - const authNames = []; const contentTypes = ['application/json']; @@ -434,7 +419,6 @@ class UserApi { headerParams, formParams, contentTypes.isEmpty ? null : contentTypes.first, - authNames, ); } diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart index 508d1b2beac9..ba7a9e692b7a 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart @@ -11,14 +11,7 @@ part of openapi.api; class ApiClient { - ApiClient({this.basePath = 'http://petstore.swagger.io:80/v2'}) { - // Setup authentications (key: authentication name, value: authentication). - _authentications[r'api_key'] = ApiKeyAuth('header', 'api_key'); - _authentications[r'api_key_query'] = ApiKeyAuth('query', 'api_key_query'); - _authentications[r'bearer_test'] = HttpBearerAuth(); - _authentications[r'http_basic_test'] = HttpBasicAuth(); - _authentications[r'petstore_auth'] = OAuth(); - } + ApiClient({this.basePath = 'http://petstore.swagger.io:80/v2', this.authentication}); final String basePath; @@ -35,7 +28,7 @@ class ApiClient { } final _defaultHeaderMap = {}; - final _authentications = {}; + final Authentication? authentication; void addDefaultHeader(String key, String value) { _defaultHeaderMap[key] = value; @@ -43,15 +36,6 @@ class ApiClient { Map get defaultHeaderMap => _defaultHeaderMap; - /// Returns an unmodifiable [Map] of the authentications, since none should be added - /// or deleted. - Map get authentications => Map.unmodifiable(_authentications); - - T? getAuthentication(String name) { - final authentication = _authentications[name]; - return authentication is T ? authentication : null; - } - // We don't use a Map for queryParams. // If collectionFormat is 'multi', a key might appear multiple times. Future invokeAPI( @@ -62,9 +46,8 @@ class ApiClient { Map headerParams, Map formParams, String? contentType, - List authNames, ) async { - _updateParamsForAuth(authNames, queryParams, headerParams); + _updateParamsForAuth(queryParams, headerParams); headerParams.addAll(_defaultHeaderMap); if (contentType != null) { @@ -183,18 +166,12 @@ class ApiClient { String serialize(Object? value) => value == null ? '' : json.encode(value); /// Update query and header parameters based on authentication settings. - /// @param authNames The authentications to apply void _updateParamsForAuth( - List authNames, List queryParams, Map headerParams, ) { - for(final authName in authNames) { - final auth = _authentications[authName]; - if (auth == null) { - throw ArgumentError('Authentication undefined: $authName'); - } - auth.applyToParams(queryParams, headerParams); + if (authentication != null) { + authentication!.applyToParams(queryParams, headerParams); } }