Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #872
Closed
Open
Issue created Aug 22, 2018 by Administrator@rootContributor

[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.

Assignee
Assign to
Time tracking