【问题标题】:Multiple file in requestbody with openapi and openapi-generator-maven-plugin带有openapi和openapi-generator-maven-plugin的requestbody中的多个文件
【发布时间】:2020-01-31 11:55:12
【问题描述】:

原来,我在 MVC-controller 中使用 spring-boot 的方法是:

public Response sendMailWithAttachment(
@RequestParam(name = "wrapper") String wrapper, 
@RequestParam(name = "file", required = false) MultipartFile... file
) {...

file - 可变参数,支持多文件请求

现在,我想在 OAS3 中描述规范,并用这个方法生成接口:

  /email/sendmail:
    post:
      tags:
        - email-controller
      summary: Send email, can add attachment
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                wrapper:
                  type: string
                  description: incoming request object
                file:
                  type: array
                  items:
                    type: string
                    format: binary
                    description: file for sending (attachment)

但是接口,openapi-generator-maven-plugin (4.2.2) 后不生成可变参数:

default ResponseEntity<EmailResponse> sendMailWithAttachmentUsingPOST(
@RequestParam(value="wrapper", required=false)  String wrapper, 
@Valid @RequestPart("file") MultipartFile file
) {...


到目前为止,我不明白如何生成具有可变参数或数组参数支持的接口。 谢谢!!

谢谢!!

【问题讨论】:

    标签: java spring openapi


    【解决方案1】:

    尝试使用最新版本的maven插件(目前为4.2.3) 生成的界面对我来说看起来不错:

    default ResponseEntity<EmailResponse> sendMailWithAttachmentUsingPOST(
        @ApiParam(value = "incoming request object") @RequestParam(value="wrapper", required=false)  String wrapper,
        @ApiParam(value = "") @Valid @RequestPart("file") List<MultipartFile> file
    )
    

    【讨论】:

      猜你喜欢
      • 2022-07-23
      • 2021-11-09
      • 2022-09-30
      • 2022-07-15
      • 2021-08-08
      • 1970-01-01
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多