typed-openapi 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-J2KG2QH2.js → chunk-UNKLDND3.js} +1 -1
- package/dist/{chunk-I2PUFY2J.js → chunk-X4A4YQN7.js} +10 -18
- package/dist/cli.js +2 -2
- package/dist/index.js +1 -1
- package/dist/node.export.js +2 -2
- package/package.json +1 -1
- package/src/generator.ts +5 -15
- package/src/tanstack-query.generator.ts +5 -7
|
@@ -449,16 +449,10 @@ var parameterObjectToString = (parameters, ctx) => {
|
|
|
449
449
|
}
|
|
450
450
|
return str + "}";
|
|
451
451
|
};
|
|
452
|
-
var responseHeadersObjectToString = (responseHeaders
|
|
452
|
+
var responseHeadersObjectToString = (responseHeaders) => {
|
|
453
453
|
let str = "{";
|
|
454
454
|
for (const [key, responseHeader] of Object.entries(responseHeaders)) {
|
|
455
|
-
|
|
456
|
-
if (Box.isReference(box) && !box.params.generics && box.value !== "null") {
|
|
457
|
-
box.value = `Schemas.${box.value}`;
|
|
458
|
-
}
|
|
459
|
-
return box;
|
|
460
|
-
}).value : responseHeader.value;
|
|
461
|
-
str += `${wrapWithQuotesIfNeeded(key.toLowerCase())}: ${value},
|
|
455
|
+
str += `${wrapWithQuotesIfNeeded(key.toLowerCase())}: ${responseHeader.value},
|
|
462
456
|
`;
|
|
463
457
|
}
|
|
464
458
|
return str + "}";
|
|
@@ -504,7 +498,7 @@ var generateEndpointSchemaList = (ctx) => {
|
|
|
504
498
|
)},` : ""}
|
|
505
499
|
}` : "parameters: never,"}
|
|
506
500
|
${endpoint.responses ? `responses: ${generateResponsesObject(endpoint.responses, ctx)},` : ""}
|
|
507
|
-
${endpoint.responseHeaders ? `responseHeaders: ${responseHeadersObjectToString(endpoint.responseHeaders
|
|
501
|
+
${endpoint.responseHeaders ? `responseHeaders: ${responseHeadersObjectToString(endpoint.responseHeaders)},` : ""}
|
|
508
502
|
}
|
|
509
503
|
`;
|
|
510
504
|
});
|
|
@@ -703,7 +697,7 @@ export class ApiClient {
|
|
|
703
697
|
"typebox",
|
|
704
698
|
"valibot",
|
|
705
699
|
() => `InferResponseByStatus<${infer(`TEndpoint`)}, SuccessStatusCode>["data"]`
|
|
706
|
-
).otherwise(() => `InferResponseByStatus<TEndpoint, SuccessStatusCode>["data"]`)}>;
|
|
700
|
+
).otherwise(() => `Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"]`)}>;
|
|
707
701
|
|
|
708
702
|
${method}<Path extends keyof ${capitalizedMethod}Endpoints, TEndpoint extends ${capitalizedMethod}Endpoints[Path]>(
|
|
709
703
|
path: Path,
|
|
@@ -739,7 +733,7 @@ export class ApiClient {
|
|
|
739
733
|
"typebox",
|
|
740
734
|
"valibot",
|
|
741
735
|
() => `as Promise<InferResponseByStatus<${infer(`TEndpoint`)}, SuccessStatusCode>["data"]>`
|
|
742
|
-
).otherwise(() => `as Promise<InferResponseByStatus<TEndpoint, SuccessStatusCode>["data"]>`)}
|
|
736
|
+
).otherwise(() => `as Promise<Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"]>`)}
|
|
743
737
|
}
|
|
744
738
|
// </ApiClient.${method}>
|
|
745
739
|
` : "";
|
|
@@ -1339,7 +1333,7 @@ var generateTanstackQueryFile = async (ctx) => {
|
|
|
1339
1333
|
withResponse: false as const
|
|
1340
1334
|
};
|
|
1341
1335
|
const res = await this.client.${method}(path, requestParams);
|
|
1342
|
-
return res as InferResponseByStatus<TEndpoint, SuccessStatusCode>["data"];
|
|
1336
|
+
return res as Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"];
|
|
1343
1337
|
},
|
|
1344
1338
|
queryKey: queryKey
|
|
1345
1339
|
}),
|
|
@@ -1354,7 +1348,7 @@ var generateTanstackQueryFile = async (ctx) => {
|
|
|
1354
1348
|
withResponse: false as const
|
|
1355
1349
|
};
|
|
1356
1350
|
const res = await this.client.${method}(path, requestParams);
|
|
1357
|
-
return res as InferResponseByStatus<TEndpoint, SuccessStatusCode>["data"];
|
|
1351
|
+
return res as Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"];
|
|
1358
1352
|
}
|
|
1359
1353
|
}
|
|
1360
1354
|
};
|
|
@@ -1377,7 +1371,7 @@ var generateTanstackQueryFile = async (ctx) => {
|
|
|
1377
1371
|
TWithResponse extends boolean = false,
|
|
1378
1372
|
TSelection = TWithResponse extends true
|
|
1379
1373
|
? InferResponseByStatus<TEndpoint, SuccessStatusCode>
|
|
1380
|
-
: TEndpoint
|
|
1374
|
+
: Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"],
|
|
1381
1375
|
TError = TEndpoint extends { responses: infer TResponses }
|
|
1382
1376
|
? TResponses extends Record<string | number, unknown>
|
|
1383
1377
|
? InferResponseByStatus<TEndpoint, ErrorStatusCode>
|
|
@@ -1387,7 +1381,7 @@ var generateTanstackQueryFile = async (ctx) => {
|
|
|
1387
1381
|
withResponse?: TWithResponse;
|
|
1388
1382
|
selectFn?: (res: TWithResponse extends true
|
|
1389
1383
|
? InferResponseByStatus<TEndpoint, SuccessStatusCode>
|
|
1390
|
-
: TEndpoint
|
|
1384
|
+
: Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"]
|
|
1391
1385
|
) => TSelection;
|
|
1392
1386
|
throwOnStatusError?: boolean
|
|
1393
1387
|
}) {
|
|
@@ -1401,9 +1395,7 @@ var generateTanstackQueryFile = async (ctx) => {
|
|
|
1401
1395
|
mutationKey: mutationKey,
|
|
1402
1396
|
mutationFn: async <TLocalWithResponse extends boolean = TWithResponse, TLocalSelection = TLocalWithResponse extends true
|
|
1403
1397
|
? InferResponseByStatus<TEndpoint, SuccessStatusCode>
|
|
1404
|
-
: TEndpoint
|
|
1405
|
-
? Res
|
|
1406
|
-
: never>
|
|
1398
|
+
: Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"]>
|
|
1407
1399
|
(params: (TEndpoint extends { parameters: infer Parameters } ? Parameters : {}) & {
|
|
1408
1400
|
withResponse?: TLocalWithResponse;
|
|
1409
1401
|
throwOnStatusError?: boolean;
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
package/dist/node.export.js
CHANGED
package/package.json
CHANGED
package/src/generator.ts
CHANGED
|
@@ -170,20 +170,10 @@ const parameterObjectToString = (parameters: Box<AnyBoxDef> | Record<string, Any
|
|
|
170
170
|
return str + "}";
|
|
171
171
|
};
|
|
172
172
|
|
|
173
|
-
const responseHeadersObjectToString = (responseHeaders: Record<string, Box<BoxObject
|
|
173
|
+
const responseHeadersObjectToString = (responseHeaders: Record<string, Box<BoxObject>>) => {
|
|
174
174
|
let str = "{";
|
|
175
175
|
for (const [key, responseHeader] of Object.entries(responseHeaders)) {
|
|
176
|
-
|
|
177
|
-
ctx.runtime === "none"
|
|
178
|
-
? responseHeader.recompute((box) => {
|
|
179
|
-
if (Box.isReference(box) && !box.params.generics && box.value !== "null") {
|
|
180
|
-
box.value = `Schemas.${box.value}`;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return box;
|
|
184
|
-
}).value
|
|
185
|
-
: responseHeader.value;
|
|
186
|
-
str += `${wrapWithQuotesIfNeeded(key.toLowerCase())}: ${value},\n`;
|
|
176
|
+
str += `${wrapWithQuotesIfNeeded(key.toLowerCase())}: ${responseHeader.value},\n`;
|
|
187
177
|
}
|
|
188
178
|
return str + "}";
|
|
189
179
|
};
|
|
@@ -245,7 +235,7 @@ const generateEndpointSchemaList = (ctx: GeneratorContext) => {
|
|
|
245
235
|
${endpoint.responses ? `responses: ${generateResponsesObject(endpoint.responses, ctx)},` : ""}
|
|
246
236
|
${
|
|
247
237
|
endpoint.responseHeaders
|
|
248
|
-
? `responseHeaders: ${responseHeadersObjectToString(endpoint.responseHeaders
|
|
238
|
+
? `responseHeaders: ${responseHeadersObjectToString(endpoint.responseHeaders)},`
|
|
249
239
|
: ""
|
|
250
240
|
}
|
|
251
241
|
}\n`;
|
|
@@ -472,7 +462,7 @@ export class ApiClient {
|
|
|
472
462
|
"valibot",
|
|
473
463
|
() => `InferResponseByStatus<${infer(`TEndpoint`)}, SuccessStatusCode>["data"]`,
|
|
474
464
|
)
|
|
475
|
-
.otherwise(() => `InferResponseByStatus<TEndpoint, SuccessStatusCode>["data"]`)}>;
|
|
465
|
+
.otherwise(() => `Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"]`)}>;
|
|
476
466
|
|
|
477
467
|
${method}<Path extends keyof ${capitalizedMethod}Endpoints, TEndpoint extends ${capitalizedMethod}Endpoints[Path]>(
|
|
478
468
|
path: Path,
|
|
@@ -514,7 +504,7 @@ export class ApiClient {
|
|
|
514
504
|
"valibot",
|
|
515
505
|
() => `as Promise<InferResponseByStatus<${infer(`TEndpoint`)}, SuccessStatusCode>["data"]>`,
|
|
516
506
|
)
|
|
517
|
-
.otherwise(() => `as Promise<InferResponseByStatus<TEndpoint, SuccessStatusCode>["data"]>`)}
|
|
507
|
+
.otherwise(() => `as Promise<Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"]>`)}
|
|
518
508
|
}
|
|
519
509
|
// </ApiClient.${method}>
|
|
520
510
|
`
|
|
@@ -95,7 +95,7 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
|
|
|
95
95
|
withResponse: false as const
|
|
96
96
|
};
|
|
97
97
|
const res = await this.client.${method}(path, requestParams);
|
|
98
|
-
return res as InferResponseByStatus<TEndpoint, SuccessStatusCode>["data"];
|
|
98
|
+
return res as Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"];
|
|
99
99
|
},
|
|
100
100
|
queryKey: queryKey
|
|
101
101
|
}),
|
|
@@ -110,7 +110,7 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
|
|
|
110
110
|
withResponse: false as const
|
|
111
111
|
};
|
|
112
112
|
const res = await this.client.${method}(path, requestParams);
|
|
113
|
-
return res as InferResponseByStatus<TEndpoint, SuccessStatusCode>["data"];
|
|
113
|
+
return res as Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"];
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
};
|
|
@@ -134,7 +134,7 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
|
|
|
134
134
|
TWithResponse extends boolean = false,
|
|
135
135
|
TSelection = TWithResponse extends true
|
|
136
136
|
? InferResponseByStatus<TEndpoint, SuccessStatusCode>
|
|
137
|
-
: TEndpoint
|
|
137
|
+
: Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"],
|
|
138
138
|
TError = TEndpoint extends { responses: infer TResponses }
|
|
139
139
|
? TResponses extends Record<string | number, unknown>
|
|
140
140
|
? InferResponseByStatus<TEndpoint, ErrorStatusCode>
|
|
@@ -144,7 +144,7 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
|
|
|
144
144
|
withResponse?: TWithResponse;
|
|
145
145
|
selectFn?: (res: TWithResponse extends true
|
|
146
146
|
? InferResponseByStatus<TEndpoint, SuccessStatusCode>
|
|
147
|
-
: TEndpoint
|
|
147
|
+
: Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"]
|
|
148
148
|
) => TSelection;
|
|
149
149
|
throwOnStatusError?: boolean
|
|
150
150
|
}) {
|
|
@@ -158,9 +158,7 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
|
|
|
158
158
|
mutationKey: mutationKey,
|
|
159
159
|
mutationFn: async <TLocalWithResponse extends boolean = TWithResponse, TLocalSelection = TLocalWithResponse extends true
|
|
160
160
|
? InferResponseByStatus<TEndpoint, SuccessStatusCode>
|
|
161
|
-
: TEndpoint
|
|
162
|
-
? Res
|
|
163
|
-
: never>
|
|
161
|
+
: Extract<InferResponseByStatus<TEndpoint, SuccessStatusCode>, { data: {} }>["data"]>
|
|
164
162
|
(params: (TEndpoint extends { parameters: infer Parameters } ? Parameters : {}) & {
|
|
165
163
|
withResponse?: TLocalWithResponse;
|
|
166
164
|
throwOnStatusError?: boolean;
|