Skip to content

Commit 0400e57

Browse files
committed
docs: add transform docs
1 parent 11b93fb commit 0400e57

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

docs/openapi-fetch/api.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ createClient<paths>(options);
1919
| `fetch` | `fetch` | Fetch instance used for requests (default: `globalThis.fetch`) |
2020
| `querySerializer` | QuerySerializer | (optional) Provide a [querySerializer](#queryserializer) |
2121
| `bodySerializer` | BodySerializer | (optional) Provide a [bodySerializer](#bodyserializer) |
22+
| `transform` | TransformOptions| (optional) Provide [transform functions](#transform) for response data |
2223
| (Fetch options) | | Any valid fetch option (`headers`, `mode`, `cache`, `signal` …) ([docs](https://developer.mozilla.org/en-US/docs/Web/API/fetch#options) |
2324

2425
## Fetch options
@@ -192,6 +193,24 @@ or when instantiating the client.
192193

193194
:::
194195

196+
## transform
197+
198+
The transform option lets you modify request and response data before it's sent or after it's received. This is useful for tasks like deserialization.
199+
200+
```ts
201+
const client = createClient<paths>({
202+
transform: {
203+
response: (method, path, data) => {
204+
// Convert date strings to Date objects
205+
if (data?.created_at) {
206+
data.created_at = new Date(data.created_at);
207+
}
208+
return data;
209+
}
210+
}
211+
});
212+
```
213+
195214
## Path serialization
196215

197216
openapi-fetch supports path serialization as [outlined in the 3.1 spec](https://swagger.io/docs/specification/serialization/#path). This happens automatically, based on the specific format in your OpenAPI schema:

0 commit comments

Comments
 (0)