You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the feature
It would be nice to have an option to not only copy attribute annotations to setter-parameters via config, but also be able to copy them on the setter-method.
Here's my use case:
While defining an openapi-spec with swagger (io.swagger.core.v3:swagger-jaxrs2) I wanted to use the magic of @Data (I boiled it down to @Setter for the issue) and copyable annotations:
Turned out annotations on setters are always copied to the corresponding parameter, not on the setter-method.
Yet @Hidden specifies the following target:
@Target({METHOD, TYPE, FIELD, ANNOTATION_TYPE})
Reviewing the documentation of lombok.copyableAnnotations I find:
Lombok will copy any of these annotations from the field to the setter parameter, ...
So the behavior is as intended, yet kept me somewhat helpless.
I found a workaround, it's putting
@Setter(onMethod_ = {@Hidden})
on every field, which makes my original @Data annotation on the class redundant for setters.
I found an older issue that addresses this behavior in regards to builders: #1961.
This issue was resolved by hardcoding the special case @JsonProperty.
While I'd favor a general configuration solution like having a setting:
an easier solution would be to add swagger's @io.swagger.v3.oas.annotations.Hidden to the list HandlerUtil.COPY_TO_SETTER_ANNOTATIONS, that already contains Json-properties, that seem to behave similarly.
Describe the target audience
Everyone that wants to use @Data or @Setter a lot with annotations that can only be put on a method level.
Additional context
This issue might be related: #3595
If the team lombok would choose to put the annotation to the COPY_TO_SETTER_ANNOTATIONS-list, I could provide a list of all swagger annotations that might fall into the same category (and of course provide a PR with this list).
Thanks for considering!
The text was updated successfully, but these errors were encountered:
dstango
changed the title
[FEATURE] Add configuration key lombok.copyableAnnotations.onMethod add swagger's @Hidden to the list of COPY_TO_SETTER_ANNOTATIONS
[FEATURE] Add configuration key lombok.copyableAnnotations.onMethod and/or add swagger's @Hidden to the list of COPY_TO_SETTER_ANNOTATIONS
May 2, 2024
dstango
changed the title
[FEATURE] Add configuration key lombok.copyableAnnotations.onMethod and/or add swagger's @Hidden to the list of COPY_TO_SETTER_ANNOTATIONS
[FEATURE] Add configuration key lombok.copyableAnnotations.onMethod and/or add swagger's @Hidden to the list of COPY_TO_SETTER_ANNOTATIONSMay 2, 2024
Describe the feature
It would be nice to have an option to not only copy attribute annotations to setter-parameters via config, but also be able to copy them on the setter-method.
Here's my use case:
While defining an openapi-spec with swagger (io.swagger.core.v3:swagger-jaxrs2) I wanted to use the magic of
@Data
(I boiled it down to@Setter
for the issue) and copyable annotations:Example class:
lombok.config:
I got the (for me) mysterious error message
The annotation @Hidden is disallowed for this location
.After lots of head scratching I found out lombok produced something like this out of it:
Turned out annotations on setters are always copied to the corresponding parameter, not on the setter-method.
Yet
@Hidden
specifies the following target:Reviewing the documentation of
lombok.copyableAnnotations
I find:So the behavior is as intended, yet kept me somewhat helpless.
I found a workaround, it's putting
on every field, which makes my original
@Data
annotation on the class redundant for setters.I found an older issue that addresses this behavior in regards to builders: #1961.
This issue was resolved by hardcoding the special case
@JsonProperty
.While I'd favor a general configuration solution like having a setting:
which would result in:
an easier solution would be to add swagger's
@io.swagger.v3.oas.annotations.Hidden
to the listHandlerUtil.COPY_TO_SETTER_ANNOTATIONS
, that already contains Json-properties, that seem to behave similarly.Describe the target audience
Everyone that wants to use
@Data
or@Setter
a lot with annotations that can only be put on a method level.Additional context
This issue might be related: #3595
If the team lombok would choose to put the annotation to the
COPY_TO_SETTER_ANNOTATIONS
-list, I could provide a list of all swagger annotations that might fall into the same category (and of course provide a PR with this list).Thanks for considering!
The text was updated successfully, but these errors were encountered: