OpenAPITools / OpenAPITools/openapi-generator

[BUG][Micronaut] When using micronaut_serde_jackson against unique arrays, JsonDeserialize is added to imports

Open
#16,527 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AbstractJavaCodegen.java near the import handling cited in the issue, then compare JavaClientCodegen.java where unused imports are removed. Reproduce with the supplied OpenAPI YAML and java-micronaut-server Maven configuration using micronaut_serde_jackson. Done means the generated model no longer imports com.fasterxml.jackson.databind.annotation.JsonDeserialize and the output compiles with Micronaut serialization.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
backend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.