openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] [Kotlin] Missing support for multiple apikey security

Open mszan opened this issue 2 years ago • 1 comments

Description

With the following spec:

...
components:
  securitySchemes:
    Apikey:
      type: apiKey
      in: header
      name: apikey
    Loginkey:
      type: apiKey
      in: header
      name: loginkey
...

Kotlin generator produces this:

import org.openapitools.client.auth.ApiKeyAuth
import org.openapitools.client.auth.ApiKeyAuth

References:

  • https://swagger.io/docs/specification/authentication/api-keys/ (Multiple API Keys section)
  • https://swagger.io/specification/
openapi-generator version

Tested both on 5.4.0 and 6.0.1.

mszan avatar Sep 09 '22 12:09 mszan

I can confirm this, in general Authentication/Authorization is very buggy at the moment and should be redone from scratch, good code is not when there is nothing more to add, its when there is nothing more to delete

Karstenx1971 avatar Sep 18 '22 03:09 Karstenx1971

Same here. Did you manage to go around this issue in any way?

MrBananaLord avatar Nov 22 '23 08:11 MrBananaLord

Same here. Did you manage to go around this issue in any way?

The trick is I did not. I've adjusted my backend to avoid this issue, so what I've got now is one securitySchemes entry (Apikey) and second entry (Loginkey) being passed via headers in each request. It's not perfect but does the job.

mszan avatar Nov 22 '23 09:11 mszan

Hey, I also had this issue (retrofit library) and I managed to make a more general workaround by simply removing the imports and using fully-qualified names of classes. It's not super pretty, but it's generated code so it's not that big of a deal.

I don't think the imports can be fixed properly in the template otherwise, using the variables that are currently being passed... If there's a way to customise those, too, then maybe, but I couldn't find how.

This is the modified template file in case anyone is interested: template.zip

mvettosi avatar Nov 22 '23 16:11 mvettosi