@sdk-it/core 0.46.3 → 0.46.5
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +2 -2
- package/dist/lib/deriver.d.ts +1 -0
- package/dist/lib/deriver.d.ts.map +1 -1
- package/dist/lib/deriver.js +33 -22
- package/dist/lib/deriver.js.map +2 -2
- package/dist/lib/paths.d.ts +2 -1
- package/dist/lib/paths.d.ts.map +1 -1
- package/dist/lib/paths.js +3 -0
- package/dist/lib/paths.js.map +2 -2
- package/dist/lib/ref.d.ts +6 -5
- package/dist/lib/ref.d.ts.map +1 -1
- package/dist/lib/ref.js.map +2 -2
- package/dist/lib/security.d.ts +39 -0
- package/dist/lib/security.d.ts.map +1 -0
- package/dist/lib/security.js +1 -0
- package/dist/lib/security.js.map +7 -0
- package/dist/lib/zod-jsonschema.d.ts.map +1 -1
- package/dist/lib/zod-jsonschema.js +19 -9
- package/dist/lib/zod-jsonschema.js.map +2 -2
- package/package.json +9 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './lib/deriver.js';
|
|
|
2
2
|
export * from './lib/paths.js';
|
|
3
3
|
export * from './lib/program.js';
|
|
4
4
|
export * from './lib/ref.js';
|
|
5
|
+
export * from './lib/security.js';
|
|
5
6
|
export * from './lib/utils.js';
|
|
6
7
|
export * from './lib/zod-jsonschema.js';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./lib/deriver.js";
|
|
|
2
2
|
export * from "./lib/paths.js";
|
|
3
3
|
export * from "./lib/program.js";
|
|
4
4
|
export * from "./lib/ref.js";
|
|
5
|
+
export * from "./lib/security.js";
|
|
5
6
|
export * from "./lib/utils.js";
|
|
6
7
|
export * from "./lib/zod-jsonschema.js";
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './lib/deriver.js';\nexport * from './lib/paths.js';\nexport * from './lib/program.js';\nexport * from './lib/ref.js';\nexport * from './lib/utils.js';\nexport * from './lib/zod-jsonschema.js';\n"],
|
|
5
|
-
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
4
|
+
"sourcesContent": ["export * from './lib/deriver.js';\nexport * from './lib/paths.js';\nexport * from './lib/program.js';\nexport * from './lib/ref.js';\nexport * from './lib/security.js';\nexport * from './lib/utils.js';\nexport * from './lib/zod-jsonschema.js';\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/lib/deriver.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare class TypeDeriver {
|
|
|
20
20
|
serializeType(type: ts.Type): any;
|
|
21
21
|
private serialize;
|
|
22
22
|
private serializeResolved;
|
|
23
|
+
private serializeValue;
|
|
23
24
|
/**
|
|
24
25
|
* Preserve the inferred type of `satisfies` expressions unless the operand is
|
|
25
26
|
* an empty array; only then recover its declared element type.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deriver.d.ts","sourceRoot":"","sources":["../../src/lib/deriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,MAAM,YAAY,CAAC;AAIvD,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"deriver.d.ts","sourceRoot":"","sources":["../../src/lib/deriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,MAAM,YAAY,CAAC;AAIvD,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAWrC,eAAO,MAAM,YAAY,eAA0B,CAAC;AACpD,eAAO,MAAM,MAAM,eAAsB,CAAC;AAC1C,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAQlD,CAAC;AAOF,wBAAgB,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,GAAG,SAAS,CAW9D;AAED,qBAAa,WAAW;IACtB,SAAgB,SAAS,EAAE,SAAS,CAAM;IAC1C,SAAgB,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC;IACxC,SAAgB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,WAAW,CAAC,CAAU;IAC9B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA+B;gBAE3D,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAmB;IAMxD,QAAQ,CAAC,GAAG,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;IAInD,OAAO,CAAC,IAAI;IAeZ,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG;IAIjC,OAAO,CAAC,SAAS;IA0BjB,OAAO,CAAC,iBAAiB;IA6RzB,OAAO,CAAC,cAAc;IAStB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IA6CxB,OAAO,CAAC,mBAAmB;IAqB3B,OAAO,CAAC,eAAe;IAiBvB,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG;CAsRlC"}
|
package/dist/lib/deriver.js
CHANGED
|
@@ -52,12 +52,12 @@ class TypeDeriver {
|
|
|
52
52
|
console.warn(parts.join("\n"));
|
|
53
53
|
}
|
|
54
54
|
serializeType(type) {
|
|
55
|
-
return this.serialize(type,
|
|
55
|
+
return this.serialize(type, "none");
|
|
56
56
|
}
|
|
57
|
-
serialize(type,
|
|
57
|
+
serialize(type, widening) {
|
|
58
58
|
const alias = type.aliasSymbol?.getName();
|
|
59
59
|
if (!alias) {
|
|
60
|
-
return this.serializeResolved(type,
|
|
60
|
+
return this.serializeResolved(type, widening);
|
|
61
61
|
}
|
|
62
62
|
if (this.activeAliases.has(type)) {
|
|
63
63
|
this.activeAliases.set(type, true);
|
|
@@ -69,7 +69,7 @@ class TypeDeriver {
|
|
|
69
69
|
}
|
|
70
70
|
this.activeAliases.set(type, false);
|
|
71
71
|
try {
|
|
72
|
-
const result = this.serializeResolved(type,
|
|
72
|
+
const result = this.serializeResolved(type, widening);
|
|
73
73
|
if (this.activeAliases.get(type)) {
|
|
74
74
|
this.collector[alias] = result;
|
|
75
75
|
}
|
|
@@ -78,7 +78,7 @@ class TypeDeriver {
|
|
|
78
78
|
this.activeAliases.delete(type);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
serializeResolved(type,
|
|
81
|
+
serializeResolved(type, widening) {
|
|
82
82
|
if (this.typesMap[type.aliasSymbol?.getName() || type.symbol?.getName()]) {
|
|
83
83
|
return {
|
|
84
84
|
[deriveSymbol]: true,
|
|
@@ -88,13 +88,21 @@ class TypeDeriver {
|
|
|
88
88
|
]
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
+
if (type.symbol?.getName() === "Date") {
|
|
92
|
+
return {
|
|
93
|
+
[deriveSymbol]: true,
|
|
94
|
+
kind: "date",
|
|
95
|
+
optional: false,
|
|
96
|
+
[$types]: ["string"]
|
|
97
|
+
};
|
|
98
|
+
}
|
|
91
99
|
const indexType = type.getStringIndexType();
|
|
92
100
|
if (indexType) {
|
|
93
101
|
return {
|
|
94
102
|
[deriveSymbol]: true,
|
|
95
103
|
kind: "record",
|
|
96
104
|
optional: false,
|
|
97
|
-
[$types]: [this.serialize(indexType,
|
|
105
|
+
[$types]: [this.serialize(indexType, widening)]
|
|
98
106
|
};
|
|
99
107
|
}
|
|
100
108
|
if (type.flags & TypeFlags.Any) {
|
|
@@ -123,7 +131,7 @@ class TypeDeriver {
|
|
|
123
131
|
return {
|
|
124
132
|
[deriveSymbol]: true,
|
|
125
133
|
optional: false,
|
|
126
|
-
...
|
|
134
|
+
...widening === "all" ? {} : { kind: "literal", value: type.value },
|
|
127
135
|
[$types]: ["string"]
|
|
128
136
|
};
|
|
129
137
|
}
|
|
@@ -131,7 +139,7 @@ class TypeDeriver {
|
|
|
131
139
|
return {
|
|
132
140
|
[deriveSymbol]: true,
|
|
133
141
|
optional: false,
|
|
134
|
-
...
|
|
142
|
+
...widening === "all" ? {} : { kind: "literal", value: type.value },
|
|
135
143
|
[$types]: ["number"]
|
|
136
144
|
};
|
|
137
145
|
}
|
|
@@ -139,7 +147,7 @@ class TypeDeriver {
|
|
|
139
147
|
return {
|
|
140
148
|
[deriveSymbol]: true,
|
|
141
149
|
optional: false,
|
|
142
|
-
...
|
|
150
|
+
...widening === "all" ? {} : {
|
|
143
151
|
kind: "literal",
|
|
144
152
|
value: this.checker.typeToString(type) === "true"
|
|
145
153
|
},
|
|
@@ -191,7 +199,7 @@ class TypeDeriver {
|
|
|
191
199
|
continue;
|
|
192
200
|
}
|
|
193
201
|
}
|
|
194
|
-
types.push(this.serialize(intersectionType,
|
|
202
|
+
types.push(this.serialize(intersectionType, widening));
|
|
195
203
|
}
|
|
196
204
|
return {
|
|
197
205
|
[deriveSymbol]: true,
|
|
@@ -210,7 +218,7 @@ class TypeDeriver {
|
|
|
210
218
|
continue;
|
|
211
219
|
}
|
|
212
220
|
}
|
|
213
|
-
types.push(this.serialize(unionType,
|
|
221
|
+
types.push(this.serialize(unionType, widening));
|
|
214
222
|
}
|
|
215
223
|
return {
|
|
216
224
|
[deriveSymbol]: true,
|
|
@@ -235,16 +243,12 @@ class TypeDeriver {
|
|
|
235
243
|
};
|
|
236
244
|
}
|
|
237
245
|
const mappedElementType = this.typesMap[elementType.aliasSymbol?.getName() || elementType.symbol?.getName()];
|
|
246
|
+
const itemWidening = widening === "all" || this.checker.isTupleType(type) ? "all" : "values";
|
|
238
247
|
return {
|
|
239
248
|
kind: "array",
|
|
240
249
|
optional: false,
|
|
241
250
|
[deriveSymbol]: true,
|
|
242
|
-
[$types]: mappedElementType ? [mappedElementType] : [
|
|
243
|
-
this.serialize(
|
|
244
|
-
elementType,
|
|
245
|
-
widenLiteralValues || this.checker.isTupleType(type)
|
|
246
|
-
)
|
|
247
|
-
]
|
|
251
|
+
[$types]: mappedElementType ? [mappedElementType] : [this.serialize(elementType, itemWidening)]
|
|
248
252
|
};
|
|
249
253
|
}
|
|
250
254
|
if (type.isClass()) {
|
|
@@ -297,14 +301,14 @@ class TypeDeriver {
|
|
|
297
301
|
);
|
|
298
302
|
const shorthandType = shorthand ? this.typeOfShorthand(shorthand) : void 0;
|
|
299
303
|
if (propAssingment) {
|
|
300
|
-
serializedProps[prop.name] = this.
|
|
304
|
+
serializedProps[prop.name] = this.serializeValue(
|
|
301
305
|
this.typeOfExpression(propAssingment.initializer),
|
|
302
|
-
|
|
306
|
+
widening
|
|
303
307
|
);
|
|
304
308
|
} else if (shorthandType) {
|
|
305
|
-
serializedProps[prop.name] = this.
|
|
309
|
+
serializedProps[prop.name] = this.serializeValue(
|
|
306
310
|
shorthandType,
|
|
307
|
-
|
|
311
|
+
widening
|
|
308
312
|
);
|
|
309
313
|
} else {
|
|
310
314
|
const propType = this.checker.getTypeOfSymbol(prop);
|
|
@@ -341,6 +345,13 @@ class TypeDeriver {
|
|
|
341
345
|
]
|
|
342
346
|
};
|
|
343
347
|
}
|
|
348
|
+
serializeValue(type, widening) {
|
|
349
|
+
const isLiteral = type.isLiteral() || (type.flags & TypeFlags.BooleanLiteral) !== 0;
|
|
350
|
+
return this.serialize(
|
|
351
|
+
type,
|
|
352
|
+
widening === "values" && isLiteral ? "all" : widening
|
|
353
|
+
);
|
|
354
|
+
}
|
|
344
355
|
/**
|
|
345
356
|
* Preserve the inferred type of `satisfies` expressions unless the operand is
|
|
346
357
|
* an empty array; only then recover its declared element type.
|
|
@@ -527,7 +538,7 @@ class TypeDeriver {
|
|
|
527
538
|
const type = this.checker.getTypeAtLocation(node);
|
|
528
539
|
return this.serializeType(type);
|
|
529
540
|
}
|
|
530
|
-
if (ts.
|
|
541
|
+
if (ts.isCallOrNewExpression(node)) {
|
|
531
542
|
const type = this.checker.getTypeAtLocation(node);
|
|
532
543
|
return this.serializeType(type);
|
|
533
544
|
}
|
package/dist/lib/deriver.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/deriver.ts"],
|
|
4
|
-
"sourcesContent": ["import ts, { TypeFlags, symbolName } from 'typescript';\n\nimport { sortObjectKeys } from './utils.js';\n\ntype Collector = Record<string, any>;\n\nexport const deriveSymbol = Symbol.for('serialize');\nexport const $types = Symbol.for('types');\nexport const defaultTypesMap: Record<string, string> = {\n Readable: 'any',\n ReadableStream: 'any',\n DateConstructor: 'string',\n ArrayBufferConstructor: 'any',\n SharedArrayBufferConstructor: 'any',\n Int8ArrayConstructor: 'any',\n Uint8Array: 'any',\n};\n\ninterface TraceContext {\n file?: string;\n operation?: string;\n}\n\nexport function nodeLocation(node: ts.Node): string | undefined {\n try {\n const sourceFile = node.getSourceFile();\n if (!sourceFile) return undefined;\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(\n node.getStart(),\n );\n return `${sourceFile.fileName}:${line + 1}:${character + 1}`;\n } catch {\n return undefined;\n }\n}\n\nexport class TypeDeriver {\n public readonly collector: Collector = {};\n public readonly checker: ts.TypeChecker;\n public readonly typesMap: Record<string, string>;\n private trace: TraceContext = {};\n private currentNode?: ts.Node;\n private readonly activeAliases = new Map<ts.Type, boolean>();\n constructor(\n checker: ts.TypeChecker,\n typeMappings: Record<string, string> = defaultTypesMap,\n ) {\n this.checker = checker;\n this.typesMap = typeMappings;\n }\n\n setTrace(ctx: { file?: string; operation?: string }) {\n this.trace = { ...ctx };\n }\n\n private warn(message: string, node?: ts.Node) {\n const parts = [`\\x1b[33m\\u26a0 ${message}\\x1b[0m`];\n const resolvedNode = node ?? this.currentNode;\n const location = resolvedNode ? nodeLocation(resolvedNode) : undefined;\n if (location) {\n parts.push(` at \\x1b[36m${location}\\x1b[0m`);\n } else if (this.trace.file) {\n parts.push(` at \\x1b[36m${this.trace.file}\\x1b[0m`);\n }\n if (this.trace.operation) {\n parts.push(` in \\x1b[2m${this.trace.operation}\\x1b[0m`);\n }\n console.warn(parts.join('\\n'));\n }\n\n serializeType(type: ts.Type): any {\n return this.serialize(type, false);\n }\n\n private serialize(type: ts.Type, widenLiteralValues: boolean): unknown {\n const alias = type.aliasSymbol?.getName();\n if (!alias) {\n return this.serializeResolved(type, widenLiteralValues);\n }\n if (this.activeAliases.has(type)) {\n this.activeAliases.set(type, true);\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${alias}`],\n };\n }\n\n this.activeAliases.set(type, false);\n try {\n const result = this.serializeResolved(type, widenLiteralValues);\n if (this.activeAliases.get(type)) {\n this.collector[alias] = result;\n }\n return result;\n } finally {\n this.activeAliases.delete(type);\n }\n }\n\n private serializeResolved(\n type: ts.Type,\n widenLiteralValues: boolean,\n ): unknown {\n if (this.typesMap[type.aliasSymbol?.getName() || type.symbol?.getName()]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [\n this.typesMap[type.aliasSymbol?.getName() || type.symbol?.getName()],\n ],\n };\n }\n const indexType = type.getStringIndexType();\n if (indexType) {\n return {\n [deriveSymbol]: true,\n kind: 'record',\n optional: false,\n [$types]: [this.serialize(indexType, widenLiteralValues)],\n };\n }\n if (type.flags & TypeFlags.Any) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [],\n };\n }\n if (type.flags & TypeFlags.Unknown) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [],\n };\n }\n if (type.flags & (TypeFlags.Never | TypeFlags.Undefined)) {\n return {\n [deriveSymbol]: true,\n kind: 'never',\n optional: (type.flags & TypeFlags.Undefined) !== 0,\n [$types]: [],\n };\n }\n if (type.isStringLiteral()) {\n return {\n [deriveSymbol]: true,\n optional: false,\n ...(widenLiteralValues ? {} : { kind: 'literal', value: type.value }),\n [$types]: ['string'],\n };\n }\n if (type.isNumberLiteral()) {\n return {\n [deriveSymbol]: true,\n optional: false,\n ...(widenLiteralValues ? {} : { kind: 'literal', value: type.value }),\n [$types]: ['number'],\n };\n }\n if (type.flags & TypeFlags.BooleanLiteral) {\n return {\n [deriveSymbol]: true,\n optional: false,\n ...(widenLiteralValues\n ? {}\n : {\n kind: 'literal',\n value: this.checker.typeToString(type) === 'true',\n }),\n [$types]: ['boolean'],\n };\n }\n if (type.flags & TypeFlags.TemplateLiteral) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['string'],\n };\n }\n if (type.flags & TypeFlags.String) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['string'],\n };\n }\n if (type.flags & TypeFlags.Number) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['number'],\n };\n }\n if (type.flags & ts.TypeFlags.Boolean) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['boolean'],\n };\n }\n if (type.flags & TypeFlags.Null) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['null'],\n };\n }\n if (type.isIntersection()) {\n let optional: boolean | undefined;\n const types: any[] = [];\n for (const intersectionType of type.types) {\n if (optional === undefined) {\n optional = (intersectionType.flags & ts.TypeFlags.Undefined) !== 0;\n if (optional) {\n continue;\n }\n }\n\n types.push(this.serialize(intersectionType, widenLiteralValues));\n }\n return {\n [deriveSymbol]: true,\n kind: 'intersection',\n optional,\n [$types]: types,\n };\n }\n if (type.isUnion()) {\n let optional: boolean | undefined;\n const types: any[] = [];\n for (const unionType of type.types) {\n if (optional === undefined) {\n // ignore undefined\n optional = (unionType.flags & ts.TypeFlags.Undefined) !== 0;\n if (optional) {\n continue;\n }\n }\n\n types.push(this.serialize(unionType, widenLiteralValues));\n }\n return {\n [deriveSymbol]: true,\n kind: 'union',\n optional,\n [$types]: types,\n };\n }\n if (this.checker.isArrayLikeType(type)) {\n const elementType = this.checker.getIndexTypeOfType(\n type,\n ts.IndexKind.Number,\n );\n if (!elementType) {\n const typeName = type.symbol?.getName() || '<unknown>';\n this.warn(`Could not find element type for array type ${typeName}`);\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'array',\n [$types]: ['any'],\n };\n }\n const mappedElementType =\n this.typesMap[\n elementType.aliasSymbol?.getName() || elementType.symbol?.getName()\n ];\n return {\n kind: 'array',\n optional: false,\n [deriveSymbol]: true,\n [$types]: mappedElementType\n ? [mappedElementType]\n : [\n this.serialize(\n elementType,\n widenLiteralValues || this.checker.isTupleType(type),\n ),\n ],\n };\n }\n if (type.isClass()) {\n const declaration = type.symbol?.valueDeclaration;\n if (!declaration) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [type.symbol.getName()],\n };\n }\n return this.serializeNode(declaration);\n }\n if (type.symbol?.flags & ts.SymbolFlags.Interface) {\n const name = type.symbol.getName();\n if (!this.collector[name]) {\n this.collector[name] = {};\n const properties: Record<string, unknown> = {};\n for (const property of this.checker.getPropertiesOfType(type)) {\n properties[property.name] = this.serializeType(\n this.checker.getTypeOfSymbol(property),\n );\n }\n this.collector[name] = sortObjectKeys(properties);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${name}`],\n };\n }\n if (type.flags & TypeFlags.Object) {\n if (this.typesMap[symbolName(type.symbol)]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[symbolName(type.symbol)]],\n };\n }\n const properties = this.checker.getPropertiesOfType(type);\n if (properties.length > 0) {\n const serializedProps: Record<string, any> = {};\n for (const prop of properties) {\n const declarations = prop.getDeclarations() ?? [];\n const propAssingment = declarations.find((it) =>\n ts.isPropertyAssignment(it),\n );\n const shorthand = declarations.find((it) =>\n ts.isShorthandPropertyAssignment(it),\n );\n const shorthandType = shorthand\n ? this.typeOfShorthand(shorthand)\n : undefined;\n // get literal properties values if any\n if (propAssingment) {\n serializedProps[prop.name] = this.serialize(\n this.typeOfExpression(propAssingment.initializer),\n widenLiteralValues,\n );\n } else if (shorthandType) {\n serializedProps[prop.name] = this.serialize(\n shorthandType,\n widenLiteralValues,\n );\n } else {\n const propType = this.checker.getTypeOfSymbol(prop);\n serializedProps[prop.name] = this.serializeType(propType);\n }\n }\n return {\n [deriveSymbol]: true,\n kind: 'object',\n optional: false,\n [$types]: [sortObjectKeys(serializedProps)],\n };\n }\n const declaration =\n type.symbol.valueDeclaration ?? type.symbol.declarations?.[0];\n if (!declaration) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [type.symbol.getName()],\n };\n }\n return this.serializeNode(declaration);\n }\n\n this.warn(`Unhandled type: ${type.flags} ${ts.TypeFlags[type.flags]}`);\n\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [\n this.checker.typeToString(\n type,\n undefined,\n ts.TypeFormatFlags.NoTruncation,\n ),\n ],\n };\n }\n\n /**\n * Preserve the inferred type of `satisfies` expressions unless the operand is\n * an empty array; only then recover its declared element type.\n */\n private typeOfExpression(\n node: ts.Expression,\n seen = new Set<ts.Symbol>(),\n ): ts.Type {\n const satisfies = this.emptyArraySatisfies(node);\n if (satisfies) {\n return this.checker.getTypeFromTypeNode(satisfies.type);\n }\n let expression = node;\n while (ts.isParenthesizedExpression(expression)) {\n expression = expression.expression;\n }\n\n if (ts.isIdentifier(expression)) {\n const symbol = this.checker.getSymbolAtLocation(expression);\n const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];\n if (\n symbol &&\n !seen.has(symbol) &&\n declaration &&\n ts.isVariableDeclaration(declaration) &&\n ts.isVariableDeclarationList(declaration.parent) &&\n declaration.parent.flags & ts.NodeFlags.Const\n ) {\n seen.add(symbol);\n if (declaration.type) {\n return this.checker.getTypeFromTypeNode(declaration.type);\n }\n if (declaration.initializer) {\n return this.typeOfExpression(declaration.initializer, seen);\n }\n }\n }\n\n if (\n ts.isArrayLiteralExpression(expression) &&\n expression.elements.length === 1 &&\n ts.isSpreadElement(expression.elements[0])\n ) {\n return this.typeOfExpression(expression.elements[0].expression, seen);\n }\n\n return this.checker.getTypeAtLocation(expression);\n }\n\n private emptyArraySatisfies(\n node: ts.Expression,\n ): ts.SatisfiesExpression | undefined {\n let expression = node;\n while (ts.isParenthesizedExpression(expression)) {\n expression = expression.expression;\n }\n if (!ts.isSatisfiesExpression(expression)) {\n return undefined;\n }\n let operand = expression.expression;\n while (ts.isParenthesizedExpression(operand)) {\n operand = operand.expression;\n }\n if (!ts.isArrayLiteralExpression(operand) || operand.elements.length > 0) {\n return undefined;\n }\n const annotation = this.checker.getTypeFromTypeNode(expression.type);\n return this.checker.isArrayLikeType(annotation) ? expression : undefined;\n }\n\n private typeOfShorthand(\n node: ts.ShorthandPropertyAssignment,\n ): ts.Type | undefined {\n const symbol = this.checker.getShorthandAssignmentValueSymbol(node);\n const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];\n if (\n !declaration ||\n !ts.isVariableDeclaration(declaration) ||\n !declaration.initializer\n ) {\n return undefined;\n }\n return this.emptyArraySatisfies(declaration.initializer)\n ? this.typeOfExpression(declaration.initializer)\n : this.checker.getTypeAtLocation(node.name);\n }\n\n serializeNode(node: ts.Node): any {\n this.currentNode = node;\n if (ts.isObjectLiteralExpression(node)) {\n const symbolType = this.checker.getTypeAtLocation(node);\n const props: Record<string, any> = {};\n\n for (const prop of node.properties) {\n if (ts.isPropertyAssignment(prop)) {\n props[prop.name.getText()] = this.serializeType(\n this.typeOfExpression(prop.initializer),\n );\n } else if (ts.isShorthandPropertyAssignment(prop)) {\n const type = this.typeOfShorthand(prop);\n if (type) {\n props[prop.name.text] = this.serializeType(type);\n }\n }\n }\n\n for (const symbol of symbolType.getProperties()) {\n if (!Object.hasOwn(props, symbol.name)) {\n const type = this.checker.getTypeOfSymbol(symbol);\n props[symbol.name] = this.serializeType(type);\n }\n }\n\n return sortObjectKeys(props);\n }\n if (ts.isPropertyAccessExpression(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isPropertySignature(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isPropertyDeclaration(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isInterfaceDeclaration(node)) {\n if (!node.name?.text) {\n throw new Error('Interface has no name');\n }\n if (this.typesMap[node.name.text]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[node.name.text]],\n };\n }\n if (!this.collector[node.name.text]) {\n this.collector[node.name.text] = {};\n const members: Record<string, any> = {};\n for (const member of node.members.filter(ts.isPropertySignature)) {\n members[member.name.getText()] = this.serializeNode(member);\n }\n this.collector[node.name.text] = sortObjectKeys(members);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${node.name.text}`],\n };\n }\n if (ts.isClassDeclaration(node)) {\n if (!node.name?.text) {\n throw new Error('Class has no name');\n }\n if (this.typesMap[node.name.text]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[node.name.text]],\n };\n }\n\n if (!this.collector[node.name.text]) {\n this.collector[node.name.text] = {};\n const members: Record<string, unknown> = {};\n for (const member of node.members.filter(ts.isPropertyDeclaration)) {\n members[member.name!.getText()] = this.serializeNode(member);\n }\n this.collector[node.name.text] = sortObjectKeys(members);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${node.name.text}`],\n $ref: `#/components/schemas/${node.name.text}`,\n };\n }\n if (ts.isVariableDeclaration(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n if (!node.type) {\n this.warn(`No type found for ${node.name.getText()}`, node);\n return 'any';\n }\n const type = this.checker.getTypeFromTypeNode(node.type);\n return this.serializeType(type);\n }\n if (ts.isIdentifier(node)) {\n const symbol = this.checker.getSymbolAtLocation(node);\n if (!symbol) {\n this.warn(`No symbol found for identifier ${node.getText()}`, node);\n return null;\n }\n const type = this.typeOfExpression(node);\n return this.serializeType(type);\n }\n if (ts.isAwaitExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isCallExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isAsExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isSatisfiesExpression(node)) {\n return this.serializeType(this.typeOfExpression(node));\n }\n if (ts.isTypeLiteralNode(node)) {\n const symbolType = this.checker.getTypeAtLocation(node);\n const props: Record<string, unknown> = {};\n for (const symbol of symbolType.getProperties()) {\n const type = this.checker.getTypeOfSymbol(symbol);\n props[symbol.name] = this.serializeType(type);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [sortObjectKeys(props)],\n };\n }\n if (node.kind === ts.SyntaxKind.NullKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['null'],\n };\n }\n if (node.kind === ts.SyntaxKind.BooleanKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['boolean'],\n };\n }\n if (node.kind === ts.SyntaxKind.TrueKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'literal',\n value: true,\n [$types]: ['boolean'],\n };\n }\n if (node.kind === ts.SyntaxKind.FalseKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'literal',\n value: false,\n [$types]: ['boolean'],\n };\n }\n if (ts.isFunctionDeclaration(node)) {\n if (!node.name) {\n this.warn('Function declaration has no name', node);\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['any'],\n };\n }\n\n const functionName = node.name.text;\n if (this.typesMap[functionName]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[functionName]],\n };\n }\n\n if (node.type) {\n const returnType = this.checker.getTypeFromTypeNode(node.type);\n return this.serializeType(returnType);\n }\n\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['any'],\n };\n }\n if (ts.isArrayLiteralExpression(node)) {\n const type = this.typeOfExpression(node);\n return this.serializeType(type);\n }\n if (ts.isStringLiteral(node) || ts.isNumericLiteral(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n // Handle template literals in expression position\n if (\n ts.isTemplateExpression(node) ||\n ts.isNoSubstitutionTemplateLiteral(node)\n ) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isTaggedTemplateExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n // Handle binary expressions (||, &&, +, -, etc.)\n if (ts.isBinaryExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n // Handle conditional/ternary expressions (x ? y : z)\n if (ts.isConditionalExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n // Handle parenthesized expressions ((value))\n if (ts.isParenthesizedExpression(node)) {\n return this.serializeType(this.typeOfExpression(node));\n }\n\n // Handle non-null assertions (value!)\n if (ts.isNonNullExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n this.warn(\n `Unhandled node: ${ts.SyntaxKind[node.kind]} \"${node.getText()}\" (type: ${this.checker.typeToString(\n this.checker.getTypeAtLocation(node),\n undefined,\n ts.TypeFormatFlags.NoTruncation,\n )})`,\n node,\n );\n\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['any'],\n };\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,MAAM,WAAW,kBAAkB;AAE1C,SAAS,sBAAsB;AAIxB,MAAM,eAAe,OAAO,IAAI,WAAW;AAC3C,MAAM,SAAS,OAAO,IAAI,OAAO;AACjC,MAAM,kBAA0C;AAAA,EACrD,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,wBAAwB;AAAA,EACxB,8BAA8B;AAAA,EAC9B,sBAAsB;AAAA,EACtB,YAAY;AACd;AAOO,SAAS,aAAa,MAAmC;AAC9D,MAAI;AACF,UAAM,aAAa,KAAK,cAAc;AACtC,QAAI,CAAC,WAAY,QAAO;AACxB,UAAM,EAAE,MAAM,UAAU,IAAI,WAAW;AAAA,MACrC,K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AAA,MACH,mBAAmB,GAAG,WAAW,KAAK,IAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,YAAY,KAAK,QAAQ;AAAA,QACrF,KAAK,QAAQ,kBAAkB,IAAI;AAAA,QACnC;AAAA,QACA,GAAG,gBAAgB;AAAA,MACrB,CAAC;AAAA,MACD;AAAA,IACF;AAEA,WAAO;AAAA,MACL,CAAC,YAAY,GAAG;AAAA,MAChB,UAAU;AAAA,MACV,CAAC,MAAM,GAAG,CAAC,KAAK;AAAA,IAClB;AAAA,EACF;AACF;",
|
|
4
|
+
"sourcesContent": ["import ts, { TypeFlags, symbolName } from 'typescript';\n\nimport { sortObjectKeys } from './utils.js';\n\ntype Collector = Record<string, any>;\n\n/**\n * How literal values met while serializing collapse to their base type.\n * - none: keep every literal (top-level response objects).\n * - values: array items are representative, so literals read straight off an\n * item's initializer collapse while declared literal types keep their values.\n * - all: const-asserted tuples collapse every literal.\n */\ntype LiteralWidening = 'none' | 'values' | 'all';\n\nexport const deriveSymbol = Symbol.for('serialize');\nexport const $types = Symbol.for('types');\nexport const defaultTypesMap: Record<string, string> = {\n Readable: 'any',\n ReadableStream: 'any',\n DateConstructor: 'string',\n ArrayBufferConstructor: 'any',\n SharedArrayBufferConstructor: 'any',\n Int8ArrayConstructor: 'any',\n Uint8Array: 'any',\n};\n\ninterface TraceContext {\n file?: string;\n operation?: string;\n}\n\nexport function nodeLocation(node: ts.Node): string | undefined {\n try {\n const sourceFile = node.getSourceFile();\n if (!sourceFile) return undefined;\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(\n node.getStart(),\n );\n return `${sourceFile.fileName}:${line + 1}:${character + 1}`;\n } catch {\n return undefined;\n }\n}\n\nexport class TypeDeriver {\n public readonly collector: Collector = {};\n public readonly checker: ts.TypeChecker;\n public readonly typesMap: Record<string, string>;\n private trace: TraceContext = {};\n private currentNode?: ts.Node;\n private readonly activeAliases = new Map<ts.Type, boolean>();\n constructor(\n checker: ts.TypeChecker,\n typeMappings: Record<string, string> = defaultTypesMap,\n ) {\n this.checker = checker;\n this.typesMap = typeMappings;\n }\n\n setTrace(ctx: { file?: string; operation?: string }) {\n this.trace = { ...ctx };\n }\n\n private warn(message: string, node?: ts.Node) {\n const parts = [`\\x1b[33m\\u26a0 ${message}\\x1b[0m`];\n const resolvedNode = node ?? this.currentNode;\n const location = resolvedNode ? nodeLocation(resolvedNode) : undefined;\n if (location) {\n parts.push(` at \\x1b[36m${location}\\x1b[0m`);\n } else if (this.trace.file) {\n parts.push(` at \\x1b[36m${this.trace.file}\\x1b[0m`);\n }\n if (this.trace.operation) {\n parts.push(` in \\x1b[2m${this.trace.operation}\\x1b[0m`);\n }\n console.warn(parts.join('\\n'));\n }\n\n serializeType(type: ts.Type): any {\n return this.serialize(type, 'none');\n }\n\n private serialize(type: ts.Type, widening: LiteralWidening): unknown {\n const alias = type.aliasSymbol?.getName();\n if (!alias) {\n return this.serializeResolved(type, widening);\n }\n if (this.activeAliases.has(type)) {\n this.activeAliases.set(type, true);\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${alias}`],\n };\n }\n\n this.activeAliases.set(type, false);\n try {\n const result = this.serializeResolved(type, widening);\n if (this.activeAliases.get(type)) {\n this.collector[alias] = result;\n }\n return result;\n } finally {\n this.activeAliases.delete(type);\n }\n }\n\n private serializeResolved(type: ts.Type, widening: LiteralWidening): unknown {\n if (this.typesMap[type.aliasSymbol?.getName() || type.symbol?.getName()]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [\n this.typesMap[type.aliasSymbol?.getName() || type.symbol?.getName()],\n ],\n };\n }\n if (type.symbol?.getName() === 'Date') {\n return {\n [deriveSymbol]: true,\n kind: 'date',\n optional: false,\n [$types]: ['string'],\n };\n }\n const indexType = type.getStringIndexType();\n if (indexType) {\n return {\n [deriveSymbol]: true,\n kind: 'record',\n optional: false,\n [$types]: [this.serialize(indexType, widening)],\n };\n }\n if (type.flags & TypeFlags.Any) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [],\n };\n }\n if (type.flags & TypeFlags.Unknown) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [],\n };\n }\n if (type.flags & (TypeFlags.Never | TypeFlags.Undefined)) {\n return {\n [deriveSymbol]: true,\n kind: 'never',\n optional: (type.flags & TypeFlags.Undefined) !== 0,\n [$types]: [],\n };\n }\n if (type.isStringLiteral()) {\n return {\n [deriveSymbol]: true,\n optional: false,\n ...(widening === 'all' ? {} : { kind: 'literal', value: type.value }),\n [$types]: ['string'],\n };\n }\n if (type.isNumberLiteral()) {\n return {\n [deriveSymbol]: true,\n optional: false,\n ...(widening === 'all' ? {} : { kind: 'literal', value: type.value }),\n [$types]: ['number'],\n };\n }\n if (type.flags & TypeFlags.BooleanLiteral) {\n return {\n [deriveSymbol]: true,\n optional: false,\n ...(widening === 'all'\n ? {}\n : {\n kind: 'literal',\n value: this.checker.typeToString(type) === 'true',\n }),\n [$types]: ['boolean'],\n };\n }\n if (type.flags & TypeFlags.TemplateLiteral) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['string'],\n };\n }\n if (type.flags & TypeFlags.String) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['string'],\n };\n }\n if (type.flags & TypeFlags.Number) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['number'],\n };\n }\n if (type.flags & ts.TypeFlags.Boolean) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['boolean'],\n };\n }\n if (type.flags & TypeFlags.Null) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['null'],\n };\n }\n if (type.isIntersection()) {\n let optional: boolean | undefined;\n const types: any[] = [];\n for (const intersectionType of type.types) {\n if (optional === undefined) {\n optional = (intersectionType.flags & ts.TypeFlags.Undefined) !== 0;\n if (optional) {\n continue;\n }\n }\n\n types.push(this.serialize(intersectionType, widening));\n }\n return {\n [deriveSymbol]: true,\n kind: 'intersection',\n optional,\n [$types]: types,\n };\n }\n if (type.isUnion()) {\n let optional: boolean | undefined;\n const types: any[] = [];\n for (const unionType of type.types) {\n if (optional === undefined) {\n // ignore undefined\n optional = (unionType.flags & ts.TypeFlags.Undefined) !== 0;\n if (optional) {\n continue;\n }\n }\n\n types.push(this.serialize(unionType, widening));\n }\n return {\n [deriveSymbol]: true,\n kind: 'union',\n optional,\n [$types]: types,\n };\n }\n if (this.checker.isArrayLikeType(type)) {\n const elementType = this.checker.getIndexTypeOfType(\n type,\n ts.IndexKind.Number,\n );\n if (!elementType) {\n const typeName = type.symbol?.getName() || '<unknown>';\n this.warn(`Could not find element type for array type ${typeName}`);\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'array',\n [$types]: ['any'],\n };\n }\n const mappedElementType =\n this.typesMap[\n elementType.aliasSymbol?.getName() || elementType.symbol?.getName()\n ];\n const itemWidening: LiteralWidening =\n widening === 'all' || this.checker.isTupleType(type) ? 'all' : 'values';\n return {\n kind: 'array',\n optional: false,\n [deriveSymbol]: true,\n [$types]: mappedElementType\n ? [mappedElementType]\n : [this.serialize(elementType, itemWidening)],\n };\n }\n if (type.isClass()) {\n const declaration = type.symbol?.valueDeclaration;\n if (!declaration) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [type.symbol.getName()],\n };\n }\n return this.serializeNode(declaration);\n }\n if (type.symbol?.flags & ts.SymbolFlags.Interface) {\n const name = type.symbol.getName();\n if (!this.collector[name]) {\n this.collector[name] = {};\n const properties: Record<string, unknown> = {};\n for (const property of this.checker.getPropertiesOfType(type)) {\n properties[property.name] = this.serializeType(\n this.checker.getTypeOfSymbol(property),\n );\n }\n this.collector[name] = sortObjectKeys(properties);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${name}`],\n };\n }\n if (type.flags & TypeFlags.Object) {\n if (this.typesMap[symbolName(type.symbol)]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[symbolName(type.symbol)]],\n };\n }\n const properties = this.checker.getPropertiesOfType(type);\n if (properties.length > 0) {\n const serializedProps: Record<string, any> = {};\n for (const prop of properties) {\n const declarations = prop.getDeclarations() ?? [];\n const propAssingment = declarations.find((it) =>\n ts.isPropertyAssignment(it),\n );\n const shorthand = declarations.find((it) =>\n ts.isShorthandPropertyAssignment(it),\n );\n const shorthandType = shorthand\n ? this.typeOfShorthand(shorthand)\n : undefined;\n // get literal properties values if any\n if (propAssingment) {\n serializedProps[prop.name] = this.serializeValue(\n this.typeOfExpression(propAssingment.initializer),\n widening,\n );\n } else if (shorthandType) {\n serializedProps[prop.name] = this.serializeValue(\n shorthandType,\n widening,\n );\n } else {\n const propType = this.checker.getTypeOfSymbol(prop);\n serializedProps[prop.name] = this.serializeType(propType);\n }\n }\n return {\n [deriveSymbol]: true,\n kind: 'object',\n optional: false,\n [$types]: [sortObjectKeys(serializedProps)],\n };\n }\n const declaration =\n type.symbol.valueDeclaration ?? type.symbol.declarations?.[0];\n if (!declaration) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [type.symbol.getName()],\n };\n }\n return this.serializeNode(declaration);\n }\n\n this.warn(`Unhandled type: ${type.flags} ${ts.TypeFlags[type.flags]}`);\n\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [\n this.checker.typeToString(\n type,\n undefined,\n ts.TypeFormatFlags.NoTruncation,\n ),\n ],\n };\n }\n\n private serializeValue(type: ts.Type, widening: LiteralWidening): unknown {\n const isLiteral =\n type.isLiteral() || (type.flags & TypeFlags.BooleanLiteral) !== 0;\n return this.serialize(\n type,\n widening === 'values' && isLiteral ? 'all' : widening,\n );\n }\n\n /**\n * Preserve the inferred type of `satisfies` expressions unless the operand is\n * an empty array; only then recover its declared element type.\n */\n private typeOfExpression(\n node: ts.Expression,\n seen = new Set<ts.Symbol>(),\n ): ts.Type {\n const satisfies = this.emptyArraySatisfies(node);\n if (satisfies) {\n return this.checker.getTypeFromTypeNode(satisfies.type);\n }\n let expression = node;\n while (ts.isParenthesizedExpression(expression)) {\n expression = expression.expression;\n }\n\n if (ts.isIdentifier(expression)) {\n const symbol = this.checker.getSymbolAtLocation(expression);\n const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];\n if (\n symbol &&\n !seen.has(symbol) &&\n declaration &&\n ts.isVariableDeclaration(declaration) &&\n ts.isVariableDeclarationList(declaration.parent) &&\n declaration.parent.flags & ts.NodeFlags.Const\n ) {\n seen.add(symbol);\n if (declaration.type) {\n return this.checker.getTypeFromTypeNode(declaration.type);\n }\n if (declaration.initializer) {\n return this.typeOfExpression(declaration.initializer, seen);\n }\n }\n }\n\n if (\n ts.isArrayLiteralExpression(expression) &&\n expression.elements.length === 1 &&\n ts.isSpreadElement(expression.elements[0])\n ) {\n return this.typeOfExpression(expression.elements[0].expression, seen);\n }\n\n return this.checker.getTypeAtLocation(expression);\n }\n\n private emptyArraySatisfies(\n node: ts.Expression,\n ): ts.SatisfiesExpression | undefined {\n let expression = node;\n while (ts.isParenthesizedExpression(expression)) {\n expression = expression.expression;\n }\n if (!ts.isSatisfiesExpression(expression)) {\n return undefined;\n }\n let operand = expression.expression;\n while (ts.isParenthesizedExpression(operand)) {\n operand = operand.expression;\n }\n if (!ts.isArrayLiteralExpression(operand) || operand.elements.length > 0) {\n return undefined;\n }\n const annotation = this.checker.getTypeFromTypeNode(expression.type);\n return this.checker.isArrayLikeType(annotation) ? expression : undefined;\n }\n\n private typeOfShorthand(\n node: ts.ShorthandPropertyAssignment,\n ): ts.Type | undefined {\n const symbol = this.checker.getShorthandAssignmentValueSymbol(node);\n const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];\n if (\n !declaration ||\n !ts.isVariableDeclaration(declaration) ||\n !declaration.initializer\n ) {\n return undefined;\n }\n return this.emptyArraySatisfies(declaration.initializer)\n ? this.typeOfExpression(declaration.initializer)\n : this.checker.getTypeAtLocation(node.name);\n }\n\n serializeNode(node: ts.Node): any {\n this.currentNode = node;\n if (ts.isObjectLiteralExpression(node)) {\n const symbolType = this.checker.getTypeAtLocation(node);\n const props: Record<string, any> = {};\n\n for (const prop of node.properties) {\n if (ts.isPropertyAssignment(prop)) {\n props[prop.name.getText()] = this.serializeType(\n this.typeOfExpression(prop.initializer),\n );\n } else if (ts.isShorthandPropertyAssignment(prop)) {\n const type = this.typeOfShorthand(prop);\n if (type) {\n props[prop.name.text] = this.serializeType(type);\n }\n }\n }\n\n for (const symbol of symbolType.getProperties()) {\n if (!Object.hasOwn(props, symbol.name)) {\n const type = this.checker.getTypeOfSymbol(symbol);\n props[symbol.name] = this.serializeType(type);\n }\n }\n\n return sortObjectKeys(props);\n }\n if (ts.isPropertyAccessExpression(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isPropertySignature(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isPropertyDeclaration(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isInterfaceDeclaration(node)) {\n if (!node.name?.text) {\n throw new Error('Interface has no name');\n }\n if (this.typesMap[node.name.text]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[node.name.text]],\n };\n }\n if (!this.collector[node.name.text]) {\n this.collector[node.name.text] = {};\n const members: Record<string, any> = {};\n for (const member of node.members.filter(ts.isPropertySignature)) {\n members[member.name.getText()] = this.serializeNode(member);\n }\n this.collector[node.name.text] = sortObjectKeys(members);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${node.name.text}`],\n };\n }\n if (ts.isClassDeclaration(node)) {\n if (!node.name?.text) {\n throw new Error('Class has no name');\n }\n if (this.typesMap[node.name.text]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[node.name.text]],\n };\n }\n\n if (!this.collector[node.name.text]) {\n this.collector[node.name.text] = {};\n const members: Record<string, unknown> = {};\n for (const member of node.members.filter(ts.isPropertyDeclaration)) {\n members[member.name!.getText()] = this.serializeNode(member);\n }\n this.collector[node.name.text] = sortObjectKeys(members);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${node.name.text}`],\n $ref: `#/components/schemas/${node.name.text}`,\n };\n }\n if (ts.isVariableDeclaration(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n this.warn(`No symbol found for ${node.name.getText()}`, node);\n return null;\n }\n if (!node.type) {\n this.warn(`No type found for ${node.name.getText()}`, node);\n return 'any';\n }\n const type = this.checker.getTypeFromTypeNode(node.type);\n return this.serializeType(type);\n }\n if (ts.isIdentifier(node)) {\n const symbol = this.checker.getSymbolAtLocation(node);\n if (!symbol) {\n this.warn(`No symbol found for identifier ${node.getText()}`, node);\n return null;\n }\n const type = this.typeOfExpression(node);\n return this.serializeType(type);\n }\n if (ts.isAwaitExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isCallOrNewExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isAsExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isSatisfiesExpression(node)) {\n return this.serializeType(this.typeOfExpression(node));\n }\n if (ts.isTypeLiteralNode(node)) {\n const symbolType = this.checker.getTypeAtLocation(node);\n const props: Record<string, unknown> = {};\n for (const symbol of symbolType.getProperties()) {\n const type = this.checker.getTypeOfSymbol(symbol);\n props[symbol.name] = this.serializeType(type);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [sortObjectKeys(props)],\n };\n }\n if (node.kind === ts.SyntaxKind.NullKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['null'],\n };\n }\n if (node.kind === ts.SyntaxKind.BooleanKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['boolean'],\n };\n }\n if (node.kind === ts.SyntaxKind.TrueKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'literal',\n value: true,\n [$types]: ['boolean'],\n };\n }\n if (node.kind === ts.SyntaxKind.FalseKeyword) {\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'literal',\n value: false,\n [$types]: ['boolean'],\n };\n }\n if (ts.isFunctionDeclaration(node)) {\n if (!node.name) {\n this.warn('Function declaration has no name', node);\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['any'],\n };\n }\n\n const functionName = node.name.text;\n if (this.typesMap[functionName]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [this.typesMap[functionName]],\n };\n }\n\n if (node.type) {\n const returnType = this.checker.getTypeFromTypeNode(node.type);\n return this.serializeType(returnType);\n }\n\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['any'],\n };\n }\n if (ts.isArrayLiteralExpression(node)) {\n const type = this.typeOfExpression(node);\n return this.serializeType(type);\n }\n if (ts.isStringLiteral(node) || ts.isNumericLiteral(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n // Handle template literals in expression position\n if (\n ts.isTemplateExpression(node) ||\n ts.isNoSubstitutionTemplateLiteral(node)\n ) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isTaggedTemplateExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n // Handle binary expressions (||, &&, +, -, etc.)\n if (ts.isBinaryExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n // Handle conditional/ternary expressions (x ? y : z)\n if (ts.isConditionalExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n // Handle parenthesized expressions ((value))\n if (ts.isParenthesizedExpression(node)) {\n return this.serializeType(this.typeOfExpression(node));\n }\n\n // Handle non-null assertions (value!)\n if (ts.isNonNullExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n\n this.warn(\n `Unhandled node: ${ts.SyntaxKind[node.kind]} \"${node.getText()}\" (type: ${this.checker.typeToString(\n this.checker.getTypeAtLocation(node),\n undefined,\n ts.TypeFormatFlags.NoTruncation,\n )})`,\n node,\n );\n\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['any'],\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,MAAM,WAAW,kBAAkB;AAE1C,SAAS,sBAAsB;AAaxB,MAAM,eAAe,OAAO,IAAI,WAAW;AAC3C,MAAM,SAAS,OAAO,IAAI,OAAO;AACjC,MAAM,kBAA0C;AAAA,EACrD,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,wBAAwB;AAAA,EACxB,8BAA8B;AAAA,EAC9B,sBAAsB;AAAA,EACtB,YAAY;AACd;AAOO,SAAS,aAAa,MAAmC;AAC9D,MAAI;AACF,UAAM,aAAa,KAAK,cAAc;AACtC,QAAI,CAAC,WAAY,QAAO;AACxB,UAAM,EAAE,MAAM,UAAU,IAAI,WAAW;AAAA,MACrC,KAAK,SAAS;AAAA,IAChB;AACA,WAAO,GAAG,WAAW,QAAQ,IAAI,OAAO,CAAC,IAAI,YAAY,CAAC;AAAA,EAC5D,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,MAAM,YAAY;AAAA,EACP,YAAuB,CAAC;AAAA,EACxB;AAAA,EACA;AAAA,EACR,QAAsB,CAAC;AAAA,EACvB;AAAA,EACS,gBAAgB,oBAAI,IAAsB;AAAA,EAC3D,YACE,SACA,eAAuC,iBACvC;A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KAAK,QAAQ,kBAAkB,IAAI;AAChD,aAAO,KAAK,cAAc,IAAI;AAAA,IAChC;AAEA,SAAK;AAAA,MACH,mBAAmB,GAAG,WAAW,KAAK,IAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,YAAY,KAAK,QAAQ;AAAA,QACrF,KAAK,QAAQ,kBAAkB,IAAI;AAAA,QACnC;AAAA,QACA,GAAG,gBAAgB;AAAA,MACrB,CAAC;AAAA,MACD;AAAA,IACF;AAEA,WAAO;AAAA,MACL,CAAC,YAAY,GAAG;AAAA,MAChB,UAAU;AAAA,MACV,CAAC,MAAM,GAAG,CAAC,KAAK;AAAA,IAClB;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/lib/paths.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { OperationObject, PathsObject, SchemaObject } from 'openapi3-ts/oas31';
|
|
1
|
+
import type { OperationObject, PathsObject, SchemaObject, SecurityRequirementObject } from 'openapi3-ts/oas31';
|
|
2
2
|
import { $types } from './deriver.js';
|
|
3
3
|
import { type InjectImport } from './zod-jsonschema.js';
|
|
4
4
|
export type OperationInfo = {
|
|
@@ -7,6 +7,7 @@ export type OperationInfo = {
|
|
|
7
7
|
summary?: string;
|
|
8
8
|
description?: string;
|
|
9
9
|
tags?: string[];
|
|
10
|
+
security?: SecurityRequirementObject[];
|
|
10
11
|
};
|
|
11
12
|
export type Method = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'trace' | 'head';
|
|
12
13
|
export declare const methods: readonly ["get", "post", "put", "patch", "delete", "trace", "head"];
|
package/dist/lib/paths.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/lib/paths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEf,WAAW,EAGX,YAAY,
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["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AM,EACZ,SAAS,EAAE,eAAe,KACvB,WAAW,CAAC;AACjB,qBAAa,KAAK;;gBAeJ,MAAM,EAAE;QAAE,OAAO,EAAE,YAAY,EAAE,CAAC;QAAC,WAAW,CAAC,EAAE,WAAW,CAAA;KAAE;IAK1E,OAAO,CACL,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,SAAS,EAAE,QAAQ,EAAE,EACrB,SAAS,EAAE,YAAY,EAAE,EACzB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,aAAa;IAyHrB,OAAO,IAAI,MAAM,EAAE;IAcnB,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IAI1C,QAAQ;CA2Ef;AAED,UAAU,QAAQ;IAChB,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,GAAG,CAoExE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,MAAM,CAEzD"}
|
package/dist/lib/paths.js
CHANGED
|
@@ -160,6 +160,7 @@ class Paths {
|
|
|
160
160
|
// || undefined would omit the value from final openapi spec
|
|
161
161
|
description: operation.info.description || void 0,
|
|
162
162
|
summary: operation.info.summary || void 0,
|
|
163
|
+
security: operation.info.security,
|
|
163
164
|
"x-tool": operation.info.tool ? {
|
|
164
165
|
name: operation.info.tool || void 0,
|
|
165
166
|
description: operation.info.toolDescription || void 0
|
|
@@ -210,6 +211,8 @@ function toSchema(data) {
|
|
|
210
211
|
return { $ref: data };
|
|
211
212
|
}
|
|
212
213
|
return { type: data };
|
|
214
|
+
} else if (data.kind === "date") {
|
|
215
|
+
return { type: "string", format: "date-time" };
|
|
213
216
|
} else if (data.kind === "never") {
|
|
214
217
|
return { not: {} };
|
|
215
218
|
} else if (data.kind === "literal") {
|
package/dist/lib/paths.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/paths.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n HeadersObject,\n OperationObject,\n ParameterObject,\n PathsObject,\n ResponseObject,\n ResponsesObject,\n SchemaObject,\n} from 'openapi3-ts/oas31';\n\nimport { $types } from './deriver.js';\nimport { sortArray, sortObjectKeys } from './utils.js';\nimport { type InjectImport, evalZod } from './zod-jsonschema.js';\n\nexport type OperationInfo = {\n tool?: string;\n toolDescription?: string;\n summary?: string;\n description?: string;\n tags?: string[];\n};\nexport type Method =\n 'get' | 'post' | 'put' | 'patch' | 'delete' | 'trace' | 'head';\n\nexport const methods = [\n 'get',\n 'post',\n 'put',\n 'patch',\n 'delete',\n 'trace',\n 'head',\n] as const;\nexport type SemanticSource =\n 'query' | 'queries' | 'body' | 'params' | 'headers';\n\nconst semanticSourceToOpenAPI = {\n queries: 'query',\n query: 'query',\n headers: 'header',\n params: 'path',\n} as const;\nexport interface Selector {\n name: string;\n against: string;\n source: SemanticSource;\n}\n\nexport interface ResponseItem {\n statusCode: string;\n response?: DateType;\n contentType: string;\n headers: (string | Record<string, string[]>)[];\n middlewareName?: string;\n}\n\nexport type OnOperation = (\n sourceFile: string,\n method: Method,\n path: string,\n operation: OperationObject,\n) => PathsObject;\nexport class Paths {\n #imports: InjectImport[] = [];\n #onOperation?: OnOperation;\n #sharedResponses = new Map<string, SchemaObject>();\n #operations: Array<{\n sourceFile: string;\n name: string;\n path: string;\n method: Method;\n selectors: Selector[];\n responses: ResponsesObject;\n contentType?: string;\n info: OperationInfo;\n }> = [];\n\n constructor(config: { imports: InjectImport[]; onOperation?: OnOperation }) {\n this.#imports = config.imports;\n this.#onOperation = config.onOperation;\n }\n\n addPath(\n name: string,\n path: string,\n method: Method,\n contentType: string | undefined,\n selectors: Selector[],\n responses: ResponseItem[],\n sourceFile: string,\n info: OperationInfo,\n ) {\n const responsesObject = this.#responseItemToResponses(responses);\n\n this.#operations.push({\n name,\n path: this.#tunePath(path),\n sourceFile,\n contentType: contentType,\n method,\n selectors,\n responses: responsesObject,\n info,\n });\n return this;\n }\n\n #responseItemToResponses(responses: ResponseItem[]): ResponsesObject {\n const responsesObject: ResponsesObject = {};\n for (const item of responses) {\n const ct = item.contentType;\n let schema = item.response ? toSchema(item.response) : {};\n\n // Deduplicate named middleware responses via $ref\n if (item.middlewareName) {\n const sanitizedCt = ct.replace(/\\//g, '_');\n const sharedKey = `${item.middlewareName}${item.statusCode}_${sanitizedCt}`;\n if (!this.#sharedResponses.has(sharedKey)) {\n this.#sharedResponses.set(sharedKey, schema);\n }\n schema = { $ref: `#/components/schemas/${sharedKey}` };\n }\n\n if (!responsesObject[item.statusCode]) {\n responsesObject[item.statusCode] = {\n description: `Response for ${item.statusCode}`,\n content:\n ct !== 'empty'\n ? {\n [ct]:\n ct === 'application/octet-stream'\n ? { schema: { type: 'string', format: 'binary' } }\n : { schema },\n }\n : undefined,\n headers: item.headers.length\n ? item.headers.reduce<HeadersObject>((acc, current) => {\n const headers =\n typeof current === 'string' ? { [current]: [] } : current;\n const sortedHeaders = Object.entries(sortObjectKeys(headers));\n return sortedHeaders.reduce<HeadersObject>(\n (subAcc, [key, value]) => {\n const header: HeadersObject = {\n [key]: {\n schema: {\n type: 'string',\n enum: value.length ? value : undefined,\n },\n },\n };\n return { ...subAcc, ...header };\n },\n acc,\n );\n }, {})\n : undefined,\n } satisfies ResponseObject;\n } else {\n if (!responsesObject[item.statusCode].content[ct]) {\n responsesObject[item.statusCode].content[ct] = { schema };\n } else {\n const existing = responsesObject[item.statusCode].content[ct]\n .schema as SchemaObject;\n if (existing.oneOf) {\n if (\n !existing.oneOf.find(\n (it) => JSON.stringify(it) === JSON.stringify(schema),\n )\n ) {\n existing.oneOf.push(schema);\n }\n } else if (JSON.stringify(existing) !== JSON.stringify(schema)) {\n responsesObject[item.statusCode].content[ct].schema = {\n oneOf: [existing, schema],\n };\n }\n }\n }\n }\n return responsesObject;\n }\n\n async #selectosToParameters(selectors: Selector[]) {\n const parameters: ParameterObject[] = [];\n const bodySchemaProps: Record<\n string,\n { required: boolean; schema: SchemaObject }\n > = {};\n for (const selector of selectors) {\n const { optional, schema } = await evalZod(\n selector.against,\n this.#imports,\n );\n if (selector.source === 'body') {\n bodySchemaProps[selector.name] = {\n required: !optional,\n schema,\n };\n continue;\n }\n const parameter: ParameterObject = {\n in: semanticSourceToOpenAPI[selector.source],\n name: selector.name,\n required: !optional,\n schema,\n };\n parameters.push(parameter);\n }\n return { parameters, bodySchemaProps };\n }\n\n getTags(): string[] {\n const tags = new Set<string>();\n\n for (const operation of this.#operations) {\n if (operation.info.tags) {\n for (const tag of operation.info.tags) {\n tags.add(tag);\n }\n }\n }\n\n return Array.from(tags);\n }\n\n getSharedSchemas(): Record<string, SchemaObject> {\n return Object.fromEntries(this.#sharedResponses);\n }\n\n async getPaths() {\n const operations: PathsObject = {};\n\n for (const operation of this.#operations) {\n const { path, method, selectors } = operation;\n const { parameters, bodySchemaProps } =\n await this.#selectosToParameters(selectors);\n const bodySchema: Record<string, SchemaObject> = {};\n const required: string[] = [];\n const sortedBodySchemaProps = Object.entries(\n sortObjectKeys(bodySchemaProps),\n );\n for (const [key, value] of sortedBodySchemaProps) {\n if (value.required) {\n required.push(key);\n }\n bodySchema[key] = value.schema;\n }\n\n const operationObject: OperationObject = {\n operationId: operation.name,\n parameters,\n tags: operation.info.tags,\n // || undefined would omit the value from final openapi spec\n description: operation.info.description || undefined,\n summary: operation.info.summary || undefined,\n 'x-tool': operation.info.tool\n ? {\n name: operation.info.tool || undefined,\n description: operation.info.toolDescription || undefined,\n }\n : undefined,\n requestBody: Object.keys(bodySchema).length\n ? {\n required: required.length ? true : false,\n content: {\n [operation.contentType || 'application/json']: {\n schema: {\n required: required.length ? sortArray(required) : undefined,\n type: 'object',\n properties: bodySchema,\n },\n },\n },\n }\n : undefined,\n responses:\n Object.keys(operation.responses).length === 0\n ? undefined\n : operation.responses,\n };\n if (!operations[path]) {\n operations[path] = {};\n }\n operations[path][method] = operationObject;\n if (this.#onOperation) {\n const paths = this.#onOperation?.(\n operation.sourceFile,\n method,\n path,\n operationObject,\n );\n Object.assign(operations, paths ?? {});\n }\n }\n return operations;\n }\n\n /**\n * Converts Express/Node.js style path parameters (/path/:param) to OpenAPI style (/path/{param})\n */\n #tunePath(path: string): string {\n return path.replace(/:([^/]+)/g, '{$1}');\n }\n}\n\ninterface DateType {\n [$types]: any[];\n kind: string;\n optional: boolean;\n value?: string;\n}\n\nexport function toSchema(data: DateType | string | null | undefined): any {\n if (data === null || data === undefined) {\n return { type: 'any' };\n } else if (typeof data === 'string') {\n const isRef = data.startsWith('#');\n if (isRef) {\n return { $ref: data };\n }\n return { type: data };\n } else if (data.kind === 'never') {\n return { not: {} };\n } else if (data.kind === 'literal') {\n return { enum: [data.value], type: data[$types][0] };\n } else if (data.kind === 'record') {\n return {\n type: 'object',\n additionalProperties: toSchema(data[$types][0]),\n };\n } else if (data.kind === 'array') {\n const items = data[$types].map(toSchema);\n return { type: 'array', items: data[$types].length ? items[0] : {} };\n } else if (data.kind === 'union') {\n const schemas = data[$types].map(toSchema);\n const unique = [\n ...new Map(\n schemas.map((schema) => [JSON.stringify(schema), schema]),\n ).values(),\n ];\n return unique.length === 1 ? unique[0] : { anyOf: unique };\n } else if (data.kind === 'intersection') {\n // TS gives anonymous/empty object types the synthetic symbol name \"__type\".\n // Members like `& {}` (the autocomplete-trick wrapper) contribute no schema\n // info \u2014 drop them so `(string & {})` emits as plain `{type:'string'}`.\n const ANON_OBJECT = '__type';\n const meaningful = (data[$types] as unknown[]).filter((m) => {\n if (!m || typeof m !== 'object') return true;\n const node = m as { kind?: unknown; [$types]?: readonly unknown[] };\n return !(\n !node.kind &&\n node[$types]?.length === 1 &&\n node[$types][0] === ANON_OBJECT\n );\n });\n if (meaningful.length === 0) return {};\n if (meaningful.length === 1)\n return toSchema(meaningful[0] as DateType | string);\n return { allOf: meaningful.map((m) => toSchema(m as DateType | string)) };\n } else if ($types in data) {\n return data[$types].map(toSchema)[0] ?? {};\n } else {\n const props: Record<string, unknown> = {};\n const required: string[] = [];\n const sortedEntries = Object.entries(sortObjectKeys(data));\n for (const [key, value] of sortedEntries) {\n props[key] = toSchema(value as any);\n if (!(value as any).optional) {\n required.push(key);\n }\n }\n return {\n type: 'object',\n properties: props,\n required: sortArray(required),\n additionalProperties: false,\n };\n }\n}\n\nexport function isHttpMethod(name: string): name is Method {\n return ['get', 'post', 'put', 'delete', 'patch'].includes(name);\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type {\n HeadersObject,\n OperationObject,\n ParameterObject,\n PathsObject,\n ResponseObject,\n ResponsesObject,\n SchemaObject,\n SecurityRequirementObject,\n} from 'openapi3-ts/oas31';\n\nimport { $types } from './deriver.js';\nimport { sortArray, sortObjectKeys } from './utils.js';\nimport { type InjectImport, evalZod } from './zod-jsonschema.js';\n\nexport type OperationInfo = {\n tool?: string;\n toolDescription?: string;\n summary?: string;\n description?: string;\n tags?: string[];\n security?: SecurityRequirementObject[];\n};\nexport type Method =\n 'get' | 'post' | 'put' | 'patch' | 'delete' | 'trace' | 'head';\n\nexport const methods = [\n 'get',\n 'post',\n 'put',\n 'patch',\n 'delete',\n 'trace',\n 'head',\n] as const;\nexport type SemanticSource =\n 'query' | 'queries' | 'body' | 'params' | 'headers';\n\nconst semanticSourceToOpenAPI = {\n queries: 'query',\n query: 'query',\n headers: 'header',\n params: 'path',\n} as const;\nexport interface Selector {\n name: string;\n against: string;\n source: SemanticSource;\n}\n\nexport interface ResponseItem {\n statusCode: string;\n response?: DateType;\n contentType: string;\n headers: (string | Record<string, string[]>)[];\n middlewareName?: string;\n}\n\nexport type OnOperation = (\n sourceFile: string,\n method: Method,\n path: string,\n operation: OperationObject,\n) => PathsObject;\nexport class Paths {\n #imports: InjectImport[] = [];\n #onOperation?: OnOperation;\n #sharedResponses = new Map<string, SchemaObject>();\n #operations: Array<{\n sourceFile: string;\n name: string;\n path: string;\n method: Method;\n selectors: Selector[];\n responses: ResponsesObject;\n contentType?: string;\n info: OperationInfo;\n }> = [];\n\n constructor(config: { imports: InjectImport[]; onOperation?: OnOperation }) {\n this.#imports = config.imports;\n this.#onOperation = config.onOperation;\n }\n\n addPath(\n name: string,\n path: string,\n method: Method,\n contentType: string | undefined,\n selectors: Selector[],\n responses: ResponseItem[],\n sourceFile: string,\n info: OperationInfo,\n ) {\n const responsesObject = this.#responseItemToResponses(responses);\n\n this.#operations.push({\n name,\n path: this.#tunePath(path),\n sourceFile,\n contentType: contentType,\n method,\n selectors,\n responses: responsesObject,\n info,\n });\n return this;\n }\n\n #responseItemToResponses(responses: ResponseItem[]): ResponsesObject {\n const responsesObject: ResponsesObject = {};\n for (const item of responses) {\n const ct = item.contentType;\n let schema = item.response ? toSchema(item.response) : {};\n\n // Deduplicate named middleware responses via $ref\n if (item.middlewareName) {\n const sanitizedCt = ct.replace(/\\//g, '_');\n const sharedKey = `${item.middlewareName}${item.statusCode}_${sanitizedCt}`;\n if (!this.#sharedResponses.has(sharedKey)) {\n this.#sharedResponses.set(sharedKey, schema);\n }\n schema = { $ref: `#/components/schemas/${sharedKey}` };\n }\n\n if (!responsesObject[item.statusCode]) {\n responsesObject[item.statusCode] = {\n description: `Response for ${item.statusCode}`,\n content:\n ct !== 'empty'\n ? {\n [ct]:\n ct === 'application/octet-stream'\n ? { schema: { type: 'string', format: 'binary' } }\n : { schema },\n }\n : undefined,\n headers: item.headers.length\n ? item.headers.reduce<HeadersObject>((acc, current) => {\n const headers =\n typeof current === 'string' ? { [current]: [] } : current;\n const sortedHeaders = Object.entries(sortObjectKeys(headers));\n return sortedHeaders.reduce<HeadersObject>(\n (subAcc, [key, value]) => {\n const header: HeadersObject = {\n [key]: {\n schema: {\n type: 'string',\n enum: value.length ? value : undefined,\n },\n },\n };\n return { ...subAcc, ...header };\n },\n acc,\n );\n }, {})\n : undefined,\n } satisfies ResponseObject;\n } else {\n if (!responsesObject[item.statusCode].content[ct]) {\n responsesObject[item.statusCode].content[ct] = { schema };\n } else {\n const existing = responsesObject[item.statusCode].content[ct]\n .schema as SchemaObject;\n if (existing.oneOf) {\n if (\n !existing.oneOf.find(\n (it) => JSON.stringify(it) === JSON.stringify(schema),\n )\n ) {\n existing.oneOf.push(schema);\n }\n } else if (JSON.stringify(existing) !== JSON.stringify(schema)) {\n responsesObject[item.statusCode].content[ct].schema = {\n oneOf: [existing, schema],\n };\n }\n }\n }\n }\n return responsesObject;\n }\n\n async #selectosToParameters(selectors: Selector[]) {\n const parameters: ParameterObject[] = [];\n const bodySchemaProps: Record<\n string,\n { required: boolean; schema: SchemaObject }\n > = {};\n for (const selector of selectors) {\n const { optional, schema } = await evalZod(\n selector.against,\n this.#imports,\n );\n if (selector.source === 'body') {\n bodySchemaProps[selector.name] = {\n required: !optional,\n schema,\n };\n continue;\n }\n const parameter: ParameterObject = {\n in: semanticSourceToOpenAPI[selector.source],\n name: selector.name,\n required: !optional,\n schema,\n };\n parameters.push(parameter);\n }\n return { parameters, bodySchemaProps };\n }\n\n getTags(): string[] {\n const tags = new Set<string>();\n\n for (const operation of this.#operations) {\n if (operation.info.tags) {\n for (const tag of operation.info.tags) {\n tags.add(tag);\n }\n }\n }\n\n return Array.from(tags);\n }\n\n getSharedSchemas(): Record<string, SchemaObject> {\n return Object.fromEntries(this.#sharedResponses);\n }\n\n async getPaths() {\n const operations: PathsObject = {};\n\n for (const operation of this.#operations) {\n const { path, method, selectors } = operation;\n const { parameters, bodySchemaProps } =\n await this.#selectosToParameters(selectors);\n const bodySchema: Record<string, SchemaObject> = {};\n const required: string[] = [];\n const sortedBodySchemaProps = Object.entries(\n sortObjectKeys(bodySchemaProps),\n );\n for (const [key, value] of sortedBodySchemaProps) {\n if (value.required) {\n required.push(key);\n }\n bodySchema[key] = value.schema;\n }\n\n const operationObject: OperationObject = {\n operationId: operation.name,\n parameters,\n tags: operation.info.tags,\n // || undefined would omit the value from final openapi spec\n description: operation.info.description || undefined,\n summary: operation.info.summary || undefined,\n security: operation.info.security,\n 'x-tool': operation.info.tool\n ? {\n name: operation.info.tool || undefined,\n description: operation.info.toolDescription || undefined,\n }\n : undefined,\n requestBody: Object.keys(bodySchema).length\n ? {\n required: required.length ? true : false,\n content: {\n [operation.contentType || 'application/json']: {\n schema: {\n required: required.length ? sortArray(required) : undefined,\n type: 'object',\n properties: bodySchema,\n },\n },\n },\n }\n : undefined,\n responses:\n Object.keys(operation.responses).length === 0\n ? undefined\n : operation.responses,\n };\n if (!operations[path]) {\n operations[path] = {};\n }\n operations[path][method] = operationObject;\n if (this.#onOperation) {\n const paths = this.#onOperation?.(\n operation.sourceFile,\n method,\n path,\n operationObject,\n );\n Object.assign(operations, paths ?? {});\n }\n }\n return operations;\n }\n\n /**\n * Converts Express/Node.js style path parameters (/path/:param) to OpenAPI style (/path/{param})\n */\n #tunePath(path: string): string {\n return path.replace(/:([^/]+)/g, '{$1}');\n }\n}\n\ninterface DateType {\n [$types]: any[];\n kind: string;\n optional: boolean;\n value?: string;\n}\n\nexport function toSchema(data: DateType | string | null | undefined): any {\n if (data === null || data === undefined) {\n return { type: 'any' };\n } else if (typeof data === 'string') {\n const isRef = data.startsWith('#');\n if (isRef) {\n return { $ref: data };\n }\n return { type: data };\n } else if (data.kind === 'date') {\n return { type: 'string', format: 'date-time' };\n } else if (data.kind === 'never') {\n return { not: {} };\n } else if (data.kind === 'literal') {\n return { enum: [data.value], type: data[$types][0] };\n } else if (data.kind === 'record') {\n return {\n type: 'object',\n additionalProperties: toSchema(data[$types][0]),\n };\n } else if (data.kind === 'array') {\n const items = data[$types].map(toSchema);\n return { type: 'array', items: data[$types].length ? items[0] : {} };\n } else if (data.kind === 'union') {\n const schemas = data[$types].map(toSchema);\n const unique = [\n ...new Map(\n schemas.map((schema) => [JSON.stringify(schema), schema]),\n ).values(),\n ];\n return unique.length === 1 ? unique[0] : { anyOf: unique };\n } else if (data.kind === 'intersection') {\n // TS gives anonymous/empty object types the synthetic symbol name \"__type\".\n // Members like `& {}` (the autocomplete-trick wrapper) contribute no schema\n // info \u2014 drop them so `(string & {})` emits as plain `{type:'string'}`.\n const ANON_OBJECT = '__type';\n const meaningful = (data[$types] as unknown[]).filter((m) => {\n if (!m || typeof m !== 'object') return true;\n const node = m as { kind?: unknown; [$types]?: readonly unknown[] };\n return !(\n !node.kind &&\n node[$types]?.length === 1 &&\n node[$types][0] === ANON_OBJECT\n );\n });\n if (meaningful.length === 0) return {};\n if (meaningful.length === 1)\n return toSchema(meaningful[0] as DateType | string);\n return { allOf: meaningful.map((m) => toSchema(m as DateType | string)) };\n } else if ($types in data) {\n return data[$types].map(toSchema)[0] ?? {};\n } else {\n const props: Record<string, unknown> = {};\n const required: string[] = [];\n const sortedEntries = Object.entries(sortObjectKeys(data));\n for (const [key, value] of sortedEntries) {\n props[key] = toSchema(value as any);\n if (!(value as any).optional) {\n required.push(key);\n }\n }\n return {\n type: 'object',\n properties: props,\n required: sortArray(required),\n additionalProperties: false,\n };\n }\n}\n\nexport function isHttpMethod(name: string): name is Method {\n return ['get', 'post', 'put', 'delete', 'patch'].includes(name);\n}\n"],
|
|
5
|
+
"mappings": "AAWA,SAAS,cAAc;AACvB,SAAS,WAAW,sBAAsB;AAC1C,SAA4B,eAAe;AAapC,MAAM,UAAU;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIA,MAAM,0BAA0B;AAAA,EAC9B,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAAQ;AACV;AAqBO,MAAM,MAAM;AAAA,EACjB,WAA2B,CAAC;AAAA,EAC5B;AAAA,EACA,mBAAm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,EAAE,CAAC,MAAM;AAAA,IAExB,CAAC;AACD,QAAI,WAAW,WAAW,EAAG,QAAO,CAAC;AACrC,QAAI,WAAW,WAAW;AACxB,aAAO,SAAS,WAAW,CAAC,CAAsB;AACpD,WAAO,EAAE,OAAO,WAAW,IAAI,CAAC,MAAM,SAAS,CAAsB,CAAC,EAAE;AAAA,EAC1E,WAAW,UAAU,MAAM;AACzB,WAAO,KAAK,MAAM,EAAE,IAAI,QAAQ,EAAE,CAAC,KAAK,CAAC;AAAA,EAC3C,OAAO;AACL,UAAM,QAAiC,CAAC;AACxC,UAAM,WAAqB,CAAC;AAC5B,UAAM,gBAAgB,OAAO,QAAQ,eAAe,IAAI,CAAC;AACzD,eAAW,CAAC,KAAK,KAAK,KAAK,eAAe;AACxC,YAAM,GAAG,IAAI,SAAS,KAAY;AAClC,UAAI,CAAE,MAAc,UAAU;AAC5B,iBAAS,KAAK,GAAG;AAAA,MACnB;AAAA,IACF;AACA,WAAO;AAAA,MACL,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,UAAU,UAAU,QAAQ;AAAA,MAC5B,sBAAsB;AAAA,IACxB;AAAA,EACF;AACF;AAEO,SAAS,aAAa,MAA8B;AACzD,SAAO,CAAC,OAAO,QAAQ,OAAO,UAAU,OAAO,EAAE,SAAS,IAAI;AAChE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/lib/ref.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { HeaderObject, OpenAPIObject, ParameterObject, PathItemObject, ReferenceObject, RequestBodyObject, SchemaObject
|
|
1
|
+
import type { HeaderObject, OpenAPIObject, ParameterObject, PathItemObject, ReferenceObject, RequestBodyObject, SchemaObject } from 'openapi3-ts/oas31';
|
|
2
|
+
import type { OpenAPIDocument, OpenAPISecuritySchemeObject } from './security.js';
|
|
2
3
|
export declare function isRef(obj: any): obj is ReferenceObject;
|
|
3
4
|
export declare function notRef(obj: any): obj is SchemaObject;
|
|
4
5
|
export declare function cleanRef(ref: string): string;
|
|
@@ -7,8 +8,8 @@ export declare function parseRef(ref: string): {
|
|
|
7
8
|
namespace: string;
|
|
8
9
|
path: string;
|
|
9
10
|
};
|
|
10
|
-
export declare function resolveRef<T extends SchemaObject | HeaderObject | ParameterObject | PathItemObject | ReferenceObject | RequestBodyObject = SchemaObject>(spec: OpenAPIObject, maybeRef: SchemaObject | ReferenceObject | ParameterObject | PathItemObject |
|
|
11
|
-
export declare function followRef<T extends SchemaObject | HeaderObject | ParameterObject | PathItemObject | ReferenceObject | RequestBodyObject = SchemaObject>(spec: OpenAPIObject, ref: string): T;
|
|
12
|
-
export declare function tapRef<T extends SchemaObject | HeaderObject | ParameterObject | ReferenceObject | RequestBodyObject = SchemaObject>(spec: OpenAPIObject, maybeRef: SchemaObject | ReferenceObject): T;
|
|
13
|
-
export declare function distillRef<T extends SchemaObject | HeaderObject | ParameterObject | ReferenceObject | RequestBodyObject = SchemaObject>(spec: OpenAPIObject, maybeRef: ReferenceObject | SchemaObject): T;
|
|
11
|
+
export declare function resolveRef<T extends SchemaObject | HeaderObject | ParameterObject | PathItemObject | ReferenceObject | RequestBodyObject | OpenAPISecuritySchemeObject = SchemaObject>(spec: OpenAPIObject | OpenAPIDocument, maybeRef: SchemaObject | ReferenceObject | ParameterObject | PathItemObject | OpenAPISecuritySchemeObject | HeaderObject): T;
|
|
12
|
+
export declare function followRef<T extends SchemaObject | HeaderObject | ParameterObject | PathItemObject | ReferenceObject | RequestBodyObject | OpenAPISecuritySchemeObject = SchemaObject>(spec: OpenAPIObject | OpenAPIDocument, ref: string): T;
|
|
13
|
+
export declare function tapRef<T extends SchemaObject | HeaderObject | ParameterObject | ReferenceObject | RequestBodyObject = SchemaObject>(spec: OpenAPIObject | OpenAPIDocument, maybeRef: SchemaObject | ReferenceObject): T;
|
|
14
|
+
export declare function distillRef<T extends SchemaObject | HeaderObject | ParameterObject | ReferenceObject | RequestBodyObject = SchemaObject>(spec: OpenAPIObject | OpenAPIDocument, maybeRef: ReferenceObject | SchemaObject): T;
|
|
14
15
|
//# sourceMappingURL=ref.d.ts.map
|
package/dist/lib/ref.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/lib/ref.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,eAAe,EACf,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,YAAY,
|
|
1
|
+
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/lib/ref.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,eAAe,EACf,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,YAAY,EACb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EACV,eAAe,EACf,2BAA2B,EAC5B,MAAM,eAAe,CAAC;AAGvB,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,eAAe,CAEtD;AACD,wBAAgB,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,YAAY,CAEpD;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,UAEnC;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM;;;;EAgBnC;AAED,wBAAgB,UAAU,CACxB,CAAC,SACG,YAAY,GACZ,YAAY,GACZ,eAAe,GACf,cAAc,GACd,eAAe,GACf,iBAAiB,GACjB,2BAA2B,GAAG,YAAY,EAE9C,IAAI,EAAE,aAAa,GAAG,eAAe,EACrC,QAAQ,EACJ,YAAY,GACZ,eAAe,GACf,eAAe,GACf,cAAc,GACd,2BAA2B,GAC3B,YAAY,GACf,CAAC,CAKH;AAED,wBAAgB,SAAS,CACvB,CAAC,SACG,YAAY,GACZ,YAAY,GACZ,eAAe,GACf,cAAc,GACd,eAAe,GACf,iBAAiB,GACjB,2BAA2B,GAAG,YAAY,EAC9C,IAAI,EAAE,aAAa,GAAG,eAAe,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,CAOvD;AAED,wBAAgB,MAAM,CACpB,CAAC,SACG,YAAY,GACZ,YAAY,GACZ,eAAe,GACf,eAAe,GACf,iBAAiB,GAAG,YAAY,EAEpC,IAAI,EAAE,aAAa,GAAG,eAAe,EACrC,QAAQ,EAAE,YAAY,GAAG,eAAe,GACvC,CAAC,CAMH;AAED,wBAAgB,UAAU,CACxB,CAAC,SACG,YAAY,GACZ,YAAY,GACZ,eAAe,GACf,eAAe,GACf,iBAAiB,GAAG,YAAY,EAEpC,IAAI,EAAE,aAAa,GAAG,eAAe,EACrC,QAAQ,EAAE,eAAe,GAAG,YAAY,GACvC,CAAC,CA8CH"}
|
package/dist/lib/ref.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/ref.ts"],
|
|
4
|
-
"sourcesContent": ["import { get } from 'lodash-es';\nimport type {\n HeaderObject,\n OpenAPIObject,\n ParameterObject,\n PathItemObject,\n ReferenceObject,\n RequestBodyObject,\n SchemaObject,\n
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAW;
|
|
4
|
+
"sourcesContent": ["import { get } from 'lodash-es';\nimport type {\n HeaderObject,\n OpenAPIObject,\n ParameterObject,\n PathItemObject,\n ReferenceObject,\n RequestBodyObject,\n SchemaObject,\n} from 'openapi3-ts/oas31';\n\nimport type {\n OpenAPIDocument,\n OpenAPISecuritySchemeObject,\n} from './security.js';\nimport { isEmpty } from './utils.js';\n\nexport function isRef(obj: any): obj is ReferenceObject {\n return obj && '$ref' in obj;\n}\nexport function notRef(obj: any): obj is SchemaObject {\n return !isRef(obj);\n}\n\nexport function cleanRef(ref: string) {\n return ref.replace(/^#\\//, '');\n}\n\nexport function parseRef(ref: string) {\n const parts = ref.split('/');\n const names: string[] = [];\n const [model] = parts.splice(-1);\n names.push(model);\n while (parts.lastIndexOf('properties') !== -1) {\n parts.splice(parts.lastIndexOf('properties'), 1);\n const [model] = parts.splice(-1);\n names.push(model);\n }\n const [namespace] = parts.splice(-1);\n return {\n model: names.reverse().join(' '),\n namespace,\n path: cleanRef(parts.join('/')),\n };\n}\n\nexport function resolveRef<\n T extends\n | SchemaObject\n | HeaderObject\n | ParameterObject\n | PathItemObject\n | ReferenceObject\n | RequestBodyObject\n | OpenAPISecuritySchemeObject = SchemaObject,\n>(\n spec: OpenAPIObject | OpenAPIDocument,\n maybeRef:\n | SchemaObject\n | ReferenceObject\n | ParameterObject\n | PathItemObject\n | OpenAPISecuritySchemeObject\n | HeaderObject,\n): T {\n if (isRef(maybeRef)) {\n return followRef<T>(spec, maybeRef.$ref!);\n }\n return maybeRef as T;\n}\n\nexport function followRef<\n T extends\n | SchemaObject\n | HeaderObject\n | ParameterObject\n | PathItemObject\n | ReferenceObject\n | RequestBodyObject\n | OpenAPISecuritySchemeObject = SchemaObject,\n>(spec: OpenAPIObject | OpenAPIDocument, ref: string): T {\n const pathParts = cleanRef(ref).split('/');\n const entry = get(spec, pathParts) as T | ReferenceObject;\n if (isRef(entry)) {\n return followRef<T>(spec, entry.$ref!);\n }\n return entry;\n}\n\nexport function tapRef<\n T extends\n | SchemaObject\n | HeaderObject\n | ParameterObject\n | ReferenceObject\n | RequestBodyObject = SchemaObject,\n>(\n spec: OpenAPIObject | OpenAPIDocument,\n maybeRef: SchemaObject | ReferenceObject,\n): T {\n if (isRef(maybeRef)) {\n const pathParts = cleanRef(maybeRef.$ref).split('/');\n return get(spec, pathParts) as T;\n }\n return maybeRef as T;\n}\n\nexport function distillRef<\n T extends\n | SchemaObject\n | HeaderObject\n | ParameterObject\n | ReferenceObject\n | RequestBodyObject = SchemaObject,\n>(\n spec: OpenAPIObject | OpenAPIDocument,\n maybeRef: ReferenceObject | SchemaObject,\n): T {\n const def = resolveRef<T>(spec, maybeRef);\n if (!def) {\n return def;\n }\n\n if ('properties' in def) {\n def.properties ??= {};\n for (const key in def.properties) {\n const prop = def.properties[key];\n if (isRef(prop)) {\n def.properties[key] = distillRef(spec, prop);\n }\n }\n }\n if ('items' in def) {\n if (isRef(def.items)) {\n def.items = distillRef<SchemaObject>(spec, def.items);\n }\n }\n if ('allOf' in def && !isEmpty(def.allOf)) {\n def.allOf = def.allOf.map((item) => {\n if (isRef(item)) {\n return distillRef<SchemaObject>(spec, item);\n }\n return item;\n });\n }\n if ('oneOf' in def && !isEmpty(def.oneOf)) {\n def.oneOf = def.oneOf.map((item) => {\n if (isRef(item)) {\n return distillRef<SchemaObject>(spec, item);\n }\n return item;\n });\n }\n if ('anyOf' in def && !isEmpty(def.anyOf)) {\n def.anyOf = def.anyOf.map((item) => {\n if (isRef(item)) {\n return distillRef<SchemaObject>(spec, item);\n }\n return item;\n });\n }\n\n return def;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAW;AAepB,SAAS,eAAe;AAEjB,SAAS,MAAM,KAAkC;AACtD,SAAO,OAAO,UAAU;AAC1B;AACO,SAAS,OAAO,KAA+B;AACpD,SAAO,CAAC,MAAM,GAAG;AACnB;AAEO,SAAS,SAAS,KAAa;AACpC,SAAO,IAAI,QAAQ,QAAQ,EAAE;AAC/B;AAEO,SAAS,SAAS,KAAa;AACpC,QAAM,QAAQ,IAAI,MAAM,GAAG;AAC3B,QAAM,QAAkB,CAAC;AACzB,QAAM,CAAC,KAAK,IAAI,MAAM,OAAO,EAAE;AAC/B,QAAM,KAAK,KAAK;AAChB,SAAO,MAAM,YAAY,YAAY,MAAM,IAAI;AAC7C,UAAM,OAAO,MAAM,YAAY,YAAY,GAAG,CAAC;AAC/C,UAAM,CAACA,MAAK,IAAI,MAAM,OAAO,EAAE;AAC/B,UAAM,KAAKA,MAAK;AAAA,EAClB;AACA,QAAM,CAAC,SAAS,IAAI,MAAM,OAAO,EAAE;AACnC,SAAO;AAAA,IACL,OAAO,MAAM,QAAQ,EAAE,KAAK,GAAG;AAAA,IAC/B;AAAA,IACA,MAAM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H;AACA,MAAI,WAAW,OAAO,CAAC,QAAQ,IAAI,KAAK,GAAG;AACzC,QAAI,QAAQ,IAAI,MAAM,IAAI,CAAC,SAAS;AAClC,UAAI,MAAM,IAAI,GAAG;AACf,eAAO,WAAyB,MAAM,IAAI;AAAA,MAC5C;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AACA,MAAI,WAAW,OAAO,CAAC,QAAQ,IAAI,KAAK,GAAG;AACzC,QAAI,QAAQ,IAAI,MAAM,IAAI,CAAC,SAAS;AAClC,UAAI,MAAM,IAAI,GAAG;AACf,eAAO,WAAyB,MAAM,IAAI;AAAA,MAC5C;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": ["model"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ComponentsObject, OpenAPIObject, ReferenceObject, SecuritySchemeObject } from 'openapi3-ts/oas31';
|
|
2
|
+
export interface OpenAPIOAuthFlowObject {
|
|
3
|
+
authorizationUrl?: string;
|
|
4
|
+
deviceAuthorizationUrl?: string;
|
|
5
|
+
tokenUrl?: string;
|
|
6
|
+
refreshUrl?: string;
|
|
7
|
+
scopes: Record<string, string>;
|
|
8
|
+
[extension: `x-${string}`]: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface OpenAPIOAuthFlowsObject {
|
|
11
|
+
implicit?: OpenAPIOAuthFlowObject;
|
|
12
|
+
password?: OpenAPIOAuthFlowObject;
|
|
13
|
+
clientCredentials?: OpenAPIOAuthFlowObject;
|
|
14
|
+
authorizationCode?: OpenAPIOAuthFlowObject;
|
|
15
|
+
deviceAuthorization?: OpenAPIOAuthFlowObject;
|
|
16
|
+
[extension: `x-${string}`]: unknown;
|
|
17
|
+
}
|
|
18
|
+
export type OpenAPISecuritySchemeObject = (SecuritySchemeObject & {
|
|
19
|
+
deprecated?: boolean;
|
|
20
|
+
}) | (Omit<SecuritySchemeObject, 'type' | 'flows'> & {
|
|
21
|
+
type: 'oauth2';
|
|
22
|
+
flows: OpenAPIOAuthFlowsObject;
|
|
23
|
+
oauth2MetadataUrl?: string;
|
|
24
|
+
deprecated?: boolean;
|
|
25
|
+
}) | {
|
|
26
|
+
type: 'mutualTLS';
|
|
27
|
+
description?: string;
|
|
28
|
+
deprecated?: boolean;
|
|
29
|
+
[extension: `x-${string}`]: unknown;
|
|
30
|
+
};
|
|
31
|
+
export type OpenAPIComponentsObject = Omit<ComponentsObject, 'securitySchemes'> & {
|
|
32
|
+
securitySchemes?: Record<string, OpenAPISecuritySchemeObject | ReferenceObject>;
|
|
33
|
+
};
|
|
34
|
+
export type OpenAPIDocument = Omit<OpenAPIObject, 'components'> & {
|
|
35
|
+
/** OpenAPI 3.2 document URI; the base for resolving relative references. */
|
|
36
|
+
$self?: string;
|
|
37
|
+
components?: OpenAPIComponentsObject;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/lib/security.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,CAAC,SAAS,EAAE,KAAK,MAAM,EAAE,GAAG,OAAO,CAAC;CACrC;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,iBAAiB,CAAC,EAAE,sBAAsB,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C;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAUF,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,YAAY,EAAO,
|
|
1
|
+
{"version":3,"file":"zod-jsonschema.d.ts","sourceRoot":"","sources":["../../src/lib/zod-jsonschema.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAUF,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,YAAY,EAAO,gBAonBzE"}
|
|
@@ -231,6 +231,12 @@ async function evalZod(schema, imports = []) {
|
|
|
231
231
|
schema.type === 'integer')
|
|
232
232
|
);
|
|
233
233
|
}`,
|
|
234
|
+
`function isNumericPair(left, right) {
|
|
235
|
+
return (
|
|
236
|
+
(left.type === 'number' && right.type === 'integer') ||
|
|
237
|
+
(left.type === 'integer' && right.type === 'number')
|
|
238
|
+
);
|
|
239
|
+
}`,
|
|
234
240
|
`function mergePrimitiveSchemas(schemas) {
|
|
235
241
|
const merged = {};
|
|
236
242
|
for (const schema of schemas) {
|
|
@@ -247,10 +253,7 @@ async function evalZod(schema, imports = []) {
|
|
|
247
253
|
if (merged.type === undefined) {
|
|
248
254
|
merged.type = schema.type;
|
|
249
255
|
} else if (merged.type !== schema.type) {
|
|
250
|
-
|
|
251
|
-
(merged.type === 'number' && schema.type === 'integer') ||
|
|
252
|
-
(merged.type === 'integer' && schema.type === 'number');
|
|
253
|
-
if (!numericPair) {
|
|
256
|
+
if (!isNumericPair(merged, schema)) {
|
|
254
257
|
return null;
|
|
255
258
|
}
|
|
256
259
|
merged.type = 'integer';
|
|
@@ -488,9 +491,6 @@ async function evalZod(schema, imports = []) {
|
|
|
488
491
|
override(ctx) {
|
|
489
492
|
const def = ctx.zodSchema._zod.def;
|
|
490
493
|
const json = ctx.jsonSchema;
|
|
491
|
-
if (def.type === 'optional') {
|
|
492
|
-
optional = true;
|
|
493
|
-
}
|
|
494
494
|
if (def.type === 'catch') {
|
|
495
495
|
delete json.default;
|
|
496
496
|
}
|
|
@@ -565,8 +565,15 @@ async function evalZod(schema, imports = []) {
|
|
|
565
565
|
);
|
|
566
566
|
if (outKeys.length > 0) {
|
|
567
567
|
const inJson = { ...json };
|
|
568
|
-
|
|
569
|
-
|
|
568
|
+
const compatible =
|
|
569
|
+
inJson.type === undefined ||
|
|
570
|
+
outJson.type === undefined ||
|
|
571
|
+
inJson.type === outJson.type ||
|
|
572
|
+
isNumericPair(inJson, outJson);
|
|
573
|
+
if (compatible) {
|
|
574
|
+
for (const key of Object.keys(json)) delete json[key];
|
|
575
|
+
json.allOf = [inJson, outJson];
|
|
576
|
+
}
|
|
570
577
|
}
|
|
571
578
|
}
|
|
572
579
|
if (def.type === 'tuple' && Array.isArray(json.items)) {
|
|
@@ -588,6 +595,9 @@ async function evalZod(schema, imports = []) {
|
|
|
588
595
|
try {
|
|
589
596
|
zodSchema = ${removeUnsupportedMethods(schema)};
|
|
590
597
|
maskBigIntDefaults(zodSchema);
|
|
598
|
+
// zod's own input-side flag: 'optional' for optional/nullish/catch,
|
|
599
|
+
// 'defaulted' for default/prefault, undefined once .nonoptional() applies.
|
|
600
|
+
optional = ['optional', 'defaulted'].includes(zodSchema._zod.optin);
|
|
591
601
|
const { $schema, ...converted } = toJsonSchema(zodSchema);
|
|
592
602
|
rawResult = converted;
|
|
593
603
|
} finally {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/zod-jsonschema.ts"],
|
|
4
|
-
"sourcesContent": ["export type InjectImport = {\n import: string;\n from: string;\n property?: string;\n};\n\nfunction removeUnsupportedMethods(schema: string) {\n return schema\n .replaceAll('.instanceof(File)', '.string().base64()')\n .replaceAll('.instanceof(Blob)', '.string().base64()')\n .replaceAll('.custom<File>()', '.string().base64()')\n .replaceAll('.custom<Blob>()', '.string().base64()');\n}\n\nexport async function evalZod(schema: string, imports: InjectImport[] = []) {\n // https://github.com/nodejs/node/issues/51956\n const lines = [\n `import { createRequire } from \"node:module\";`,\n `const filename = \"${import.meta.url}\";`,\n `const require = createRequire(filename);`,\n `const z = require(\"zod\");`,\n // zod 4 removed ZodString.ip/.cidr; restore them for analyzed user source\n // that still uses the v3 spellings.\n `const stringProto = Object.getPrototypeOf(z.string());\n const installedShims = [];\n function withReceiverChecks(receiver, format) {\n return (receiver._zod.def.checks ?? []).length\n ? z.intersection(receiver, format)\n : format;\n }\n if (!stringProto.ip) {\n installedShims.push('ip');\n stringProto.ip = function (options) {\n if (options?.version === 'v4') return withReceiverChecks(this, z.ipv4());\n if (options?.version === 'v6') return withReceiverChecks(this, z.ipv6());\n return withReceiverChecks(this, z.union([z.ipv4(), z.ipv6()]));\n };\n }\n if (!stringProto.cidr) {\n installedShims.push('cidr');\n stringProto.cidr = function (options) {\n if (options?.version === 'v4') return withReceiverChecks(this, z.cidrv4());\n if (options?.version === 'v6') return withReceiverChecks(this, z.cidrv6());\n return withReceiverChecks(this, z.union([z.cidrv4(), z.cidrv6()]));\n };\n }`,\n ...imports.map(\n (imp) =>\n `const ${imp.import} = require(${JSON.stringify(imp.from)})${\n imp.property ? `[${JSON.stringify(imp.property)}]` : ''\n };`,\n ),\n `let optional = false;`,\n `const WRAPPER_TYPES = new Set([\n 'optional',\n 'nullable',\n 'default',\n 'prefault',\n 'catch',\n 'readonly',\n 'nonoptional',\n ]);`,\n `function unwrapSchemaDef(def) {\n while (def) {\n if (WRAPPER_TYPES.has(def.type)) {\n def = def.innerType?._zod?.def;\n continue;\n }\n if (def.type === 'pipe') {\n def = def.in?._zod?.def;\n continue;\n }\n return def;\n }\n return def;\n }`,\n `function matchesDefType(schema, defType) {\n if (!schema || typeof schema !== 'object') return false;\n if (defType === 'number') {\n return schema.type === 'number' || schema.type === 'integer';\n }\n if (defType === 'bigint') {\n return schema.type === 'integer';\n }\n if (defType === 'string') {\n return schema.type === 'string';\n }\n if (defType === 'boolean') {\n return schema.type === 'boolean';\n }\n if (defType === 'date') {\n return schema.type === 'string' && schema.format === 'date-time';\n }\n return typeof schema.type === 'string';\n }`,\n `function applyZodType(schema, zodType, defType) {\n if (!schema || typeof schema !== 'object') return false;\n if (schema['x-zod-type']) return true;\n if (matchesDefType(schema, defType)) {\n schema['x-zod-type'] = zodType;\n return true;\n }\n for (const key of ['anyOf', 'oneOf', 'allOf']) {\n if (!Array.isArray(schema[key])) continue;\n const candidates = schema[key].filter(\n (candidate) => candidate && candidate.type !== 'null',\n );\n if (candidates.length === 1 && applyZodType(candidates[0], zodType, defType)) {\n return true;\n }\n for (const candidate of candidates) {\n if (applyZodType(candidate, zodType, defType)) {\n return true;\n }\n }\n }\n return false;\n }`,\n `const BIGINT_SENTINEL = '__sdkit_bigint__';`,\n // zod v4 JSON-round-trips default values before the override callback\n // runs, which throws on bigint. Mask them as sentinel strings up front\n // and restore after conversion.\n `function maskBigIntDefaults(schema, seen = new Set()) {\n if (!schema || !schema._zod || seen.has(schema)) return;\n seen.add(schema);\n const def = schema._zod.def;\n if (\n (def.type === 'default' || def.type === 'prefault') &&\n typeof def.defaultValue === 'bigint'\n ) {\n Object.defineProperty(def, 'defaultValue', {\n value: BIGINT_SENTINEL + def.defaultValue.toString(),\n configurable: true,\n });\n }\n for (const key of ['innerType', 'in', 'out', 'element', 'valueType', 'keyType', 'left', 'right', 'catchall', 'rest']) {\n if (def[key]) maskBigIntDefaults(def[key], seen);\n }\n if (typeof def.getter === 'function') {\n const inner = def.getter();\n maskBigIntDefaults(inner, seen);\n Object.defineProperty(def, 'getter', {\n value: () => inner,\n configurable: true,\n });\n }\n if (def.shape) {\n for (const value of Object.values(def.shape)) maskBigIntDefaults(value, seen);\n }\n if (Array.isArray(def.options)) {\n for (const option of def.options) maskBigIntDefaults(option, seen);\n }\n if (Array.isArray(def.items)) {\n for (const item of def.items) maskBigIntDefaults(item, seen);\n }\n }`,\n // int64 is a plain number in sdk-it, so masked bigint defaults unmask to\n // JS numbers \u2014 the spec stays plain JSON with no bigint values to trip up\n // JSON.stringify.\n `function unmaskBigIntDefaults(schema) {\n if (!schema || typeof schema !== 'object') return;\n for (const [key, value] of Object.entries(schema)) {\n if (typeof value === 'string' && value.startsWith(BIGINT_SENTINEL)) {\n schema[key] = Number(value.slice(BIGINT_SENTINEL.length));\n } else if (Array.isArray(value)) {\n value.forEach(unmaskBigIntDefaults);\n } else if (value && typeof value === 'object') {\n unmaskBigIntDefaults(value);\n }\n }\n }`,\n `function hasExplicitRegexCheck(def) {\n return (def.checks ?? []).some(\n (check) => check._zod?.def?.format === 'regex',\n );\n }`,\n `const STANDARD_STRING_FORMATS = new Set([\n 'email',\n 'uri',\n 'url',\n 'uuid',\n 'guid',\n 'date-time',\n 'date',\n 'time',\n 'duration',\n 'ipv4',\n 'ipv6',\n 'hostname',\n 'binary',\n ]);`,\n // Nonstandard formats that sdk-it's own converters map to semantic zod\n // validators. Keep both keys: format for our converters, pattern for\n // third-party validators that do not recognize the format.\n `const MAPPED_NONSTANDARD_FORMATS = new Set(['cidrv4', 'cidrv6']);`,\n `function normalizeDefaultValue(value) {\n return value instanceof Date ? value.toISOString() : value;\n }`,\n `function mergeComparableValue(target, key, value) {\n if (value === undefined) return true;\n const normalized = normalizeDefaultValue(value);\n if (target[key] === undefined) {\n target[key] = normalized;\n return true;\n }\n return Object.is(target[key], normalized);\n }`,\n `function mergeLowerBound(target, key, value) {\n if (value === undefined) return true;\n if (typeof value !== 'number') return false;\n if (target[key] === undefined || value > target[key]) {\n target[key] = value;\n }\n return true;\n }`,\n `function mergeUpperBound(target, key, value) {\n if (value === undefined) return true;\n if (typeof value !== 'number') return false;\n if (target[key] === undefined || value < target[key]) {\n target[key] = value;\n }\n return true;\n }`,\n `function mergeEnumValues(target, values) {\n if (!Array.isArray(values)) return false;\n if (!Array.isArray(target.enum)) {\n target.enum = [...values];\n return true;\n }\n target.enum = target.enum.filter((candidate) =>\n values.some((value) => Object.is(candidate, value)),\n );\n return target.enum.length > 0;\n }`,\n `function isMergeablePrimitiveSchema(schema) {\n return (\n schema &&\n typeof schema === 'object' &&\n !schema.$ref &&\n !schema.anyOf &&\n !schema.oneOf &&\n !schema.allOf &&\n (schema.type === 'string' ||\n schema.type === 'boolean' ||\n schema.type === 'number' ||\n schema.type === 'integer')\n );\n }`,\n `function mergePrimitiveSchemas(schemas) {\n const merged = {};\n for (const schema of schemas) {\n if (\n schema &&\n typeof schema === 'object' &&\n Object.keys(schema).length === 0\n ) {\n continue;\n }\n if (!isMergeablePrimitiveSchema(schema)) {\n return null;\n }\n if (merged.type === undefined) {\n merged.type = schema.type;\n } else if (merged.type !== schema.type) {\n const numericPair =\n (merged.type === 'number' && schema.type === 'integer') ||\n (merged.type === 'integer' && schema.type === 'number');\n if (!numericPair) {\n return null;\n }\n merged.type = 'integer';\n }\n\n for (const [key, value] of Object.entries(schema)) {\n if (key === 'type') {\n continue;\n }\n switch (key) {\n case 'minimum':\n case 'exclusiveMinimum':\n case 'minLength':\n case 'minItems':\n case 'minProperties':\n if (!mergeLowerBound(merged, key, value)) {\n return null;\n }\n break;\n case 'maximum':\n case 'exclusiveMaximum':\n case 'maxLength':\n case 'maxItems':\n case 'maxProperties':\n if (!mergeUpperBound(merged, key, value)) {\n return null;\n }\n break;\n case 'enum':\n if (!mergeEnumValues(merged, value)) {\n return null;\n }\n break;\n default:\n if (!mergeComparableValue(merged, key, value)) {\n return null;\n }\n }\n }\n }\n return merged;\n }`,\n `function normalizeSchema(schema, isIntersectionMember = false) {\n if (!schema || typeof schema !== 'object') {\n return schema;\n }\n\n if (schema.default !== undefined) {\n schema.default = normalizeDefaultValue(schema.default);\n }\n\n if (Array.isArray(schema.items)) {\n schema.items = schema.items.map((item) => normalizeSchema(item));\n } else if (schema.items && typeof schema.items === 'object') {\n schema.items = normalizeSchema(schema.items);\n }\n\n if (schema.properties && typeof schema.properties === 'object') {\n for (const [key, value] of Object.entries(schema.properties)) {\n schema.properties[key] = normalizeSchema(value);\n }\n }\n\n if (\n schema.additionalProperties &&\n typeof schema.additionalProperties === 'object'\n ) {\n schema.additionalProperties = normalizeSchema(schema.additionalProperties);\n }\n\n for (const key of ['anyOf', 'oneOf', 'allOf']) {\n if (!Array.isArray(schema[key])) continue;\n schema[key] = schema[key].map((candidate) =>\n normalizeSchema(candidate, key === 'allOf'),\n );\n }\n\n if (Array.isArray(schema.oneOf) && !schema.anyOf) {\n schema.anyOf = schema.oneOf;\n delete schema.oneOf;\n }\n\n if (\n Array.isArray(schema.anyOf) &&\n schema.anyOf.every(\n (member) =>\n member &&\n typeof member === 'object' &&\n Object.keys(member).length === 1 &&\n typeof member.type === 'string',\n )\n ) {\n const { anyOf, ...rest } = schema;\n schema = { ...rest, type: anyOf.map((member) => member.type) };\n }\n\n if (\n schema.type === 'object' &&\n schema.properties &&\n schema.additionalProperties === undefined &&\n !isIntersectionMember\n ) {\n schema.additionalProperties = false;\n }\n\n if (\n schema.type === 'object' &&\n schema.propertyNames &&\n JSON.stringify(schema.propertyNames) === '{\"type\":\"string\"}'\n ) {\n delete schema.propertyNames;\n }\n\n if (\n typeof schema.$ref === 'string' &&\n !schema.$ref.startsWith('#/components/schemas')\n ) {\n schema.$ref =\n schema.$ref === '#'\n ? '#/components/schemas'\n : schema.$ref.replace(/^#\\\\//, '#/components/schemas/');\n }\n\n if (Array.isArray(schema.allOf)) {\n const merged = mergePrimitiveSchemas(schema.allOf);\n if (merged) {\n const { allOf, ...rest } = schema;\n return { ...rest, ...merged };\n }\n if (schema.allOf.length === 1 && Object.keys(schema).length === 1) {\n return schema.allOf[0];\n }\n }\n\n return schema;\n }`,\n `function escapePointerSegment(segment) {\n return String(segment).replaceAll('~', '~0').replaceAll('/', '~1');\n }`,\n `function componentPointer(path) {\n return ['#', 'components', 'schemas', ...path.map(escapePointerSegment)].join('/');\n }`,\n // Nested toJsonSchema passes (set/map values, pipe outputs) return\n // self-contained draft-7 documents whose '#' and '#/definitions/*' refs\n // are relative to the embedded document root, not the outer schema.\n // Resolve them to outer-root structural pointers before the outer\n // definitions/normalize passes rewrite them into dangling refs.\n `function resolveEmbeddedDocs(root) {\n function process(node, path, docRoot) {\n if (!node || typeof node !== 'object') return;\n if (Array.isArray(node)) {\n node.forEach((item, index) => process(item, [...path, index], docRoot));\n return;\n }\n if (node['x-sdkit-embedded-root']) {\n delete node['x-sdkit-embedded-root'];\n const defs = node.definitions ?? Object.create(null);\n delete node.definitions;\n docRoot = { path, defs, firstSite: Object.create(null) };\n }\n if (docRoot && typeof node.$ref === 'string') {\n if (node.$ref === '#') {\n node.$ref = componentPointer(docRoot.path);\n return;\n }\n const match = node.$ref.match(/^#\\\\/definitions\\\\/(.+)$/);\n if (match) {\n const name = match[1];\n if (name in docRoot.firstSite) {\n node.$ref = docRoot.firstSite[name];\n return;\n }\n docRoot.firstSite[name] = componentPointer(path);\n delete node.$ref;\n Object.assign(node, docRoot.defs[name]);\n }\n }\n for (const [key, value] of Object.entries(node)) {\n process(value, [...path, key], docRoot);\n }\n }\n process(root, [], null);\n return root;\n }`,\n // zod v4 breaks non-root cycles with a draft-7 definitions block plus\n // #/definitions/* refs, which OpenAPI consumers cannot resolve. Inline\n // each definition at its first use site and point the remaining\n // (recursive) refs structurally at that site, mirroring the v3\n // $refStrategy: 'root' output.\n `function inlineDefinitions(root) {\n const defs = root.definitions;\n if (!defs || typeof defs !== 'object') return root;\n delete root.definitions;\n const firstSite = Object.create(null);\n function walk(node, path) {\n if (!node || typeof node !== 'object') return;\n if (Array.isArray(node)) {\n node.forEach((item, index) => walk(item, [...path, index]));\n return;\n }\n const match =\n typeof node.$ref === 'string' &&\n node.$ref.match(/^#\\\\/definitions\\\\/(.+)$/);\n if (match) {\n const name = match[1];\n if (name in firstSite) {\n node.$ref = firstSite[name];\n return;\n }\n firstSite[name] = componentPointer(path);\n delete node.$ref;\n Object.assign(node, defs[name]);\n }\n for (const [key, value] of Object.entries(node)) {\n walk(value, [...path, key]);\n }\n }\n walk(root, []);\n return root;\n }`,\n // Wraps nested conversions: when the embedded document carries refs or a\n // definitions block, tag its root so resolveEmbeddedDocs can rebase them.\n `function convertEmbedded(schema) {\n const { $schema: _ignored, ...doc } = toJsonSchema(schema);\n if (doc.definitions || JSON.stringify(doc).includes('\"$ref\"')) {\n doc['x-sdkit-embedded-root'] = true;\n }\n return doc;\n }`,\n `function toJsonSchema(schema) {\n return z.toJSONSchema(schema, {\n target: 'draft-7',\n io: 'input',\n unrepresentable: 'any',\n override(ctx) {\n const def = ctx.zodSchema._zod.def;\n const json = ctx.jsonSchema;\n if (def.type === 'optional') {\n optional = true;\n }\n if (def.type === 'catch') {\n delete json.default;\n }\n if (def.type === 'date') {\n json.type = 'string';\n json.format = 'date-time';\n json['x-zod-type'] = def.coerce ? 'coerce-date' : 'date';\n }\n if (def.type === 'bigint') {\n json.type = 'integer';\n // z.bigint() carries no format; treat it as int64.\n json.format = ctx.zodSchema._zod.bag.format ?? 'int64';\n if (def.coerce) {\n json['x-zod-type'] = 'coerce-bigint';\n }\n }\n if (def.type === 'set') {\n json.type = 'array';\n json.uniqueItems = true;\n json.items = convertEmbedded(def.valueType);\n }\n if (def.type === 'map') {\n json.type = 'array';\n json.items = {\n type: 'array',\n items: [convertEmbedded(def.keyType), convertEmbedded(def.valueType)],\n minItems: 2,\n maxItems: 2,\n };\n }\n if (def.type === 'string' && json.format === 'base64') {\n json.format = 'binary';\n delete json.pattern;\n delete json.contentEncoding;\n }\n if (\n def.type === 'string' &&\n json.format &&\n json.pattern &&\n !hasExplicitRegexCheck(def)\n ) {\n if (STANDARD_STRING_FORMATS.has(json.format)) {\n delete json.pattern;\n } else if (!MAPPED_NONSTANDARD_FORMATS.has(json.format)) {\n delete json.format;\n }\n }\n if (def.type === 'number') {\n const explicitBound = (kind, value) =>\n (def.checks ?? []).some(\n (check) =>\n check._zod?.def?.check === kind &&\n Number(check._zod.def.value) === value,\n );\n if (\n json.maximum === Number.MAX_SAFE_INTEGER &&\n !explicitBound('less_than', Number.MAX_SAFE_INTEGER)\n ) {\n delete json.maximum;\n }\n if (\n json.minimum === Number.MIN_SAFE_INTEGER &&\n !explicitBound('greater_than', Number.MIN_SAFE_INTEGER)\n ) {\n delete json.minimum;\n }\n }\n if (def.type === 'pipe') {\n const outJson = convertEmbedded(def.out);\n const outKeys = Object.keys(outJson).filter(\n (key) => key !== 'x-sdkit-embedded-root',\n );\n if (outKeys.length > 0) {\n const inJson = { ...json };\n for (const key of Object.keys(json)) delete json[key];\n json.allOf = [inJson, outJson];\n }\n }\n if (def.type === 'tuple' && Array.isArray(json.items)) {\n if (json.minItems === undefined) {\n json.minItems = json.items.length;\n }\n if (\n json.additionalItems === undefined &&\n json.maxItems === undefined\n ) {\n json.maxItems = json.items.length;\n }\n }\n },\n });\n }`,\n `let zodSchema;\n let rawResult;\n try {\n zodSchema = ${removeUnsupportedMethods(schema)};\n maskBigIntDefaults(zodSchema);\n const { $schema, ...converted } = toJsonSchema(zodSchema);\n rawResult = converted;\n } finally {\n // The v3 shims exist only while the analyzed source evaluates and\n // converts (lazy getters can call them mid-conversion); remove them so\n // the shared zod instance is not left with v3 API surface process-wide.\n for (const method of installedShims) delete stringProto[method];\n }\n unmaskBigIntDefaults(rawResult);\n const result = normalizeSchema(\n inlineDefinitions(resolveEmbeddedDocs(rawResult)),\n );`,\n `const innerDef = unwrapSchemaDef(zodSchema._zod.def);\n if (innerDef?.coerce && !result['x-zod-type']) {\n const zodType = 'coerce-' + innerDef.type;\n if (!applyZodType(result, zodType, innerDef.type)) {\n result['x-zod-type'] = zodType;\n }\n }`,\n `export default {schema: result, optional}`,\n ];\n\n const base64 = Buffer.from(lines.join('\\n')).toString('base64');\n return import(\n /* @vite-ignore */\n `data:text/javascript;base64,${base64}`\n ).then((mod) => mod.default);\n}\n"],
|
|
5
|
-
"mappings": "AAMA,SAAS,yBAA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A;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAqCA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAYA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAkBA;AAAA,IACA;AAAA;AAAA;AAAA,IAGA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IASA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["export type InjectImport = {\n import: string;\n from: string;\n property?: string;\n};\n\nfunction removeUnsupportedMethods(schema: string) {\n return schema\n .replaceAll('.instanceof(File)', '.string().base64()')\n .replaceAll('.instanceof(Blob)', '.string().base64()')\n .replaceAll('.custom<File>()', '.string().base64()')\n .replaceAll('.custom<Blob>()', '.string().base64()');\n}\n\nexport async function evalZod(schema: string, imports: InjectImport[] = []) {\n // https://github.com/nodejs/node/issues/51956\n const lines = [\n `import { createRequire } from \"node:module\";`,\n `const filename = \"${import.meta.url}\";`,\n `const require = createRequire(filename);`,\n `const z = require(\"zod\");`,\n // zod 4 removed ZodString.ip/.cidr; restore them for analyzed user source\n // that still uses the v3 spellings.\n `const stringProto = Object.getPrototypeOf(z.string());\n const installedShims = [];\n function withReceiverChecks(receiver, format) {\n return (receiver._zod.def.checks ?? []).length\n ? z.intersection(receiver, format)\n : format;\n }\n if (!stringProto.ip) {\n installedShims.push('ip');\n stringProto.ip = function (options) {\n if (options?.version === 'v4') return withReceiverChecks(this, z.ipv4());\n if (options?.version === 'v6') return withReceiverChecks(this, z.ipv6());\n return withReceiverChecks(this, z.union([z.ipv4(), z.ipv6()]));\n };\n }\n if (!stringProto.cidr) {\n installedShims.push('cidr');\n stringProto.cidr = function (options) {\n if (options?.version === 'v4') return withReceiverChecks(this, z.cidrv4());\n if (options?.version === 'v6') return withReceiverChecks(this, z.cidrv6());\n return withReceiverChecks(this, z.union([z.cidrv4(), z.cidrv6()]));\n };\n }`,\n ...imports.map(\n (imp) =>\n `const ${imp.import} = require(${JSON.stringify(imp.from)})${\n imp.property ? `[${JSON.stringify(imp.property)}]` : ''\n };`,\n ),\n `let optional = false;`,\n `const WRAPPER_TYPES = new Set([\n 'optional',\n 'nullable',\n 'default',\n 'prefault',\n 'catch',\n 'readonly',\n 'nonoptional',\n ]);`,\n `function unwrapSchemaDef(def) {\n while (def) {\n if (WRAPPER_TYPES.has(def.type)) {\n def = def.innerType?._zod?.def;\n continue;\n }\n if (def.type === 'pipe') {\n def = def.in?._zod?.def;\n continue;\n }\n return def;\n }\n return def;\n }`,\n `function matchesDefType(schema, defType) {\n if (!schema || typeof schema !== 'object') return false;\n if (defType === 'number') {\n return schema.type === 'number' || schema.type === 'integer';\n }\n if (defType === 'bigint') {\n return schema.type === 'integer';\n }\n if (defType === 'string') {\n return schema.type === 'string';\n }\n if (defType === 'boolean') {\n return schema.type === 'boolean';\n }\n if (defType === 'date') {\n return schema.type === 'string' && schema.format === 'date-time';\n }\n return typeof schema.type === 'string';\n }`,\n `function applyZodType(schema, zodType, defType) {\n if (!schema || typeof schema !== 'object') return false;\n if (schema['x-zod-type']) return true;\n if (matchesDefType(schema, defType)) {\n schema['x-zod-type'] = zodType;\n return true;\n }\n for (const key of ['anyOf', 'oneOf', 'allOf']) {\n if (!Array.isArray(schema[key])) continue;\n const candidates = schema[key].filter(\n (candidate) => candidate && candidate.type !== 'null',\n );\n if (candidates.length === 1 && applyZodType(candidates[0], zodType, defType)) {\n return true;\n }\n for (const candidate of candidates) {\n if (applyZodType(candidate, zodType, defType)) {\n return true;\n }\n }\n }\n return false;\n }`,\n `const BIGINT_SENTINEL = '__sdkit_bigint__';`,\n // zod v4 JSON-round-trips default values before the override callback\n // runs, which throws on bigint. Mask them as sentinel strings up front\n // and restore after conversion.\n `function maskBigIntDefaults(schema, seen = new Set()) {\n if (!schema || !schema._zod || seen.has(schema)) return;\n seen.add(schema);\n const def = schema._zod.def;\n if (\n (def.type === 'default' || def.type === 'prefault') &&\n typeof def.defaultValue === 'bigint'\n ) {\n Object.defineProperty(def, 'defaultValue', {\n value: BIGINT_SENTINEL + def.defaultValue.toString(),\n configurable: true,\n });\n }\n for (const key of ['innerType', 'in', 'out', 'element', 'valueType', 'keyType', 'left', 'right', 'catchall', 'rest']) {\n if (def[key]) maskBigIntDefaults(def[key], seen);\n }\n if (typeof def.getter === 'function') {\n const inner = def.getter();\n maskBigIntDefaults(inner, seen);\n Object.defineProperty(def, 'getter', {\n value: () => inner,\n configurable: true,\n });\n }\n if (def.shape) {\n for (const value of Object.values(def.shape)) maskBigIntDefaults(value, seen);\n }\n if (Array.isArray(def.options)) {\n for (const option of def.options) maskBigIntDefaults(option, seen);\n }\n if (Array.isArray(def.items)) {\n for (const item of def.items) maskBigIntDefaults(item, seen);\n }\n }`,\n // int64 is a plain number in sdk-it, so masked bigint defaults unmask to\n // JS numbers \u2014 the spec stays plain JSON with no bigint values to trip up\n // JSON.stringify.\n `function unmaskBigIntDefaults(schema) {\n if (!schema || typeof schema !== 'object') return;\n for (const [key, value] of Object.entries(schema)) {\n if (typeof value === 'string' && value.startsWith(BIGINT_SENTINEL)) {\n schema[key] = Number(value.slice(BIGINT_SENTINEL.length));\n } else if (Array.isArray(value)) {\n value.forEach(unmaskBigIntDefaults);\n } else if (value && typeof value === 'object') {\n unmaskBigIntDefaults(value);\n }\n }\n }`,\n `function hasExplicitRegexCheck(def) {\n return (def.checks ?? []).some(\n (check) => check._zod?.def?.format === 'regex',\n );\n }`,\n `const STANDARD_STRING_FORMATS = new Set([\n 'email',\n 'uri',\n 'url',\n 'uuid',\n 'guid',\n 'date-time',\n 'date',\n 'time',\n 'duration',\n 'ipv4',\n 'ipv6',\n 'hostname',\n 'binary',\n ]);`,\n // Nonstandard formats that sdk-it's own converters map to semantic zod\n // validators. Keep both keys: format for our converters, pattern for\n // third-party validators that do not recognize the format.\n `const MAPPED_NONSTANDARD_FORMATS = new Set(['cidrv4', 'cidrv6']);`,\n `function normalizeDefaultValue(value) {\n return value instanceof Date ? value.toISOString() : value;\n }`,\n `function mergeComparableValue(target, key, value) {\n if (value === undefined) return true;\n const normalized = normalizeDefaultValue(value);\n if (target[key] === undefined) {\n target[key] = normalized;\n return true;\n }\n return Object.is(target[key], normalized);\n }`,\n `function mergeLowerBound(target, key, value) {\n if (value === undefined) return true;\n if (typeof value !== 'number') return false;\n if (target[key] === undefined || value > target[key]) {\n target[key] = value;\n }\n return true;\n }`,\n `function mergeUpperBound(target, key, value) {\n if (value === undefined) return true;\n if (typeof value !== 'number') return false;\n if (target[key] === undefined || value < target[key]) {\n target[key] = value;\n }\n return true;\n }`,\n `function mergeEnumValues(target, values) {\n if (!Array.isArray(values)) return false;\n if (!Array.isArray(target.enum)) {\n target.enum = [...values];\n return true;\n }\n target.enum = target.enum.filter((candidate) =>\n values.some((value) => Object.is(candidate, value)),\n );\n return target.enum.length > 0;\n }`,\n `function isMergeablePrimitiveSchema(schema) {\n return (\n schema &&\n typeof schema === 'object' &&\n !schema.$ref &&\n !schema.anyOf &&\n !schema.oneOf &&\n !schema.allOf &&\n (schema.type === 'string' ||\n schema.type === 'boolean' ||\n schema.type === 'number' ||\n schema.type === 'integer')\n );\n }`,\n `function isNumericPair(left, right) {\n return (\n (left.type === 'number' && right.type === 'integer') ||\n (left.type === 'integer' && right.type === 'number')\n );\n }`,\n `function mergePrimitiveSchemas(schemas) {\n const merged = {};\n for (const schema of schemas) {\n if (\n schema &&\n typeof schema === 'object' &&\n Object.keys(schema).length === 0\n ) {\n continue;\n }\n if (!isMergeablePrimitiveSchema(schema)) {\n return null;\n }\n if (merged.type === undefined) {\n merged.type = schema.type;\n } else if (merged.type !== schema.type) {\n if (!isNumericPair(merged, schema)) {\n return null;\n }\n merged.type = 'integer';\n }\n\n for (const [key, value] of Object.entries(schema)) {\n if (key === 'type') {\n continue;\n }\n switch (key) {\n case 'minimum':\n case 'exclusiveMinimum':\n case 'minLength':\n case 'minItems':\n case 'minProperties':\n if (!mergeLowerBound(merged, key, value)) {\n return null;\n }\n break;\n case 'maximum':\n case 'exclusiveMaximum':\n case 'maxLength':\n case 'maxItems':\n case 'maxProperties':\n if (!mergeUpperBound(merged, key, value)) {\n return null;\n }\n break;\n case 'enum':\n if (!mergeEnumValues(merged, value)) {\n return null;\n }\n break;\n default:\n if (!mergeComparableValue(merged, key, value)) {\n return null;\n }\n }\n }\n }\n return merged;\n }`,\n `function normalizeSchema(schema, isIntersectionMember = false) {\n if (!schema || typeof schema !== 'object') {\n return schema;\n }\n\n if (schema.default !== undefined) {\n schema.default = normalizeDefaultValue(schema.default);\n }\n\n if (Array.isArray(schema.items)) {\n schema.items = schema.items.map((item) => normalizeSchema(item));\n } else if (schema.items && typeof schema.items === 'object') {\n schema.items = normalizeSchema(schema.items);\n }\n\n if (schema.properties && typeof schema.properties === 'object') {\n for (const [key, value] of Object.entries(schema.properties)) {\n schema.properties[key] = normalizeSchema(value);\n }\n }\n\n if (\n schema.additionalProperties &&\n typeof schema.additionalProperties === 'object'\n ) {\n schema.additionalProperties = normalizeSchema(schema.additionalProperties);\n }\n\n for (const key of ['anyOf', 'oneOf', 'allOf']) {\n if (!Array.isArray(schema[key])) continue;\n schema[key] = schema[key].map((candidate) =>\n normalizeSchema(candidate, key === 'allOf'),\n );\n }\n\n if (Array.isArray(schema.oneOf) && !schema.anyOf) {\n schema.anyOf = schema.oneOf;\n delete schema.oneOf;\n }\n\n if (\n Array.isArray(schema.anyOf) &&\n schema.anyOf.every(\n (member) =>\n member &&\n typeof member === 'object' &&\n Object.keys(member).length === 1 &&\n typeof member.type === 'string',\n )\n ) {\n const { anyOf, ...rest } = schema;\n schema = { ...rest, type: anyOf.map((member) => member.type) };\n }\n\n if (\n schema.type === 'object' &&\n schema.properties &&\n schema.additionalProperties === undefined &&\n !isIntersectionMember\n ) {\n schema.additionalProperties = false;\n }\n\n if (\n schema.type === 'object' &&\n schema.propertyNames &&\n JSON.stringify(schema.propertyNames) === '{\"type\":\"string\"}'\n ) {\n delete schema.propertyNames;\n }\n\n if (\n typeof schema.$ref === 'string' &&\n !schema.$ref.startsWith('#/components/schemas')\n ) {\n schema.$ref =\n schema.$ref === '#'\n ? '#/components/schemas'\n : schema.$ref.replace(/^#\\\\//, '#/components/schemas/');\n }\n\n if (Array.isArray(schema.allOf)) {\n const merged = mergePrimitiveSchemas(schema.allOf);\n if (merged) {\n const { allOf, ...rest } = schema;\n return { ...rest, ...merged };\n }\n if (schema.allOf.length === 1 && Object.keys(schema).length === 1) {\n return schema.allOf[0];\n }\n }\n\n return schema;\n }`,\n `function escapePointerSegment(segment) {\n return String(segment).replaceAll('~', '~0').replaceAll('/', '~1');\n }`,\n `function componentPointer(path) {\n return ['#', 'components', 'schemas', ...path.map(escapePointerSegment)].join('/');\n }`,\n // Nested toJsonSchema passes (set/map values, pipe outputs) return\n // self-contained draft-7 documents whose '#' and '#/definitions/*' refs\n // are relative to the embedded document root, not the outer schema.\n // Resolve them to outer-root structural pointers before the outer\n // definitions/normalize passes rewrite them into dangling refs.\n `function resolveEmbeddedDocs(root) {\n function process(node, path, docRoot) {\n if (!node || typeof node !== 'object') return;\n if (Array.isArray(node)) {\n node.forEach((item, index) => process(item, [...path, index], docRoot));\n return;\n }\n if (node['x-sdkit-embedded-root']) {\n delete node['x-sdkit-embedded-root'];\n const defs = node.definitions ?? Object.create(null);\n delete node.definitions;\n docRoot = { path, defs, firstSite: Object.create(null) };\n }\n if (docRoot && typeof node.$ref === 'string') {\n if (node.$ref === '#') {\n node.$ref = componentPointer(docRoot.path);\n return;\n }\n const match = node.$ref.match(/^#\\\\/definitions\\\\/(.+)$/);\n if (match) {\n const name = match[1];\n if (name in docRoot.firstSite) {\n node.$ref = docRoot.firstSite[name];\n return;\n }\n docRoot.firstSite[name] = componentPointer(path);\n delete node.$ref;\n Object.assign(node, docRoot.defs[name]);\n }\n }\n for (const [key, value] of Object.entries(node)) {\n process(value, [...path, key], docRoot);\n }\n }\n process(root, [], null);\n return root;\n }`,\n // zod v4 breaks non-root cycles with a draft-7 definitions block plus\n // #/definitions/* refs, which OpenAPI consumers cannot resolve. Inline\n // each definition at its first use site and point the remaining\n // (recursive) refs structurally at that site, mirroring the v3\n // $refStrategy: 'root' output.\n `function inlineDefinitions(root) {\n const defs = root.definitions;\n if (!defs || typeof defs !== 'object') return root;\n delete root.definitions;\n const firstSite = Object.create(null);\n function walk(node, path) {\n if (!node || typeof node !== 'object') return;\n if (Array.isArray(node)) {\n node.forEach((item, index) => walk(item, [...path, index]));\n return;\n }\n const match =\n typeof node.$ref === 'string' &&\n node.$ref.match(/^#\\\\/definitions\\\\/(.+)$/);\n if (match) {\n const name = match[1];\n if (name in firstSite) {\n node.$ref = firstSite[name];\n return;\n }\n firstSite[name] = componentPointer(path);\n delete node.$ref;\n Object.assign(node, defs[name]);\n }\n for (const [key, value] of Object.entries(node)) {\n walk(value, [...path, key]);\n }\n }\n walk(root, []);\n return root;\n }`,\n // Wraps nested conversions: when the embedded document carries refs or a\n // definitions block, tag its root so resolveEmbeddedDocs can rebase them.\n `function convertEmbedded(schema) {\n const { $schema: _ignored, ...doc } = toJsonSchema(schema);\n if (doc.definitions || JSON.stringify(doc).includes('\"$ref\"')) {\n doc['x-sdkit-embedded-root'] = true;\n }\n return doc;\n }`,\n `function toJsonSchema(schema) {\n return z.toJSONSchema(schema, {\n target: 'draft-7',\n io: 'input',\n unrepresentable: 'any',\n override(ctx) {\n const def = ctx.zodSchema._zod.def;\n const json = ctx.jsonSchema;\n if (def.type === 'catch') {\n delete json.default;\n }\n if (def.type === 'date') {\n json.type = 'string';\n json.format = 'date-time';\n json['x-zod-type'] = def.coerce ? 'coerce-date' : 'date';\n }\n if (def.type === 'bigint') {\n json.type = 'integer';\n // z.bigint() carries no format; treat it as int64.\n json.format = ctx.zodSchema._zod.bag.format ?? 'int64';\n if (def.coerce) {\n json['x-zod-type'] = 'coerce-bigint';\n }\n }\n if (def.type === 'set') {\n json.type = 'array';\n json.uniqueItems = true;\n json.items = convertEmbedded(def.valueType);\n }\n if (def.type === 'map') {\n json.type = 'array';\n json.items = {\n type: 'array',\n items: [convertEmbedded(def.keyType), convertEmbedded(def.valueType)],\n minItems: 2,\n maxItems: 2,\n };\n }\n if (def.type === 'string' && json.format === 'base64') {\n json.format = 'binary';\n delete json.pattern;\n delete json.contentEncoding;\n }\n if (\n def.type === 'string' &&\n json.format &&\n json.pattern &&\n !hasExplicitRegexCheck(def)\n ) {\n if (STANDARD_STRING_FORMATS.has(json.format)) {\n delete json.pattern;\n } else if (!MAPPED_NONSTANDARD_FORMATS.has(json.format)) {\n delete json.format;\n }\n }\n if (def.type === 'number') {\n const explicitBound = (kind, value) =>\n (def.checks ?? []).some(\n (check) =>\n check._zod?.def?.check === kind &&\n Number(check._zod.def.value) === value,\n );\n if (\n json.maximum === Number.MAX_SAFE_INTEGER &&\n !explicitBound('less_than', Number.MAX_SAFE_INTEGER)\n ) {\n delete json.maximum;\n }\n if (\n json.minimum === Number.MIN_SAFE_INTEGER &&\n !explicitBound('greater_than', Number.MIN_SAFE_INTEGER)\n ) {\n delete json.minimum;\n }\n }\n if (def.type === 'pipe') {\n const outJson = convertEmbedded(def.out);\n const outKeys = Object.keys(outJson).filter(\n (key) => key !== 'x-sdkit-embedded-root',\n );\n if (outKeys.length > 0) {\n const inJson = { ...json };\n const compatible =\n inJson.type === undefined ||\n outJson.type === undefined ||\n inJson.type === outJson.type ||\n isNumericPair(inJson, outJson);\n if (compatible) {\n for (const key of Object.keys(json)) delete json[key];\n json.allOf = [inJson, outJson];\n }\n }\n }\n if (def.type === 'tuple' && Array.isArray(json.items)) {\n if (json.minItems === undefined) {\n json.minItems = json.items.length;\n }\n if (\n json.additionalItems === undefined &&\n json.maxItems === undefined\n ) {\n json.maxItems = json.items.length;\n }\n }\n },\n });\n }`,\n `let zodSchema;\n let rawResult;\n try {\n zodSchema = ${removeUnsupportedMethods(schema)};\n maskBigIntDefaults(zodSchema);\n // zod's own input-side flag: 'optional' for optional/nullish/catch,\n // 'defaulted' for default/prefault, undefined once .nonoptional() applies.\n optional = ['optional', 'defaulted'].includes(zodSchema._zod.optin);\n const { $schema, ...converted } = toJsonSchema(zodSchema);\n rawResult = converted;\n } finally {\n // The v3 shims exist only while the analyzed source evaluates and\n // converts (lazy getters can call them mid-conversion); remove them so\n // the shared zod instance is not left with v3 API surface process-wide.\n for (const method of installedShims) delete stringProto[method];\n }\n unmaskBigIntDefaults(rawResult);\n const result = normalizeSchema(\n inlineDefinitions(resolveEmbeddedDocs(rawResult)),\n );`,\n `const innerDef = unwrapSchemaDef(zodSchema._zod.def);\n if (innerDef?.coerce && !result['x-zod-type']) {\n const zodType = 'coerce-' + innerDef.type;\n if (!applyZodType(result, zodType, innerDef.type)) {\n result['x-zod-type'] = zodType;\n }\n }`,\n `export default {schema: result, optional}`,\n ];\n\n const base64 = Buffer.from(lines.join('\\n')).toString('base64');\n return import(\n /* @vite-ignore */\n `data:text/javascript;base64,${base64}`\n ).then((mod) => mod.default);\n}\n"],
|
|
5
|
+
"mappings": "AAMA,SAAS,yBAAyB,QAAgB;AAChD,SAAO,OACJ,WAAW,qBAAqB,oBAAoB,EACpD,WAAW,qBAAqB,oBAAoB,EACpD,WAAW,mBAAmB,oBAAoB,EAClD,WAAW,mBAAmB,oBAAoB;AACvD;AAEA,eAAsB,QAAQ,QAAgB,UAA0B,CAAC,GAAG;AAE1E,QAAM,QAAQ;AAAA,IACZ;AAAA,IACA,qBAAqB,YAAY,GAAG;AAAA,IACpC;AAAA,IACA;AAAA;AAAA;AAAA,IAGA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAuBA,GAAG,QAAQ;AAAA,MACT,CAAC,QACC,SAAS,IAAI,MAAM,cAAc,KAAK,UAAU,IAAI,IAAI,CAAC,IACvD,IAAI,WAAW,IAAI,KAAK,UAAU,IAAI,QAAQ,CAAC,MAAM,EACvD;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IASA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAmBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAuBA;AAAA;AAAA;AAAA;AAAA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35,14 @@
|
|
|
35
35
|
"typescript": "^6.0.3",
|
|
36
36
|
"openapi3-ts": "^4.4.0"
|
|
37
37
|
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"openapi3-ts": {
|
|
40
|
+
"optional": true
|
|
41
|
+
},
|
|
42
|
+
"typescript": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
45
|
+
},
|
|
38
46
|
"devDependencies": {
|
|
39
47
|
"@types/debug": "^4.1.12"
|
|
40
48
|
}
|