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

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

Closed
5 of 6 tasks
ripdajacker opened this issue Jan 26, 2024 · 0 comments · Fixed by #17716
Closed
5 of 6 tasks

Comments

@ripdajacker
Copy link
Contributor

ripdajacker commented Jan 26, 2024

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.

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