Skip to content

[REQ] Add @Generated annotation to EnumConverterConfiguration for JavaSpring generator #23923

Closed

Description

@jorgerod

Is your feature request related to a problem? Please describe.

When using the spring generator (JavaSpring), the supporting file EnumConverterConfiguration.java is generated without the @Generated annotation. All other generated files (models, API interfaces, delegate interfaces, etc.) are correctly annotated with @Generated via the generatedAnnotation partial. This inconsistency means tools that use @Generated to skip static analysis, formatting, or coverage checks (e.g., Checkstyle, JaCoCo, SonarQube) will incorrectly process EnumConverterConfiguration as hand-written code.

Describe the solution you'd like

Update modules/openapi-generator/src/main/resources/JavaSpring/converter.mustache to include:

  1. The jakarta.annotation.Generated import (using {{javaxPackage}}):

    import {{javaxPackage}}.annotation.Generated;
  2. The {{>generatedAnnotation}} partial before the class declaration, consistent with pojo.mustache, api.mustache, etc.:

    {{>generatedAnnotation}}
    
    @Configuration(value = "{{configPackage}}.enumConverterConfiguration")
    public class EnumConverterConfiguration {

The resulting generated file would look like:

import jakarta.annotation.Generated;
// ...

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", ...)
@Configuration(value = "com.example.config.enumConverterConfiguration")
public class EnumConverterConfiguration {
    // ...
}

Describe alternatives you've considered

  • Overriding converter.mustache locally in each project — works but requires every consumer to maintain a copy and track upstream changes manually.

Additional context

  • The issue affects at least the JavaSpring generator (spring generator name). Other generators with a similar converter.mustache (e.g., java-micronaut-server) may be affected too.
  • pojo.mustache, api.mustache, and apiDelegate.mustache all already use {{>generatedAnnotation}} as a reference for the correct pattern.
  • generatedAnnotation.mustache (the partial) already exists and handles the hideGenerationTimestamp flag correctly.

Activity

  1. jorgerod commented on Jun 2, 2026

    @jorgerod
    ContributorAuthor

    Why this matters: static analysis tools skip @Generated code

    Tools like SonarQube, JaCoCo, Checkstyle, and SpotBugs have built-in support to automatically exclude classes annotated with @Generated from their analysis. This is the intended mechanism for distinguishing generated code from hand-written code.

    Without @Generated on EnumConverterConfiguration, these tools treat it as regular source code, which leads to:

    • SonarQube: reports issues (code smells, coverage gaps) on code that developers cannot and should not modify.
    • JaCoCo: counts uncovered lines in EnumConverterConfiguration against the project's coverage threshold, potentially failing the build for code that is not hand-written.
    • Checkstyle / formatting tools: flag style violations in generated code, forcing projects to add explicit exclusion rules for this specific file.

    Adding @Generated aligns EnumConverterConfiguration with all other generated files and allows these tools to correctly ignore it out of the box, without requiring per-project workarounds.

  2. Chrimle commented on Jul 2, 2026

    @Chrimle
    Contributor

    Yep, known issue: #23832 #23863
    It's a hassle to implement, due to how many java generators there are...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions