[Java] Generate valid code if no Authentication implementations present (#5788)

* generate valid code if no Authentication implementations present

resurrects https://github.com/OpenAPITools/openapi-generator/pull/2861

* remove what I assume are human generated test cases

* need to iterate over authMethods in order to pull out name

* fix another test

* update more tests

* rename hasTokenAuthMethods to hasApiKeyAuthMethods

* remove duplicate methods, fix hasHttpBearerMethods check

* update templates

* update windows java-petstore files

* update windows java-petstore files

* re-generate

* re-generate

* restore samples.ci tests

* restore samples.ci tests
This commit is contained in:
Jon Freedman 2020-05-23 11:36:03 +01:00 committed by GitHub
parent f200122c09
commit 950508fd4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 288 additions and 280 deletions

View File

@ -122,7 +122,6 @@ public class ApiClientTest {
} }
} }
@Ignore("There is no more basic auth in petstore security definitions")
@Test @Test
public void testSetUsernameAndPassword() { public void testSetUsernameAndPassword() {
HttpBasicAuth auth = null; HttpBasicAuth auth = null;

View File

@ -122,7 +122,6 @@ public class ApiClientTest {
} }
} }
@Ignore("There is no more basic auth in petstore security definitions")
@Test @Test
public void testSetUsernameAndPassword() { public void testSetUsernameAndPassword() {
HttpBasicAuth auth = null; HttpBasicAuth auth = null;

View File

@ -128,7 +128,6 @@ public class ApiClientTest {
} }
} }
@Ignore("There is no more basic auth in petstore security definitions")
@Test @Test
public void testSetUsernameAndPassword() { public void testSetUsernameAndPassword() {
HttpBasicAuth auth = null; HttpBasicAuth auth = null;

View File

@ -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-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-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-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-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-play24.bat
call .\bin\windows\java-petstore-retrofit2-play25.bat call .\bin\windows\java-petstore-retrofit2-play25.bat
call .\bin\windows\java-petstore-retrofit2-play26.bat call .\bin\windows\java-petstore-retrofit2-play26.bat
call .\bin\windows\java-petstore-jersey2-java6.bat call .\bin\windows\java-petstore-retrofit2.bat
call .\bin\windows\java-petstore-resttemplate.bat call .\bin\windows\java-petstore-retrofit2rx.bat
call .\bin\windows\java-petstore-resttemplate-withxml.bat call .\bin\windows\java-petstore-retrofit2rx2.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-vertx.bat call .\bin\windows\java-petstore-vertx.bat
call .\bin\windows\java-petstore-webclient.bat

View File

@ -5,6 +5,6 @@ If Not Exist %executable% (
) )
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M 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% java %JAVA_OPTS% -jar %executable% %ags%

View File

@ -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%

View File

@ -5,6 +5,6 @@ If Not Exist %executable% (
) )
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M 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% java %JAVA_OPTS% -jar %executable% %ags%

View File

@ -5,6 +5,6 @@ If Not Exist %executable% (
) )
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M 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% java %JAVA_OPTS% -jar %executable% %ags%

View File

@ -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%

View File

