I'm developing spring-boot app with swagger-ui and lombok. Currently I'm trying to hide nested object from request body, but it still shows in example json on swagger-ui page.
I have my class with annotations(simplified to only related stuff):
@Data
@ApiModel(description = "Character model")
public class Character {
@ApiModelProperty(readOnly = true)
private Long id;
@ApiModelProperty(readOnly = true)
private SearchAnnouncement searchAnnouncement;
}
Note: @Data is Lombok annotation that generates getters, setters and few other things
When I access example model on swagger page "id" filed is properly hidden in example json, and visible in response model. But "searchAnnouncement" is not hidden in example json.
I tried:but in all cases example json looks like this (id hidden, and searchAnnouncement visible):
{ "searchAnnouncement": { "id": 0, }, }
So in short my question is:
EDIT: Forgot to mention I currently have swagger2 & swagger-ui with version 2.9.2 in my dependencies, but I moved up from 2.8.0 hoping to hide this nested object
I had the same issue, I fixed it by setting jsonIgnore
on my setters. I'm using dependency version 2.9.2.
Using swagger3
:
@JsonReadOnly
@Schema(description = "ID", accessMode = Schema.AccessMode.READ_ONLY)
private Long id;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.