hey-api / openapi-ts

🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more. Support: @mrlubos
https://heyapi.dev
Other
1.39k stars 107 forks source link

Return empty data in schema #1182

Open amy-fang opened 1 month ago

amy-fang commented 1 month ago

Description

I used interceptors.response.use to return data. When I used Promise.allSettled , it always add en empty data in my response data. The client is '@hey-api/client-axios'. See screenshot. 微信截图_20241022123726

Reproducible example or configuration

OpenAPI specification (optional)

No response

System information (optional)

No response

stackblitz[bot] commented 1 month ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

mrlubos commented 1 month ago

Hey @amy-fang, can you share a link to the StackBlitz example I believe you've already created?

amy-fang commented 1 month ago

Hey @amy-fang, can you share a link to the StackBlitz example I believe you've already created?

https://stackblitz.com/edit/hey-api-client-axios-example-febun4?file=src%2FApp.tsx

I found that cause this part.

const response = await _axios({
        ...opts,
        data: opts.body,
        params: opts.query,
        url,
      });

      let { data } = response;

      if (opts.responseType === 'json' && opts.responseTransformer) {
        data = await opts.responseTransformer(data);
      }

      return {
        ...response,
        data: data ?? {},
      };

Always return with data. Is there an easy way to package the response data? I want to handler the response data in a global function. But now the axios interceptors don't seem to be the right way.