简体   繁体   中英

How to add button for file upload in swagger-ui (spring doc) which accepts Flux<ByteBuffer>?

I use spring doc 1.6.12:

<spring-doc.version>1.6.12</spring-doc.version>
...
<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-webmvc-core</artifactId>
  <version>${spring-doc.version}</version>
</dependency>
<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-webflux-ui</artifactId>
  <version>${spring-doc.version}</version>
</dependency>
<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-data-rest</artifactId>
  <version>${spring-doc.version}</version>
</dependency>
<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-security</artifactId>
  <version>${spring-doc.version}</version>
</dependency>

I have following controller method:

  @PostMapping(produces = "application/hal+json")
  @ResponseStatus(code = HttpStatus.CREATED)
  public Mono<ResponseEntity<MyDTO>> upload(
      @RequestBody Flux<ByteBuffer> data,
      @RequestHeader(name = CONTENT_LENGTH) long contentLength,
      @RequestHeader(name = CONTENT_TYPE, required = false) MediaType contentType,
      @RequestHeader(name = CONTENT_DISPOSITION) @ContentDispositionConstraint ContentDisposition contentDisposition,
      @RequestParam(name = "archive", required = false, defaultValue = "false") boolean archive,
      @RequestParam(name = "folder", required = false) @Pattern(regexp = FOLDER_PATTERN) String folder,
      @RequestParam(name = "folderOwner", required = false) String folderOwner,
      @RequestParam(value = "folderUuid", required = false) UUID folderUuid,
      @RequestParam(name = "expirationDate", required = false) Instant expirationDate,
      JwtAuthenticationToken jwtToken,
      ServerHttpRequest request) {

In swagger ui I see:

在此处输入图像描述

So I have no button to upload file. Is there way to acheve it?

PS

If I change

@RequestBody Flux<ByteBuffer> data

to

@RequestPart ("file") MultipartFile data,

I see the upload button in swagger but underlying code depends on Flux<ByteBuffer> data so I don't wanna change it.

I think that it will be displayed if you use @Schema.

@Schema(type = "string", format = "binary") @RequestBody Flux<ByteBuffer> data

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM