useAbStractionForfiles OpenAPI WebClient无法正常工作

发布于 2025-01-26 14:24:43 字数 1287 浏览 5 评论 0原文

我使用OpenAPI Generator(Gradle插件5.4.0)来生成一些API调用。所述电话之一,从外部服务下载文件,即我的应用程序呼叫并下载,然后代表事件。对于该API,请调用我返回的content-type设置为application-zip。当直接调用该API时(IE从浏览器)都可以正常工作。

使用该API定义,我正在尝试生成一个可以有效下载该文件的项目使用的WebClient。这样做我面临以下问题:

  1. 每当我尝试调用API下载文件时,我会收到以下错误:nested Exception是org.springframework.web.reaeactive.function.function.unsupportedmediatiatiatypeepection:内容类型'application/zip'不支持bodytype = java.io.file

  2. 我生成的webclient似乎返回mono< file>而不是其他对象实例。我试图通过设置以下OpenAPI Generator配置选项useAbstractionForfiles来禁用此行为。

    似乎被忽略了。

谁能为我如何解决这个问题提供一些启示?在这里参考是我的OpenApi Gradle插件配置选项:

    configOptions = [
            dateLibrary            : 'java8',
            serializationLibrary   : 'jackson',
            library                : 'webclient',
            useAbstractionForFiles : 'true',
            useBeanValidation      : "true",
            interfaceOnly          : "true",
            serializableModel      : "true",
            useTags                : "true",
            reactive               : "true",
            sourceFolder           : 'src/main/java',
            testFolder             : 'src/test/java'
    ]

I am using OpenAPI generator (Gradle plugin version 5.4.0) to generate a few API calls. One of said calls, revolves a file download from an external service i.e my application calls that one and downloads and then should proxy the event. For that API call my returned content-type is set to application-zip. When invoking that API directly (i.e from a browser) everything works OK.

Using that API definition, I am trying to generate a WebClient to be used by another project that will effectively download that file. Doing so I am facing the following problems:

  1. Whenever I try to invoke the API to download the file I am getting the following error: nested exception is org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/zip' not supported for bodyType=java.io.File

  2. My generated WebClient seems to return a Mono<File> instead of some other object instance. I tried to disable this behavior by setting the following openapi generator configuration option useAbstractionForFiles but is seems to get ignored.

Can anyone shed some light as to how I can resolve this issue? For reference here is my OpenAPI Gradle Plugin configuration options:

    configOptions = [
            dateLibrary            : 'java8',
            serializationLibrary   : 'jackson',
            library                : 'webclient',
            useAbstractionForFiles : 'true',
            useBeanValidation      : "true",
            interfaceOnly          : "true",
            serializableModel      : "true",
            useTags                : "true",
            reactive               : "true",
            sourceFolder           : 'src/main/java',
            testFolder             : 'src/test/java'
    ]

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很快妥协 2025-02-02 14:24:44

基于OpenAPI-Generator中的测试类,此属性旨在与以下类型的请求主体一起使用:

  requestBody:
    content:
      multipart/form-data:
        schema:
          type: object
          properties:
            files:
              type: array
              description: "Many files"
              items:
                type: string
                format: binary

您可以将文件映射到此类所需类型:

openApiGenerate {
    typeMappings = ['File': 'byte[]']
}

Based on test classes in openapi-generator, this property is intended to work with request body of the following type:

  requestBody:
    content:
      multipart/form-data:
        schema:
          type: object
          properties:
            files:
              type: array
              description: "Many files"
              items:
                type: string
                format: binary

You can map File to any desired type like this:

openApiGenerate {
    typeMappings = ['File': 'byte[]']
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文