swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.94k stars 6.03k forks source link

Java: 0 Warnings for generated code #6678

Open jfiala opened 6 years ago

jfiala commented 6 years ago
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?

jfiala commented 6 years ago

@wing328 what do you think of this?