How can I prevent openapi-generator
from using wildcard imports like import javax.validation.constraints.*;
in Java?
This import is used in every class of a specified REST API in which the keyword required
is used for a property. For example in this snipped:
...
components:
schemas:
SimpleRequest:
description: Simple request with a required property.
type: object
required:
- requestID
properties:
requestID:
type: string
...
Here the generated java code has a class for the object SimpleRequest which has the property requestID which can't be Null.
This is indicated by a @NotNull
above the field in the generated code. Instead of using the wildcard import, the generator could have used this import intead: import javax.validation.constraints.NotNull;
By default, the code is generated based on the default templates defined for each languages. For java, you can find the template file used to generate the model DTO here.
Since wild card import is mentioned in [1], the code is generated accordingly. You can customize the template files and configure it with the parameter -
templateDirectory
, when generating the code.[1] https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/model.mustache#L36