diff --git a/CI/samples.ci/client/petstore/java/test-manual/jersey1/ApiClientTest.java b/CI/samples.ci/client/petstore/java/test-manual/jersey1/ApiClientTest.java index 405267d4131..682690f049d 100644 --- a/CI/samples.ci/client/petstore/java/test-manual/jersey1/ApiClientTest.java +++ b/CI/samples.ci/client/petstore/java/test-manual/jersey1/ApiClientTest.java @@ -122,7 +122,6 @@ public class ApiClientTest { } } - @Ignore("There is no more basic auth in petstore security definitions") @Test public void testSetUsernameAndPassword() { HttpBasicAuth auth = null; diff --git a/CI/samples.ci/client/petstore/java/test-manual/jersey2/ApiClientTest.java b/CI/samples.ci/client/petstore/java/test-manual/jersey2/ApiClientTest.java index 09659fb4700..1fcc0bca7f4 100644 --- a/CI/samples.ci/client/petstore/java/test-manual/jersey2/ApiClientTest.java +++ b/CI/samples.ci/client/petstore/java/test-manual/jersey2/ApiClientTest.java @@ -122,7 +122,6 @@ public class ApiClientTest { } } - @Ignore("There is no more basic auth in petstore security definitions") @Test public void testSetUsernameAndPassword() { HttpBasicAuth auth = null; diff --git a/CI/samples.ci/client/petstore/java/test-manual/resttemplate/ApiClientTest.java b/CI/samples.ci/client/petstore/java/test-manual/resttemplate/ApiClientTest.java index a6bedae3e95..62068d754ea 100644 --- a/CI/samples.ci/client/petstore/java/test-manual/resttemplate/ApiClientTest.java +++ b/CI/samples.ci/client/petstore/java/test-manual/resttemplate/ApiClientTest.java @@ -128,7 +128,6 @@ public class ApiClientTest { } } - @Ignore("There is no more basic auth in petstore security definitions") @Test public void testSetUsernameAndPassword() { HttpBasicAuth auth = null; diff --git a/bin/windows/java-petstore-all.bat b/bin/windows/java-petstore-all.bat index e141ec8ef9f..0ac9ddb0628 100644 --- a/bin/windows/java-petstore-all.bat +++ b/bin/windows/java-petstore-all.bat @@ -1,24 +1,24 @@ -call .\bin\windows\java-petstore-jersey1.bat -call .\bin\windows\java-petstore-jersey2-java8.bat -call .\bin\windows\java-petstore-feign.bat call .\bin\windows\java-petstore-feign-10x.bat +call .\bin\windows\java-petstore-feign.bat +call .\bin\windows\java-petstore-google-api-client.bat +call .\bin\windows\java-petstore-jersey1.bat +call .\bin\windows\java-petstore-jersey2-java6.bat +call .\bin\windows\java-petstore-jersey2-java7.bat +call .\bin\windows\java-petstore-jersey2-java8.bat call .\bin\windows\java-petstore-native.bat -call .\bin\windows\java-petstore-okhttp-gson.bat call .\bin\windows\java-petstore-okhttp-gson-parcelable.bat +call .\bin\windows\java-petstore-okhttp-gson.bat +call .\bin\windows\java-petstore-rest-assured.bat +call .\bin\windows\java-petstore-rest-assured-jackson.bat +call .\bin\windows\java-petstore-resteasy.bat +call .\bin\windows\java-petstore-resttemplate-withxml.bat +call .\bin\windows\java-petstore-resttemplate.bat call .\bin\windows\java-petstore-retrofit.bat -call .\bin\windows\java-petstore-retrofit2.bat -call .\bin\windows\java-petstore-retrofit2rx.bat -call .\bin\windows\java-petstore-retrofit2rx2.bat -call .\bin\windows\java8-petstore-jersey2.bat call .\bin\windows\java-petstore-retrofit2-play24.bat call .\bin\windows\java-petstore-retrofit2-play25.bat call .\bin\windows\java-petstore-retrofit2-play26.bat -call .\bin\windows\java-petstore-jersey2-java6.bat -call .\bin\windows\java-petstore-resttemplate.bat -call .\bin\windows\java-petstore-resttemplate-withxml.bat -call .\bin\windows\java-petstore-webclient.bat -call .\bin\windows\java-petstore-resteasy.bat -call .\bin\windows\java-petstore-google-api-client.bat -call .\bin\windows\java-petstore-rest-assured.bat -call .\bin\windows\java-petstore-rest-assured-jackson.bat +call .\bin\windows\java-petstore-retrofit2.bat +call .\bin\windows\java-petstore-retrofit2rx.bat +call .\bin\windows\java-petstore-retrofit2rx2.bat call .\bin\windows\java-petstore-vertx.bat +call .\bin\windows\java-petstore-webclient.bat diff --git a/bin/windows/java-petstore-jersey1.bat b/bin/windows/java-petstore-jersey1.bat index a65093cce34..b862cb16d9f 100644 --- a/bin/windows/java-petstore-jersey1.bat +++ b/bin/windows/java-petstore-jersey1.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate --artifact-id petstore-java-client-jersey1 -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -o samples\client\petstore\java\jersey1 --additional-properties hideGenerationTimestamp=true --library=jersey1 --additional-properties useNullForUnknownEnumValue=true +set ags=generate --artifact-id petstore-java-client-jersey1 -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -o samples\client\petstore\java\jersey1 --additional-properties hideGenerationTimestamp=true --library=jersey1 java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-jersey2-java7.bat b/bin/windows/java-petstore-jersey2-java7.bat new file mode 100644 index 00000000000..aede25e62f1 --- /dev/null +++ b/bin/windows/java-petstore-jersey2-java7.bat @@ -0,0 +1,10 @@ +set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M +set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-jersey2-java7.json -o samples\client\petstore\java\jersey2-java7 --additional-properties hideGenerationTimestamp=true + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-jersey2-java8.bat b/bin/windows/java-petstore-jersey2-java8.bat index 7ea0c334e78..5880a6554f3 100644 --- a/bin/windows/java-petstore-jersey2-java8.bat +++ b/bin/windows/java-petstore-jersey2-java8.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-jersey2-java7.json -o samples\client\petstore\java\jersey2 --additional-properties hideGenerationTimestamp=true +set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-jersey2-java8.json -o samples\client\petstore\java\jersey2-java8 --additional-properties hideGenerationTimestamp=true java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-rest-assured.bat b/bin/windows/java-petstore-rest-assured.bat index d7c05416262..758af247586 100644 --- a/bin/windows/java-petstore-rest-assured.bat +++ b/bin/windows/java-petstore-rest-assured.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\rest-assured -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-rest-assured.json -o samples\client\petstore\java\rest-assured --additional-properties hideGenerationTimestamp=true,booleanGetterPrefix=is +set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\rest-assured -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-rest-assured.json -o samples\client\petstore\java\rest-assured --additional-properties hideGenerationTimestamp=true --additional-properties useBeanValidation=true --additional-properties performBeanValidation=true --additional-properties booleanGetterPrefix=is java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-webclient.bat b/bin/windows/java-petstore-webclient.bat new file mode 100644 index 00000000000..17fb94b012a --- /dev/null +++ b/bin/windows/java-petstore-webclient.bat @@ -0,0 +1,10 @@ +set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M +set ags=generate -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-webclient.json -o samples/client/petstore/java/webclient --additional-properties hideGenerationTimestamp=true + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java index aa7956728f0..5ed856248b5 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java @@ -933,7 +933,6 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { bundle.put("hasOAuthMethods", true); bundle.put("oauthMethods", ProcessUtils.getOAuthMethods(authMethods)); } - if (ProcessUtils.hasHttpBearerMethods(authMethods)) { bundle.put("hasHttpBearerMethods", true); } @@ -1473,8 +1472,6 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { return result; } - - protected File writeInputStreamToFile(String filename, InputStream in, String templateFile) throws IOException { if (in != null) { byte[] bytes = IOUtils.toByteArray(in); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ProcessUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ProcessUtils.java index 5b41544b50f..4ded5b25505 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ProcessUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ProcessUtils.java @@ -108,7 +108,7 @@ public class ProcessUtils { public static boolean hasHttpBearerMethods(List authMethods) { if (authMethods != null && !authMethods.isEmpty()) { for (CodegenSecurity cs : authMethods) { - if (Boolean.TRUE.equals(cs.isBasicBasic)) { + if (Boolean.TRUE.equals(cs.isBasicBearer)) { return true; } } diff --git a/modules/openapi-generator/src/main/resources/Java/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/ApiClient.mustache index 8b71c1551e3..b2e3b198651 100644 --- a/modules/openapi-generator/src/main/resources/Java/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/ApiClient.mustache @@ -53,9 +53,15 @@ import java.io.UnsupportedEncodingException; import java.text.DateFormat; import {{invokerPackage}}.auth.Authentication; +{{#hasHttpBasicMethods}} import {{invokerPackage}}.auth.HttpBasicAuth; +{{/hasHttpBasicMethods}} +{{#hasHttpBearerMethods}} import {{invokerPackage}}.auth.HttpBearerAuth; +{{/hasHttpBearerMethods}} +{{#hasApiKeyMethods}} import {{invokerPackage}}.auth.ApiKeyAuth; +{{/hasApiKeyMethods}} {{#hasOAuthMethods}} import {{invokerPackage}}.auth.OAuth; {{/hasOAuthMethods}} @@ -267,6 +273,24 @@ public class ApiClient { return authentications.get(authName); } + {{#hasHttpBearerMethods}} + /** + * Helper method to set access token for the first Bearer authentication. + * @param bearerToken Bearer token + */ + public void setBearerToken(String bearerToken) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBearerAuth) { + ((HttpBearerAuth) auth).setBearerToken(bearerToken); + return; + } + } + throw new RuntimeException("No Bearer authentication configured!"); + } + + {{/hasHttpBearerMethods}} + + {{#hasHttpBasicMethods}} /** * Helper method to set username for the first HTTP basic authentication. * @param username Username @@ -295,6 +319,9 @@ public class ApiClient { throw new RuntimeException("No HTTP basic authentication configured!"); } + {{/hasHttpBasicMethods}} + + {{#hasApiKeyMethods}} /** * Helper method to set API key value for the first API key authentication. * @param apiKey the API key @@ -323,6 +350,8 @@ public class ApiClient { throw new RuntimeException("No API key authentication configured!"); } + {{/hasApiKeyMethods}} + {{#hasOAuthMethods}} /** * Helper method to set access token for the first OAuth2 authentication. @@ -340,20 +369,6 @@ public class ApiClient { {{/hasOAuthMethods}} - /** - * Helper method to set access token for the first Bearer authentication. - * @param bearerToken Bearer token - */ - public void setBearerToken(String bearerToken) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBearerAuth) { - ((HttpBearerAuth) auth).setBearerToken(bearerToken); - return; - } - } - throw new RuntimeException("No Bearer authentication configured!"); - } - /** * Set the User-Agent header's value (by adding to the default header map). * @param userAgent User agent diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache index a2e66a62b61..f4add57c3e1 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache @@ -66,9 +66,15 @@ import java.util.Map.Entry; import java.util.TimeZone; import {{invokerPackage}}.auth.Authentication; +{{#hasHttpBasicMethods}} import {{invokerPackage}}.auth.HttpBasicAuth; +{{/hasHttpBasicMethods}} +{{#hasHttpBearerMethods}} import {{invokerPackage}}.auth.HttpBearerAuth; +{{/hasHttpBearerMethods}} +{{#hasApiKeyMethods}} import {{invokerPackage}}.auth.ApiKeyAuth; +{{/hasApiKeyMethods}} {{#hasOAuthMethods}} import {{invokerPackage}}.auth.OAuth; {{/hasOAuthMethods}} @@ -170,93 +176,103 @@ public class ApiClient { return authentications.get(authName); } - /** - * Helper method to set token for HTTP bearer authentication. - * @param bearerToken the token - */ - public void setBearerToken(String bearerToken) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBearerAuth) { - ((HttpBearerAuth) auth).setBearerToken(bearerToken); - return; - } + {{#hasHttpBearerMethods}} + /** + * Helper method to set token for HTTP bearer authentication. + * @param bearerToken the token + */ + public void setBearerToken(String bearerToken) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBearerAuth) { + ((HttpBearerAuth) auth).setBearerToken(bearerToken); + return; } - throw new RuntimeException("No Bearer authentication configured!"); } + throw new RuntimeException("No Bearer authentication configured!"); + } - /** - * Helper method to set username for the first HTTP basic authentication. - * @param username the username - */ - public void setUsername(String username) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBasicAuth) { - ((HttpBasicAuth) auth).setUsername(username); - return; - } - } - throw new RuntimeException("No HTTP basic authentication configured!"); + {{/hasHttpBearerMethods}} + + {{#hasHttpBasicMethods}} + /** + * Helper method to set username for the first HTTP basic authentication. + * @param username Username + */ + public void setUsername(String username) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBasicAuth) { + ((HttpBasicAuth) auth).setUsername(username); + return; + } } + throw new RuntimeException("No HTTP basic authentication configured!"); + } - /** - * Helper method to set password for the first HTTP basic authentication. - * @param password the password - */ - public void setPassword(String password) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBasicAuth) { - ((HttpBasicAuth) auth).setPassword(password); - return; - } - } - throw new RuntimeException("No HTTP basic authentication configured!"); + /** + * Helper method to set password for the first HTTP basic authentication. + * @param password Password + */ + public void setPassword(String password) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBasicAuth) { + ((HttpBasicAuth) auth).setPassword(password); + return; + } } + throw new RuntimeException("No HTTP basic authentication configured!"); + } - /** - * Helper method to set API key value for the first API key authentication. - * @param apiKey the API key - */ - public void setApiKey(String apiKey) { - for (Authentication auth : authentications.values()) { - if (auth instanceof ApiKeyAuth) { - ((ApiKeyAuth) auth).setApiKey(apiKey); - return; - } - } - throw new RuntimeException("No API key authentication configured!"); + {{/hasHttpBasicMethods}} + + {{#hasApiKeyMethods}} + /** + * Helper method to set API key value for the first API key authentication. + * @param apiKey the API key + */ + public void setApiKey(String apiKey) { + for (Authentication auth : authentications.values()) { + if (auth instanceof ApiKeyAuth) { + ((ApiKeyAuth) auth).setApiKey(apiKey); + return; + } } + throw new RuntimeException("No API key authentication configured!"); + } - /** - * Helper method to set API key prefix for the first API key authentication. - * @param apiKeyPrefix the API key prefix - */ - public void setApiKeyPrefix(String apiKeyPrefix) { - for (Authentication auth : authentications.values()) { - if (auth instanceof ApiKeyAuth) { - ((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix); - return; - } - } - throw new RuntimeException("No API key authentication configured!"); + /** + * Helper method to set API key prefix for the first API key authentication. + * @param apiKeyPrefix API key prefix + */ + public void setApiKeyPrefix(String apiKeyPrefix) { + for (Authentication auth : authentications.values()) { + if (auth instanceof ApiKeyAuth) { + ((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix); + return; + } } + throw new RuntimeException("No API key authentication configured!"); + } - {{#hasOAuthMethods}} - /** - * Helper method to set access token for the first OAuth2 authentication. - * @param accessToken the access token - */ - public void setAccessToken(String accessToken) { - for (Authentication auth : authentications.values()) { - if (auth instanceof OAuth) { - ((OAuth) auth).setAccessToken(accessToken); - return; - } - } - throw new RuntimeException("No OAuth2 authentication configured!"); + {{/hasApiKeyMethods}} + + {{#hasOAuthMethods}} + /** + * Helper method to set access token for the first OAuth2 authentication. + * @param accessToken Access token + */ + public void setAccessToken(String accessToken) { + for (Authentication auth : authentications.values()) { + if (auth instanceof OAuth) { + ((OAuth) auth).setAccessToken(accessToken); + return; + } } + throw new RuntimeException("No OAuth2 authentication configured!"); + } - {{/hasOAuthMethods}} - /** + {{/hasOAuthMethods}} + + /** * Set the User-Agent header's value (by adding to the default header map). * @param userAgent the user agent string * @return ApiClient this client diff --git a/samples/client/petstore/java/jersey1/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey1/src/main/java/org/openapitools/client/ApiClient.java index 5707dc8c747..74a543e6bba 100644 --- a/samples/client/petstore/java/jersey1/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey1/src/main/java/org/openapitools/client/ApiClient.java @@ -55,7 +55,6 @@ import java.text.DateFormat; import org.openapitools.client.auth.Authentication; import org.openapitools.client.auth.HttpBasicAuth; -import org.openapitools.client.auth.HttpBearerAuth; import org.openapitools.client.auth.ApiKeyAuth; import org.openapitools.client.auth.OAuth; @@ -240,6 +239,7 @@ public class ApiClient { return authentications.get(authName); } + /** * Helper method to set username for the first HTTP basic authentication. * @param username Username @@ -268,6 +268,7 @@ public class ApiClient { throw new RuntimeException("No HTTP basic authentication configured!"); } + /** * Helper method to set API key value for the first API key authentication. * @param apiKey the API key @@ -296,6 +297,7 @@ public class ApiClient { throw new RuntimeException("No API key authentication configured!"); } + /** * Helper method to set access token for the first OAuth2 authentication. * @param accessToken Access token @@ -311,20 +313,6 @@ public class ApiClient { } - /** - * Helper method to set access token for the first Bearer authentication. - * @param bearerToken Bearer token - */ - public void setBearerToken(String bearerToken) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBearerAuth) { - ((HttpBearerAuth) auth).setBearerToken(bearerToken); - return; - } - } - throw new RuntimeException("No Bearer authentication configured!"); - } - /** * Set the User-Agent header's value (by adding to the default header map). * @param userAgent User agent diff --git a/samples/client/petstore/java/jersey1/src/test/java/org/openapitools/client/ApiClientTest.java b/samples/client/petstore/java/jersey1/src/test/java/org/openapitools/client/ApiClientTest.java index 405267d4131..682690f049d 100644 --- a/samples/client/petstore/java/jersey1/src/test/java/org/openapitools/client/ApiClientTest.java +++ b/samples/client/petstore/java/jersey1/src/test/java/org/openapitools/client/ApiClientTest.java @@ -122,7 +122,6 @@ public class ApiClientTest { } } - @Ignore("There is no more basic auth in petstore security definitions") @Test public void testSetUsernameAndPassword() { HttpBasicAuth auth = null; diff --git a/samples/client/petstore/java/jersey2-java8/src/test/java/org/openapitools/client/ApiClientTest.java b/samples/client/petstore/java/jersey2-java8/src/test/java/org/openapitools/client/ApiClientTest.java index 09659fb4700..1fcc0bca7f4 100644 --- a/samples/client/petstore/java/jersey2-java8/src/test/java/org/openapitools/client/ApiClientTest.java +++ b/samples/client/petstore/java/jersey2-java8/src/test/java/org/openapitools/client/ApiClientTest.java @@ -122,7 +122,6 @@ public class ApiClientTest { } } - @Ignore("There is no more basic auth in petstore security definitions") @Test public void testSetUsernameAndPassword() { HttpBasicAuth auth = null; diff --git a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java index cfdc5b1b8c8..fa898ad686f 100644 --- a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java @@ -61,7 +61,6 @@ import java.util.TimeZone; import org.openapitools.client.auth.Authentication; import org.openapitools.client.auth.HttpBasicAuth; -import org.openapitools.client.auth.HttpBearerAuth; import org.openapitools.client.auth.ApiKeyAuth; import org.openapitools.client.auth.OAuth; @@ -162,91 +161,81 @@ public class ApiClient { return authentications.get(authName); } - /** - * Helper method to set token for HTTP bearer authentication. - * @param bearerToken the token - */ - public void setBearerToken(String bearerToken) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBearerAuth) { - ((HttpBearerAuth) auth).setBearerToken(bearerToken); - return; - } + + /** + * Helper method to set username for the first HTTP basic authentication. + * @param username Username + */ + public void setUsername(String username) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBasicAuth) { + ((HttpBasicAuth) auth).setUsername(username); + return; } - throw new RuntimeException("No Bearer authentication configured!"); } + throw new RuntimeException("No HTTP basic authentication configured!"); + } - /** - * Helper method to set username for the first HTTP basic authentication. - * @param username the username - */ - public void setUsername(String username) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBasicAuth) { - ((HttpBasicAuth) auth).setUsername(username); - return; - } - } - throw new RuntimeException("No HTTP basic authentication configured!"); + /** + * Helper method to set password for the first HTTP basic authentication. + * @param password Password + */ + public void setPassword(String password) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBasicAuth) { + ((HttpBasicAuth) auth).setPassword(password); + return; + } } + throw new RuntimeException("No HTTP basic authentication configured!"); + } - /** - * Helper method to set password for the first HTTP basic authentication. - * @param password the password - */ - public void setPassword(String password) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBasicAuth) { - ((HttpBasicAuth) auth).setPassword(password); - return; - } - } - throw new RuntimeException("No HTTP basic authentication configured!"); + + /** + * Helper method to set API key value for the first API key authentication. + * @param apiKey the API key + */ + public void setApiKey(String apiKey) { + for (Authentication auth : authentications.values()) { + if (auth instanceof ApiKeyAuth) { + ((ApiKeyAuth) auth).setApiKey(apiKey); + return; + } } + throw new RuntimeException("No API key authentication configured!"); + } - /** - * Helper method to set API key value for the first API key authentication. - * @param apiKey the API key - */ - public void setApiKey(String apiKey) { - for (Authentication auth : authentications.values()) { - if (auth instanceof ApiKeyAuth) { - ((ApiKeyAuth) auth).setApiKey(apiKey); - return; - } - } - throw new RuntimeException("No API key authentication configured!"); + /** + * Helper method to set API key prefix for the first API key authentication. + * @param apiKeyPrefix API key prefix + */ + public void setApiKeyPrefix(String apiKeyPrefix) { + for (Authentication auth : authentications.values()) { + if (auth instanceof ApiKeyAuth) { + ((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix); + return; + } } + throw new RuntimeException("No API key authentication configured!"); + } - /** - * Helper method to set API key prefix for the first API key authentication. - * @param apiKeyPrefix the API key prefix - */ - public void setApiKeyPrefix(String apiKeyPrefix) { - for (Authentication auth : authentications.values()) { - if (auth instanceof ApiKeyAuth) { - ((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix); - return; - } - } - throw new RuntimeException("No API key authentication configured!"); + + /** + * Helper method to set access token for the first OAuth2 authentication. + * @param accessToken Access token + */ + public void setAccessToken(String accessToken) { + for (Authentication auth : authentications.values()) { + if (auth instanceof OAuth) { + ((OAuth) auth).setAccessToken(accessToken); + return; + } } + throw new RuntimeException("No OAuth2 authentication configured!"); + } - /** - * Helper method to set access token for the first OAuth2 authentication. - * @param accessToken the access token - */ - public void setAccessToken(String accessToken) { - for (Authentication auth : authentications.values()) { - if (auth instanceof OAuth) { - ((OAuth) auth).setAccessToken(accessToken); - return; - } - } - throw new RuntimeException("No OAuth2 authentication configured!"); - } - /** + /** * Set the User-Agent header's value (by adding to the default header map). * @param userAgent the user agent string * @return ApiClient this client diff --git a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java index 8220b56a308..1b100928730 100644 --- a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java @@ -56,7 +56,6 @@ import java.util.TimeZone; import org.openapitools.client.auth.Authentication; import org.openapitools.client.auth.HttpBasicAuth; -import org.openapitools.client.auth.HttpBearerAuth; import org.openapitools.client.auth.ApiKeyAuth; import org.openapitools.client.auth.OAuth; @@ -157,91 +156,81 @@ public class ApiClient { return authentications.get(authName); } - /** - * Helper method to set token for HTTP bearer authentication. - * @param bearerToken the token - */ - public void setBearerToken(String bearerToken) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBearerAuth) { - ((HttpBearerAuth) auth).setBearerToken(bearerToken); - return; - } + + /** + * Helper method to set username for the first HTTP basic authentication. + * @param username Username + */ + public void setUsername(String username) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBasicAuth) { + ((HttpBasicAuth) auth).setUsername(username); + return; } - throw new RuntimeException("No Bearer authentication configured!"); } + throw new RuntimeException("No HTTP basic authentication configured!"); + } - /** - * Helper method to set username for the first HTTP basic authentication. - * @param username the username - */ - public void setUsername(String username) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBasicAuth) { - ((HttpBasicAuth) auth).setUsername(username); - return; - } - } - throw new RuntimeException("No HTTP basic authentication configured!"); + /** + * Helper method to set password for the first HTTP basic authentication. + * @param password Password + */ + public void setPassword(String password) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBasicAuth) { + ((HttpBasicAuth) auth).setPassword(password); + return; + } } + throw new RuntimeException("No HTTP basic authentication configured!"); + } - /** - * Helper method to set password for the first HTTP basic authentication. - * @param password the password - */ - public void setPassword(String password) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBasicAuth) { - ((HttpBasicAuth) auth).setPassword(password); - return; - } - } - throw new RuntimeException("No HTTP basic authentication configured!"); + + /** + * Helper method to set API key value for the first API key authentication. + * @param apiKey the API key + */ + public void setApiKey(String apiKey) { + for (Authentication auth : authentications.values()) { + if (auth instanceof ApiKeyAuth) { + ((ApiKeyAuth) auth).setApiKey(apiKey); + return; + } } + throw new RuntimeException("No API key authentication configured!"); + } - /** - * Helper method to set API key value for the first API key authentication. - * @param apiKey the API key - */ - public void setApiKey(String apiKey) { - for (Authentication auth : authentications.values()) { - if (auth instanceof ApiKeyAuth) { - ((ApiKeyAuth) auth).setApiKey(apiKey); - return; - } - } - throw new RuntimeException("No API key authentication configured!"); + /** + * Helper method to set API key prefix for the first API key authentication. + * @param apiKeyPrefix API key prefix + */ + public void setApiKeyPrefix(String apiKeyPrefix) { + for (Authentication auth : authentications.values()) { + if (auth instanceof ApiKeyAuth) { + ((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix); + return; + } } + throw new RuntimeException("No API key authentication configured!"); + } - /** - * Helper method to set API key prefix for the first API key authentication. - * @param apiKeyPrefix the API key prefix - */ - public void setApiKeyPrefix(String apiKeyPrefix) { - for (Authentication auth : authentications.values()) { - if (auth instanceof ApiKeyAuth) { - ((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix); - return; - } - } - throw new RuntimeException("No API key authentication configured!"); + + /** + * Helper method to set access token for the first OAuth2 authentication. + * @param accessToken Access token + */ + public void setAccessToken(String accessToken) { + for (Authentication auth : authentications.values()) { + if (auth instanceof OAuth) { + ((OAuth) auth).setAccessToken(accessToken); + return; + } } + throw new RuntimeException("No OAuth2 authentication configured!"); + } - /** - * Helper method to set access token for the first OAuth2 authentication. - * @param accessToken the access token - */ - public void setAccessToken(String accessToken) { - for (Authentication auth : authentications.values()) { - if (auth instanceof OAuth) { - ((OAuth) auth).setAccessToken(accessToken); - return; - } - } - throw new RuntimeException("No OAuth2 authentication configured!"); - } - /** + /** * Set the User-Agent header's value (by adding to the default header map). * @param userAgent the user agent string * @return ApiClient this client diff --git a/samples/client/petstore/java/resttemplate/src/test/java/org/openapitools/client/ApiClientTest.java b/samples/client/petstore/java/resttemplate/src/test/java/org/openapitools/client/ApiClientTest.java index a6bedae3e95..62068d754ea 100644 --- a/samples/client/petstore/java/resttemplate/src/test/java/org/openapitools/client/ApiClientTest.java +++ b/samples/client/petstore/java/resttemplate/src/test/java/org/openapitools/client/ApiClientTest.java @@ -128,7 +128,6 @@ public class ApiClientTest { } } - @Ignore("There is no more basic auth in petstore security definitions") @Test public void testSetUsernameAndPassword() { HttpBasicAuth auth = null;