Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Micronaut] Improving micronaut-model and micronaut-client generation #14065

Merged
merged 4 commits into from Nov 25, 2022

Conversation

DmitryKubahov
Copy link
Contributor

@DmitryKubahov DmitryKubahov commented Nov 18, 2022

These improvements are related only to the java-micronaut generator.

Model generating change:

  • Adding a new parameter serializationLibrary. Right now it contains only 2 values: jackson and micronaut_serde_jackson. Jackson is the default one and does not change anything. micronaut_serde_jackson - Micronaut Serialization with support of jackson annotation. This library supports not all jackson annotations feature - limitation.

Client generating change:

  • new additionalClientTypeAnnotations parameter. As micronaut-client generator will declarative http client and it is really nice to have the opportunity to add custom/additional annotations to it.

@andriy-dmytruk please, take a look.

@DmitryKubahov DmitryKubahov changed the title improving micronaut model and micronaut-client generation Improving micronaut-model and micronaut-client generation Nov 18, 2022
@DmitryKubahov DmitryKubahov marked this pull request as draft November 18, 2022 14:21
@DmitryKubahov DmitryKubahov marked this pull request as ready for review November 18, 2022 14:57
@DmitryKubahov DmitryKubahov changed the title Improving micronaut-model and micronaut-client generation [Micronaut] Improving micronaut-model and micronaut-client generation Nov 18, 2022
@andriy-dmytruk
Copy link
Contributor

Hi @DmitryKubahov. Thank you for the PR. Implementation looks good.

Could you also take a look at these annotations unsupported by micronaut serialization: micronaut-projects/micronaut-serialization#286. These seem to have pretty simple fixes related to your PR:

  • The @JsonTypeInfo annotation is created in the common/model/typeInfoAnnotation.mustache and needs the removal of , visible=true.
  • The @JsonDeserialize is added in the AbstractJavaCodegen with the x-setter-extra-annotation parameter:
    if ("set".equals(property.containerType)) {
                  model.imports.add("LinkedHashSet");
                  boolean canNotBeWrappedToNullable = !openApiNullable || !property.isNullable;
                  if (canNotBeWrappedToNullable) {
                      model.imports.add("JsonDeserialize");
                      property.vendorExtensions.put("x-setter-extra-annotation", "@JsonDeserialize(as = LinkedHashSet.class)");
                  }
              }
    
    We could fix this in the common/model/pojo.mustache file by putting this block
    {{#vendorExtensions.x-setter-extra-annotation}}
        {{{vendorExtensions.x-setter-extra-annotation}}}  
    {{/vendorExtensions.x-setter-extra-annotation}}
    
    inside the {{#jackson}} block above.

@andriy-dmytruk
Copy link
Contributor

It would also be beneficial to change the build.gradle and pom.xml mustache files to include the serialization-jackson feature as dependency similar to how micronaut launcher does it.

Changes would need to include the following:

@DmitryKubahov Could you take a look at that? Use the OpenAPI generator slack if you need to discuss anything with me.

dmitry.kubakhov added 3 commits November 21, 2022 08:58
@DmitryKubahov
Copy link
Contributor Author

@andriy-dmytruk I made all the changes according to your comments, please, check them.

@andriy-dmytruk
Copy link
Contributor

Thanks @DmitryKubahov. LGTM
@wing328 Could you please merge?

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

Successfully merging this pull request may close these issues.

None yet

3 participants