OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.82k stars 6.58k forks source link

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

Open mszan opened 2 years ago

mszan commented 2 years ago
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:

Tested both on 5.4.0 and 6.0.1.

Karstenx1971 commented 2 years ago

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

MrBananaLord commented 11 months ago

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

mszan commented 11 months ago

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.

mvettosi commented 11 months ago

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

tsznober commented 1 month ago

I'm hitting this issue as well... apparently 2 years after it's been reported here. In my case I am generating a Kotlin Retrofit client at build time (Android TV app), so I can't tweak the generated output on-the-fly; it gets overwritten every time it builds. Has anyone else figured out a way to get around this bug with a similar setup?