Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use javax.annotation.processing.Generated for Java 11 native client #3637

Merged
merged 1 commit into from
Aug 15, 2019

Conversation

bbdouglas
Copy link
Contributor

@bbdouglas bbdouglas commented Aug 13, 2019

Before Java 9, the Generated annotation was part of JEE and in the
javax.annotation package. Starting with Java 9, it is now part
of the standard SDK, under the new javax.annotation.processing
package.

This change creates a custom Generated annotation template for the
native clientlib, since it is guaranteed to be run in Java 11+.

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

Adds a new custom generatedAnnotation.mustache template for the native HttpClient library with the correct Generated package name for Java 9+.

Fixes #3636

Before Java 9, the `Generated` annotation was part of JEE and in the
`javax.annotation` package. Starting with Java 9, it is now part
of the standard SDK, under the new `javax.annotation.processing`
package.

This change creates a custom Generated annotation template for the
native clientlib, since it is guaranteed to be run in Java 11+.
@bbdouglas
Copy link
Contributor Author

CC @cbornet @jeff9finger @karismann @Zomzog Java technical committee

@macjohnny as reviewer of #3434 that introduced this new generator.

This is meant to address bug #3636

Copy link
Contributor

@jeff9finger jeff9finger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@macjohnny
Copy link
Member

@bbdouglas where/how is this file included/referenced?

@jmini
Copy link
Member

jmini commented Aug 14, 2019

@macjohnny:

This is with usage of {{>generatedAnnotation}} in the templates.


But you are right, when this construct is used, inside Java/pojo.mustache:

{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}

Then I think that Java/generatedAnnotation.mustache is used and not Java/libraries/native/generatedAnnotation.mustache even if you are generating the native client.

So I guess this PR does not really work.

@bbdouglas
Copy link
Contributor Author

@macjohnny @jmini As you rightly pointed out, this is referenced in pojo.mustache. I do believe that this PR is working, as I have tested it locally. Unfortunately, the checked-in samples have the timestamp omitted, so it can't be checked there.

I remember looking this up before, and there is a hierarchy of file locations that are searched when looking for a mustache file. First it tries the library directory, and if it doesn't exist there, it backs off to the general Java directory. That's how I can have my own custom pom.mustache file, for example. I can't remember where I saw the code that does the mustache file locating, though, so let me see if I can find it.

@macjohnny macjohnny merged commit eb6ca91 into OpenAPITools:master Aug 15, 2019
@jmini
Copy link
Member

jmini commented Aug 15, 2019

I can't remember where I saw the code that does the mustache file locating, though, so let me see if I can find it.

The place I know is:

public String getFullTemplateFile(CodegenConfig config, String templateFile) {

But I thought this is not used when a template calls an other template.

@jmini jmini added this to the 4.1.1 milestone Aug 15, 2019
@bbdouglas bbdouglas deleted the javax_annotation branch August 21, 2019 06:04
@wing328
Copy link
Member

wing328 commented Aug 26, 2019

@bbdouglas thanks for the PR, which has been included in the v4.1.1 release: https://twitter.com/oas_generator/status/1165944867391860737

@evanlott
Copy link

evanlott commented Jan 4, 2020

Does this issue still exist? I have tried plugin versions 4.2.2 and 4.1.3 and keep getting javax.annotation.Generated in my gen'd server stubs. Was the solution not carried over to versions beyond 4.1.1 or something? Perhaps I'm not using the solution correctly, like maybe missing a config option?

Edit: I see now that I just need to specify the hideGenerationTimestamp=true in my configOptions. Disregard my comment :)

@dmitry-weirdo
Copy link

dmitry-weirdo commented Jun 22, 2020

Still not clear how to use it.

When I add

                            <configOptions>
                                <hideGenerationTimestamp>true</hideGenerationTimestamp>
                            </configOptions>

, no @Generated annotation is generated at all.

Can you please explain how to set up the custom annotation? AFAIU, I have to somehow override generatedAnnotation.mustache within the generator that I am using (namely jaxrs-jersey).

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG][Java][native] Wrong Generated annotation package for Java 9+
7 participants