OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.87k stars 6.59k forks source link

[BUG] [spring] [server] 5.0.1 unused imports in generated interfaces #8776

Open lfischer opened 3 years ago

lfischer commented 3 years ago

Bug Report Checklist

Description

Generated API interfaces contain the following unused imports, which introduce unnecessary dependencies:

openapi-generator version

5.0.1

OpenAPI declaration file content or url

https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml

Generation Details
Steps to reproduce

file "springboot-options.json"

{
"basePackage":"io.swagger",
"configPackage":"io.swagger.config",
"parentGroupId":"org.springframework.boot",
"parentArtifactId":"spring-boot-starter-parent",
"parentVersion":"2.4.3",
"serverPort":9230,
"dateLibrary":"java8"
}

command line

java -jar ./openapi-generator-cli-5.0.1.jar generate -g spring -i petstore.yaml -o server\springboot\openapi -c springboot-options.json

Example: imports within generated file UserApi

package org.openapitools.api;

import java.util.List;
import org.openapitools.model.User;
import io.swagger.annotations.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;
Related issues/PRs
Suggest a fix

Remove imports of springfox.documentation.annotations.ApiIgnore and data.domain.Pageable within the api interfaces, as they are not used and not needed.

auto-labeler[bot] commented 3 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

piotrpolak commented 3 years ago

I am facing the same issue after upgrading from 4.2.3.

I explicitly disabled useSpringfox in my configuration but no luck:

{
  // ...
  "useSpringfox": false,
  "reactive": false
}
morphlne commented 3 years ago

This issue described earlier in https://github.com/OpenAPITools/openapi-generator/issues/8360

flabbamann commented 3 years ago

Seems to be fixed in 5.3.0