Skip to content

Commit c16fa14

Browse files
fedorgaurabirb
authored andcommitted
fix request body type being ignored
1 parent 8aecdf6 commit c16fa14

File tree

3 files changed

+105
-2
lines changed

3 files changed

+105
-2
lines changed

src/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ export type OpArgType<OP> = OP extends {
1818
path?: infer P
1919
query?: infer Q
2020
body?: infer B
21-
header?: unknown // ignore
22-
cookie?: unknown // ignore
21+
[k: string]: any
2322
}
2423
// openapi 3
2524
requestBody?: {

test/examples/stations.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* This file was auto-generated by openapi-typescript.
3+
* Do not make direct changes to the file.
4+
*/
5+
6+
export interface paths {
7+
"/stations": {
8+
post: operations["create_station_stations_post"];
9+
};
10+
}
11+
12+
export interface components {
13+
schemas: {
14+
/** CreateStation */
15+
CreateStation: {
16+
/** Name */
17+
name: string;
18+
/** Comment */
19+
comment?: string;
20+
};
21+
/** HTTPValidationError */
22+
HTTPValidationError: {
23+
/** Detail */
24+
detail?: components["schemas"]["ValidationError"][];
25+
};
26+
/** Station */
27+
Station: {
28+
/** Id */
29+
id: number;
30+
/** Name */
31+
name?: string;
32+
/** Comment */
33+
comment?: string;
34+
/**
35+
* Created At
36+
* Format: date-time
37+
*/
38+
created_at: string;
39+
/**
40+
* Updated At
41+
* Format: date-time
42+
*/
43+
updated_at?: string;
44+
/** Api Key */
45+
api_key: string;
46+
};
47+
/** ValidationError */
48+
ValidationError: {
49+
/** Location */
50+
loc: string[];
51+
/** Message */
52+
msg: string;
53+
/** Error Type */
54+
type: string;
55+
};
56+
};
57+
}
58+
59+
export interface operations {
60+
create_station_stations_post: {
61+
parameters: {
62+
header: {
63+
"user-jwt"?: string;
64+
};
65+
};
66+
responses: {
67+
/** Successful Response */
68+
200: {
69+
content: {
70+
"application/json": components["schemas"]["Station"];
71+
};
72+
};
73+
/** Validation Error */
74+
422: {
75+
content: {
76+
"application/json": components["schemas"]["HTTPValidationError"];
77+
};
78+
};
79+
};
80+
requestBody: {
81+
content: {
82+
"application/json": components["schemas"]["CreateStation"];
83+
};
84+
};
85+
};
86+
}
87+
88+
export interface external {}

test/stations.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { OpArgType } from '../src'
2+
3+
import { components, paths } from './examples/stations'
4+
type Op = paths['/stations']['post']
5+
type Argument = components['schemas']['CreateStation']
6+
7+
type InferredArgument = OpArgType<Op>
8+
9+
type Same<A, B> = A extends B ? (B extends A ? true : false) : false
10+
11+
describe('infer', () => {
12+
it('argument', () => {
13+
const same: Same<Argument, InferredArgument> = true
14+
expect(same).toBe(true)
15+
})
16+
})

0 commit comments

Comments
 (0)