Repository navigation
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- 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 plugin with version 7.23.0, and setting a boolean field for a header I'm getting this output:
fun Route.DefaultApi() {
post<Paths.pathPost> { pathPost ->
val defaultApiDelegate: DefaultApiDelegate? by call.delegates
val path = pathPost.path
val indexField = call.request.headers["IndexField"]
val indexContents = call.request.headers["IndexContents"]?.let { runCatching { it.tokotlin.Boolean() }.getOrElse { throw BadParameterException(message = "Invalid format for parameter IndexContents: $it", parameterName = "IndexContents") } }
val indexDate = call.request.headers["IndexDate"]?.let { runCatching { it.tokotlin.Boolean() }.getOrElse { throw BadParameterException(message = "Invalid format for parameter IndexDate: $it", parameterName = "IndexDate") } }
val indexName = call.request.headers["IndexName"]?.let { runCatching { it.tokotlin.Boolean() }.getOrElse { throw BadParameterException(message = "Invalid format for parameter IndexName: $it", parameterName = "IndexName") } }
val authorizedUserID = call.request.headers["AuthorizedUserID"]
if (!"^\\$(?:\\.[_A-Za-z]\\w*|\\[\\d+\\]|\\[\\*\\])*(?:\\.[_A-Za-z]\\w*|\\[\\d+\\]|\\[\\*\\])?$".toRegex().matches(indexField.toString())) {
throw BadParameterException(
message = "Header parameter indexField does not match pattern ^\\$(?:\\.[_A-Za-z]\\w*|\\[\\d+\\]|\\[\\*\\])*(?:\\.[_A-Za-z]\\w*|\\[\\d+\\]|\\[\\*\\])?$",
parameterName = "indexField",
validationType = "pattern",
expectedValue = "^\\$(?:\\.[_A-Za-z]\\w*|\\[\\d+\\]|\\[\\*\\])*(?:\\.[_A-Za-z]\\w*|\\[\\d+\\]|\\[\\*\\])?$",
actualValue = indexField
)
}
val delegate = defaultApiDelegate ?: throw APINotImplementedException("API operation pathPost has not been implemented yet.")
val result = delegate.pathPost(path, indexField, indexContents, indexDate, indexName, authorizedUserID, call)
call.respond(result)
}
}That it.tokotlin.Boolean() bit is invalid code, should have been toBoolean(), and that is the expected result I see in the templates as well. Downgrading the plugin also produced invalid code (multiple errors instead of just this), so I really don't have options other than just fixing it by hand and committing the generated code.
openapi-generator version
7.23.0, the code has fewer errors than 7.22.0.
OpenAPI declaration file content or url
openapi: "3.1.0"
info:
title: API Title
version: "1.0"
servers:
- url: https://api.server.test/v1
paths:
/{path}:
parameters:
- name: path
in: path
schema:
type: string
required: true
- name: AuthorizedUserID
in: header
required: false
schema:
type: string
post:
parameters:
- name: IndexField
in: header
required: false
schema:
type: string
pattern: ^\$(?:\.[_A-Za-z]\w*|\[\d+\]|\[\*\])*(?:\.[_A-Za-z]\w*|\[\d+\]|\[\*\])?$
- name: IndexContents
in: header
required: false
schema:
type: boolean
- name: IndexDate
in: header
required: false
schema:
type: boolean
- name: IndexName
in: header
required: false
schema:
type: boolean
Generation Details
gradlew openapi generate task, with this configuration:
openApiGenerate {
val packagePath = "$group.api"
generatorName = "kotlin-server"
packageName = packagePath
inputSpec.set("./src/main/resources/report-api.yaml")
outputDir.set(layout.buildDirectory.dir("generated").get().asFile.path)
apiPackage = "$packagePath.api"
invokerPackage = "$packagePath.invoker"
modelPackage = "$packagePath.models"
additionalProperties = mapOf(
"engine" to "netty",
"useGradle" to "false",
"serialization" to "kotlinx",
"dateLibrary" to " kotlinx-datetime",
"useCoroutines" to "true",
"suppressWarnings" to "true",
"delegatePattern" to "true",
"omitGradleWrapper" to "true",
)
}
Steps to reproduce
Related issues/PRs
Suggest a fix
The template is complicated, and I don't have time/energy to try to understand what it is attempting to do.
This is going to be the exact template that is causing this.
https://raw.githubusercontent.com/OpenAPITools/openapi-generator/refs/heads/master/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/_extract_param_value.mustache
Activity