Is there a way to generate source code with Jakarta instead Javax using swagger-codegen
Asked Answered
C

3

9

I need to generate spring controller source code using swagger codegen gradle plugin with Jakarta packages but I could not see an option in config to do so

I have tried to use below options to generate swagger code:

additionalProperties = [
                "errorOnUnknownEnum": true,
                "dateLibrary": "java8",
                "hideGenerationTimestamp": true,
                "modelPackage": "com.delphix.api.gw.model${version}",
                "apiPackage": "com.delphix.api.gw.api${version}",
                "interfaceOnly": true,
                "packageName": "api",
                "useTags": true,
                "useJakartaEe" : true,
                "useSpringBoot3" : true,
                "generateSupportingFiles" : false,
                "java11" : true,
        ]
Cristionna answered 15/2, 2023 at 5:37 Comment(0)
A
5

As @Raster R mentioned, setting <jakarta>true</jakarta> in configOptions of the plugin solves the issue. See this PR for more info.

Ascend answered 3/8, 2023 at 9:15 Comment(0)
I
1

Just faced with the same issue but hideGenerationTimestamp did the trick.

Gradle:

plugins {
    id "org.hidetake.swagger.generator" version "2.19.2"
}

implementation "io.swagger.core.v3:swagger-annotations"
swaggerCodegen "io.swagger.codegen.v3:swagger-codegen-cli"

Plugin:

additionalProperties = [
    modelPackage            : "<my-package>.models",
    apiPackage              : "<my-package>",
    dateLibrary             : 'java8',
    interfacesOnly          : 'true',
    hideGenerationTimestamp : 'true'
]
Ipecac answered 6/3, 2023 at 22:47 Comment(1)
I too had the same issue. I suppose it might get solved by migrating to openapi generator as suggested by @jeet427. I was able to make the codegenerator spewout jakarta code by using configOption of <jakarta>true</jakarta> But springfox in the generated code then caused some compatibility issues. springfox seems to be still on only javax. I didnt need springfox so removed it using maven-antrun-plugin. I would suggest try what jeet427 said. If needed try what I said as a fallback. I do see that you are using gradle which is quite different from maven that i based my experience on.Odette
S
0

I had the same problem, but using openapi-generator-cli instead of swagger-codegen-cli fixed it for me.

command line: npx @openapitools/openapi-generator-cli generate -i employees.yaml -g spring -c swaggerConfig.json -o out

swaggerConfig.json:

    {
    "library": "spring-boot",
    "useSpringBoot3": true,
    "useJakartaEe": true,
    "artifactId": "my-api",
    "groupId": "test",
    "apiPackage": "test.api",
    "modelPackage": "test.model",
    "basePackage": "test",
    "interfaceOnly": false,
    "java8": false,
    "javaVersion": "17",
    "useTags": true,
    "hideGenerationTimestamp": true
}   
Sheffield answered 14/6, 2024 at 3:36 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.