Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hemynem opened this issue Feb 28, 2020 · 11 comments · Fixed by #6084
Closed

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

hemynem opened this issue Feb 28, 2020 · 11 comments · Fixed by #6084

Comments

@hemynem
Copy link

hemynem commented Feb 28, 2020

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)
@hemynem hemynem changed the title [BUG] The kotlin-spring generator ApiUtil object which doesn't compile [BUG] The kotlin-spring generator ApiUtil object doesn't compile Feb 28, 2020
@quackes
Copy link
Contributor

quackes commented Mar 2, 2020

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:
#3925

@EivindAntonsen
Copy link

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.

@sylvainmoindron
Copy link
Contributor

I submitted a PR for fixing this bug #6084

@huehnerlady
Copy link

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

@sylvainmoindron
Copy link
Contributor

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

@huehnerlady
Copy link

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

jimschubert added a commit that referenced this issue Jun 5, 2020
* master: (345 commits)
  [kotlin][spring] Fix ApiUtil compilation (#6084)
  update python samples
  [Python] Fixed docstrings in api.mustache (#6391)
  [BUG][python] Support named arrays (#6493)
  [Go] whitelist AdditionalProperties in the field name (#6543)
  [kotlin][client] remove tabs usage (#6526)
  [PS] automatically derive discriminator mapping for oneOf/anyOf  (#6542)
  [C++][Ue4] various bus fixes (#6539)
  Fix incorrect npx command (#6537)
  update pester to 5.x (#6536)
  comment out openapi3 java jersey2-java8 tests
  add additional properties support to powershell client generator (#6528)
  [Go][Experimental] Support additionalProperties (#6525)
  #5476 [kotlin] [spring] fix swagger and spring annotation for defaultValue (#6101)
  [samples] regenerate (#6533)
  [python] Fix date-time parsing (#6458)
  Register OAuth2ClientContext as bean (#6172)
  [Go][Experimental] Fix discriminator lookup (#6521)
  Typescript-rxjs: print param name (#6368)
  add oneof discrimistrator lookup to go experimental (#6517)
  ...
@huehnerlady
Copy link

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

jimschubert added a commit that referenced this issue Jun 6, 2020
* master:
  Fix typescript generator for parameter collectionFormat for pipes ssv (#6553)
  [C++][Pistache] Catch HttpError from user-provided handler (#6520)
  remove scala related profile from the pom (#6554)
  move ruby tests to travis (#6555)
  [Java][jersey2] fix cast error for default value in DateTimeOffset object (#6547)
  [Swift] fix GET request with array parameter (#6549)
  [kotlin][spring] Fix ApiUtil compilation (#6084)
  update python samples
  [Python] Fixed docstrings in api.mustache (#6391)
  [BUG][python] Support named arrays (#6493)
  [Go] whitelist AdditionalProperties in the field name (#6543)
  [kotlin][client] remove tabs usage (#6526)
  [PS] automatically derive discriminator mapping for oneOf/anyOf  (#6542)
  [C++][Ue4] various bus fixes (#6539)
  Fix incorrect npx command (#6537)
  update pester to 5.x (#6536)
  comment out openapi3 java jersey2-java8 tests
  add additional properties support to powershell client generator (#6528)
  [Go][Experimental] Support additionalProperties (#6525)
  #5476 [kotlin] [spring] fix swagger and spring annotation for defaultValue (#6101)
@jimschubert
Copy link
Member

@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).

@huehnerlady
Copy link

@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 :)

@huehnerlady
Copy link

@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

denniseffing added a commit to codecentric/habitcentric that referenced this issue Jan 18, 2022
We deliberately use v4.2.1 because v4.2.3 generates code that does not
compile.

See OpenAPITools/openapi-generator#5476
@shrralis
Copy link

Hey!
The same Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver error pops up for nullable enums
A part of my OpenAPI spec:

...
  /oauth2/token:
    post:
      tags:
      - authorization-server-endpoints
      parameters:
      - name: Authorization
        in: header
        schema:
          type: string
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                grant_type:
                  type: string
                  enum:
                  - authorization_code
                  - refresh_token
                  - client_credentials
...

The generated code:

fun oauth2TokenPostRequestConfig(authorization: kotlin.String?, grantType: GrantTypeOauth2TokenPost?, code: kotlin.String?, redirectUri: kotlin.String?, refreshToken: kotlin.String?, scope: kotlin.String?, clientId: kotlin.String?, clientSecret: kotlin.String?, clientAssertionType: kotlin.String?, clientAssertion: kotlin.String?, additionalParameters: kotlin.collections.Map<kotlin.String, kotlin.String>?) : RequestConfig<Map<String, PartConfig<*>>> {
        val localVariableBody = mapOf(
            "grant_type" to PartConfig(body = grantType.value, headers = mutableMapOf()), // <-- the problem in this line, `grantType?.value` should be
            "code" to PartConfig(body = code, headers = mutableMapOf()),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants