-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
ACTUAL:
@lombok.Data
@lombok.NoArgsConstructor
@lombok.AllArgsConstructor
@generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2025-12-04T00:18:24.316599800+01:00[Europe/Madrid]", comments = "Generator version: 7.17.0")
public class UserDto {
private Integer id;
private String username = "anonymous";
}
Expected something like this:
@DaTa
@NoArgsConstructor
@AllArgsConstructor
@generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2025-12-04T00:12:38.229297500+01:00[Europe/Madrid]", comments = "Generator version: 7.17.0")
public class UserDto {
@NotNull
@min(value = 1)
@max(value = 100)
@Schema(name = "id", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@JsonProperty("id")
private Integer id;
@SiZe(min = 3, max = 20)
@Schema(name = "username", example = "user", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("username")
private String username = "anonymous";
}
Description
After adding @lombok.Data; @lombok.NoArgsConstructor; @lombok.AllArgsConstructor;
(or /@Getter instead of Data)
The getters get removed as expected, but since the validation is made on those, the @min,@max...etc, gets overriden.
openapi-generator version
1.17.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: TEST API
version: 1.0.0
servers:
- url: http://localhost
paths:
/users:
get:
tags:
- users
summary: Obtener todos los usuarios
responses:
'200':
description: Lista de usuarios
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/UserDto'
operationId: getAllUsers
components:
schemas:
UserDto:
type: object
properties:
id:
type: integer
example: 1
minimum: 1
maximum: 100
username:
type: string
example: "user"
default: "anonymous"
minLength: 3
maxLength: 20
required:
- id
Generation Details
Steps to reproduce
Simplified .pom with what i think is all the needed information.
<properties>
<springVersion>3.3.0</springVersion>
<java.version>21</java.version>
<openapi-generator.version>7.17.0</openapi-generator.version>
<contract.package>com.example</contract.package>
<openapi.contract>${project.basedir}/contract/main.yaml</openapi.contract>
<swagger.apiPackage>domain.api</swagger.apiPackage>
<swagger.modelPackage>domain.model</swagger.modelPackage>
</properties>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${openapi.contract}</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>${contract.package}.${swagger.apiPackage}</apiPackage>
<modelPackage>${contract.package}.${swagger.modelPackage}</modelPackage>
<invokerPackage>com.urnhinkoo.domain.invoker</invokerPackage>
<output>${project.basedir}/</output>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<sourceFolder>src/main/java</sourceFolder>
<useBeanValidation>true</useBeanValidation>
<useJakartaEe>true</useJakartaEe>
<openApiNullable>false</openApiNullable>
<skipDefaultInterface>true</skipDefaultInterface>
<interfaceOnly>true</interfaceOnly>
<!--@Getter can be used aswell to make this warning go away, but that would be annoying to use -->
<!--suppress UnresolvedMavenProperty -->
<additionalModelTypeAnnotations>@lombok.Data; @lombok.NoArgsConstructor; @lombok.AllArgsConstructor;</additionalModelTypeAnnotations>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Related issues/PRs
Suggest a fix
Validation should be on the field declarator, and not on the getMethod, so @DaTa works as expectted