meldevep
meldevep

Reputation: 880

Is there a way to configure openapi-generator to use jakarta package during generation

I've recently upgraded my project to use spring-boot 3.0.0. So I don't have javax.* modules in the project anymore. But the Open API generator keeps trying to import javax modules. Especially, it uses javax.annotation.Generated for the @Generated annotation which is not present in the project anymore. Is there a way to reconfigure it somehow?

Upvotes: 72

Views: 62593

Answers (4)

Nawaz Shareef
Nawaz Shareef

Reputation: 1

You can add a tag to solve this issue i was facing the same issue when i was migrating my app from SB-2 to SB-3. Kindly see the screen shot attached enter image description here

Kindly follow the documentation for better understanding: https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin

Upvotes: 0

Ikomyon
Ikomyon

Reputation: 49

I use openapi-generator generate command and adding options that

--additional-properties=useSpringBoot3=true

also worked. Here is the reference: https://openapi-generator.tech/docs/generators/spring/

Upvotes: 2

sashok_bg
sashok_bg

Reputation: 2971

You should follow the documentation whenever possible.

The property that you need is either "useSpringBoot3" or "useJakartaEe"

  1. Go to https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin

  2. At the end of the table you see "configHelp" property which will give you configs for the current generator "spring" in my case

  3. Rerun "mvn clean install" - this will give you a list of available "configOptions".

  4. Read the list and found a property

    useJakartaEe: whether to use Jakarta EE namespace instead of javax (Default: false)

My final pom:

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>6.4.0</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <configHelp>false</configHelp>
                <configOptions>
                    <useJakartaEe>true</useJakartaEe>
                </configOptions>
                <inputSpec>
                    ${project.basedir}/src/main/resources/api.openapi.yaml
                </inputSpec>
                <generatorName>spring</generatorName>
                <apiPackage>some.package</apiPackage>
                <modelPackage>some.package.model</modelPackage>
            </configuration>
        </execution>
    </executions>
</plugin>

Cheers

Upvotes: 52

Shaki
Shaki

Reputation: 557

Yes, you can use useSpringBoot3: "true" in your configoptions of the generator. Example in gradle:

        configOptions = [
            useSpringBoot3: "true"
        ]

Upvotes: 54

Related Questions