OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
22.02k stars 6.61k forks source link

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

Open turneand opened 1 year ago

turneand commented 1 year ago

Bug Report Checklist

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.

altro3 commented 3 months ago

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