question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
NightEule5commented, Oct 29, 2021

I did find the problem and submitted a fix

0reactions
mobilekosmoscommented, Oct 29, 2021

I don’t have idea why the one class is not being generated, the samples here on github do include a package “auth” with that class inside.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OAuth2 Autoconfig - Spring
This project is a port of the Spring Security OAuth support that came with Spring Boot 1.x. Support was removed in favor of...
Read more >
Gen 8.6 Consuming REST APIs: Security
The goal of this document is to show you how to implement REST API security schemes using existing functionality. We will illustrate how...
Read more >
Using OAuth2 RBAC - Quarkus
This extension provides a light-weight support for using the opaque Bearer Tokens and validating them by calling an introspection endpoint. If the OAuth2...
Read more >
Authentication - Swagger
In the following example, the API calls can be authenticated using either an API key or OAuth 2. The ApiKeyAuth and OAuth2 names...
Read more >
Using Spring Boot for OAuth2 and JWT REST Protection - Toptal
Let's take a quick look at Spring Security architecture (a more detailed guide can be found here). Security is mostly about authentication, i.e....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found