Openapi-generator: [BUG] The kotlin-spring generator ApiUtil object doesn't compile

Created on 28 Feb 2020  路  10Comments  路  Source: OpenAPITools/openapi-generator

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)
Bug

All 10 comments

I encountered the same error.
Still works with 4.2.1, but ApiUtil.kt is not generated.

I suspect the following PR to be the cause:
https://github.com/OpenAPITools/openapi-generator/pull/3925

In case this helps for anybody..

In the tasks with KotlinCompile, they come by default with strict compiler args. You can disable these like so:

tasks.withType<KotlinCompile> {
    dependsOn(generateTask)

    kotlinOptions {
        //freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}

After that, the compiler wasn't as strict and the code was compiled.

I submitted a PR for fixing this bug #6084

Any update on this? We run into the same problem.

my PR has been reviewed but not yet merged in the master branch

@sylvainmoindron thanks, do you know why this is? I had a look and your branch was approved 25 days ago... 馃槥

@jimschubert could you maybe estimate when this will be released?

@huehnerlady we'll likely have a beta of 5.0 within the next few weeks. If you need this now, you could pull the latest docker image (it tracks master).

@jimschubert thanks for the info. I am using the gradle plugin, so not sure how I would do that with a docker image. I am happy to wait for a beta to come out to use it :)

@jimschubert I have seen that there is a beta of 5.0 out now. Will there also be a beta release for the gradle plugin soon, or can I use this generator version in the current gradle-plugin-version somehow?

Many thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TiFu picture TiFu  路  70Comments

jonrimmer picture jonrimmer  路  80Comments

wing328 picture wing328  路  25Comments

vinodchitrali picture vinodchitrali  路  22Comments

seunlanlege picture seunlanlege  路  23Comments