Skip to content

[BUG] [Kotlin] [Gradle Plugin] ApiKeyAuth is not generated under jvm-retrofit2 when no "oauth2" security scheme is present in the spec #10679

@NightEule5

Description

@NightEule5

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When using the Gradle plugin to generation Kotlin code under the jvm-retrofit2 library type, ApiKeyAuth doesn't generate causing compilation to fail. The class is referenced in ApiClient here:

constructor(
    baseUrl: String = defaultBasePath,
    okHttpClientBuilder: OkHttpClient.Builder? = null,
    serializerBuilder: Moshi.Builder = Serializer.moshiBuilder,
    authNames: Array<String>
) : this(baseUrl, okHttpClientBuilder, serializerBuilder) {
    authNames.forEach { authName ->
        val auth = when (authName) {
            "TokenAuth" -> ApiKeyAuth("header", "Authorization")
            else -> throw RuntimeException("auth name $authName not found in available auth names")
        }
        addAuthorization(authName, auth);
    }
}
openapi-generator version

I've tested this on plugin versions 5.1.1, 5.2.1, and 5.3.0.

OpenAPI declaration file content or url

The spec I'm using can be found here.

Generation Details
generatorName: kotlin
outputDir: out
library: jvm-retrofit2
inputSpec: modrinth.yaml
Steps to reproduce

I've attached a minimal project that reproduces the bug:

OpenAPIBugReproduction.zip

Related issues/PRs

Might be related to this issue #8147.

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