File tree Expand file tree Collapse file tree 4 files changed +163
-1
lines changed
packages/rtk-query-codegen-openapi Expand file tree Collapse file tree 4 files changed +163
-1
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ export function parseConfig(fullConfig: ConfigFile) {
42
42
}
43
43
44
44
/**
45
- * Enforces `oazapfts` to use the same TypeScript version as this module itself uses.
45
+ * Enforces `@rtk-query/ oazapfts-patched ` to use the same TypeScript version as this module itself uses.
46
46
* That should prevent enums from running out of sync if both libraries use different TS versions.
47
47
*/
48
48
function enforceOazapftsTsVersion < T > ( cb : ( ) => T ) : T {
Original file line number Diff line number Diff line change @@ -445,6 +445,40 @@ export type PatchApiV1ListByItemIdApiArg = {
445
445
446
446
`;
447
447
448
+ exports[`tests from issues issue #2002: should be able to generate proper intersection types 1`] = `
449
+ import { api } from './tmp/emptyApi';
450
+ const injectedRtkApi = api.injectEndpoints({
451
+ endpoints: (build) => ({
452
+ getApiV1Animals: build.query<GetApiV1AnimalsApiResponse, GetApiV1AnimalsApiArg>({
453
+ query: (queryArg) => ({
454
+ url: \`/api/v1/animals\`,
455
+ params: { type: queryArg['type'] },
456
+ }),
457
+ }),
458
+ }),
459
+ overrideExisting: false,
460
+ });
461
+ export { injectedRtkApi as enhancedApi };
462
+ export type GetApiV1AnimalsApiResponse = /** status 200 Success */ (Dog | Cat)[];
463
+ export type GetApiV1AnimalsApiArg = {
464
+ type?: AnimalType;
465
+ };
466
+ export type AnimalType = 'All' | 'Cats' | 'Dogs';
467
+ export type Animal = {
468
+ type: AnimalType;
469
+ id?: number;
470
+ name?: string | null;
471
+ };
472
+ export type Dog = Animal & {
473
+ dogUniqueProp?: string | null;
474
+ };
475
+ export type Cat = Animal & {
476
+ catUniqueProp?: string | null;
477
+ };
478
+ export const { useGetApiV1AnimalsQuery } = injectedRtkApi;
479
+
480
+ `;
481
+
448
482
exports[`yaml parsing should be able to use read a yaml file 1`] = `
449
483
import { api } from './tmp/emptyApi';
450
484
const injectedRtkApi = api.injectEndpoints({
Original file line number Diff line number Diff line change
1
+ {
2
+ "openapi" : " 3.0.1" ,
3
+ "info" : {
4
+ "title" : " Animals API" ,
5
+ "version" : " 1.0.0"
6
+ },
7
+ "servers" : [
8
+ {
9
+ "url" : " https://localhost:8000"
10
+ }
11
+ ],
12
+ "paths" : {
13
+ "/api/v1/animals" : {
14
+ "get" : {
15
+ "parameters" : [
16
+ {
17
+ "name" : " type" ,
18
+ "in" : " query" ,
19
+ "schema" : {
20
+ "$ref" : " #/components/schemas/AnimalType"
21
+ }
22
+ }
23
+ ],
24
+ "responses" : {
25
+ "200" : {
26
+ "description" : " Success" ,
27
+ "content" : {
28
+ "application/json" : {
29
+ "schema" : {
30
+ "type" : " array" ,
31
+ "items" : {
32
+ "oneOf" : [
33
+ {
34
+ "$ref" : " #/components/schemas/Dog"
35
+ },
36
+ {
37
+ "$ref" : " #/components/schemas/Cat"
38
+ }
39
+ ],
40
+ "description" : " Base animal type."
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+ }
49
+ },
50
+ "components" : {
51
+ "schemas" : {
52
+ "AnimalType" : {
53
+ "type" : " string" ,
54
+ "enum" : [" All" , " Cats" , " Dogs" ]
55
+ },
56
+ "Animal" : {
57
+ "required" : [" type" ],
58
+ "type" : " object" ,
59
+ "properties" : {
60
+ "type" : {
61
+ "type" : " string" ,
62
+ "$ref" : " #/components/schemas/AnimalType"
63
+ },
64
+ "id" : {
65
+ "type" : " integer" ,
66
+ "format" : " int64"
67
+ },
68
+ "name" : {
69
+ "type" : " string" ,
70
+ "nullable" : true
71
+ }
72
+ },
73
+ "additionalProperties" : false ,
74
+ "description" : " Base animal type." ,
75
+ "discriminator" : {
76
+ "propertyName" : " type" ,
77
+ "mapping" : {
78
+ "Dog" : " #/components/schemas/Dog" ,
79
+ "Cat" : " #/components/schemas/Cat"
80
+ }
81
+ }
82
+ },
83
+ "Dog" : {
84
+ "type" : " object" ,
85
+ "allOf" : [
86
+ {
87
+ "$ref" : " #/components/schemas/Animal"
88
+ }
89
+ ],
90
+ "properties" : {
91
+ "dogUniqueProp" : {
92
+ "type" : " string" ,
93
+ "nullable" : true
94
+ }
95
+ },
96
+ "additionalProperties" : false ,
97
+ "description" : " Dog animal"
98
+ },
99
+ "Cat" : {
100
+ "type" : " object" ,
101
+ "allOf" : [
102
+ {
103
+ "$ref" : " #/components/schemas/Animal"
104
+ }
105
+ ],
106
+ "properties" : {
107
+ "catUniqueProp" : {
108
+ "type" : " string" ,
109
+ "nullable" : true
110
+ }
111
+ },
112
+ "additionalProperties" : false ,
113
+ "description" : " Cat animal"
114
+ }
115
+ }
116
+ }
117
+ }
Original file line number Diff line number Diff line change @@ -211,3 +211,14 @@ describe('yaml parsing', () => {
211
211
expect ( output ) . toContain ( '"foo:bar-foo.bar/foo": queryArg["foo:bar-foo.bar/foo"],' ) ;
212
212
} ) ;
213
213
} ) ;
214
+
215
+ describe ( 'tests from issues' , ( ) => {
216
+ it ( 'issue #2002: should be able to generate proper intersection types' , async ( ) => {
217
+ const result = await generateEndpoints ( {
218
+ apiFile : './tmp/emptyApi.ts' ,
219
+ schemaFile : `./fixtures/issue-2002.json` ,
220
+ hooks : true ,
221
+ } ) ;
222
+ expect ( result ) . toMatchSnapshot ( ) ;
223
+ } ) ;
224
+ } ) ;
You can’t perform that action at this time.
0 commit comments