OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA] regressions introduced by #17622 (lombok)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- 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?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
#17622 allows the use of lombok. It works for simple cases but I don't think it is production ready.
There are multiple regressions
- contraints not generated
- JsonProperty gone even if the property name is different than the field name
- javadoc not generated
- incorrect constructors and builders for inheritance
- toString is different (minor)
- x-setter-extra-annotation ignored ( x-extra-field-annotation works)
- probably other missing features : Optional,
@Valid...
openapi-generator version
7.3.0-SNAPHOT
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: lombok issues
description: lombok issues
version: 1.0.0
paths:
/testLombok:
get:
description: test
responses:
200:
description: 'response'
content:
application/json:
schema:
$ref: '#/components/schemas/LombokData'
components:
schemas:
ParentData:
type: object
properties:
type:
type: string
discriminator:
propertyName: type
LombokData:
allOf:
- $ref: '#/components/schemas/ParentData'
- type: object
properties:
extra-data:
description: 'This is an extra-data'
type: string
minLength: 10
Here the generated LombokData.java
@lombok.Data
@lombok.NoArgsConstructor
@lombok.AllArgsConstructor
@lombok.Builder
public class LombokData extends ParentData {
private String extraData;
}
compared to the non lombok version:
/**
* This is an extra-data
* @return extraData
*/
@Size(min = 10)
@Schema(name = "extra-data", description = "This is an extra-data", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("extra-data")
public String getExtraData() {
return extraData;
}
Generation Details
java -jar openapi-generator-cli.jar generate -g spring -i issue_lombok.yaml -p additionalModelTypeAnnotations='@lombok.Data;@lombok.NoArgsConstructor;@lombok.AllArgsConstructor;@lombok.Builder'
Steps to reproduce
Build with 7.3.0-SNAPSHOT with lombok additionalModelTypeAnnotations
java -jar openapi-generator-cli.jar generate -g spring -i issue_lombok.yaml -p additionalModelTypeAnnotations='@lombok.Data;@lombok.NoArgsConstructor;@lombok.AllArgsConstructor;@lombok.Builder'
Related issues/PRs
#17622
Suggest a fix
Fix the different pojo.mustache with
-
Constraints on the field
-
lombok superBuilder for inheritance
-
javadoc on the field
-
@JsonProperty on the field (using
@Getter(onMethod=@__({@JsonProperty("extra-data")})))
General question: Do we really need a openapi generator that needs lombok to create java classes?
pojo.mustache is already complex.
Configuring lombok is also complex. How to generate for example @Builder(toBuilder=true)?
Lombok is nice when writing code. Here the openapi generator does the job.
The only valid reason I see is the lack of the builder pattern in the current pojo.mustache.
It can be introduced. The generated code can be equivalent or better than a lombok annotated class.
IMHO it will be easier to implements new features without the extra lombok handling (immutability, records, genericity, merging the different java generators...)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the spring generator's pojo.mustache and reproduce the issue using the provided issue_lombok.yaml and generation command. Compare LombokData.java with the non-Lombok output, then verify that constraints, JSON property annotations, Javadoc, inheritance constructors/builders, and extra annotations are preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100