Remove @Generated annotations when using the OpenAPI client generator

The OpenAPI Generator can generate a Java client based on an OpenAPI spec. Super useful for integrating with any sort of REST(-ish) API. I typically check in the generated client, in part because generation can take a while, but also because I like being able to track changes in the generated code.

Unfortunately, the generated code contains some unnecessarily verbose metadata, which make it harder to diff the code cleanly.

@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2025-06-19T16:23:34.186622362+01:00[Germany/Berlin]", comments = "Generator version: 7.13.0")
public class FooResponse {
// ...

I don’t particularly mind the presence of @Generated in and of itself. My issue is with the timestamp and the generator version. The timestamp can actually be disabled using a generator option (hideGenerationTimestamp), but the version cannot.

The solution

Getting rid of the entire annotation requires overriding/overwriting one of the templates the generator uses internally, in this case the file generatedAnnotation.mustache. You can find the original file here.

  1. Create a template folder somewhere in your source structure (I used src/openapi/template)
  2. Create an empty file called generatedAnnotation.mustache in that directory
  3. Tell the maven generator plugin to use the templates directory
<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>7.13.0</version>
    <configuration>
        <templateDirectory>${project.basedir}/src/openapi/template</templateDirectory>
        <generatorName>java</generatorName>
        <library>native</library>
        <!-- ... more stuff -->
    </configuration>
</plugin>

The next time the generator runs, the @Generated annotation will be gone. Yay for clean diffs!

Of course, the same thing applies to all the other templates. However, if you’re going to make significant changes, e.g. by renaming generated methods, you may have to edit multiple templates to keep things consistent. In that case, a custom generator might be a better option. Baeldung has you covered.

— Elric