[Java][webclient] NullPointerException on generated code - getAuthentication
Created by: marcoreni
Description
I have a spec that includes authentication. I successfully generated sources using java/webclient, but as I try to use the generated code and set the authentication as explained in the generated README I get NullPointerException.
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure API key authorization: secret
ApiKeyAuth apiKey = (ApiKeyAuth) defaultClient.getAuthentication("secret");
apiKey.setApiKey("YOUR API KEY");
[...]
Caused by: java.lang.NullPointerException: null
at com.example.ApiClient.getAuthentication(ApiClient.java:168)
[...]
LineRef:
167 public Authentication getAuthentication(String authName) {
168 return authentications.get(authName);
169 }
openapi-generator version
3.2.2
OpenAPI declaration file content or url
openapi: 3.0.0
security:
- secret: []
# Application Components
components:
securitySchemes:
secret:
type: apiKey
in: query
name: secret
Suggest a fix/enhancement
Checking the code at https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache#L108 it seems that init()
method is never called while creating the client, so authentications
is null.