Skip to content

@OpenApiByFields including Setters showing up as schema fields #249

@sammaher1

Description

@sammaher1

I use lombok with the openApi plugin and all works well, unless I use a field with @Data. @Data generates setters that return the object after use. If this happens, the openApi spec generated becomes a self reference:

DataClass": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string"
          },
          "value1": {
            "type": "integer",
            "format": "int32"
          },
          "nonFinalIntegerValue": {
            "$ref": "#/components/schemas/DataClass"
          },
        },

For example:

@Data @OpenApiByFields(Visibility.PRIVATE)
public class DataClass
     private final String name;
     private final int finalIntegerValue; // Shows up correctly in the spec as it's final so no setter is generated
     private int nonFinalIntegerValue; // Shows up as a self reference

// Generated
     public DataClass nonFinalIntegerValue(int nonFinalIntegerValue) {
             this.nonFinalIntegerValue = nonFinalIntegerValue;
             return this;
     }


Generated setters:
public DataClass 

The only way I'm able to undo this is by manually writing out the setters and adding @OpenApiIgnore above them. Is there no way to ensure that @OpenApiByFields ONLY looks at fields and ignores any methods?

Metadata

Metadata

Assignees

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions