I have a class with the @RestController annotation which contains an endpoint defined like this
@PostMapping(path = "/submitJob", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }, produces = {MediaType.APPLICATION_JSON_VALUE})
@RequestBody(content = { @Content(encoding = { @Encoding(name = "jobData", contentType = "application/json")})})
public ResponseEntity<ApiCallStatus<SimpleJobStatus>> postJob(
@ParameterObject @RequestPart(name = "jobData", required = true) @Valid JobData jobData,
@Parameter(description = "portfolio file with fund and holding information") @RequestPart(name = "portfolioFile", required = true) MultipartFile portfolioFile,
@Parameter(description = "optional benchmark file for trigger thresholds") @RequestPart(name = "benchMarkFile", required = false) MultipartFile benchMarkFile)
which looks great in the swagger-ui; the JobData object is expanded into its fields, each with their own descriptions which come from the @Schema annotations on those fields.
However, when I fill in the form and try to execute the call, I get
{
"status": "fail",
"message": "An error occurred while processing the request.",
"errors": [
"Required part 'jobData' is not present."
]
}
Removing the @ParameterObject will display the object as JSON and then I can execute the call. Keeping @ParameterObject and removing the @RequestBody gives the same error.
Spring 6.1.15; what am I missing that is preventing this from working?
-- EDIT --
I know part of what I'm missing, namely that @ParameterObject wants to put the individual fields back onto http query parameters exactly like it does for a GET request. So is there an equivalent that will get me a the pretty form but still reassemble it into the JSON as part of the body?
@Parameterit behaves the same and displays the object just as a block of JSON.@PostMapping( path = "/submitJob", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE ) public ResponseEntity<ApiCallStatus<SimpleJobStatus>> postJob( @RequestPart("jobData") @Valid JobData jobData, @RequestPart("portfolioFile") MultipartFile portfolioFile, @RequestPart(value = "benchMarkFile", required = false) MultipartFile benchMarkFile ) { // ... }