.xlsx文件上传,swagger codegn不会为Multipartfile生成@RequestParam

发布于 2025-01-09 02:19:02 字数 1507 浏览 2 评论 0原文

我必须上传存储在 .xlsx 文件中的交易。我正在尝试使用 swagger codegen 生成 api。我浏览了有关该问题的每个 stackoverflow 线程,但没有找到解决方案。

我确实有一个合同:

  /accounts/import/transactions:
    post:
      tags:
        - Account Transaction
      operationId: uploadTransactions
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
      responses:
        200:
          description: 'Upload successful'
        400:
        ...

swagger 依赖项:

<springfox-swagger-ui>3.0.0</springfox-swagger-ui>
<springfox-swagger2>3.0.0</springfox-swagger2>
<swagger-codegen-maven-plugin>3.0.21</swagger-codegen-maven-plugin>

我获得的 API 缺少 @RequestParam("file") MultiPartFile 文件。知道我做错了什么吗?这和 Swagger 版本有什么关系吗?

@RequestMapping(value = "/accounts/import/transactions",
    produces = { "application/json" }, 
    consumes = { "multipart/form-data" },
    method = RequestMethod.POST)
default ResponseEntity<Void> uploadTransactions() {
    if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
    } else {
        log.warn("ObjectMapper or HttpServletRequest not configured in default AccountsApi interface so no example is generated");
    }
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}

I have to upload transactions stored in .xlsx file. I'm trying to generate api using swagger codegen. I have browsed through every stackoverflow thread regarding the problem, but found no solution.

I do have a contract:

  /accounts/import/transactions:
    post:
      tags:
        - Account Transaction
      operationId: uploadTransactions
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
      responses:
        200:
          description: 'Upload successful'
        400:
        ...

swagger dependencies:

<springfox-swagger-ui>3.0.0</springfox-swagger-ui>
<springfox-swagger2>3.0.0</springfox-swagger2>
<swagger-codegen-maven-plugin>3.0.21</swagger-codegen-maven-plugin>

The API I get is missing @RequestParam("file") MultiPartFile file. Any idea what I'm doing wrong? Does this have anything to do with Swagger versions?

@RequestMapping(value = "/accounts/import/transactions",
    produces = { "application/json" }, 
    consumes = { "multipart/form-data" },
    method = RequestMethod.POST)
default ResponseEntity<Void> uploadTransactions() {
    if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
    } else {
        log.warn("ObjectMapper or HttpServletRequest not configured in default AccountsApi interface so no example is generated");
    }
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文