diziaq
diziaq

Reputation: 7775

How to describe multipart-form-data in swagger @Operation?

There is an endpoint with request body of type MULTIPART-FORM-DATA, with three fields:

  1. "my-attachment" - required field of type File
  2. "options" - required field of any type (File or Text)
  3. "note" - optional field of type Text

What is a proper way to describe this request body in Springdoc (or Swagger v3) using java annotations?

I supposed that @Operation is eligible for this, but cannot find any appropriate way to use it.

io.swagger.core.v3 - version 2.1.3

Upvotes: 3

Views: 7195

Answers (1)

brianbro
brianbro

Reputation: 4769

Here a sample working code:

@PostMapping(value = "/upload2", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public String upload2(@RequestPart("my-attachment") MultipartFile myAttachment, @RequestPart("options") options options, Optional<Text> note) {
    return "Ok";
}

Upvotes: 3

Related Questions