Skip to content

Commit 13042b7

Browse files
authored
[java] Add setBearerToken method in okhttp-gson (#8200)
* Add setBearerToken method in okhttp-gson * Update generated files
1 parent 49f55b0 commit 13042b7

File tree

5 files changed

+19
-0
lines changed
  • modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson
  • samples/client/petstore/java

5 files changed

+19
-0
lines changed

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,22 @@ public class ApiClient {
413413
return authentications.get(authName);
414414
}
415415

416+
{{#hasHttpBearerMethods}}
417+
/**
418+
* Helper method to set access token for the first Bearer authentication.
419+
* @param bearerToken Bearer token
420+
*/
421+
public void setBearerToken(String bearerToken) {
422+
for (Authentication auth : authentications.values()) {
423+
if (auth instanceof HttpBearerAuth) {
424+
((HttpBearerAuth) auth).setBearerToken(bearerToken);
425+
return;
426+
}
427+
}
428+
throw new RuntimeException("No Bearer authentication configured!");
429+
}
430+
{{/hasHttpBearerMethods}}
431+
416432
/**
417433
* Helper method to set username for the first HTTP basic authentication.
418434
*

samples/client/petstore/java/okhttp-gson-dynamicOperations/gradlew

100644100755
File mode changed.

samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ public Authentication getAuthentication(String authName) {
376376
return authentications.get(authName);
377377
}
378378

379+
379380
/**
380381
* Helper method to set username for the first HTTP basic authentication.
381382
*

samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ public Authentication getAuthentication(String authName) {
365365
return authentications.get(authName);
366366
}
367367

368+
368369
/**
369370
* Helper method to set username for the first HTTP basic authentication.
370371
*

samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ public Authentication getAuthentication(String authName) {
365365
return authentications.get(authName);
366366
}
367367

368+
368369
/**
369370
* Helper method to set username for the first HTTP basic authentication.
370371
*

0 commit comments

Comments
 (0)