From 1f7404f6682312409c4d7b6d741ce299bcccf503 Mon Sep 17 00:00:00 2001 From: Pete Kruskall Date: Thu, 3 Sep 2020 23:50:58 -0400 Subject: [PATCH 1/2] Adds cookie auth support to dart2 templates --- .../src/main/resources/dart2/api_client.mustache | 2 +- .../src/main/resources/dart2/auth/api_key_auth.mustache | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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 d307654943b3..a933252c0de6 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api_client.mustache @@ -31,7 +31,7 @@ class ApiClient { {{/isBasicBearer}} {{/isBasic}} {{#isApiKey}} - _authentications['{{name}}'] = ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"); + _authentications['{{name}}'] = ApiKeyAuth({{#isKeyInCookie}}"cookie"{{/isKeyInCookie}}{{^isKeyInCookie}}{{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}{{/isKeyInCookie}}, "{{keyParamName}}"); {{/isApiKey}} {{#isOAuth}} _authentications['{{name}}'] = OAuth(); diff --git a/modules/openapi-generator/src/main/resources/dart2/auth/api_key_auth.mustache b/modules/openapi-generator/src/main/resources/dart2/auth/api_key_auth.mustache index c5e53204dc01..e429cd61dda2 100644 --- a/modules/openapi-generator/src/main/resources/dart2/auth/api_key_auth.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/auth/api_key_auth.mustache @@ -24,6 +24,10 @@ class ApiKeyAuth implements Authentication { queryParams.add(QueryParam(paramName, value)); } else if (location == 'header' && value != null) { headerParams[paramName] = value; + } else if (location == 'cookie' && value != null) { + headerParams.update('Cookie', (String existingCookie) { + return "$existingCookie; $paramName=$value"; + }, ifAbsent: () => '$paramName=$value'); } } } From c66926f5552ce39e93260941b39aebd3ca55816c Mon Sep 17 00:00:00 2001 From: Pete Kruskall Date: Fri, 4 Sep 2020 00:45:04 -0400 Subject: [PATCH 2/2] Updating pet store sample templates --- .../dart2/petstore_client_lib/lib/auth/api_key_auth.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/auth/api_key_auth.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/auth/api_key_auth.dart index 8384f0516ce2..78ffb2e0a216 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/auth/api_key_auth.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/auth/api_key_auth.dart @@ -24,6 +24,10 @@ class ApiKeyAuth implements Authentication { queryParams.add(QueryParam(paramName, value)); } else if (location == 'header' && value != null) { headerParams[paramName] = value; + } else if (location == 'cookie' && value != null) { + headerParams.update('Cookie', (String existingCookie) { + return "$existingCookie; $paramName=$value"; + }, ifAbsent: () => '$paramName=$value'); } } }