-
-
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 (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
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...)