openapi-processor/openapi-processor-spring

Use annotation for generated code instead of comment

aburmeis opened this issue · 4 comments

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.

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... ;-)

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)

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... ;-).

released with 2022.5