2

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'
    ]
akortex
  • 5,067
  • 2
  • 25
  • 57
  • could you share more details about OpenAPI generator you are using and probably generated code for the WebClient? In case of "non-standard" content types, you need to provide encoder/decoder using `ClientCodecConfigurer` `clientCodecConfigurer.customCodecs().decoder(...)`. – Alex May 09 '22 at 14:35
  • Details requested. The generator is the OpenAPI generator for Gradle version 5.4.0 as mentioned in my question. My current Gradle version is 7.4.1. I do not use any kind of custom content-types. My problem is that I am simply trying to instruct the generator to use abstracted file representations instead of the concrete `File` type as mentioned here https://openapi-generator.tech/docs/generators/java/#config-options – akortex May 09 '22 at 15:36
  • Looking at the error, `application/zip` is a custom content type for WebClient. Also `Mono` looks strange for body mapping. It's very hard to tell more without open api definition and generated code. – Alex May 09 '22 at 15:58
  • I think this is not a custom mapping and per their documentation this should be working fine. When using the Spring generator, everything works fine and maps to a `Mono` which is OK. The problem occurs only when using the `WebClient` generator, which seems to ignore the flag in question. – akortex May 10 '22 at 07:28

0 Answers0