rametta / rapini

:leafy_green: OpenAPI to React Query (or SWR) & Axios
Apache License 2.0
147 stars 17 forks source link

Does Rapini generate code which is able to handle files download where the content-type=application/octet-stream? #31

Closed BuilderHarrison closed 1 year ago

BuilderHarrison commented 1 year ago

Hello, I was wondering if the code that rapini generates is able to handle files served with a content-type of application/octet-stream? When I use insomnia the file is downloaded correctly, however, when using the function created by rapini and a blob it generates a corrupt file.

  return useExportPpt(
    searchCriteria.search || '',
    true,
    {
      enabled: false,
      onSuccess: (response) => {
        const fileName = exportFilename('pptx');
        const data = new Blob([response as BlobPart], {
          type: 'application/octet-stream'
        });
        const url = window.URL.createObjectURL(data);
        const link = document.createElement('a');
        document.body.appendChild(link);
        link.href = url;
        link.setAttribute('download', fileName);
        link.click();
        document.body.removeChild(link);
      }
    }
  );

After executing this code a file corrupt file is produced, it is double the size and contains characters when opened in a text editor which do not exist if you download it by insomnia. Also, the response variable has type unknown.

Any assistance, would be helpful. Thanks!

rametta commented 1 year ago

@BuilderHarrison ill be able to take a look next week. Thanks for your patience

rametta commented 1 year ago

Hi @BuilderHarrison do you have an example OpenAPI file I can use to reproduce the issue? I am interested in resolving this issue.

chihabhajji commented 1 year ago

octet-stream and multipart/form-data can theoretically be easily supported using the first content property in the operation in OAS3

rametta commented 1 year ago

@chihabhajji please open a PR if possible, would be very helpful

chihabhajji commented 1 year ago

okay, ill start by adding the content type, but i think a totally better idea is being able to pass the axiosconfig params as an optional argument to queries and mutations, so the global config is the default, and then per request optionally