[BUG][Micronaut] When using micronaut_serde_jackson against unique arrays, JsonDeserialize is added to imports
Bug Report Checklist
- [X] Have you provided a full/minimal spec to reproduce the issue?
- [X] Have you validated the input using an OpenAPI validator (example)?
- [X] Have you tested with the latest master to confirm the issue still exists?
- [X] Have you searched for related issues/PRs?
- [X] What's the actual output vs expected output?
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generating code using "java-micronaut-server" (or java-micronaut-client) and micronaut_serde_jackson as the serialization library, against an openapi spec that contains a component with a unique array, the generated code includes an import for "com.fasterxml.jackson.databind.annotation.JsonDeserialize" that will fail compilation (as using micronaut-serialization instead of jackson).
Note, that for non-unique lists, the code generates correctly and this additional import is NOT present.
openapi-generator version
org.openapitools#openapi-generator-maven-plugin#7.0.0
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: Hello
version: '1.0'
paths:
/getStuff:
get:
operationId: getStuff
responses:
default:
description: something
content:
application/json:
schema:
type: array
uniqueItems: true
items:
$ref: '#/components/schemas/Simple'
components:
schemas:
Simple:
type: object
properties:
list:
type: array
uniqueItems: true
items:
type: string
Generation Details
See maven pom.xml snippet below, and yaml spec file above.
Steps to reproduce
Given above yaml file, execute the following maven plugin:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.0.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/server.yaml</inputSpec>
<generatorName>java-micronaut-server</generatorName>
<configOptions>
<serializationLibrary>micronaut_serde_jackson</serializationLibrary>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
This then generates the model file that includes the following import statement:
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Related issues/PRs
The original work for removing jackson for Micronaut was done under https://github.com/OpenAPITools/openapi-generator/pull/14065
Suggest a fix
Not sure on this, but ... I believe this import is being added in AbstractJavaCodegen but should be removed later if unused, such as in JavaClientCodegen.java (although not sure why it has the "set".equals(..)" part.
Already fixed.
Just use official micronaut generator for java and kotlin by micronaut-opeanpi gradle or maven plugin from this repo: https://github.com/micronaut-projects/micronaut-openapi
Look to this guide: https://guides.micronaut.io/latest/micronaut-openapi-generator-server.html
Also, please describe problems and suggestions here: https://github.com/micronaut-projects/micronaut-openapi/issues