swagger-api / swagger-api/swagger-codegen

Java: 0 Warnings for generated code

Open
#6,678 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Currently the generated Java files reference imports that are not used, resulting in compiler warnings.

e.g. for Java jaxrs-cxf Models:

import java.io.File; // Warning e.g. in Models
import io.swagger.model.HelloModel;

import java.io.InputStream; // Warning e.g. in Models
import java.io.OutputStream; // Warning e.g. in Models
import java.util.List; // Warning e.g. in Models
import java.util.Map; // Warning e.g. in Models
import javax.ws.rs.*;
import javax.ws.rs.core.Response; // Warning e.g. in Models
Swagger-codegen version

master

Suggest a fix/enhancement

The quick fix would be to use more generalized imports like :

import java.io.*;
import javax.ws.rs.*;
import javax.ws.rs.core.*;

Alternatively or supplementing this, we could use a routine to automatically cleanup the unused imports after generating the code?

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 locating the Java jaxrs-cxf templates responsible for generated Models and inspecting how their imports are assembled. Compare the generated imports with the types each file uses, then determine how to verify the result through generation and Java compilation checks. Done means generated Java files no longer produce warnings for unused imports.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.