I have two fields in my class startDate
and endDate
of LocalDateTime
. Internally, these need to be returned as Optional<ZonedDateTime>
, while in the query they are provided as LocalDateTimes.
@ApiModel
public class SearchQuery {
private static final ZoneId UTC_TIMEZONE = ZoneId.of("UTC");
@ApiParam(value = "Start date and time of the requested time frame.", example = "2019-06-01T12:30", defaultValue = "0000-01-01T00:00")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private LocalDateTime startDate;
@ApiParam(value = "End date and time of the requested time frame.", example = "2019-06-30T23:59", defaultValue = "9999-12-31T23:59")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private LocalDateTime endDate;
public LocalDateTime getStartDate() {
return this.startDate;
}
public LocalDateTime getEndDate() {
return this.endDate;
}
public Optional<ZonedDateTime> getStartDateWithTimezone() {
return Optional.ofNullable(startDate)
.map(date -> date.atZone(UTC_TIMEZONE));
}
public Optional<ZonedDateTime> getEndDateWithTimezone() {
return Optional.ofNullable(endDate)
.map(date -> date.atZone(UTC_TIMEZONE));
}
}
Swagger (Springfox v2.9.2) now shows the needed fields but also endDateWithTimezone.present
and startDateWithTimezone.present
, which are of course both not needed as parameters:
I have been trying for some time now to find ways to hide these from my swagger documentation. How can I do this?
I believe this might be a duplicate?: https://stackoverflow.com/a/41677559/8932643
Ronny Shibley answers:
For Parameters
public void getApi(@ApiIgnore String param){}
@ApiModelProperty(hidden="true")
public String paramInsideClass
The solution was quite simple in the end.
You have to use the annotation @ApiModelProperty(hidden = true)
directly on the getter you want to hide.
rename getStartDateWithTimezone
to findStartDateWithTimezone
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.