OpenAPITools / OpenAPITools/openapi-generator

[BUG] Support for cookie-based security schemas in Kotlin clients

Open
#10,008 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

While trying to generate Kotlin Client code for cookie-based security schema with OpenAPI Spec version 3.0.0, the below lines were seen in the ApiClient.kt file.


constructor(
        baseUrl: String = defaultBasePath,
        okHttpClientBuilder: OkHttpClient.Builder? = null,
        serializerBuilder: GsonBuilder = Serializer.gsonBuilder,
        authNames: Array<String>
    ) : this(baseUrl, okHttpClientBuilder, serializerBuilder) {
        authNames.forEach { authName ->
            val auth = when (authName) {
                "cookieAuth" -> ApiKeyAuth("cookie", "sess")
                else -> throw RuntimeException("auth name $authName not found in available auth names")
            }
            addAuthorization(authName, auth);
        }
    }
    

But, the file ApiKeyAuth.kt was not found in the generated code.

openapi-generator version

5.2.0

OpenAPI declaration file content or url

https://gist.github.com/puneetugru/ec65183b4ad2da3ee8a7b43def2eea4a

Generation Details

openapi-generator generate -i TestCookieAuthInAPI.yaml -g kotlin -c config_android.json

Steps to reproduce
  1. Create a config file like below to put the Kotlin client code in a required directory and use some required libraries, called as config_android.json.
{
    "packageName": "com.test",
    "serializationLibrary": "gson",
    "sourceFolder": "src/main/java",
    "library": "jvm-retrofit2"
}
  1. Run the command, openapi-generator generate -i TestCookieAuthInAPI.yaml -g kotlin -c config_android.json
Related issues/PRs

None

Suggest a fix

None

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the stated openapi-generator command with TestCookieAuthInAPI.yaml and config_android.json, then compare the generated ApiClient.kt with the missing ApiKeyAuth.kt. Trace how the cookieAuth security schema is represented in the generated Kotlin client; done means cookie-based authentication generates all referenced files and the client builds successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.