Skip to content

Commit 82835db

Browse files
authored
fix issue with api key (query) in c# (#6199)
1 parent e4e9a98 commit 82835db

File tree

20 files changed

+79
-15
lines changed

20 files changed

+79
-15
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ namespace {{packageName}}.{{apiPackage}}
262262
{{#isKeyInQuery}}
263263
if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("{{keyParamName}}")))
264264
{
265-
localVarQueryParams["{{keyParamName}}"] = Configuration.GetApiKeyWithPrefix("{{keyParamName}}");
265+
localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "{{keyParamName}}", Configuration.GetApiKeyWithPrefix("{{keyParamName}}")));
266266
}
267267
{{/isKeyInQuery}}
268268
{{/isApiKey}}
@@ -278,7 +278,8 @@ namespace {{packageName}}.{{apiPackage}}
278278
if (!String.IsNullOrEmpty(Configuration.AccessToken))
279279
{
280280
localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken;
281-
}{{/isOAuth}}
281+
}
282+
{{/isOAuth}}
282283
{{/authMethods}}
283284

284285
// make the HTTP request
@@ -397,7 +398,7 @@ namespace {{packageName}}.{{apiPackage}}
397398
{{#isKeyInQuery}}
398399
if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("{{keyParamName}}")))
399400
{
400-
localVarQueryParams["{{keyParamName}}"] = Configuration.GetApiKeyWithPrefix("{{keyParamName}}");
401+
localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "{{keyParamName}}", Configuration.GetApiKeyWithPrefix("{{keyParamName}}")));
401402
}
402403
{{/isKeyInQuery}}
403404
{{/isApiKey}}

modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ paths:
583583
description: successful operation
584584
schema:
585585
$ref: '#/definitions/Client'
586+
security:
587+
- api_key_query: []
586588
/fake:
587589
patch:
588590
tags:
@@ -908,6 +910,10 @@ securityDefinitions:
908910
type: apiKey
909911
name: api_key
910912
in: header
913+
api_key_query:
914+
type: apiKey
915+
name: api_key_query
916+
in: query
911917
http_basic_test:
912918
type: basic
913919
definitions:

samples/client/petstore/csharp/SwaggerClient/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ Class | Method | HTTP request | Description
175175
- **API key parameter name**: api_key
176176
- **Location**: HTTP header
177177

178+
<a name="api_key_query"></a>
179+
### api_key_query
180+
181+
- **Type**: API key
182+
- **API key parameter name**: api_key_query
183+
- **Location**: URL query string
184+
178185
<a name="http_basic_test"></a>
179186
### http_basic_test
180187

samples/client/petstore/csharp/SwaggerClient/docs/Fake_classname_tags123Api.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ namespace Example
2727
{
2828
public void main()
2929
{
30+
// Configure API key authorization: api_key_query
31+
Configuration.Default.AddApiKey("api_key_query", "YOUR_API_KEY");
32+
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
33+
// Configuration.Default.AddApiKeyPrefix("api_key_query", "Bearer");
34+
3035
var apiInstance = new Fake_classname_tags123Api();
3136
var body = new ModelClient(); // ModelClient | client model
3237
@@ -57,7 +62,7 @@ Name | Type | Description | Notes
5762

5863
### Authorization
5964

60-
No authorization required
65+
[api_key_query](../README.md#api_key_query)
6166

6267
### HTTP request headers
6368

samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/FakeApi.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,6 @@ public ApiResponse<Object> TestEndpointParametersWithHttpInfo (decimal? number,
13551355
localVarHeaderParams["Authorization"] = "Basic " + ApiClient.Base64Encode(Configuration.Username + ":" + Configuration.Password);
13561356
}
13571357

1358-
13591358
// make the HTTP request
13601359
IRestResponse localVarResponse = (IRestResponse) Configuration.ApiClient.CallApi(localVarPath,
13611360
Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,

samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/Fake_classname_tags123Api.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ public ApiResponse< ModelClient > TestClassnameWithHttpInfo (ModelClient body)
223223
localVarPostBody = body; // byte array
224224
}
225225

226+
// authentication (api_key_query) required
227+
if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key_query")))
228+
{
229+
localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "api_key_query", Configuration.GetApiKeyWithPrefix("api_key_query")));
230+
}
226231

227232
// make the HTTP request
228233
IRestResponse localVarResponse = (IRestResponse) Configuration.ApiClient.CallApi(localVarPath,
@@ -298,6 +303,11 @@ public async System.Threading.Tasks.Task<ApiResponse<ModelClient>> TestClassname
298303
localVarPostBody = body; // byte array
299304
}
300305

306+
// authentication (api_key_query) required
307+
if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key_query")))
308+
{
309+
localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "api_key_query", Configuration.GetApiKeyWithPrefix("api_key_query")));
310+
}
301311

302312
// make the HTTP request
303313
IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath,

samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/PetApi.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,6 @@ public ApiResponse< Pet > GetPetByIdWithHttpInfo (long? petId)
11441144
localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key");
11451145
}
11461146

1147-
11481147
// make the HTTP request
11491148
IRestResponse localVarResponse = (IRestResponse) Configuration.ApiClient.CallApi(localVarPath,
11501149
Method.GET, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,

samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/Api/StoreApi.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,6 @@ public async System.Threading.Tasks.Task<ApiResponse<Object>> DeleteOrderAsyncWi
470470
localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key");
471471
}
472472

473-
474473
// make the HTTP request
475474
IRestResponse localVarResponse = (IRestResponse) Configuration.ApiClient.CallApi(localVarPath,
476475
Method.GET, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,

samples/client/petstore/csharp/SwaggerClientNetStandard/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ Class | Method | HTTP request | Description
155155
- **API key parameter name**: api_key
156156
- **Location**: HTTP header
157157

158+
<a name="api_key_query"></a>
159+
### api_key_query
160+
161+
- **Type**: API key
162+
- **API key parameter name**: api_key_query
163+
- **Location**: URL query string
164+
158165
<a name="http_basic_test"></a>
159166
### http_basic_test
160167

samples/client/petstore/csharp/SwaggerClientNetStandard/docs/Fake_classname_tags123Api.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ namespace Example
2727
{
2828
public void main()
2929
{
30+
// Configure API key authorization: api_key_query
31+
Configuration.Default.AddApiKey("api_key_query", "YOUR_API_KEY");
32+
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
33+
// Configuration.Default.AddApiKeyPrefix("api_key_query", "Bearer");
34+
3035
var apiInstance = new Fake_classname_tags123Api();
3136
var body = new ModelClient(); // ModelClient | client model
3237
@@ -57,7 +62,7 @@ Name | Type | Description | Notes
5762

5863
### Authorization
5964

60-
No authorization required
65+
[api_key_query](../README.md#api_key_query)
6166

6267
### HTTP request headers
6368

0 commit comments

Comments
 (0)