Comments (19)
You can do this with the new Fetch API client, is that an option for you?
from openapi-ts.
I'm using the new fetch api client (I think, I have client: "@hey-api/client-fetch"
set in my openapi-ts.config.ts
file), but the examples on the page all seem to work with the request headers, but I need access to the response headers. The generated client functions all return types like ...get<GetSomeResponse, GetSomeError>
so it's not clear how I can get at the raw response.
from openapi-ts.
@mfinelli the new Fetch API client returns 4 things: data, error, request, and response. Response is the raw object containing your headers. They won't be properly typed, but they are there
from openapi-ts.
Ok, I see how it works now. For anyone else finding this issue I'm able to get the raw response like so:
const { data, error, response } = await yourClientFunction(...);
Then you can pull individual headers like this
response.headers.get("X-Your-Header");
@mrlubos I still think it would be a good idea if the generated client could read the headers from the openapi spec and expose them in a more standard way along with the proper types, but if you disagree then you can close this issue as resolved. Thanks for your help!
from openapi-ts.
@mfinelli It depends on how you imagine the standardised way. My understanding is that getting headers from response is straightforward, minus the missing type support. I'd argue that the more stuff you put in the data
field (if that was your proposal), the closer it gets to being a typed response
object
from openapi-ts.
I'm not sure that I'd like it in the data
object unless the data object had two keys body
and headers
. My usecase is to add extra information on the server side into some custom headers (e.g., pagination details) without affecting the response body itself which corresponds directly to a model that exists in the database and in the openapi spec (e.g., GET /category
returns an array of Category
objects, I wouldn't want to try and stuff the pagination information in there too)
from openapi-ts.
If you have any ideas around implementation feel free to propose, I didn't spend too much time thinking about this feature
from openapi-ts.
can you tell me how to get headers from that kind of code using v.0.49 of "@hey-api/openapi-ts"?
![image](https://private-user-images.githubusercontent.com/18617906/350071931-feb013a8-1f68-4ecd-b7b6-69a5758302bd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjMyNzQ5NzMsIm5iZiI6MTcyMzI3NDY3MywicGF0aCI6Ii8xODYxNzkwNi8zNTAwNzE5MzEtZmViMDEzYTgtMWY2OC00ZWNkLWI3YjYtNjlhNTc1ODMwMmJkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODEwVDA3MjQzM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTlmNzFkNzI0NzExNmM5YzE1NGM0NWNjZjhhY2MxNDk4NjdmODdjMDZhNDExOGZjNTljOGY3MzE2YWM2MDFlYWQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.PNTc8uOWp_Ff9-R1NKO2mEysfBVu3fTDhK6_WXC4I6o)
from openapi-ts.
@bielas looks like you're using Angular with the new Fetch API client? See my comment in #667 (comment). I didn't prioritise this use case yet, sorry!
from openapi-ts.
@mrlubos nope, I am using react and default client
from openapi-ts.
I am confused then, parseAs
is available only in the new Fetch API client?
from openapi-ts.
@mrlubos I am using client version 0.1.3 and hey api version 0.49. Seems that is is possible...
from openapi-ts.
How then I should proceed?
from openapi-ts.
If you provide me any other solution I can stop using parseAs and go with the other one
from openapi-ts.
@bielas here's how you can obtain response headers https://stackblitz.com/edit/hey-api-client-fetch-example?file=src%2FApp.tsx%3AL106
from openapi-ts.
how this is possible to work as open api generated code looks like:
export const downloadSubscription = (options: Options<DownloadSubscriptionData>) => {
return (options?.client ?? client).get<DownloadSubscriptionResponse, DownloadSubscriptionError>(
{
...options,
url: '/v1/self/trainer/subscription/{subscriptionId}/invoice'
}
);
};
export type DownloadSubscriptionResponse = Blob | File;
i am not able to extract it like you do here:
const { data, error, response } = await getPetById({
from openapi-ts.
@bielas please create a StackBlitz example, hard to tell from the code, it looks fine to me
from openapi-ts.
@mrlubos I hope you will get my point: https://stackblitz.com/edit/vitejs-vite-kemti5?file=src%2FApp.tsx
from openapi-ts.
@bielas I can't reproduce it with that. However, I see you're accessing data
in the tap()
function. data
will not contain the headers, you need the raw response
object for that
from openapi-ts.
Related Issues (20)
- multipart/form-data with fetch client sends content-type application/json HOT 2
- Make `"auto"` the default `parseAs` option in `@hey-api/client-fetch` HOT 5
- Error with binary response HOT 8
- Wrong infered content type for excel documents HOT 13
- Transformed Date(s) in query ends up as empty string(s) HOT 3
- securitySchemes won't support GET api key authentication HOT 4
- fetch-client does not correctly handle multipart/form-data HOT 1
- Streaming HTTP query support HOT 2
- additionalProperties creates invalid key type
- Generated client-fetch services declares client locally, but it is not exported. HOT 2
- Fetch API docs don't match implementation HOT 7
- Some config options cannot be set through cli flags HOT 3
- Create explicit client interface
- Zod plugin HOT 4
- schemas.type form removes properties from schema HOT 1
- Cannot find name 'ThrowOnError' error TS2304 HOT 13
- Make `body` optional if all fields are optional
- `client-fetch` now required a `ThrowOnError` generic which breaks manually created services with `fetch-client` HOT 4
- ThrowOnError can not be set to true HOT 7
- client type error in services.gen.ts HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openapi-ts.