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][kotlin-server][jaxrs-spec] Model classes don't use jakarta package when useJakartaEe is true #15617

Open
5 of 6 tasks
gdiegel opened this issue May 23, 2023 · 6 comments

Comments

@gdiegel
Copy link

gdiegel commented May 23, 2023

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

Model classes generated with the combination of kotlin-server generator and jaxrs-spec library don't import jakarta packages when the config option useJakartaEe is set to true.

Actual result
import javax.validation.constraints.*
import javax.validation.Valid

data class CreateLocation (

    @JsonProperty("name")
    @field:Valid
    @field:NotNull
    @field:Size(min=1,max=512) val name: kotlin.String,
Expected result
import jakarta.validation.constraints.*
import jakarta.validation.Valid

data class CreateLocation (

    @JsonProperty("name")
    @field:Valid
    @field:NotNull
    @field:Size(min=1,max=512) val name: kotlin.String,
openapi-generator version

6.6.0

OpenAPI declaration file content or url
openapi: "3.0.1"
info:
  title: example
  version: "1.0"
paths:
  /locations:
    post:
      operationId: createLocation
      tags:
        - location
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateLocation'
      responses:
        '201':
          description: Success
components:
  schemas:
    CreateLocation:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          nullable: false
          minLength: 1
          maxLength: 512
Generation Details
val runOpenApiCodeGenerator = tasks.register<GenerateTask>("runOpenApiCodeGenerator") {
    generatorName.set("kotlin-server")
    inputSpec.set(project.property("openapi.spec") as String)
    outputDir.set("$buildDir/openapi")
    templateDir.set("$rootDir/src/main/resources/openapi/templates")
    apiPackage.set("com.leagueapps.openapi.api")
    modelPackage.set("com.leagueapps.openapi.model")
    typeMappings.set(
        mapOf(
            "DateTime" to "LocalDateTime"
        )
    )
    importMappings.set(
        mapOf(
            "java.time.OffsetDateTime" to "java.time.LocalDateTime"
        )
    )
    configOptions.set(
        mapOf(
            "library" to "jaxrs-spec",
            "useTags" to "true",
            "interfaceOnly" to "true",
            "useCoroutines" to "true",
            "useBeanValidation" to "true",
            "dateLibrary" to "java8",
            "enumPropertyNaming" to "UPPERCASE",
            "hideGenerationTimestamp" to "true",
            "useSwaggerAnnotations" to "false",
            "returnResponse" to "true",
            "useJakartaEe" to "true"
        )
    )
    generateApiTests.set(false)
    generateModelTests.set(false)
    generateApiDocumentation.set(false)
    generateModelDocumentation.set(false)
    outputs.upToDateWhen { false }
    outputs.cacheIf { false }
}
Steps to reproduce
Related issues/PRs
Suggest a fix

I've submitted PR #15618 to fix this issue.

@gdiegel
Copy link
Author

gdiegel commented May 24, 2023

This is very probably fixed with #15593.

@drohne1673
Copy link

drohne1673 commented Oct 25, 2023

says merged. but it looks like it still doesnt work with version 7.0.1 of the plugin.
i just tried in a quarkus app and the openapi-generator-maven-plugin 7.0.1: it still generates javax. Even after setting the configOptions
is it ?
"my solution" using microprofileRestClientVersion: "3.0" fixed my issue. the useJakartaEe option seems irrelevant.

@marcelstoer
Copy link
Contributor

I can confirm that this definitely works with 7.1.0. Issue should be closed I guess.

@JenniferKiesel
Copy link

This is only partly fixed. The config option useJakartaEe still produces this error, even though in our case we use the gradle plugin of the openapi generator (org.openapi.generator). It only works when setting as additionalProperties, which clashes with the documentation that says this would be only required for the CLI version.

@aaronjwhiteside
Copy link

This is only partly fixed. The config option useJakartaEe still produces this error, even though in our case we use the gradle plugin of the openapi generator (org.openapi.generator). It only works when setting as additionalProperties, which clashes with the documentation that says this would be only required for the CLI version.

This!

And I think the issue is that the code expects a Boolean vs a String, as

This works

    additionalProperties = mapOf(
        "useJakartaEe" to true
    )

But this doesn't

    additionalProperties = mapOf(
        "useJakartaEe" to "true"
    )

This had my scratching my head for a while.

@Frontrider
Copy link

I have a second error for it: the generated build file also has the wrong version of jakarta, at least updating it is what fixes intellij not recognizing the annotations.

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