OpenAPITools / OpenAPITools/openapi-generator

[BUG][kotlin-server][jaxrs-spec] Model classes don't use jakarta package when `useJakartaEe` is true

Open
#15,617 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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 https://github.com/OpenAPITools/openapi-generator/pull/15618 to fix this issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the kotlin-server generator with the supplied OpenAPI YAML and the jaxrs-spec, useBeanValidation, and useJakartaEe options. Inspect the generated CreateLocation model imports; done means validation imports use jakarta.validation rather than javax.validation. The issue references PR #15618, so check that work before starting.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.