Skip to content

Use annotation for generated code instead of comment #144

Closed

Description

@aburmeis

It would be useful to have a javax.annotation.Generated annotation for each generated class instead of the current code comment header. This would prevent generated code from multiple scanning jobs out of the box (like spotbugs and jacoco) instead of additional tool configurations to prevent this.

Filling the date() of the annotation should be configurable (options.suppress-generator-timestamp: true) so generated classes would not differ without API changes.

Activity

  1. hauner commented on Aug 12, 2022

    @hauner
    Member

    I can add something like this but I would like to understand where the benefit is. :-)

    I looked at it in the past and decided against it because I didn't really see the benefit in it (I probably didn't investigate very much) and because it is an annotation processing specific annotation. It doesn't seem to be a general annotation for generated code.

    With a quick search I found the following issues and it looks like spotbugs/jacoco do/can not use that information:

    spotbugs/spotbugs#464
    jacoco/jacoco#831

    Looking at this

    https://stackoverflow.com/questions/47824761/how-would-i-add-an-annotation-to-exclude-a-method-from-a-jacoco-code-coverage-re

    jacoco ignores code annotated with any Generated annotation that has runtime retention.

    To support this we would need a configurable annotation. That should be easy. Configuring parameters for it would be more interesting... ;-)

  2. aburmeis commented on Aug 15, 2022

    @aburmeis
    Author

    You are right, Lombok has its own annotation with runtime retention. So openapi-processor could follow this approach and offer its own annotation to make such tool integration easier (I don't think it should allow any external annotation to be used). By doing so, replacing the comment is less useful and could be skipped.

    (Btw, I had the wrong annotation package in the original comment, sorry)

  3. hauner commented on Aug 16, 2022

    @hauner
    Member

    yes, guess we need our own @Generated annotation with retention runtime (class may work too).

    should it generate {package-name}.Generated or a use a common package name io.openapiprocessor.annotation.Generated.

    I think I prefer the first variation.

    Parameters would be similar to javax @Generated: value (generator) and date and a fixed comment. This could replace the header comment (ah, that would require an update all the integration tests... ;-).

  4. added this to the core: next milestone on Aug 22, 2022
  5. modified the milestones: core: next, 2022.5 on Aug 30, 2022
  6. 2 remaining items

  7. hauner commented on Oct 13, 2022

    @hauner
    Member

    released with 2022.5

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions