OpenAPITools / OpenAPITools/openapi-generator

[BUG] Java: unnecessary imports in generated files?

Open
#8,016 0 comments 2 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

Description

OpenAPI Gradle plug-in (underlying generator) adds an unnecessary import:

import org.apache.cxf.jaxrs.ext.multipart.*;

when the Java configuration option "library" is set to "microprofile". Such imports are not needed - manually deleting them cause no compile errors.

openapi-generator version

5.0.0-SNAPSHOT

OpenAPI declaration file content or url

https://raw.githubusercontent.com/ory/kratos-client-java/master/api/openapi.yaml

Generation Details

I use the Gradle plugin, but I beleive the problem is in the core generator itself :

plugins {
    id 'org.openapi.generator'
}
openApiGenerate {
        generatorName = "java"
        inputSpec = "$rootDir/ory-kratos.yaml".toString() //get from the url above!
        outputDir = "$rootDir".toString()
        apiPackage = "kratos.api"
        invokerPackage = "kratos.invoker"
        modelPackage = "kratos.model"
        configOptions = [
                dateLibrary: "java8",
                java8: "true",
                library:"microprofile"
        ]
    }
Steps to reproduce

generate source code with the above configuration, see file kratos.api.AdminApi.java - the problematic import is there.

Related issues/PRs
Suggest a fix

Manually deleting the necessary import after each generation .

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 by reproducing generation with the supplied OpenAPI declaration, Gradle configuration, and library set to microprofile. Inspect the generated kratos.api.AdminApi.java and trace where its imports are produced. Done means the org.apache.cxf.jaxrs.ext.multipart.* import is no longer generated for this configuration without causing compilation errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.