@ -933,7 +933,6 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
bundle.put("hasOAuthMethods", true); bundle.put("hasOAuthMethods", true);
bundle.put("oauthMethods", ProcessUtils.getOAuthMethods(authMethods)); bundle.put("oauthMethods", ProcessUtils.getOAuthMethods(authMethods));
} }
if (ProcessUtils.hasHttpBearerMethods(authMethods)) { if (ProcessUtils.hasHttpBearerMethods(authMethods)) {
bundle.put("hasHttpBearerMethods", true); bundle.put("hasHttpBearerMethods", true);
} }
@ -1473,8 +1472,6 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
return result; return result;
} }
protected File writeInputStreamToFile(String filename, InputStream in, String templateFile) throws IOException { protected File writeInputStreamToFile(String filename, InputStream in, String templateFile) throws IOException {
if (in != null) { if (in != null) {
byte[] bytes = IOUtils.toByteArray(in); byte[] bytes = IOUtils.toByteArray(in);

View File

@ -108,7 +108,7 @@ public class ProcessUtils {
public static boolean hasHttpBearerMethods(List<CodegenSecurity> authMethods) { public static boolean hasHttpBearerMethods(List<CodegenSecurity> authMethods) {
if (authMethods != null && !authMethods.isEmpty()) { if (authMethods != null && !authMethods.isEmpty()) {
for (CodegenSecurity cs : authMethods) { for (CodegenSecurity cs : authMethods) {
if (Boolean.TRUE.equals(cs.isBasicBasic)) { if (Boolean.TRUE.equals(cs.isBasicBearer)) {
return true; return true;
} }
} }

View File

@ -53,9 +53,15 @@ import java.io.UnsupportedEncodingException;
import java.text.DateFormat; import java.text.DateFormat;
import {{invokerPackage}}.auth.Authentication; import {{invokerPackage}}.auth.Authentication;
{{#hasHttpBasicMethods}}
import {{invokerPackage}}.auth.HttpBasicAuth; import {{invokerPackage}}.auth.HttpBasicAuth;
{{/hasHttpBasicMethods}}
{{#hasHttpBearerMethods}}
import {{invokerPackage}}.auth.HttpBearerAuth; import {{invokerPackage}}.auth.HttpBearerAuth;
{{/hasHttpBearerMethods}}
{{#hasApiKeyMethods}}
import {{invokerPackage}}.auth.ApiKeyAuth; import {{invokerPackage}}.auth.ApiKeyAuth;
{{/hasApiKeyMethods}}
{{#hasOAuthMethods}} {{#hasOAuthMethods}}
import {{invokerPackage}}.auth.OAuth; import {{invokerPackage}}.auth.OAuth;
{{/hasOAuthMethods}} {{/hasOAuthMethods}}
@ -267,6 +273,24 @@ public class ApiClient {
return authentications.get(authName); 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. * Helper method to set username for the first HTTP basic authentication.
* @param username Username * @param username Username
@ -295,6 +319,9 @@ public class ApiClient {
throw new RuntimeException("No HTTP basic authentication configured!"); throw new RuntimeException("No HTTP basic authentication configured!");
} }
{{/hasHttpBasicMethods}}
{{#hasApiKeyMethods}}
/** /**
* Helper method to set API key value for the first API key authentication. * Helper method to set API key value for the first API key authentication.
* @param apiKey the API key * @param apiKey the API key
@ -323,6 +350,8 @@ public class ApiClient {
throw new RuntimeException("No API key authentication configured!"); throw new RuntimeException("No API key authentication configured!");
} }
{{/hasApiKeyMethods}}
{{#hasOAuthMethods}} {{#hasOAuthMethods}}
/** /**
* Helper method to set access token for the first OAuth2 authentication. * Helper method to set access token for the first OAuth2 authentication.
@ -340,20 +369,6 @@ public class ApiClient {
{{/hasOAuthMethods}} {{/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). * Set the User-Agent header's value (by adding to the default header map).
* @param userAgent User agent * @param userAgent User agent

View File

@ -66,9 +66,15 @@ import java.util.Map.Entry;
import java.util.TimeZone; import java.util.TimeZone;
import {{invokerPackage}}.auth.Authentication; import {{invokerPackage}}.auth.Authentication;
{{#hasHttpBasicMethods}}
import {{invokerPackage}}.auth.HttpBasicAuth; import {{invokerPackage}}.auth.HttpBasicAuth;
{{/hasHttpBasicMethods}}
{{#hasHttpBearerMethods}}
import {{invokerPackage}}.auth.HttpBearerAuth; import {{invokerPackage}}.auth.HttpBearerAuth;
{{/hasHttpBearerMethods}}
{{#hasApiKeyMethods}}
import {{invokerPackage}}.auth.ApiKeyAuth; import {{invokerPackage}}.auth.ApiKeyAuth;
{{/hasApiKeyMethods}}
{{#hasOAuthMethods}} {{#hasOAuthMethods}}
import {{invokerPackage}}.auth.OAuth; import {{invokerPackage}}.auth.OAuth;
{{/hasOAuthMethods}} {{/hasOAuthMethods}}
@ -170,6 +176,7 @@ public class ApiClient {
return authentications.get(authName); return authentications.get(authName);
} }
{{#hasHttpBearerMethods}}
/** /**
* Helper method to set token for HTTP bearer authentication. * Helper method to set token for HTTP bearer authentication.
* @param bearerToken the token * @param bearerToken the token
@ -184,9 +191,12 @@ public class ApiClient {
throw new RuntimeException("No Bearer authentication configured!"); throw new RuntimeException("No Bearer authentication configured!");
} }
{{/hasHttpBearerMethods}}
{{#hasHttpBasicMethods}}
/** /**
* Helper method to set username for the first HTTP basic authentication. * Helper method to set username for the first HTTP basic authentication.
* @param username the username * @param username Username
*/ */
public void setUsername(String username) { public void setUsername(String username) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
@ -200,7 +210,7 @@ public class ApiClient {
/** /**
* Helper method to set password for the first HTTP basic authentication. * Helper method to set password for the first HTTP basic authentication.
* @param password the password * @param password Password
*/ */
public void setPassword(String password) { public void setPassword(String password) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
@ -212,6 +222,9 @@ public class ApiClient {
throw new RuntimeException("No HTTP basic authentication configured!"); throw new RuntimeException("No HTTP basic authentication configured!");
} }
{{/hasHttpBasicMethods}}
{{#hasApiKeyMethods}}
/** /**
* Helper method to set API key value for the first API key authentication. * Helper method to set API key value for the first API key authentication.
* @param apiKey the API key * @param apiKey the API key
@ -228,7 +241,7 @@ public class ApiClient {
/** /**
* Helper method to set API key prefix for the first API key authentication. * Helper method to set API key prefix for the first API key authentication.
* @param apiKeyPrefix the API key prefix * @param apiKeyPrefix API key prefix
*/ */
public void setApiKeyPrefix(String apiKeyPrefix) { public void setApiKeyPrefix(String apiKeyPrefix) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
@ -240,10 +253,12 @@ public class ApiClient {
throw new RuntimeException("No API key authentication configured!"); throw new RuntimeException("No API key authentication configured!");
} }
{{/hasApiKeyMethods}}
{{#hasOAuthMethods}} {{#hasOAuthMethods}}
/** /**
* Helper method to set access token for the first OAuth2 authentication. * Helper method to set access token for the first OAuth2 authentication.
* @param accessToken the access token * @param accessToken Access token
*/ */
public void setAccessToken(String accessToken) { public void setAccessToken(String accessToken) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
@ -256,6 +271,7 @@ public class ApiClient {
} }
{{/hasOAuthMethods}} {{/hasOAuthMethods}}
/** /**
* Set the User-Agent header's value (by adding to the default header map). * Set the User-Agent header's value (by adding to the default header map).
* @param userAgent the user agent string * @param userAgent the user agent string

View File

@ -55,7 +55,6 @@ import java.text.DateFormat;
import org.openapitools.client.auth.Authentication; import org.openapitools.client.auth.Authentication;
import org.openapitools.client.auth.HttpBasicAuth; import org.openapitools.client.auth.HttpBasicAuth;
import org.openapitools.client.auth.HttpBearerAuth;
import org.openapitools.client.auth.ApiKeyAuth; import org.openapitools.client.auth.ApiKeyAuth;
import org.openapitools.client.auth.OAuth; import org.openapitools.client.auth.OAuth;
@ -240,6 +239,7 @@ public class ApiClient {
return authentications.get(authName); return authentications.get(authName);
} }
/** /**
* Helper method to set username for the first HTTP basic authentication. * Helper method to set username for the first HTTP basic authentication.
* @param username Username * @param username Username
@ -268,6 +268,7 @@ public class ApiClient {
throw new RuntimeException("No HTTP basic authentication configured!"); throw new RuntimeException("No HTTP basic authentication configured!");
} }
/** /**
* Helper method to set API key value for the first API key authentication. * Helper method to set API key value for the first API key authentication.
* @param apiKey the API key * @param apiKey the API key
@ -296,6 +297,7 @@ public class ApiClient {
throw new RuntimeException("No API key authentication configured!"); throw new RuntimeException("No API key authentication configured!");
} }
/** /**
* Helper method to set access token for the first OAuth2 authentication. * Helper method to set access token for the first OAuth2 authentication.
* @param accessToken Access token * @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). * Set the User-Agent header's value (by adding to the default header map).
* @param userAgent User agent * @param userAgent User agent

View File

@ -122,7 +122,6 @@ public class ApiClientTest {
} }
} }
@Ignore("There is no more basic auth in petstore security definitions")
@Test @Test
public void testSetUsernameAndPassword() { public void testSetUsernameAndPassword() {
HttpBasicAuth auth = null; HttpBasicAuth auth = null;

View File

@ -122,7 +122,6 @@ public class ApiClientTest {
} }
} }
@Ignore("There is no more basic auth in petstore security definitions")
@Test @Test
public void testSetUsernameAndPassword() { public void testSetUsernameAndPassword() {
HttpBasicAuth auth = null; HttpBasicAuth auth = null;

View File

@ -61,7 +61,6 @@ import java.util.TimeZone;
import org.openapitools.client.auth.Authentication; import org.openapitools.client.auth.Authentication;
import org.openapitools.client.auth.HttpBasicAuth; import org.openapitools.client.auth.HttpBasicAuth;
import org.openapitools.client.auth.HttpBearerAuth;
import org.openapitools.client.auth.ApiKeyAuth; import org.openapitools.client.auth.ApiKeyAuth;
import org.openapitools.client.auth.OAuth; import org.openapitools.client.auth.OAuth;
@ -162,23 +161,10 @@ public class ApiClient {
return authentications.get(authName); 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;
}
}
throw new RuntimeException("No Bearer authentication configured!");
}
/** /**
* Helper method to set username for the first HTTP basic authentication. * Helper method to set username for the first HTTP basic authentication.
* @param username the username * @param username Username
*/ */
public void setUsername(String username) { public void setUsername(String username) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
@ -192,7 +178,7 @@ public class ApiClient {
/** /**
* Helper method to set password for the first HTTP basic authentication. * Helper method to set password for the first HTTP basic authentication.
* @param password the password * @param password Password
*/ */
public void setPassword(String password) { public void setPassword(String password) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
@ -204,6 +190,7 @@ public class ApiClient {
throw new RuntimeException("No HTTP basic authentication configured!"); throw new RuntimeException("No HTTP basic authentication configured!");
} }
/** /**
* Helper method to set API key value for the first API key authentication. * Helper method to set API key value for the first API key authentication.
* @param apiKey the API key * @param apiKey the API key
@ -220,7 +207,7 @@ public class ApiClient {
/** /**
* Helper method to set API key prefix for the first API key authentication. * Helper method to set API key prefix for the first API key authentication.
* @param apiKeyPrefix the API key prefix * @param apiKeyPrefix API key prefix
*/ */
public void setApiKeyPrefix(String apiKeyPrefix) { public void setApiKeyPrefix(String apiKeyPrefix) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
@ -232,9 +219,10 @@ public class ApiClient {
throw new RuntimeException("No API key authentication configured!"); throw new RuntimeException("No API key authentication configured!");
} }
/** /**
* Helper method to set access token for the first OAuth2 authentication. * Helper method to set access token for the first OAuth2 authentication.
* @param accessToken the access token * @param accessToken Access token
*/ */
public void setAccessToken(String accessToken) { public void setAccessToken(String accessToken) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
@ -246,6 +234,7 @@ public class ApiClient {
throw new RuntimeException("No OAuth2 authentication configured!"); throw new RuntimeException("No OAuth2 authentication configured!");
} }
/** /**
* Set the User-Agent header's value (by adding to the default header map). * Set the User-Agent header's value (by adding to the default header map).
* @param userAgent the user agent string * @param userAgent the user agent string

View File

@ -56,7 +56,6 @@ import java.util.TimeZone;
import org.openapitools.client.auth.Authentication; import org.openapitools.client.auth.Authentication;
import org.openapitools.client.auth.HttpBasicAuth; import org.openapitools.client.auth.HttpBasicAuth;
import org.openapitools.client.auth.HttpBearerAuth;
import org.openapitools.client.auth.ApiKeyAuth; import org.openapitools.client.auth.ApiKeyAuth;
import org.openapitools.client.auth.OAuth; import org.openapitools.client.auth.OAuth;
@ -157,23 +156,10 @@ public class ApiClient {
return authentications.get(authName); 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;
}
}
throw new RuntimeException("No Bearer authentication configured!");
}
/** /**
* Helper method to set username for the first HTTP basic authentication. * Helper method to set username for the first HTTP basic authentication.
* @param username the username * @param username Username
*/ */
public void setUsername(String username) { public void setUsername(String username) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
@ -187,7 +173,7 @@ public class ApiClient {
/** /**
* Helper method to set password for the first HTTP basic authentication. * Helper method to set password for the first HTTP basic authentication.
* @param password the password * @param password Password
*/ */
public void setPassword(String password) { public void setPassword(String password) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
@ -199,6 +185,7 @@ public class ApiClient {
throw new RuntimeException("No HTTP basic authentication configured!"); throw new RuntimeException("No HTTP basic authentication configured!");
} }
/** /**
* Helper method to set API key value for the first API key authentication. * Helper method to set API key value for the first API key authentication.
* @param apiKey the API key * @param apiKey the API key
@ -215,7 +202,7 @@ public class ApiClient {
/** /**
* Helper method to set API key prefix for the first API key authentication. * Helper method to set API key prefix for the first API key authentication.
* @param apiKeyPrefix the API key prefix * @param apiKeyPrefix API key prefix
*/ */
public void setApiKeyPrefix(String apiKeyPrefix) { public void setApiKeyPrefix(String apiKeyPrefix) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
@ -227,9 +214,10 @@ public class ApiClient {
throw new RuntimeException("No API key authentication configured!"); throw new RuntimeException("No API key authentication configured!");
} }
/** /**
* Helper method to set access token for the first OAuth2 authentication. * Helper method to set access token for the first OAuth2 authentication.
* @param accessToken the access token * @param accessToken Access token
*/ */
public void setAccessToken(String accessToken) { public void setAccessToken(String accessToken) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
@ -241,6 +229,7 @@ public class ApiClient {
throw new RuntimeException("No OAuth2 authentication configured!"); throw new RuntimeException("No OAuth2 authentication configured!");
} }
/** /**
* Set the User-Agent header's value (by adding to the default header map). * Set the User-Agent header's value (by adding to the default header map).
* @param userAgent the user agent string * @param userAgent the user agent string

View File

@ -128,7 +128,6 @@ public class ApiClientTest {
} }
} }
@Ignore("There is no more basic auth in petstore security definitions")
@Test @Test
public void testSetUsernameAndPassword() { public void testSetUsernameAndPassword() {
HttpBasicAuth auth = null; HttpBasicAuth auth = null;