Reputation: 5289
When reading about @ApiModelProperty
, I thought I had finally found how to solve this, but it just didn't work.
Here is what I'm working with:
@RestController
@Api(value = "inventorySnapshot")
@RequestMapping("/business/v1/inventorySnapshots")
@Slf4j
public class InventorySnapshotController {
@ApiOperation(value = "@api.operation.summary.put_dtos@")
@PutMapping
public ResponseEntity<Void> put(final @RequestBody List<MyDTO> dtos) {
log.debug("Put InventorySnapshots");
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MyDTO {
@NotNull(groups = ForDocumentationOnly.class)
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", lenient = OptBoolean.FALSE)
private Date availableFromDate;
@ApiModelProperty(example = "2021-01-11T11:11:11Z")
@NotNull(groups = ForDocumentationOnly.class)
@DateTimeFormat(pattern = "yyyy-MM-ddThh:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", lenient = OptBoolean.FALSE)
private Timestamp calculationDateTime;
// more properties for which I wish to keep the default suggested by Swagger...
}
I'm rather looking forward to having it like so:
Any clues ?
Upvotes: 2
Views: 2647
Reputation: 180
You can use JSON INPUT for the default value.
example:
public ResponseEntity<Void> put(
@RequestBody
@ApiParam(defaultValue="\\"availableFromDate\\":\\"2021-10-28\\",\\"calculationDateTime\\":\\"2021-10-28T01:35:46Z\\"")
MyDTO dto)
or if you are using open api use below
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema
public class MyDTO {
@NotNull(groups = ForDocumentationOnly.class)
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", lenient = OptBoolean.FALSE)
@Schema(example="2021-01-11")
private Date availableFromDate;
@Schema(example = "2021-01-11T11:11:11Z")
@NotNull(groups = ForDocumentationOnly.class)
@DateTimeFormat(pattern = "yyyy-MM-ddThh:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", lenient = OptBoolean.FALSE)
private Timestamp calculationDateTime;
// more properties for which I wish to keep the default suggested by Swagger...
}
Upvotes: 3