Skip to content

[BUG][kotlin][client] When all auth maps to null, ApiClient.kt does not compile #16716

@WonderCsabo

Description

@WonderCsabo
Description

If all auth methods maps to null, so ApiClient does not add them, the generated ApiClient will not compile:

authNames.forEach { authName ->
            val auth =
                when (authName) {
                    "openId" -> null
                    else -> throw RuntimeException("auth name $authName not found in available auth names")
                }
            if (auth != null) {
                addAuthorization(authName, auth) // Smart cast to 'Nothing' is impossible, because 'auth' is a complex expression
            }
        }
openapi-generator version

7.0.1

OpenAPI declaration file content or url
components:
  securitySchemes:
    openId:
      type: openIdConnect
      openIdConnectUrl: "???"
Suggest a fix

An easy fix would be to explicitly specify the type of auth variable. This is unnecessary if we have handled auths, bot does not cause any issues either way:

authNames.forEach { authName ->
            val auth: Interceptor? =
                when (authName) {
                    "openId" -> null
                    else -> throw RuntimeException("auth name $authName not found in available auth names")
                }
            if (auth != null) {
                addAuthorization(authName, auth) // Smart cast to 'Nothing' is impossible, because 'auth' is a complex expression
            }
        }

I would happily contribute this, if accepted.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions