You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`Orval` generates code that properly types responses streamed from `NDJSON`.
9
+
[NDJSON](https://en.wikipedia.org/wiki/JSON_streaming#Newline-delimited_JSON) is a technique to stream an array of JSON objects. This is mostly used when the data set is large.
10
+
11
+
### How to use
12
+
13
+
`Orval` does not generate code for actually parsing the stream, but rather provides type safety. You can use the code in the example below to see how you can achieve reading streamed data.
14
+
Proper type support is only supported when using the `fetch` client as either a standalone client, or as a [httpClient](../reference/configuration/output#httpclient).
15
+
16
+
#### Example
17
+
18
+
```ts
19
+
// orval.config.ts
20
+
import { defineConfig } from'orval';
21
+
22
+
exportdefaultdefineConfig({
23
+
petstore: {
24
+
input: {
25
+
target: './stream.yaml',
26
+
},
27
+
output: {
28
+
client: 'fetch',
29
+
target: 'src/endpoints.ts',
30
+
schemas: 'src/model',
31
+
},
32
+
},
33
+
});
34
+
```
35
+
36
+
```yml
37
+
openapi: 3.1.0
38
+
info:
39
+
version: 1.0.0
40
+
title: Stream
41
+
paths:
42
+
/stream:
43
+
get:
44
+
operationId: stream
45
+
description: Stream results
46
+
responses:
47
+
'200':
48
+
description: The stream result.
49
+
content:
50
+
application/x-ndjson:
51
+
schema:
52
+
$ref: '#/components/schemas/StreamEntry'
53
+
components:
54
+
schemas:
55
+
StreamEntry:
56
+
type: object
57
+
properties:
58
+
foo:
59
+
type: number
60
+
bar:
61
+
type: string
62
+
```
63
+
64
+
```ts
65
+
// Generated code
66
+
interface TypedResponse<T> extends Response {
67
+
json(): Promise<T>;
68
+
}
69
+
70
+
/**
71
+
* Stream results
72
+
*/
73
+
export type streamResponse200 = {
74
+
stream: TypedResponse<StreamEntry>;
75
+
status: 200;
76
+
};
77
+
export type streamResponseComposite = streamResponse200;
78
+
79
+
export type streamResponse = streamResponseComposite & {
0 commit comments