@trpc/openapi 11.18.1-canary.9 → 11.19.0-alpha
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/{cli.js → cli.mjs} +104 -109
- package/dist/heyapi/index.cjs +24 -38
- package/dist/heyapi/index.d.cts +9 -12
- package/dist/heyapi/index.d.cts.map +1 -1
- package/dist/heyapi/index.d.mts +9 -12
- package/dist/heyapi/index.d.mts.map +1 -1
- package/dist/heyapi/index.mjs +23 -38
- package/dist/heyapi/index.mjs.map +1 -1
- package/dist/index.cjs +128 -108
- package/dist/index.d.cts +3 -8
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -9
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +89 -103
- package/dist/index.mjs.map +1 -1
- package/dist/objectSpread2-C2ceYbQe.cjs +67 -0
- package/dist/objectSpread2-Dh4InpQf.mjs +62 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/package.json +10 -10
- package/src/generate.ts +67 -8
- package/src/heyapi/index.ts +1 -2
- package/src/types.ts +9 -16
- package/dist/chunk-CJ2cON1m.mjs +0 -33
- package/dist/objectSpread2-Blgb1OZh.mjs +0 -90
- package/dist/objectSpread2-Blgb1OZh.mjs.map +0 -1
- package/dist/objectSpread2-Cw30I7tb.cjs +0 -131
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __exportAll = (all, no_symbols) => {
|
|
10
|
+
let target = {};
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
+
return target;
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
20
|
+
key = keys[i];
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
22
|
+
get: ((k) => from[k]).bind(null, key),
|
|
23
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
29
|
+
value: mod,
|
|
30
|
+
enumerable: true
|
|
31
|
+
}) : target, mod));
|
|
32
|
+
//#endregion
|
|
33
|
+
const require_objectSpread2 = require("./objectSpread2-C2ceYbQe.cjs");
|
|
34
|
+
let node_fs = require("node:fs");
|
|
35
|
+
node_fs = __toESM(node_fs, 1);
|
|
36
|
+
let node_path = require("node:path");
|
|
37
|
+
node_path = __toESM(node_path, 1);
|
|
38
|
+
let typescript = require("typescript");
|
|
39
|
+
typescript = __toESM(typescript, 1);
|
|
40
|
+
let node_url = require("node:url");
|
|
7
41
|
//#region src/schemaExtraction.ts
|
|
8
42
|
/**
|
|
9
43
|
* Zod v4 stores `.describe()` strings in `globalThis.__zod_globalRegistry`,
|
|
@@ -33,7 +67,7 @@ function zodArrayElement(schema) {
|
|
|
33
67
|
return null;
|
|
34
68
|
}
|
|
35
69
|
/** Wrapper def types whose inner schema is accessible via `innerType` or `in`. */
|
|
36
|
-
const wrapperDefTypes = new Set([
|
|
70
|
+
const wrapperDefTypes = /* @__PURE__ */ new Set([
|
|
37
71
|
"optional",
|
|
38
72
|
"nullable",
|
|
39
73
|
"nonoptional",
|
|
@@ -157,8 +191,7 @@ function findRouterExport(mod, exportName) {
|
|
|
157
191
|
*/
|
|
158
192
|
async function tryImportRouter(resolvedPath, exportName) {
|
|
159
193
|
try {
|
|
160
|
-
|
|
161
|
-
return findRouterExport(mod, exportName);
|
|
194
|
+
return findRouterExport(await import((0, node_url.pathToFileURL)(resolvedPath).href), exportName);
|
|
162
195
|
} catch (_unused) {
|
|
163
196
|
return null;
|
|
164
197
|
}
|
|
@@ -246,9 +279,8 @@ function setNestedDescription({ schema, pathParts, description, schemas }) {
|
|
|
246
279
|
if (rest.length === 0) setLeafDescription(items, description);
|
|
247
280
|
else {
|
|
248
281
|
var _resolveSchemaRef;
|
|
249
|
-
const target = (_resolveSchemaRef = resolveSchemaRef(items, schemas)) !== null && _resolveSchemaRef !== void 0 ? _resolveSchemaRef : items;
|
|
250
282
|
setNestedDescription({
|
|
251
|
-
schema:
|
|
283
|
+
schema: (_resolveSchemaRef = resolveSchemaRef(items, schemas)) !== null && _resolveSchemaRef !== void 0 ? _resolveSchemaRef : items,
|
|
252
284
|
pathParts: rest,
|
|
253
285
|
description,
|
|
254
286
|
schemas
|
|
@@ -262,19 +294,16 @@ function setNestedDescription({ schema, pathParts, description, schemas }) {
|
|
|
262
294
|
else {
|
|
263
295
|
var _getArrayItemsSchema, _resolveSchemaRef2;
|
|
264
296
|
const target = (_getArrayItemsSchema = getArrayItemsSchema(propSchema)) !== null && _getArrayItemsSchema !== void 0 ? _getArrayItemsSchema : propSchema;
|
|
265
|
-
const resolvedTarget = (_resolveSchemaRef2 = resolveSchemaRef(target, schemas)) !== null && _resolveSchemaRef2 !== void 0 ? _resolveSchemaRef2 : target;
|
|
266
297
|
setNestedDescription({
|
|
267
|
-
schema:
|
|
298
|
+
schema: (_resolveSchemaRef2 = resolveSchemaRef(target, schemas)) !== null && _resolveSchemaRef2 !== void 0 ? _resolveSchemaRef2 : target,
|
|
268
299
|
pathParts: rest,
|
|
269
300
|
description,
|
|
270
301
|
schemas
|
|
271
302
|
});
|
|
272
303
|
}
|
|
273
304
|
}
|
|
274
|
-
|
|
275
305
|
//#endregion
|
|
276
306
|
//#region src/generate.ts
|
|
277
|
-
var import_objectSpread2 = require_objectSpread2$1.__toESM(require_objectSpread2$1.require_objectSpread2(), 1);
|
|
278
307
|
const PRIMITIVE_FLAGS = typescript.TypeFlags.String | typescript.TypeFlags.Number | typescript.TypeFlags.Boolean | typescript.TypeFlags.StringLiteral | typescript.TypeFlags.NumberLiteral | typescript.TypeFlags.BooleanLiteral;
|
|
279
308
|
function hasFlag(type, flag) {
|
|
280
309
|
return (type.getFlags() & flag) !== 0;
|
|
@@ -285,6 +314,30 @@ function isPrimitive(type) {
|
|
|
285
314
|
function isObjectType(type) {
|
|
286
315
|
return hasFlag(type, typescript.TypeFlags.Object);
|
|
287
316
|
}
|
|
317
|
+
const STANDARD_FUNCTION_INTERFACES = /* @__PURE__ */ new Set([
|
|
318
|
+
"Function",
|
|
319
|
+
"CallableFunction",
|
|
320
|
+
"NewableFunction"
|
|
321
|
+
]);
|
|
322
|
+
function isStandardFunctionInterface(type) {
|
|
323
|
+
var _symbol$declarations$, _symbol$declarations;
|
|
324
|
+
const symbol = type.getSymbol();
|
|
325
|
+
const name = symbol === null || symbol === void 0 ? void 0 : symbol.getName();
|
|
326
|
+
if (!name || !STANDARD_FUNCTION_INTERFACES.has(name)) return false;
|
|
327
|
+
return (_symbol$declarations$ = symbol === null || symbol === void 0 || (_symbol$declarations = symbol.declarations) === null || _symbol$declarations === void 0 ? void 0 : _symbol$declarations.some((d) => /(^|[\\/])lib\.[^\\/]*\.d\.ts$/.test(d.getSourceFile().fileName))) !== null && _symbol$declarations$ !== void 0 ? _symbol$declarations$ : false;
|
|
328
|
+
}
|
|
329
|
+
function isFunctionType(type) {
|
|
330
|
+
return type.getCallSignatures().length > 0 || type.getConstructSignatures().length > 0 || isStandardFunctionInterface(type);
|
|
331
|
+
}
|
|
332
|
+
function hasFunctionMember(type) {
|
|
333
|
+
if (isFunctionType(type)) return true;
|
|
334
|
+
return type.isUnion() && type.types.some(isFunctionType);
|
|
335
|
+
}
|
|
336
|
+
function isUnserialisableType(type) {
|
|
337
|
+
if (isFunctionType(type)) return true;
|
|
338
|
+
if (!type.isUnion() || !type.types.some(isFunctionType)) return false;
|
|
339
|
+
return !type.types.some((m) => !isFunctionType(m) && !hasFlag(m, typescript.TypeFlags.Undefined | typescript.TypeFlags.Void | typescript.TypeFlags.Null));
|
|
340
|
+
}
|
|
288
341
|
function isOptionalSymbol(sym) {
|
|
289
342
|
return (sym.flags & typescript.SymbolFlags.Optional) !== 0;
|
|
290
343
|
}
|
|
@@ -300,7 +353,7 @@ function unwrapBrand(type) {
|
|
|
300
353
|
if (first && hasObject) return first;
|
|
301
354
|
return type;
|
|
302
355
|
}
|
|
303
|
-
const ANONYMOUS_NAMES = new Set([
|
|
356
|
+
const ANONYMOUS_NAMES = /* @__PURE__ */ new Set([
|
|
304
357
|
"__type",
|
|
305
358
|
"__object",
|
|
306
359
|
"Object",
|
|
@@ -362,8 +415,8 @@ function typeToJsonSchema(type, ctx, depth = 0) {
|
|
|
362
415
|
const storedSchema = ctx.schemas[existingRef];
|
|
363
416
|
if (storedSchema && (isNonEmptySchema(storedSchema) || ctx.visited.has(type))) return schemaRef(existingRef);
|
|
364
417
|
ctx.schemas[existingRef] = storedSchema !== null && storedSchema !== void 0 ? storedSchema : {};
|
|
365
|
-
const schema
|
|
366
|
-
if (!isSelfSchemaRef(schema
|
|
418
|
+
const schema = convertTypeToSchema(type, ctx, depth);
|
|
419
|
+
if (!isSelfSchemaRef(schema, existingRef)) ctx.schemas[existingRef] = schema;
|
|
367
420
|
return schemaRef(existingRef);
|
|
368
421
|
}
|
|
369
422
|
const schema = convertTypeToSchema(type, ctx, depth);
|
|
@@ -387,8 +440,7 @@ function handleCyclicRef(type, ctx) {
|
|
|
387
440
|
let refName = ctx.typeToRef.get(type);
|
|
388
441
|
if (!refName) {
|
|
389
442
|
var _getTypeName;
|
|
390
|
-
|
|
391
|
-
refName = ensureUniqueName(name, ctx.schemas);
|
|
443
|
+
refName = ensureUniqueName((_getTypeName = getTypeName(type)) !== null && _getTypeName !== void 0 ? _getTypeName : "RecursiveType", ctx.schemas);
|
|
392
444
|
ctx.typeToRef.set(type, refName);
|
|
393
445
|
ctx.schemas[refName] = {};
|
|
394
446
|
}
|
|
@@ -415,18 +467,14 @@ function convertPrimitiveOrLiteral(type, flags, checker) {
|
|
|
415
467
|
type: "number",
|
|
416
468
|
const: type.value
|
|
417
469
|
};
|
|
418
|
-
if (flags & typescript.TypeFlags.BooleanLiteral) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
const: isTrue
|
|
423
|
-
};
|
|
424
|
-
}
|
|
470
|
+
if (flags & typescript.TypeFlags.BooleanLiteral) return {
|
|
471
|
+
type: "boolean",
|
|
472
|
+
const: checker.typeToString(type) === "true"
|
|
473
|
+
};
|
|
425
474
|
return null;
|
|
426
475
|
}
|
|
427
476
|
function convertUnionType(type, ctx, depth) {
|
|
428
|
-
const
|
|
429
|
-
const defined = members.filter((m) => !hasFlag(m, typescript.TypeFlags.Undefined | typescript.TypeFlags.Void));
|
|
477
|
+
const defined = type.types.filter((m) => !hasFlag(m, typescript.TypeFlags.Undefined | typescript.TypeFlags.Void) && !isFunctionType(m));
|
|
430
478
|
if (defined.length === 0) return {};
|
|
431
479
|
const hasNull = defined.some((m) => hasFlag(m, typescript.TypeFlags.Null));
|
|
432
480
|
const nonNull = defined.filter((m) => !hasFlag(m, typescript.TypeFlags.Null));
|
|
@@ -460,14 +508,11 @@ function detectDiscriminatorProperty(schemas) {
|
|
|
460
508
|
const first = schemas[0];
|
|
461
509
|
if (!(first === null || first === void 0 ? void 0 : first.properties)) return null;
|
|
462
510
|
const firstProps = Object.keys(first.properties);
|
|
463
|
-
for (const prop of firstProps) {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
});
|
|
469
|
-
if (allHaveConst) return prop;
|
|
470
|
-
}
|
|
511
|
+
for (const prop of firstProps) if (schemas.every((s) => {
|
|
512
|
+
var _s$properties, _s$required;
|
|
513
|
+
const propSchema = (_s$properties = s.properties) === null || _s$properties === void 0 ? void 0 : _s$properties[prop];
|
|
514
|
+
return (propSchema === null || propSchema === void 0 ? void 0 : propSchema.const) !== void 0 && ((_s$required = s.required) === null || _s$required === void 0 ? void 0 : _s$required.includes(prop));
|
|
515
|
+
})) return prop;
|
|
471
516
|
return null;
|
|
472
517
|
}
|
|
473
518
|
/** A schema that is just `{ type: "somePrimitive" }` with no other keys. */
|
|
@@ -481,14 +526,12 @@ function isSimpleTypeSchema(s) {
|
|
|
481
526
|
*/
|
|
482
527
|
function tryCollapseLiteralUnion(nonNull, hasNull) {
|
|
483
528
|
if (nonNull.length <= 1) return null;
|
|
484
|
-
|
|
485
|
-
if (!allLiterals) return null;
|
|
529
|
+
if (!nonNull.every((m) => hasFlag(m, typescript.TypeFlags.StringLiteral | typescript.TypeFlags.NumberLiteral))) return null;
|
|
486
530
|
const [first] = nonNull;
|
|
487
531
|
if (!first) return null;
|
|
488
532
|
const isString = hasFlag(first, typescript.TypeFlags.StringLiteral);
|
|
489
533
|
const targetFlag = isString ? typescript.TypeFlags.StringLiteral : typescript.TypeFlags.NumberLiteral;
|
|
490
|
-
|
|
491
|
-
if (!allSameKind) return null;
|
|
534
|
+
if (!nonNull.every((m) => hasFlag(m, targetFlag))) return null;
|
|
492
535
|
const values = nonNull.map((m) => isString ? m.value : m.value);
|
|
493
536
|
const baseType = isString ? "string" : "number";
|
|
494
537
|
return {
|
|
@@ -497,9 +540,7 @@ function tryCollapseLiteralUnion(nonNull, hasNull) {
|
|
|
497
540
|
};
|
|
498
541
|
}
|
|
499
542
|
function convertIntersectionType(type, ctx, depth) {
|
|
500
|
-
const
|
|
501
|
-
const nonBrand = hasPrimitiveMember ? type.types.filter((m) => !isObjectType(m)) : type.types;
|
|
502
|
-
const schemas = nonBrand.map((m) => typeToJsonSchema(m, ctx, depth + 1)).filter(isNonEmptySchema);
|
|
543
|
+
const schemas = (type.types.some(isPrimitive) ? type.types.filter((m) => !isObjectType(m)) : type.types).map((m) => typeToJsonSchema(m, ctx, depth + 1)).filter(isNonEmptySchema);
|
|
503
544
|
if (schemas.length === 0) return {};
|
|
504
545
|
const [onlySchema] = schemas;
|
|
505
546
|
if (schemas.length === 1 && onlySchema !== void 0) return onlySchema;
|
|
@@ -559,10 +600,9 @@ function convertArrayType(type, ctx, depth) {
|
|
|
559
600
|
}
|
|
560
601
|
function convertTupleType(type, ctx, depth) {
|
|
561
602
|
const args = ctx.checker.getTypeArguments(type);
|
|
562
|
-
const schemas = args.map((a) => typeToJsonSchema(a, ctx, depth + 1));
|
|
563
603
|
return {
|
|
564
604
|
type: "array",
|
|
565
|
-
prefixItems:
|
|
605
|
+
prefixItems: args.map((a) => typeToJsonSchema(a, ctx, depth + 1)),
|
|
566
606
|
items: false,
|
|
567
607
|
minItems: args.length,
|
|
568
608
|
maxItems: args.length
|
|
@@ -579,8 +619,7 @@ function convertPlainObject(type, ctx, depth) {
|
|
|
579
619
|
};
|
|
580
620
|
let autoRegName = null;
|
|
581
621
|
const tsName = getTypeName(type);
|
|
582
|
-
|
|
583
|
-
if (isNamedUnregisteredType) {
|
|
622
|
+
if (tsName !== null && typeProps.length > 0 && !ctx.typeToRef.has(type)) {
|
|
584
623
|
autoRegName = ensureUniqueName(tsName, ctx.schemas);
|
|
585
624
|
ctx.typeToRef.set(type, autoRegName);
|
|
586
625
|
ctx.schemas[autoRegName] = {};
|
|
@@ -591,18 +630,19 @@ function convertPlainObject(type, ctx, depth) {
|
|
|
591
630
|
for (const prop of typeProps) {
|
|
592
631
|
if (shouldSkipPropertySymbol(prop)) continue;
|
|
593
632
|
const propType = checker.getTypeOfSymbol(prop);
|
|
633
|
+
if (isUnserialisableType(propType)) continue;
|
|
594
634
|
const propSchema = typeToJsonSchema(propType, ctx, depth + 1);
|
|
595
635
|
const jsDoc = getJsDocComment(prop, checker);
|
|
596
636
|
if (jsDoc && !propSchema.description && !propSchema.$ref) propSchema.description = jsDoc;
|
|
597
637
|
properties[prop.name] = propSchema;
|
|
598
|
-
if (!isOptionalSymbol(prop)) required.push(prop.name);
|
|
638
|
+
if (!isOptionalSymbol(prop) && !hasFunctionMember(propType)) required.push(prop.name);
|
|
599
639
|
}
|
|
600
640
|
ctx.visited.delete(type);
|
|
601
641
|
const result = { type: "object" };
|
|
602
642
|
if (Object.keys(properties).length > 0) result.properties = properties;
|
|
603
643
|
if (required.length > 0) result.required = required;
|
|
604
644
|
if (stringIndexType) result.additionalProperties = typeToJsonSchema(stringIndexType, ctx, depth + 1);
|
|
605
|
-
else if (
|
|
645
|
+
else if (typeProps.length > 0) result.additionalProperties = false;
|
|
606
646
|
const registeredName = (_autoRegName = autoRegName) !== null && _autoRegName !== void 0 ? _autoRegName : ctx.typeToRef.get(type);
|
|
607
647
|
if (registeredName) {
|
|
608
648
|
ctx.schemas[registeredName] = result;
|
|
@@ -620,8 +660,7 @@ function convertObjectType(type, ctx, depth) {
|
|
|
620
660
|
/** Core type-to-schema conversion (no ref handling). */
|
|
621
661
|
function convertTypeToSchema(type, ctx, depth) {
|
|
622
662
|
if (ctx.visited.has(type)) return handleCyclicRef(type, ctx);
|
|
623
|
-
const
|
|
624
|
-
const primitive = convertPrimitiveOrLiteral(type, flags, ctx.checker);
|
|
663
|
+
const primitive = convertPrimitiveOrLiteral(type, type.getFlags(), ctx.checker);
|
|
625
664
|
if (primitive) return primitive;
|
|
626
665
|
if (type.isUnion()) {
|
|
627
666
|
ctx.visited.add(type);
|
|
@@ -635,6 +674,7 @@ function convertTypeToSchema(type, ctx, depth) {
|
|
|
635
674
|
ctx.visited.delete(type);
|
|
636
675
|
return result;
|
|
637
676
|
}
|
|
677
|
+
if (isFunctionType(type)) return {};
|
|
638
678
|
if (isObjectType(type)) return convertObjectType(type, ctx, depth);
|
|
639
679
|
return {};
|
|
640
680
|
}
|
|
@@ -652,10 +692,8 @@ function getProcedureTypeName(defType, checker) {
|
|
|
652
692
|
}
|
|
653
693
|
function isVoidLikeInput(inputType) {
|
|
654
694
|
if (!inputType) return true;
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
const isUnionOfVoids = inputType.isUnion() && inputType.types.every((t) => hasFlag(t, typescript.TypeFlags.Void | typescript.TypeFlags.Undefined));
|
|
658
|
-
return isUnionOfVoids;
|
|
695
|
+
if (hasFlag(inputType, typescript.TypeFlags.Void | typescript.TypeFlags.Undefined | typescript.TypeFlags.Never)) return true;
|
|
696
|
+
return inputType.isUnion() && inputType.types.every((t) => hasFlag(t, typescript.TypeFlags.Void | typescript.TypeFlags.Undefined));
|
|
659
697
|
}
|
|
660
698
|
function shouldIncludeProcedureInOpenAPI(type) {
|
|
661
699
|
return type !== "subscription";
|
|
@@ -671,8 +709,7 @@ function getProcedureInputTypeName(type, path) {
|
|
|
671
709
|
if (declarationName && !ANONYMOUS_NAMES.has(declarationName) && !declarationName.startsWith("__")) return declarationName;
|
|
672
710
|
}
|
|
673
711
|
}
|
|
674
|
-
|
|
675
|
-
return `${fallbackName || "Procedure"}Input`;
|
|
712
|
+
return `${path.split(".").filter(Boolean).map((segment) => segment.split(/[^A-Za-z0-9]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")).join("") || "Procedure"}Input`;
|
|
676
713
|
}
|
|
677
714
|
function isUnknownLikeType(type) {
|
|
678
715
|
return hasFlag(type, typescript.TypeFlags.Unknown | typescript.TypeFlags.Any);
|
|
@@ -703,14 +740,11 @@ function recoverProcedureInputType(def, checker) {
|
|
|
703
740
|
if (callee.name.text !== "input") return;
|
|
704
741
|
const [parserExpr] = expr.arguments;
|
|
705
742
|
if (!parserExpr) return;
|
|
706
|
-
const
|
|
707
|
-
const standardSym = parserType.getProperty("~standard");
|
|
743
|
+
const standardSym = checker.getTypeAtLocation(parserExpr).getProperty("~standard");
|
|
708
744
|
if (!standardSym) return;
|
|
709
|
-
const
|
|
710
|
-
const typesSym = standardType.getProperty("types");
|
|
745
|
+
const typesSym = checker.getTypeOfSymbolAtLocation(standardSym, parserExpr).getProperty("types");
|
|
711
746
|
if (!typesSym) return;
|
|
712
|
-
const
|
|
713
|
-
const outputSym = typesType.getProperty("output");
|
|
747
|
+
const outputSym = checker.getNonNullableType(checker.getTypeOfSymbolAtLocation(typesSym, parserExpr)).getProperty("output");
|
|
714
748
|
if (!outputSym) return;
|
|
715
749
|
const outputType = checker.getTypeOfSymbolAtLocation(outputSym, parserExpr);
|
|
716
750
|
if (!isUnknownLikeType(outputType)) recovered = outputType;
|
|
@@ -766,22 +800,18 @@ function getJsDocComment(sym, checker) {
|
|
|
766
800
|
var _sym$declarations2;
|
|
767
801
|
const normalize = (filePath) => filePath.replace(/\\/g, "/");
|
|
768
802
|
const declarations = (_sym$declarations2 = sym.declarations) !== null && _sym$declarations2 !== void 0 ? _sym$declarations2 : [];
|
|
769
|
-
|
|
803
|
+
if (declarations.length > 0 && declarations.every((declaration) => {
|
|
770
804
|
const sourceFile = declaration.getSourceFile();
|
|
771
805
|
if (!sourceFile.isDeclarationFile) return false;
|
|
772
|
-
|
|
773
|
-
if (!declarationPath.includes("/node_modules/")) return false;
|
|
806
|
+
if (!normalize(sourceFile.fileName).includes("/node_modules/")) return false;
|
|
774
807
|
try {
|
|
775
|
-
|
|
776
|
-
if (!realPath.includes("/node_modules/")) return false;
|
|
808
|
+
if (!normalize(node_fs.realpathSync.native(sourceFile.fileName)).includes("/node_modules/")) return false;
|
|
777
809
|
} catch (_unused) {}
|
|
778
810
|
return true;
|
|
779
|
-
});
|
|
780
|
-
if (isExternalNodeModulesDeclaration) return void 0;
|
|
811
|
+
})) return;
|
|
781
812
|
const parts = sym.getDocumentationComment(checker);
|
|
782
|
-
if (parts.length === 0) return
|
|
783
|
-
|
|
784
|
-
return text || void 0;
|
|
813
|
+
if (parts.length === 0) return;
|
|
814
|
+
return parts.map((p) => p.text).join("") || void 0;
|
|
785
815
|
}
|
|
786
816
|
function walkType(opts) {
|
|
787
817
|
const { type, ctx, currentPath, description, symbol } = opts;
|
|
@@ -812,28 +842,21 @@ function walkType(opts) {
|
|
|
812
842
|
}
|
|
813
843
|
const routerSym = defType.getProperty("router");
|
|
814
844
|
if (!routerSym) return;
|
|
815
|
-
|
|
816
|
-
if (!isRouter) return;
|
|
845
|
+
if (!(checker.typeToString(checker.getTypeOfSymbol(routerSym)) === "true")) return;
|
|
817
846
|
const recordSym = defType.getProperty("record");
|
|
818
847
|
if (!recordSym) return;
|
|
819
848
|
ctx.seen.add(type);
|
|
820
|
-
|
|
821
|
-
walkRecord(recordType, ctx, currentPath);
|
|
849
|
+
walkRecord(checker.getTypeOfSymbol(recordSym), ctx, currentPath);
|
|
822
850
|
ctx.seen.delete(type);
|
|
823
851
|
}
|
|
824
852
|
function walkRecord(recordType, ctx, prefix) {
|
|
825
|
-
for (const prop of recordType.getProperties()) {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
currentPath: fullPath,
|
|
833
|
-
description,
|
|
834
|
-
symbol: prop
|
|
835
|
-
});
|
|
836
|
-
}
|
|
853
|
+
for (const prop of recordType.getProperties()) walkType({
|
|
854
|
+
type: ctx.schemaCtx.checker.getTypeOfSymbol(prop),
|
|
855
|
+
ctx,
|
|
856
|
+
currentPath: prefix ? `${prefix}.${prop.name}` : prop.name,
|
|
857
|
+
description: getJsDocComment(prop, ctx.schemaCtx.checker),
|
|
858
|
+
symbol: prop
|
|
859
|
+
});
|
|
837
860
|
}
|
|
838
861
|
function loadCompilerOptions(startDir) {
|
|
839
862
|
const configPath = typescript.findConfigFile(startDir, (f) => typescript.sys.fileExists(f), "tsconfig.json");
|
|
@@ -845,7 +868,7 @@ function loadCompilerOptions(startDir) {
|
|
|
845
868
|
};
|
|
846
869
|
const configFile = typescript.readConfigFile(configPath, (f) => typescript.sys.readFile(f));
|
|
847
870
|
const parsed = typescript.parseJsonConfigFileContent(configFile.config, typescript.sys, node_path.dirname(configPath));
|
|
848
|
-
const options =
|
|
871
|
+
const options = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, parsed.options), {}, { noEmit: true });
|
|
849
872
|
if (options.moduleResolution === void 0) {
|
|
850
873
|
const mod = options.module;
|
|
851
874
|
if (mod === typescript.ModuleKind.Node16 || mod === typescript.ModuleKind.NodeNext) options.moduleResolution = typescript.ModuleResolutionKind.NodeNext;
|
|
@@ -898,19 +921,18 @@ const DEFAULT_ERROR_SCHEMA = {
|
|
|
898
921
|
*/
|
|
899
922
|
function wrapInSuccessEnvelope(outputSchema) {
|
|
900
923
|
const hasOutput = outputSchema !== null && isNonEmptySchema(outputSchema);
|
|
901
|
-
const resultSchema = (0, import_objectSpread2.default)({
|
|
902
|
-
type: "object",
|
|
903
|
-
properties: (0, import_objectSpread2.default)({}, hasOutput ? { data: outputSchema } : {})
|
|
904
|
-
}, hasOutput ? { required: ["data"] } : {});
|
|
905
924
|
return {
|
|
906
925
|
type: "object",
|
|
907
|
-
properties: { result:
|
|
926
|
+
properties: { result: require_objectSpread2._objectSpread2({
|
|
927
|
+
type: "object",
|
|
928
|
+
properties: require_objectSpread2._objectSpread2({}, hasOutput ? { data: outputSchema } : {})
|
|
929
|
+
}, hasOutput ? { required: ["data"] } : {}) },
|
|
908
930
|
required: ["result"]
|
|
909
931
|
};
|
|
910
932
|
}
|
|
911
933
|
function buildProcedureOperation(proc, method) {
|
|
912
934
|
const [tag = proc.path] = proc.path.split(".");
|
|
913
|
-
const operation =
|
|
935
|
+
const operation = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({ operationId: proc.path }, proc.description ? { description: proc.description } : {}), {}, {
|
|
914
936
|
tags: [tag],
|
|
915
937
|
responses: {
|
|
916
938
|
"200": {
|
|
@@ -947,7 +969,7 @@ function buildOpenAPIDocument(procedures, options, meta = { errorSchema: null })
|
|
|
947
969
|
pathItem[method] = buildProcedureOperation(proc, method);
|
|
948
970
|
}
|
|
949
971
|
const hasNamedSchemas = meta.schemas !== void 0 && Object.keys(meta.schemas).length > 0;
|
|
950
|
-
return
|
|
972
|
+
return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({
|
|
951
973
|
openapi: "3.1.1",
|
|
952
974
|
jsonSchemaDialect: "https://spec.openapis.org/oas/3.1/dialect/base",
|
|
953
975
|
info: {
|
|
@@ -956,7 +978,7 @@ function buildOpenAPIDocument(procedures, options, meta = { errorSchema: null })
|
|
|
956
978
|
}
|
|
957
979
|
}, ((_options$servers = options.servers) === null || _options$servers === void 0 ? void 0 : _options$servers.length) ? { servers: options.servers } : {}), {}, {
|
|
958
980
|
paths,
|
|
959
|
-
components:
|
|
981
|
+
components: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, hasNamedSchemas && meta.schemas ? { schemas: meta.schemas } : {}), {}, { responses: { Error: {
|
|
960
982
|
description: "Error response",
|
|
961
983
|
content: { "application/json": { schema: {
|
|
962
984
|
type: "object",
|
|
@@ -1020,16 +1042,14 @@ async function generateOpenAPIDocument(routerFilePath, options = {}) {
|
|
|
1020
1042
|
schemas: schemaCtx.schemas
|
|
1021
1043
|
});
|
|
1022
1044
|
}
|
|
1023
|
-
|
|
1024
1045
|
//#endregion
|
|
1025
1046
|
//#region src/types.ts
|
|
1026
|
-
var types_exports = {};
|
|
1027
|
-
|
|
1047
|
+
var types_exports = /* @__PURE__ */ __exportAll({});
|
|
1028
1048
|
//#endregion
|
|
1029
|
-
Object.defineProperty(exports,
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1049
|
+
Object.defineProperty(exports, "OpenAPIV3_1", {
|
|
1050
|
+
enumerable: true,
|
|
1051
|
+
get: function() {
|
|
1052
|
+
return types_exports;
|
|
1053
|
+
}
|
|
1034
1054
|
});
|
|
1035
|
-
exports.generateOpenAPIDocument = generateOpenAPIDocument;
|
|
1055
|
+
exports.generateOpenAPIDocument = generateOpenAPIDocument;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { OpenAPIV3_1 } from "openapi-types";
|
|
2
|
-
|
|
3
|
-
//#region rolldown:runtime
|
|
4
2
|
declare namespace types_d_exports {
|
|
5
3
|
export { ArraySchemaObject, CallbackObject, ComponentsObject, DiscriminatorObject, Document, ExampleObject, ExternalDocumentationObject, HeaderObject, HttpMethods, LinkObject, MediaTypeObject, OperationObject, ParameterBaseObject, ParameterObject, PathItemObject, PathsObject, PrimitiveSchemaType, ReferenceObject, Replace, RequestBodyObject, ResponseObject, ResponsesObject, SchemaLike, SchemaObject, SchemaType, SecuritySchemeObject, ServerObject, XMLObject };
|
|
6
4
|
}
|
|
@@ -75,7 +73,7 @@ type OperationObject<T extends {} = {}> = Replace<OpenAPIV3_1.OperationObject<T>
|
|
|
75
73
|
}> & T;
|
|
76
74
|
type PathItemObject<T extends {} = {}> = Replace<OpenAPIV3_1.PathItemObject<T>, {
|
|
77
75
|
parameters?: (ReferenceObject | ParameterObject)[];
|
|
78
|
-
}> & { [method in HttpMethods]?: OperationObject<T
|
|
76
|
+
}> & { [method in HttpMethods]?: OperationObject<T>; };
|
|
79
77
|
type PathsObject<T extends {} = {}, TPath extends {} = {}> = Record<string, (PathItemObject<T> & TPath) | undefined>;
|
|
80
78
|
type CallbackObject = Record<string, PathItemObject | ReferenceObject>;
|
|
81
79
|
type ComponentsObject = Replace<OpenAPIV3_1.ComponentsObject, {
|
|
@@ -92,7 +90,6 @@ type Document<T extends {} = {}> = Replace<OpenAPIV3_1.Document<T>, {
|
|
|
92
90
|
paths?: PathsObject<T>;
|
|
93
91
|
components?: ComponentsObject;
|
|
94
92
|
}>;
|
|
95
|
-
//# sourceMappingURL=types.d.ts.map
|
|
96
93
|
//#endregion
|
|
97
94
|
//#region src/generate.d.ts
|
|
98
95
|
interface GenerateOptions {
|
|
@@ -121,9 +118,7 @@ interface GenerateOptions {
|
|
|
121
118
|
* the AppRouter.
|
|
122
119
|
* @param options - Optional generation settings (export name, title, version).
|
|
123
120
|
*/
|
|
124
|
-
declare function generateOpenAPIDocument(routerFilePath: string, options?: GenerateOptions): Promise<Document>;
|
|
125
|
-
//# sourceMappingURL=generate.d.ts.map
|
|
126
|
-
|
|
121
|
+
export declare function generateOpenAPIDocument(routerFilePath: string, options?: GenerateOptions): Promise<Document>;
|
|
127
122
|
//#endregion
|
|
128
|
-
export { GenerateOptions, types_d_exports as OpenAPIV3_1
|
|
123
|
+
export { type GenerateOptions, types_d_exports as OpenAPIV3_1 };
|
|
129
124
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/generate.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/generate.ts"],"mappings":";;;;KAEY,QAAQ,SAAS,gBAAgB,KAAK,eAAe,gBAC/D;KAEU;KAGA,sBAAsB;KAEtB,cAAc,YAAgB;KAC9B,kBAAkB,YAAgB;KAClC,gBAAgB,YAAgB;KAChC,sBAAsB,YAAgB;KACtC,8BACV,YAAgB;KACN,YAAY,YAAgB;KAC5B,aAAa,YAAgB;KAC7B,uBAAuB,YAAgB;KACvC,eAAe,YAAgB;KAE/B,eAAe,QACzB,YAAgB;EAEd;EACA,QAAQ,eAAe;EACvB;EACA;EACA,aAAa,eAAe;EAC5B;EACA,QAAQ;EACR,cAAc;EACd;EACA;EACA,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,MAAM;EACN,iCAAiC;EACjC,gBAAgB;EAChB,eAAe;EACf,MAAM;EACN;EACA;EACA;;KAIQ,aAAa;UAER,0BAA0B;EACzC;EACA,OAAO;;KAGG,kBAAkB,QAC5B,YAAgB;EAEd,SAAS,eAAe;EACxB,WAAW,eAAe,kBAAkB;;UAI/B,4BAA4B,QAC3C,YAAgB;EAEd,SAAS,eAAe;EACxB,WAAW,eAAe,kBAAkB;EAC5C,UAAU,eAAe;;UAIZ,wBAAwB;EACvC;EACA;;KAGU,eAAe;KAEf,oBAAoB,QAC9B,YAAgB;EAEd,SAAS,eAAe;;KAIhB,iBAAiB,QAC3B,YAAgB;EAEd,UAAU,eAAe,kBAAkB;EAC3C,UAAU,eAAe;EACzB,QAAQ,eAAe,kBAAkB;;KAIjC,kBAAkB,eAAe,kBAAkB;KAEnD,gBAAgB,qBAAqB,QAC/C,YAAgB,gBAAgB;EAE9B,cAAc,kBAAkB;EAChC,cAAc,kBAAkB;EAChC,YAAY;EACZ,YAAY,eAAe,kBAAkB;KAG/C;KAEU,eAAe,qBAAqB,QAC9C,YAAgB,eAAe;EAE7B,cAAc,kBAAkB;QAGjC,UAAU,eAAe,gBAAgB;KAGhC,YAAY,mBAAmB,yBAAyB,gBAEjE,eAAe,KAAK;KAGX,iBAAiB,eAAe,iBAAiB;KAEjD,mBAAmB,QAC7B,YAAgB;EAEd,UAAU,eAAe;EACzB,YAAY,eAAe,kBAAkB;EAC7C,aAAa,eAAe,kBAAkB;EAC9C,gBAAgB,eAAe,kBAAkB;EACjD,UAAU,eAAe,kBAAkB;EAC3C,QAAQ,eAAe,kBAAkB;EACzC,YAAY,eAAe,kBAAkB;EAC7C,YAAY,eAAe,kBAAkB;;KAIrC,SAAS,qBAAqB,QACxC,YAAgB,SAAS;EAEvB,QAAQ,YAAY;EACpB,aAAa;;;;UC9GA;;;;;EAKf;;EAEA;;EAEA;;;;;;;EAOA,UAAU;;;;;;;;;;wBA88CU,wBACpB,wBACA,UAAS,kBACR,QAAQ"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { __export } from "./chunk-CJ2cON1m.mjs";
|
|
2
1
|
import { OpenAPIV3_1 } from "openapi-types";
|
|
3
|
-
|
|
4
|
-
//#region src/types.d.ts
|
|
5
2
|
declare namespace types_d_exports {
|
|
6
3
|
export { ArraySchemaObject, CallbackObject, ComponentsObject, DiscriminatorObject, Document, ExampleObject, ExternalDocumentationObject, HeaderObject, HttpMethods, LinkObject, MediaTypeObject, OperationObject, ParameterBaseObject, ParameterObject, PathItemObject, PathsObject, PrimitiveSchemaType, ReferenceObject, Replace, RequestBodyObject, ResponseObject, ResponsesObject, SchemaLike, SchemaObject, SchemaType, SecuritySchemeObject, ServerObject, XMLObject };
|
|
7
4
|
}
|
|
@@ -76,7 +73,7 @@ type OperationObject<T extends {} = {}> = Replace<OpenAPIV3_1.OperationObject<T>
|
|
|
76
73
|
}> & T;
|
|
77
74
|
type PathItemObject<T extends {} = {}> = Replace<OpenAPIV3_1.PathItemObject<T>, {
|
|
78
75
|
parameters?: (ReferenceObject | ParameterObject)[];
|
|
79
|
-
}> & { [method in HttpMethods]?: OperationObject<T
|
|
76
|
+
}> & { [method in HttpMethods]?: OperationObject<T>; };
|
|
80
77
|
type PathsObject<T extends {} = {}, TPath extends {} = {}> = Record<string, (PathItemObject<T> & TPath) | undefined>;
|
|
81
78
|
type CallbackObject = Record<string, PathItemObject | ReferenceObject>;
|
|
82
79
|
type ComponentsObject = Replace<OpenAPIV3_1.ComponentsObject, {
|
|
@@ -93,7 +90,6 @@ type Document<T extends {} = {}> = Replace<OpenAPIV3_1.Document<T>, {
|
|
|
93
90
|
paths?: PathsObject<T>;
|
|
94
91
|
components?: ComponentsObject;
|
|
95
92
|
}>;
|
|
96
|
-
//# sourceMappingURL=types.d.ts.map
|
|
97
93
|
//#endregion
|
|
98
94
|
//#region src/generate.d.ts
|
|
99
95
|
interface GenerateOptions {
|
|
@@ -122,9 +118,7 @@ interface GenerateOptions {
|
|
|
122
118
|
* the AppRouter.
|
|
123
119
|
* @param options - Optional generation settings (export name, title, version).
|
|
124
120
|
*/
|
|
125
|
-
declare function generateOpenAPIDocument(routerFilePath: string, options?: GenerateOptions): Promise<Document>;
|
|
126
|
-
//# sourceMappingURL=generate.d.ts.map
|
|
127
|
-
|
|
121
|
+
export declare function generateOpenAPIDocument(routerFilePath: string, options?: GenerateOptions): Promise<Document>;
|
|
128
122
|
//#endregion
|
|
129
|
-
export { GenerateOptions, types_d_exports as OpenAPIV3_1
|
|
123
|
+
export { type GenerateOptions, types_d_exports as OpenAPIV3_1 };
|
|
130
124
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/generate.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/generate.ts"],"mappings":";;;;KAEY,QAAQ,SAAS,gBAAgB,KAAK,eAAe,gBAC/D;KAEU;KAGA,sBAAsB;KAEtB,cAAc,YAAgB;KAC9B,kBAAkB,YAAgB;KAClC,gBAAgB,YAAgB;KAChC,sBAAsB,YAAgB;KACtC,8BACV,YAAgB;KACN,YAAY,YAAgB;KAC5B,aAAa,YAAgB;KAC7B,uBAAuB,YAAgB;KACvC,eAAe,YAAgB;KAE/B,eAAe,QACzB,YAAgB;EAEd;EACA,QAAQ,eAAe;EACvB;EACA;EACA,aAAa,eAAe;EAC5B;EACA,QAAQ;EACR,cAAc;EACd;EACA;EACA,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,MAAM;EACN,iCAAiC;EACjC,gBAAgB;EAChB,eAAe;EACf,MAAM;EACN;EACA;EACA;;KAIQ,aAAa;UAER,0BAA0B;EACzC;EACA,OAAO;;KAGG,kBAAkB,QAC5B,YAAgB;EAEd,SAAS,eAAe;EACxB,WAAW,eAAe,kBAAkB;;UAI/B,4BAA4B,QAC3C,YAAgB;EAEd,SAAS,eAAe;EACxB,WAAW,eAAe,kBAAkB;EAC5C,UAAU,eAAe;;UAIZ,wBAAwB;EACvC;EACA;;KAGU,eAAe;KAEf,oBAAoB,QAC9B,YAAgB;EAEd,SAAS,eAAe;;KAIhB,iBAAiB,QAC3B,YAAgB;EAEd,UAAU,eAAe,kBAAkB;EAC3C,UAAU,eAAe;EACzB,QAAQ,eAAe,kBAAkB;;KAIjC,kBAAkB,eAAe,kBAAkB;KAEnD,gBAAgB,qBAAqB,QAC/C,YAAgB,gBAAgB;EAE9B,cAAc,kBAAkB;EAChC,cAAc,kBAAkB;EAChC,YAAY;EACZ,YAAY,eAAe,kBAAkB;KAG/C;KAEU,eAAe,qBAAqB,QAC9C,YAAgB,eAAe;EAE7B,cAAc,kBAAkB;QAGjC,UAAU,eAAe,gBAAgB;KAGhC,YAAY,mBAAmB,yBAAyB,gBAEjE,eAAe,KAAK;KAGX,iBAAiB,eAAe,iBAAiB;KAEjD,mBAAmB,QAC7B,YAAgB;EAEd,UAAU,eAAe;EACzB,YAAY,eAAe,kBAAkB;EAC7C,aAAa,eAAe,kBAAkB;EAC9C,gBAAgB,eAAe,kBAAkB;EACjD,UAAU,eAAe,kBAAkB;EAC3C,QAAQ,eAAe,kBAAkB;EACzC,YAAY,eAAe,kBAAkB;EAC7C,YAAY,eAAe,kBAAkB;;KAIrC,SAAS,qBAAqB,QACxC,YAAgB,SAAS;EAEvB,QAAQ,YAAY;EACpB,aAAa;;;;UC9GA;;;;;EAKf;;EAEA;;EAEA;;;;;;;EAOA,UAAU;;;;;;;;;;wBA88CU,wBACpB,wBACA,UAAS,kBACR,QAAQ"}
|