Skip to content

Generation of invalid security schema  #239

@rchomczyk

Description

@rchomczyk

Actual behavior (the bug)
Generation of security schema, where in parameter is equal to name:

"securitySchemes" : {
      "ApiKeyAuth" : {
        "in" : "X-API-Key",
        "name" : "X-API-Key",
        "type" : "apiKey"
      }
}

Expected behavior
Generation of security schema, where in parameter is equal to header and name remains without any changes:

"securitySchemes" : {
      "ApiKeyAuth" : {
        "in" : "header",
        "name" : "X-API-Key",
        "type" : "apiKey"
      }
}

To Reproduce
Create an openapi schema definition with api key authentication by using withApiKeyAuth method in Java project. It can be workarounded by manually setting in field by consumer provided as third parameter for withApiKeyAuth method.

Additional context
It seems like in Java project the value defined as apiKeyHeader is assigned to in field, which leads to generation of invalid openapi definition.

@JvmOverloads
fun withApiKeyAuth(schemeName: String = "ApiKeyAuth", apiKeyHeader: String = "X-Api-Key", securityScheme: Consumer<ApiKeyAuth> = Consumer {}): SecurityComponentConfiguration =
withSecurityScheme(schemeName, ApiKeyAuth(apiKeyHeader).also { securityScheme.accept(it) })

open class ApiKeyAuth(
open var `in`: String = "header",
open var name: String = "X-API-Key"
) : SecurityScheme {
override val type: String = "apiKey"
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions