1

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?

4
  • Have you tried @Parameter(description = "some info") @RequestPart(name = "jobData") @Valid JobData jobData ? Commented Nov 5 at 19:59
  • @Max, yes, with or without @Parameter it behaves the same and displays the object just as a block of JSON. Commented Nov 5 at 20:09
  • @RolandRoberts, can you try the below format. @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 ) { // ... } Commented Nov 9 at 20:49
  • @Vijay, no difference with that; when I click "Try it out" I still only JSON/text, not fields :(. I'm not surprised at this point; I've lost the link among my bazillion open tabs, but I found a feature request that sounded like it was asking for this, but no one available to pick it up. Commented Nov 11 at 16:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.