openapi-generator: [BUG] Missing dependencies in java generator

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What’s the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What’s the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

When I try to run the generated gradle, some dependencies are missing. I get some errors like the following:

/path/File.java:xx: error: package org.openapitools.jackson.nullable does not exist
import org.openapitools.jackson.nullable.JsonNullableModule;

Which is solved by adding the following line to the dependencies section:

    compile "org.openapitools:jackson-databind-nullable:0.2.1"

This is the configuration of the gradle task that generates the failing gradle script:

task openApiJavaClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
    generatorName = "java"
    inputSpec = specFile
    outputDir = generatedSubproject
    invokerPackage = "com.foo"
    modelPackage = "com.foo"

    configOptions = [
                      dateLibrary    : "java8",
                      library        : "native",
                      artifactId     : "java-api-client",
                      artifactVersion: project.version,
                      java8          : "true",
    ]
    systemProperties = [
            modelDocs: "false"
    ]
}

javadoc {
    failOnError = false
}

jar.dependsOn tasks.openApiJavaClient
openapi-generator version

4.2.3

OpenAPI declaration file content or url

N/A

Command line used for generation

./gradlew clean build

Steps to reproduce

./gradlew clean build

Related issues/PRs

It seems this issue was fixed in v4.1.2 but it happens again in v4.2.3:

https://github.com/OpenAPITools/openapi-generator/pull/3793

Suggest a fix

N/A

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 9
  • Comments: 18 (10 by maintainers)

Most upvoted comments

@black-snow I’ve filed https://github.com/OpenAPITools/openapi-generator/pull/7777 to fix the missing dependency issue in Java webclient client

@gausnes : In fact, it is more than that.

The may objective of #2901 was to remove a jar (and also all associated imports) from the generated code. When I made this PR, I ensure that all dependencies was properly in the classpath (pom.xml or build.gradle) when you enable the property openApiNullable. In this case, I noticed that the dependencies were missing and I added.

In the future release of openapi-generator (the 5.0.0), this should be fix.

I’m seeing this issue using 4.3.1. Was able to resolve by manually adding the respective dependency to the classpath.

#2901 appears to just be cleaning up this import is not used. Model generation is still failing if properties are flagged with nullable: true

I also encountered the same issue with OpenAPI generator v4.3.0 in a Spring Boot project. It could be reproduced by using the Pet API and the following plugin configuration:

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>4.3.0</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
                <generatorName>spring</generatorName>
                <configOptions>
                    <sourceFolder>src/gen/java/main</sourceFolder>
                    <interfaceOnly>true</interfaceOnly>
                    <java8>true</java8>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

So the same issue also applies to spring generator. I would be happy to create a separate bug report if needed.