Skip to content

[BUG] [Java] Deprecation and serial warnings in JSON.java and ApiException.java when generating using native #17715

@ripdajacker

Description

@ripdajacker

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

Using the native Java generator with a new-enough jackson fails our build because of deprecation warnings in JSON.java:

[WARNING] COMPILATION WARNING : 
[INFO] -------------------------------------------------------------
[WARNING] /redacted/rest/client/ApiException.java:[19,7] [serial] serializable class ApiException has no definition of serialVersionUID
[WARNING] /redacted/rest/client/JSON.java:[21,10] [deprecation] configure(MapperFeature,boolean) in ObjectMapper has been deprecated

The JSON.java problem seems to have been fixed in jersey2 and jersey3 so it's an easy fix.

The serial warnings can be fixed with a one-liner in apException.mustache:

private static final long serialVersionUID = 1L;

The serial warning impacts most of the Java generators except microprofile, which declares a serialVersionUID.

openapi-generator version

7.2.0 but the issue is also on the newest master.

OpenAPI declaration file content or url
{
  "openapi": "3.0.3",
  "info": {
    "version": "1.0.0",
    "description": "Spec to show serial and deprecation warnings",
    "title": "Minimal example"
  },
  "paths": {
    "/whatever": {
      "get": {
        "operationId": "operation",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "field": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "model1": {
        "type": "object",
        "properties": {
          "field": {
            "type": "string"
          }
        }
      }
    }
  }
}
Generation Details

Generated using mvn compile.

Steps to reproduce

I have this pom.xml that reproduces it:

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>openapi-deprecation-serial</artifactId>
  <packaging>jar</packaging>
  <version>1.0.0</version>

  <dependencies>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.16.1</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.datatype</groupId>
      <artifactId>jackson-datatype-jsr310</artifactId>
      <version>2.16.1</version>
    </dependency>
    <dependency>
      <groupId>jakarta.annotation</groupId>
      <artifactId>jakarta.annotation-api</artifactId>
      <version>2.1.1</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.12.1</version>
        <configuration>
          <showWarnings>true</showWarnings>
          <compilerArgs>
            <arg>-Xlint:all</arg>
            <arg>-Xlint:-processing</arg>
            <arg>-Xlint:-options</arg>
            <arg>-Werror</arg>
          </compilerArgs>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>7.2.0</version>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <apiNameSuffix>Client</apiNameSuffix>
              <inputSpec>${project.basedir}/openapi.json</inputSpec>
              <generatorName>java</generatorName>

              <apiPackage>com.example.rest.client.api</apiPackage>
              <generateApiTests>false</generateApiTests>
              <generateApiDocumentation>false</generateApiDocumentation>

              <modelPackage>com.example.rest</modelPackage>
              <generateModelTests>false</generateModelTests>
              <generateModelDocumentation>false</generateModelDocumentation>

              <configOptions>
                <annotationLibrary>none</annotationLibrary>
                <library>native</library>
                <serializationLibrary>jackson</serializationLibrary>
                <useJakartaEe>true</useJakartaEe>
                <openApiNullable>false</openApiNullable>
                <supportUrlQuery>false</supportUrlQuery>
              </configOptions>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
Related issues/PRs

#17716

Suggest a fix

Fixed in the linked PR.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions