[BUG][Java Spring OAS3] Openapi 2 imports in oas3 mode in the POJOs
Created by: whydoievenneedthis
Description
Every POJO that is generated contains the following two imports in it:
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
openapi-generator version
5.3.1
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Api Documentation
description: Api Documentation
termsOfService: urn:tos
contact: {}
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0
version: '1.0'
paths:
/thingy:
get:
operationId: get
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ResponseList'
components:
schemas:
ResponseList:
type: array
items:
$ref: '#/components/schemas/ResponseEntry'
ResponseEntry:
type: object
properties:
id:
type: string
format: uuid
name:
type: string
Generation Details
Generator name: spring Config options: oas3 = true
Generated java code for ResponseEntry class
import java.net.URI;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.UUID;
import java.time.OffsetDateTime;
import javax.validation.Valid;
import javax.validation.constraints.*;
import io.swagger.v3.oas.annotations.media.Schema;
...
Expected java code for ResponseEntry class
import java.net.URI;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import java.util.UUID;
import java.time.OffsetDateTime;
import javax.validation.Valid;
import javax.validation.constraints.*;
import io.swagger.v3.oas.annotations.media.Schema;
...
Additional info
The source of these two imports are the model.mustache
file, particularly these lines:
{{#imports}}import {{import}};
{{/imports}}
Unfortunately, these are also pulling in other imports, eg.
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
As a result, it is not trivial to try and circumvent this particular bug by tweaking the mustache files.