Skip to content

[BUG] The kotlin-spring generator ApiUtil object doesn't compile #5476

Closed
@hemynem

Description

@hemynem
Description

the kotlin-spring generator produces code which doesn't compile.

openapi-generator version

openapi-generator version: 4.2.3
gradle version: 5.6.2

Command line used for generation

I'm using gradle to generate the classes

tasks.create<GenerateTask>("generateEndpoint") {
	generatorName.set("kotlin-spring")
	inputSpec.set("${specsDir}/test.yaml")
	outputDir.set("${genDir}/something")
	apiPackage.set("${package}.api")
        invokerPackage.set("${package}.invoker")
	modelPackage.set("${package}.model")
	additionalProperties.set(mapOf("serviceInterface" to "true"))
}
Steps to reproduce

just call gradle task generate endpoints and build, after that you see three compile errors.

e: /home/.../api/ApiUtil.kt: (12, 16): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type HttpServletResponse?
e: /home/.../api/ApiUtil.kt: (13, 16): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type HttpServletResponse?
e: /home/.../api/ApiUtil.kt: (14, 16): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type HttpServletResponse?

Suggest a fix

fix mustache file: apit-mustache

and add questionmarks

            res?.setCharacterEncoding("UTF-8")
            res?.addHeader("Content-Type", contentType)
            res?.getWriter()?.print(example)

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