File tree Expand file tree Collapse file tree
modules/openapi-generator/src/main/resources/Java/libraries/restclient
samples/client/petstore/java
restclient-swagger2/src/main/java/org/openapitools/client
restclient-useSingleRequestParameter-static/src/main/java/org/openapitools/client
restclient-useSingleRequestParameter/src/main/java/org/openapitools/client
restclient/src/main/java/org/openapitools/client Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -388,11 +388,21 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
388388 * Helper method to set access token for the first OAuth2 authentication.
389389 * @param accessToken the access token
390390 */
391- public void setAccessToken(String accessToken) {
391+ public ApiClient setAccessToken(String accessToken) {
392+ return setAccessToken(() -> accessToken);
393+ }
394+
395+ /**
396+ * Helper method to set the supplier of access tokens for OAuth2 authentication.
397+ *
398+ * @param tokenSupplier The supplier of access tokens
399+ * @return ApiClient this client
400+ */
401+ public ApiClient setAccessToken(Supplier<String > tokenSupplier) {
392402 for (Authentication auth : authentications.values()) {
393403 if (auth instanceof OAuth) {
394- ((OAuth) auth).setAccessToken(accessToken );
395- return;
404+ ((OAuth) auth).setAccessToken(tokenSupplier );
405+ return this ;
396406 }
397407 }
398408 throw new RuntimeException("No OAuth2 authentication configured!");
Original file line number Diff line number Diff line change @@ -385,11 +385,21 @@ public void setApiKeyPrefix(String apiKeyPrefix) {
385385 * Helper method to set access token for the first OAuth2 authentication.
386386 * @param accessToken the access token
387387 */
388- public void setAccessToken (String accessToken ) {
388+ public ApiClient setAccessToken (String accessToken ) {
389+ return setAccessToken (() -> accessToken );
390+ }
391+
392+ /**
393+ * Helper method to set the supplier of access tokens for OAuth2 authentication.
394+ *
395+ * @param tokenSupplier The supplier of access tokens
396+ * @return ApiClient this client
397+ */
398+ public ApiClient setAccessToken (Supplier <String > tokenSupplier ) {
389399 for (Authentication auth : authentications .values ()) {
390400 if (auth instanceof OAuth ) {
391- ((OAuth ) auth ).setAccessToken (accessToken );
392- return ;
401+ ((OAuth ) auth ).setAccessToken (tokenSupplier );
402+ return this ;
393403 }
394404 }
395405 throw new RuntimeException ("No OAuth2 authentication configured!" );
Original file line number Diff line number Diff line change @@ -385,11 +385,21 @@ public void setApiKeyPrefix(String apiKeyPrefix) {
385385 * Helper method to set access token for the first OAuth2 authentication.
386386 * @param accessToken the access token
387387 */
388- public void setAccessToken (String accessToken ) {
388+ public ApiClient setAccessToken (String accessToken ) {
389+ return setAccessToken (() -> accessToken );
390+ }
391+
392+ /**
393+ * Helper method to set the supplier of access tokens for OAuth2 authentication.
394+ *
395+ * @param tokenSupplier The supplier of access tokens
396+ * @return ApiClient this client
397+ */
398+ public ApiClient setAccessToken (Supplier <String > tokenSupplier ) {
389399 for (Authentication auth : authentications .values ()) {
390400 if (auth instanceof OAuth ) {
391- ((OAuth ) auth ).setAccessToken (accessToken );
392- return ;
401+ ((OAuth ) auth ).setAccessToken (tokenSupplier );
402+ return this ;
393403 }
394404 }
395405 throw new RuntimeException ("No OAuth2 authentication configured!" );
Original file line number Diff line number Diff line change @@ -385,11 +385,21 @@ public void setApiKeyPrefix(String apiKeyPrefix) {
385385 * Helper method to set access token for the first OAuth2 authentication.
386386 * @param accessToken the access token
387387 */
388- public void setAccessToken (String accessToken ) {
388+ public ApiClient setAccessToken (String accessToken ) {
389+ return setAccessToken (() -> accessToken );
390+ }
391+
392+ /**
393+ * Helper method to set the supplier of access tokens for OAuth2 authentication.
394+ *
395+ * @param tokenSupplier The supplier of access tokens
396+ * @return ApiClient this client
397+ */
398+ public ApiClient setAccessToken (Supplier <String > tokenSupplier ) {
389399 for (Authentication auth : authentications .values ()) {
390400 if (auth instanceof OAuth ) {
391- ((OAuth ) auth ).setAccessToken (accessToken );
392- return ;
401+ ((OAuth ) auth ).setAccessToken (tokenSupplier );
402+ return this ;
393403 }
394404 }
395405 throw new RuntimeException ("No OAuth2 authentication configured!" );
Original file line number Diff line number Diff line change @@ -385,11 +385,21 @@ public void setApiKeyPrefix(String apiKeyPrefix) {
385385 * Helper method to set access token for the first OAuth2 authentication.
386386 * @param accessToken the access token
387387 */
388- public void setAccessToken (String accessToken ) {
388+ public ApiClient setAccessToken (String accessToken ) {
389+ return setAccessToken (() -> accessToken );
390+ }
391+
392+ /**
393+ * Helper method to set the supplier of access tokens for OAuth2 authentication.
394+ *
395+ * @param tokenSupplier The supplier of access tokens
396+ * @return ApiClient this client
397+ */
398+ public ApiClient setAccessToken (Supplier <String > tokenSupplier ) {
389399 for (Authentication auth : authentications .values ()) {
390400 if (auth instanceof OAuth ) {
391- ((OAuth ) auth ).setAccessToken (accessToken );
392- return ;
401+ ((OAuth ) auth ).setAccessToken (tokenSupplier );
402+ return this ;
393403 }
394404 }
395405 throw new RuntimeException ("No OAuth2 authentication configured!" );
You can’t perform that action at this time.
0 commit comments