@depup/openapi-typescript 7.13.0-depup.0
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/CHANGELOG.md +1162 -0
- package/CONTRIBUTING.md +149 -0
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/bin/cli.js +297 -0
- package/changes.json +14 -0
- package/dist/index.cjs +152 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +517 -0
- package/dist/index.d.mts +515 -0
- package/dist/index.d.ts +517 -0
- package/dist/index.mjs +85 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/redoc.cjs +129 -0
- package/dist/lib/redoc.cjs.map +1 -0
- package/dist/lib/redoc.mjs +122 -0
- package/dist/lib/redoc.mjs.map +1 -0
- package/dist/lib/ts.cjs +470 -0
- package/dist/lib/ts.cjs.map +1 -0
- package/dist/lib/ts.mjs +431 -0
- package/dist/lib/ts.mjs.map +1 -0
- package/dist/lib/utils.cjs +295 -0
- package/dist/lib/utils.cjs.map +1 -0
- package/dist/lib/utils.mjs +278 -0
- package/dist/lib/utils.mjs.map +1 -0
- package/dist/transform/components-object.cjs +150 -0
- package/dist/transform/components-object.cjs.map +1 -0
- package/dist/transform/components-object.mjs +127 -0
- package/dist/transform/components-object.mjs.map +1 -0
- package/dist/transform/header-object.cjs +48 -0
- package/dist/transform/header-object.cjs.map +1 -0
- package/dist/transform/header-object.mjs +42 -0
- package/dist/transform/header-object.mjs.map +1 -0
- package/dist/transform/index.cjs +124 -0
- package/dist/transform/index.cjs.map +1 -0
- package/dist/transform/index.mjs +118 -0
- package/dist/transform/index.mjs.map +1 -0
- package/dist/transform/media-type-object.cjs +14 -0
- package/dist/transform/media-type-object.cjs.map +1 -0
- package/dist/transform/media-type-object.mjs +12 -0
- package/dist/transform/media-type-object.mjs.map +1 -0
- package/dist/transform/operation-object.cjs +105 -0
- package/dist/transform/operation-object.cjs.map +1 -0
- package/dist/transform/operation-object.mjs +96 -0
- package/dist/transform/operation-object.mjs.map +1 -0
- package/dist/transform/parameter-object.cjs +11 -0
- package/dist/transform/parameter-object.cjs.map +1 -0
- package/dist/transform/parameter-object.mjs +9 -0
- package/dist/transform/parameter-object.mjs.map +1 -0
- package/dist/transform/parameters-array.cjs +120 -0
- package/dist/transform/parameters-array.cjs.map +1 -0
- package/dist/transform/parameters-array.mjs +114 -0
- package/dist/transform/parameters-array.mjs.map +1 -0
- package/dist/transform/path-item-object.cjs +84 -0
- package/dist/transform/path-item-object.cjs.map +1 -0
- package/dist/transform/path-item-object.mjs +78 -0
- package/dist/transform/path-item-object.mjs.map +1 -0
- package/dist/transform/paths-enum.cjs +35 -0
- package/dist/transform/paths-enum.cjs.map +1 -0
- package/dist/transform/paths-enum.mjs +33 -0
- package/dist/transform/paths-enum.mjs.map +1 -0
- package/dist/transform/paths-object.cjs +134 -0
- package/dist/transform/paths-object.cjs.map +1 -0
- package/dist/transform/paths-object.mjs +128 -0
- package/dist/transform/paths-object.mjs.map +1 -0
- package/dist/transform/request-body-object.cjs +68 -0
- package/dist/transform/request-body-object.cjs.map +1 -0
- package/dist/transform/request-body-object.mjs +62 -0
- package/dist/transform/request-body-object.mjs.map +1 -0
- package/dist/transform/response-object.cjs +123 -0
- package/dist/transform/response-object.cjs.map +1 -0
- package/dist/transform/response-object.mjs +117 -0
- package/dist/transform/response-object.mjs.map +1 -0
- package/dist/transform/responses-object.cjs +36 -0
- package/dist/transform/responses-object.cjs.map +1 -0
- package/dist/transform/responses-object.mjs +30 -0
- package/dist/transform/responses-object.mjs.map +1 -0
- package/dist/transform/schema-object.cjs +502 -0
- package/dist/transform/schema-object.cjs.map +1 -0
- package/dist/transform/schema-object.mjs +493 -0
- package/dist/transform/schema-object.mjs.map +1 -0
- package/dist/transform/webhooks-object.cjs +37 -0
- package/dist/transform/webhooks-object.cjs.map +1 -0
- package/dist/transform/webhooks-object.mjs +31 -0
- package/dist/transform/webhooks-object.mjs.map +1 -0
- package/package.json +102 -0
- package/src/index.ts +108 -0
- package/src/lib/redoc.ts +164 -0
- package/src/lib/ts.ts +616 -0
- package/src/lib/utils.ts +394 -0
- package/src/transform/components-object.ts +161 -0
- package/src/transform/header-object.ts +45 -0
- package/src/transform/index.ts +116 -0
- package/src/transform/media-type-object.ts +18 -0
- package/src/transform/operation-object.ts +104 -0
- package/src/transform/parameter-object.ts +15 -0
- package/src/transform/parameters-array.ts +129 -0
- package/src/transform/path-item-object.ts +102 -0
- package/src/transform/paths-enum.ts +43 -0
- package/src/transform/paths-object.ts +134 -0
- package/src/transform/request-body-object.ts +59 -0
- package/src/transform/response-object.ts +112 -0
- package/src/transform/responses-object.ts +36 -0
- package/src/transform/schema-object.ts +737 -0
- package/src/transform/webhooks-object.ts +27 -0
- package/src/types.ts +735 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const refUtils_js = require('@redocly/openapi-core/lib/ref-utils.js');
|
|
4
|
+
const c = require('ansi-colors');
|
|
5
|
+
const supportsColor = require('supports-color');
|
|
6
|
+
const ts = require('typescript');
|
|
7
|
+
const ts$1 = require('./ts.cjs');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
10
|
+
|
|
11
|
+
const c__default = /*#__PURE__*/_interopDefaultCompat(c);
|
|
12
|
+
const supportsColor__default = /*#__PURE__*/_interopDefaultCompat(supportsColor);
|
|
13
|
+
const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
|
|
14
|
+
|
|
15
|
+
if (!supportsColor__default.stdout || supportsColor__default.stdout.hasBasic === false) {
|
|
16
|
+
c__default.enabled = false;
|
|
17
|
+
}
|
|
18
|
+
const DEBUG_GROUPS = {
|
|
19
|
+
redoc: c__default.cyanBright,
|
|
20
|
+
lint: c__default.yellowBright,
|
|
21
|
+
bundle: c__default.magentaBright,
|
|
22
|
+
ts: c__default.blueBright
|
|
23
|
+
};
|
|
24
|
+
function createDiscriminatorProperty(discriminator, { path, readonly = false }) {
|
|
25
|
+
let value = refUtils_js.parseRef(path).pointer.pop();
|
|
26
|
+
if (discriminator.mapping) {
|
|
27
|
+
const matchedValue = Object.entries(discriminator.mapping).find(
|
|
28
|
+
([, v]) => !v.startsWith("#") && v === value || v.startsWith("#") && refUtils_js.parseRef(v).pointer.pop() === value
|
|
29
|
+
);
|
|
30
|
+
if (matchedValue) {
|
|
31
|
+
value = matchedValue[0];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return ts__default.factory.createPropertySignature(
|
|
35
|
+
/* modifiers */
|
|
36
|
+
ts$1.tsModifiers({
|
|
37
|
+
readonly
|
|
38
|
+
}),
|
|
39
|
+
/* name */
|
|
40
|
+
ts$1.tsPropertyIndex(discriminator.propertyName),
|
|
41
|
+
/* questionToken */
|
|
42
|
+
void 0,
|
|
43
|
+
/* type */
|
|
44
|
+
ts$1.tsLiteral(value)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
function createRef(parts) {
|
|
48
|
+
let pointer = "#";
|
|
49
|
+
for (const part of parts) {
|
|
50
|
+
if (part === void 0 || part === null || part === "") {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const maybeRef = refUtils_js.parseRef(String(part)).pointer;
|
|
54
|
+
if (maybeRef.length) {
|
|
55
|
+
for (const refPart of maybeRef) {
|
|
56
|
+
pointer += `/${refUtils_js.escapePointer(refPart)}`;
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
pointer += `/${refUtils_js.escapePointer(part)}`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return pointer;
|
|
63
|
+
}
|
|
64
|
+
function debug(msg, group, time) {
|
|
65
|
+
if (process.env.DEBUG && (!group || process.env.DEBUG === "*" || process.env.DEBUG === "openapi-ts:*" || process.env.DEBUG.toLocaleLowerCase() === `openapi-ts:${group.toLocaleLowerCase()}`)) {
|
|
66
|
+
const groupColor = group && DEBUG_GROUPS[group] || c__default.whiteBright;
|
|
67
|
+
const groupName = groupColor(`openapi-ts:${group ?? "info"}`);
|
|
68
|
+
let timeFormatted = "";
|
|
69
|
+
if (typeof time === "number") {
|
|
70
|
+
timeFormatted = c__default.green(` ${formatTime(time)} `);
|
|
71
|
+
}
|
|
72
|
+
console.debug(` ${c__default.bold(groupName)}${timeFormatted}${msg}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function error(msg) {
|
|
76
|
+
console.error(c__default.red(` \u2718 ${msg}`));
|
|
77
|
+
}
|
|
78
|
+
function formatTime(t) {
|
|
79
|
+
if (typeof t === "number") {
|
|
80
|
+
if (t < 1e3) {
|
|
81
|
+
return `${Math.round(10 * t) / 10}ms`;
|
|
82
|
+
}
|
|
83
|
+
if (t < 6e4) {
|
|
84
|
+
return `${Math.round(t / 100) / 10}s`;
|
|
85
|
+
}
|
|
86
|
+
return `${Math.round(t / 6e3) / 10}m`;
|
|
87
|
+
}
|
|
88
|
+
return t;
|
|
89
|
+
}
|
|
90
|
+
function getEntries(obj, options) {
|
|
91
|
+
let entries = Object.entries(obj);
|
|
92
|
+
if (options?.alphabetize) {
|
|
93
|
+
entries.sort(([a], [b]) => a.localeCompare(b, "en-us", { numeric: true }));
|
|
94
|
+
}
|
|
95
|
+
if (options?.excludeDeprecated) {
|
|
96
|
+
entries = entries.filter(([, v]) => !(v && typeof v === "object" && "deprecated" in v && v.deprecated));
|
|
97
|
+
}
|
|
98
|
+
return entries;
|
|
99
|
+
}
|
|
100
|
+
function resolveRef(schema, $ref, { silent = false, visited = [] }) {
|
|
101
|
+
const { pointer } = refUtils_js.parseRef($ref);
|
|
102
|
+
if (!pointer.length) {
|
|
103
|
+
return void 0;
|
|
104
|
+
}
|
|
105
|
+
let node = schema;
|
|
106
|
+
for (const key of pointer) {
|
|
107
|
+
if (node && typeof node === "object" && node[key]) {
|
|
108
|
+
node = node[key];
|
|
109
|
+
} else {
|
|
110
|
+
warn(`Could not resolve $ref "${$ref}"`, silent);
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (node && typeof node === "object" && node.$ref) {
|
|
115
|
+
if (visited.includes(node.$ref)) {
|
|
116
|
+
warn(`Could not resolve circular $ref "${$ref}"`, silent);
|
|
117
|
+
return void 0;
|
|
118
|
+
}
|
|
119
|
+
return resolveRef(schema, node.$ref, {
|
|
120
|
+
silent,
|
|
121
|
+
visited: [...visited, node.$ref]
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return node;
|
|
125
|
+
}
|
|
126
|
+
function createDiscriminatorEnum(values, prevSchema) {
|
|
127
|
+
return {
|
|
128
|
+
type: "string",
|
|
129
|
+
enum: values,
|
|
130
|
+
description: prevSchema?.description ? `${prevSchema.description} (enum property replaced by openapi-typescript)` : "discriminator enum property added by openapi-typescript"
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function patchDiscriminatorEnum(schema, ref, values, discriminator, discriminatorRef, options) {
|
|
134
|
+
const resolvedSchema = resolveRef(schema, ref, {
|
|
135
|
+
silent: options.silent ?? false
|
|
136
|
+
});
|
|
137
|
+
if (resolvedSchema?.allOf) {
|
|
138
|
+
resolvedSchema.allOf.push({
|
|
139
|
+
type: "object",
|
|
140
|
+
// discriminator enum properties always need to be required
|
|
141
|
+
required: [discriminator.propertyName],
|
|
142
|
+
properties: {
|
|
143
|
+
[discriminator.propertyName]: createDiscriminatorEnum(values)
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return true;
|
|
147
|
+
} else if (typeof resolvedSchema === "object" && "type" in resolvedSchema && resolvedSchema.type === "object") {
|
|
148
|
+
if (!resolvedSchema.properties) {
|
|
149
|
+
resolvedSchema.properties = {};
|
|
150
|
+
}
|
|
151
|
+
if (!resolvedSchema.required) {
|
|
152
|
+
resolvedSchema.required = [discriminator.propertyName];
|
|
153
|
+
} else if (!resolvedSchema.required.includes(discriminator.propertyName)) {
|
|
154
|
+
resolvedSchema.required.push(discriminator.propertyName);
|
|
155
|
+
}
|
|
156
|
+
resolvedSchema.properties[discriminator.propertyName] = createDiscriminatorEnum(
|
|
157
|
+
values,
|
|
158
|
+
resolvedSchema.properties[discriminator.propertyName]
|
|
159
|
+
);
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
warn(
|
|
163
|
+
`Discriminator mapping has an invalid schema (neither an object schema nor an allOf array): ${ref} => ${values.join(
|
|
164
|
+
", "
|
|
165
|
+
)} (Discriminator: ${discriminatorRef})`,
|
|
166
|
+
options.silent
|
|
167
|
+
);
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
function scanDiscriminators(schema, options) {
|
|
171
|
+
const objects = {};
|
|
172
|
+
const refsHandled = [];
|
|
173
|
+
walk(schema, (obj, path) => {
|
|
174
|
+
const discriminator = obj?.discriminator;
|
|
175
|
+
if (!discriminator?.propertyName) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const ref = createRef(path);
|
|
179
|
+
objects[ref] = discriminator;
|
|
180
|
+
if (!obj?.oneOf || !Array.isArray(obj.oneOf)) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const oneOf = obj.oneOf;
|
|
184
|
+
const mapping = {};
|
|
185
|
+
for (const item of oneOf) {
|
|
186
|
+
if ("$ref" in item) {
|
|
187
|
+
const value = item.$ref.split("/").pop();
|
|
188
|
+
if (value) {
|
|
189
|
+
if (!mapping[item.$ref]) {
|
|
190
|
+
mapping[item.$ref] = { inferred: value };
|
|
191
|
+
} else {
|
|
192
|
+
mapping[item.$ref].inferred = value;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (discriminator.mapping) {
|
|
198
|
+
for (const mappedValue in discriminator.mapping) {
|
|
199
|
+
const mappedRef = discriminator.mapping[mappedValue];
|
|
200
|
+
if (!mappedRef) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (!mapping[mappedRef]?.defined) {
|
|
204
|
+
mapping[mappedRef] = { defined: [] };
|
|
205
|
+
}
|
|
206
|
+
mapping[mappedRef].defined?.push(mappedValue);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
for (const [mappedRef, { inferred, defined }] of Object.entries(mapping)) {
|
|
210
|
+
if (refsHandled.includes(mappedRef)) {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (!inferred && !defined) {
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
const mappedValues = defined ?? [inferred];
|
|
217
|
+
if (patchDiscriminatorEnum(schema, mappedRef, mappedValues, discriminator, ref, options)) {
|
|
218
|
+
refsHandled.push(mappedRef);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
walk(schema, (obj, path) => {
|
|
223
|
+
if (!obj || !Array.isArray(obj.allOf)) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
for (const item of obj.allOf) {
|
|
227
|
+
if ("$ref" in item) {
|
|
228
|
+
if (!objects[item.$ref]) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const ref = createRef(path);
|
|
232
|
+
const discriminator = objects[item.$ref];
|
|
233
|
+
const mappedValues = [];
|
|
234
|
+
if (discriminator.mapping) {
|
|
235
|
+
for (const mappedValue in discriminator.mapping) {
|
|
236
|
+
if (discriminator.mapping[mappedValue] === ref) {
|
|
237
|
+
mappedValues.push(mappedValue);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (mappedValues.length > 0) {
|
|
241
|
+
if (patchDiscriminatorEnum(
|
|
242
|
+
schema,
|
|
243
|
+
ref,
|
|
244
|
+
mappedValues,
|
|
245
|
+
discriminator,
|
|
246
|
+
item.$ref,
|
|
247
|
+
options
|
|
248
|
+
)) {
|
|
249
|
+
refsHandled.push(ref);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
objects[ref] = {
|
|
254
|
+
...objects[item.$ref]
|
|
255
|
+
};
|
|
256
|
+
} else if (item.discriminator?.propertyName) {
|
|
257
|
+
objects[createRef(path)] = { ...item.discriminator };
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
return { objects, refsHandled };
|
|
262
|
+
}
|
|
263
|
+
function walk(obj, cb, path = []) {
|
|
264
|
+
if (!obj || typeof obj !== "object") {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (Array.isArray(obj)) {
|
|
268
|
+
for (let i = 0; i < obj.length; i++) {
|
|
269
|
+
walk(obj[i], cb, path.concat(i));
|
|
270
|
+
}
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
cb(obj, path);
|
|
274
|
+
for (const k of Object.keys(obj)) {
|
|
275
|
+
walk(obj[k], cb, path.concat(k));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function warn(msg, silent = false) {
|
|
279
|
+
if (!silent) {
|
|
280
|
+
console.warn(c__default.yellow(` \u26A0 ${msg}`));
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
exports.c = c__default;
|
|
285
|
+
exports.createDiscriminatorProperty = createDiscriminatorProperty;
|
|
286
|
+
exports.createRef = createRef;
|
|
287
|
+
exports.debug = debug;
|
|
288
|
+
exports.error = error;
|
|
289
|
+
exports.formatTime = formatTime;
|
|
290
|
+
exports.getEntries = getEntries;
|
|
291
|
+
exports.resolveRef = resolveRef;
|
|
292
|
+
exports.scanDiscriminators = scanDiscriminators;
|
|
293
|
+
exports.walk = walk;
|
|
294
|
+
exports.warn = warn;
|
|
295
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sources":["../../src/lib/utils.ts"],"sourcesContent":["import { escapePointer, parseRef } from \"@redocly/openapi-core/lib/ref-utils.js\";\nimport c from \"ansi-colors\";\nimport supportsColor from \"supports-color\";\nimport ts from \"typescript\";\nimport type { DiscriminatorObject, OpenAPI3, OpenAPITSOptions, ReferenceObject, SchemaObject } from \"../types.js\";\nimport { tsLiteral, tsModifiers, tsPropertyIndex } from \"./ts.js\";\n\nif (!supportsColor.stdout || supportsColor.stdout.hasBasic === false) {\n c.enabled = false;\n}\n\nconst DEBUG_GROUPS: Record<string, c.StyleFunction | undefined> = {\n redoc: c.cyanBright,\n lint: c.yellowBright,\n bundle: c.magentaBright,\n ts: c.blueBright,\n};\n\nexport { c };\n\n/** Given a discriminator object, get the property name */\nexport function createDiscriminatorProperty(\n discriminator: DiscriminatorObject,\n { path, readonly = false }: { path: string; readonly?: boolean },\n): ts.TypeElement {\n // get the inferred propertyName value from the last section of the path (as the spec suggests to do)\n let value = parseRef(path).pointer.pop();\n // if mapping, and there’s a match, use this rather than the inferred name\n if (discriminator.mapping) {\n // Mapping value can either be a fully-qualified ref (#/components/schemas/XYZ) or a schema name (XYZ)\n const matchedValue = Object.entries(discriminator.mapping).find(\n ([, v]) => (!v.startsWith(\"#\") && v === value) || (v.startsWith(\"#\") && parseRef(v).pointer.pop() === value),\n );\n if (matchedValue) {\n value = matchedValue[0]; // why was this designed backwards!?\n }\n }\n return ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({\n readonly,\n }),\n /* name */ tsPropertyIndex(discriminator.propertyName),\n /* questionToken */ undefined,\n /* type */ tsLiteral(value),\n );\n}\n\n/** Create a $ref pointer (even from other $refs) */\nexport function createRef(parts: (number | string | undefined | null)[]): string {\n let pointer = \"#\";\n for (const part of parts) {\n if (part === undefined || part === null || part === \"\") {\n continue;\n }\n const maybeRef = parseRef(String(part)).pointer;\n if (maybeRef.length) {\n for (const refPart of maybeRef) {\n pointer += `/${escapePointer(refPart)}`;\n }\n } else {\n pointer += `/${escapePointer(part)}`;\n }\n }\n return pointer;\n}\n\n/** Print debug message (cribbed from the `debug` package, but without all the bells & whistles */\nexport function debug(msg: string, group?: string, time?: number) {\n if (\n process.env.DEBUG &&\n (!group ||\n process.env.DEBUG === \"*\" ||\n process.env.DEBUG === \"openapi-ts:*\" ||\n process.env.DEBUG.toLocaleLowerCase() === `openapi-ts:${group.toLocaleLowerCase()}`)\n ) {\n const groupColor = (group && DEBUG_GROUPS[group]) || c.whiteBright;\n const groupName = groupColor(`openapi-ts:${group ?? \"info\"}`);\n let timeFormatted = \"\";\n if (typeof time === \"number\") {\n timeFormatted = c.green(` ${formatTime(time)} `);\n }\n // biome-ignore lint/suspicious/noConsole: this is a CLI\n console.debug(` ${c.bold(groupName)}${timeFormatted}${msg}`);\n }\n}\n\n/** Print error message */\nexport function error(msg: string) {\n // biome-ignore lint/suspicious/noConsole: this is a CLI\n console.error(c.red(` ✘ ${msg}`));\n}\n\n/** Format a performance log in a friendly format */\nexport function formatTime(t: number) {\n if (typeof t === \"number\") {\n if (t < 1000) {\n return `${Math.round(10 * t) / 10}ms`;\n }\n if (t < 60000) {\n return `${Math.round(t / 100) / 10}s`;\n }\n return `${Math.round(t / 6000) / 10}m`;\n }\n return t;\n}\n\n/** Call Object.entries() and optionally sort */\nexport function getEntries<T>(\n obj: ArrayLike<T> | Record<string, T>,\n options?: {\n alphabetize?: boolean;\n excludeDeprecated?: boolean;\n },\n) {\n let entries = Object.entries(obj);\n if (options?.alphabetize) {\n entries.sort(([a], [b]) => a.localeCompare(b, \"en-us\", { numeric: true }));\n }\n if (options?.excludeDeprecated) {\n entries = entries.filter(([, v]) => !(v && typeof v === \"object\" && \"deprecated\" in v && v.deprecated));\n }\n return entries;\n}\n\n/** resolve a $ref in a schema */\nexport function resolveRef<T>(\n schema: any,\n $ref: string,\n { silent = false, visited = [] }: { silent: boolean; visited?: string[] },\n): T | undefined {\n const { pointer } = parseRef($ref);\n if (!pointer.length) {\n return undefined;\n }\n let node = schema;\n for (const key of pointer) {\n if (node && typeof node === \"object\" && node[key]) {\n node = node[key];\n } else {\n warn(`Could not resolve $ref \"${$ref}\"`, silent);\n return undefined;\n }\n }\n\n // if this is also a $ref, keep tracing\n if (node && typeof node === \"object\" && node.$ref) {\n if (visited.includes(node.$ref)) {\n warn(`Could not resolve circular $ref \"${$ref}\"`, silent);\n return undefined;\n }\n return resolveRef(schema, node.$ref, {\n silent,\n visited: [...visited, node.$ref],\n });\n }\n\n return node;\n}\n\nfunction createDiscriminatorEnum(values: string[], prevSchema?: SchemaObject): SchemaObject {\n return {\n type: \"string\",\n enum: values,\n description: prevSchema?.description\n ? `${prevSchema.description} (enum property replaced by openapi-typescript)`\n : \"discriminator enum property added by openapi-typescript\",\n };\n}\n\n/** Adds or replaces the discriminator enum with the passed `values` in a schema defined by `ref` */\nfunction patchDiscriminatorEnum(\n schema: SchemaObject,\n ref: string,\n values: string[],\n discriminator: DiscriminatorObject,\n discriminatorRef: string,\n options: OpenAPITSOptions,\n): boolean {\n const resolvedSchema = resolveRef<SchemaObject>(schema, ref, {\n silent: options.silent ?? false,\n });\n\n if (resolvedSchema?.allOf) {\n // if the schema is an allOf, we can append a new schema object to the allOf array\n resolvedSchema.allOf.push({\n type: \"object\",\n // discriminator enum properties always need to be required\n required: [discriminator.propertyName],\n properties: {\n [discriminator.propertyName]: createDiscriminatorEnum(values),\n },\n });\n\n return true;\n } else if (typeof resolvedSchema === \"object\" && \"type\" in resolvedSchema && resolvedSchema.type === \"object\") {\n // if the schema is an object, we can apply the discriminator enums to its properties\n if (!resolvedSchema.properties) {\n resolvedSchema.properties = {};\n }\n\n // discriminator enum properties always need to be required\n if (!resolvedSchema.required) {\n resolvedSchema.required = [discriminator.propertyName];\n } else if (!resolvedSchema.required.includes(discriminator.propertyName)) {\n resolvedSchema.required.push(discriminator.propertyName);\n }\n\n // add/replace the discriminator enum property\n resolvedSchema.properties[discriminator.propertyName] = createDiscriminatorEnum(\n values,\n resolvedSchema.properties[discriminator.propertyName] as SchemaObject,\n );\n\n return true;\n }\n\n warn(\n `Discriminator mapping has an invalid schema (neither an object schema nor an allOf array): ${ref} => ${values.join(\n \", \",\n )} (Discriminator: ${discriminatorRef})`,\n options.silent,\n );\n\n return false;\n}\n\ntype InternalDiscriminatorMapping = Record<string, { inferred?: string; defined?: string[] }>;\n\n/** Return a key–value map of discriminator objects found in a schema */\nexport function scanDiscriminators(schema: OpenAPI3, options: OpenAPITSOptions) {\n // all discriminator objects found in the schema\n const objects: Record<string, DiscriminatorObject> = {};\n\n // refs of all mapped schema objects we have successfully handled to infer the discriminator enum value\n const refsHandled: string[] = [];\n\n // perform 2 passes: first, collect all discriminator definitions and handle oneOf and mappings\n walk(schema, (obj, path) => {\n const discriminator = obj?.discriminator as DiscriminatorObject | undefined;\n if (!discriminator?.propertyName) {\n return;\n }\n\n // collect discriminator object for later usage\n const ref = createRef(path);\n\n objects[ref] = discriminator;\n\n // if a mapping is available we will help Typescript to infer properties by adding the discriminator enum with its single mapped value to each schema\n // we only handle the mapping in advance for discriminator + oneOf compositions right now\n if (!obj?.oneOf || !Array.isArray(obj.oneOf)) {\n return;\n }\n\n const oneOf: (SchemaObject | ReferenceObject)[] = obj.oneOf;\n const mapping: InternalDiscriminatorMapping = {};\n\n // the mapping can be inferred from the oneOf refs next to the discriminator object\n for (const item of oneOf) {\n if (\"$ref\" in item) {\n // the name of the schema is the inferred discriminator enum value\n const value = item.$ref.split(\"/\").pop();\n\n if (value) {\n if (!mapping[item.$ref]) {\n mapping[item.$ref] = { inferred: value };\n } else {\n mapping[item.$ref].inferred = value;\n }\n }\n }\n }\n\n // the mapping can be defined in the discriminator object itself\n if (discriminator.mapping) {\n for (const mappedValue in discriminator.mapping) {\n const mappedRef = discriminator.mapping[mappedValue];\n if (!mappedRef) {\n continue;\n }\n\n if (!mapping[mappedRef]?.defined) {\n // this overrides inferred values, but we don't need them anymore as soon as we have a defined value\n mapping[mappedRef] = { defined: [] };\n }\n\n mapping[mappedRef].defined?.push(mappedValue);\n }\n }\n\n for (const [mappedRef, { inferred, defined }] of Object.entries(mapping)) {\n if (refsHandled.includes(mappedRef)) {\n continue;\n }\n\n if (!inferred && !defined) {\n continue;\n }\n\n // prefer defined values over automatically inferred ones\n // the inferred enum values from the schema might not represent the actual enum values of the discriminator,\n // so if we have defined values, use them instead\n // biome-ignore lint/style/noNonNullAssertion: we just checked for this\n const mappedValues = defined ?? [inferred!];\n\n if (\n patchDiscriminatorEnum(schema as unknown as SchemaObject, mappedRef, mappedValues, discriminator, ref, options)\n ) {\n refsHandled.push(mappedRef);\n }\n }\n });\n\n // second, collect the schema objects that inherit from discriminators\n // (sometimes this mapping is implicit, so it can’t be done until we know\n // about every discriminator in the document)\n walk(schema, (obj, path) => {\n if (!obj || !Array.isArray(obj.allOf)) {\n return;\n }\n\n for (const item of (obj as any).allOf) {\n if (\"$ref\" in item) {\n if (!objects[item.$ref]) {\n return;\n }\n\n const ref = createRef(path);\n const discriminator = objects[item.$ref];\n const mappedValues: string[] = [];\n\n if (discriminator.mapping) {\n for (const mappedValue in discriminator.mapping) {\n if (discriminator.mapping[mappedValue] === ref) {\n mappedValues.push(mappedValue);\n }\n }\n\n if (mappedValues.length > 0) {\n if (\n patchDiscriminatorEnum(\n schema as unknown as SchemaObject,\n ref,\n mappedValues,\n discriminator,\n item.$ref,\n options,\n )\n ) {\n refsHandled.push(ref);\n }\n }\n }\n\n objects[ref] = {\n ...objects[item.$ref],\n };\n } else if (item.discriminator?.propertyName) {\n objects[createRef(path)] = { ...item.discriminator };\n }\n }\n });\n\n return { objects, refsHandled };\n}\n\n/** Walk through any JSON-serializable (i.e. non-circular) object */\nexport function walk(\n obj: unknown,\n cb: (value: Record<string, unknown>, path: (string | number)[]) => void,\n path: (string | number)[] = [],\n): void {\n if (!obj || typeof obj !== \"object\") {\n return;\n }\n if (Array.isArray(obj)) {\n for (let i = 0; i < obj.length; i++) {\n walk(obj[i], cb, path.concat(i));\n }\n return;\n }\n cb(obj as Record<string, unknown>, path);\n for (const k of Object.keys(obj)) {\n walk((obj as Record<string, unknown>)[k], cb, path.concat(k));\n }\n}\n\n/** Print warning message */\nexport function warn(msg: string, silent = false) {\n if (!silent) {\n // biome-ignore lint/suspicious/noConsole: this is a CLI\n console.warn(c.yellow(`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-utils.js';
|
|
2
|
+
import c from 'ansi-colors';
|
|
3
|
+
export { default as c } from 'ansi-colors';
|
|
4
|
+
import supportsColor from 'supports-color';
|
|
5
|
+
import ts from 'typescript';
|
|
6
|
+
import { tsModifiers, tsPropertyIndex, tsLiteral } from './ts.mjs';
|
|
7
|
+
|
|
8
|
+
if (!supportsColor.stdout || supportsColor.stdout.hasBasic === false) {
|
|
9
|
+
c.enabled = false;
|
|
10
|
+
}
|
|
11
|
+
const DEBUG_GROUPS = {
|
|
12
|
+
redoc: c.cyanBright,
|
|
13
|
+
lint: c.yellowBright,
|
|
14
|
+
bundle: c.magentaBright,
|
|
15
|
+
ts: c.blueBright
|
|
16
|
+
};
|
|
17
|
+
function createDiscriminatorProperty(discriminator, { path, readonly = false }) {
|
|
18
|
+
let value = parseRef(path).pointer.pop();
|
|
19
|
+
if (discriminator.mapping) {
|
|
20
|
+
const matchedValue = Object.entries(discriminator.mapping).find(
|
|
21
|
+
([, v]) => !v.startsWith("#") && v === value || v.startsWith("#") && parseRef(v).pointer.pop() === value
|
|
22
|
+
);
|
|
23
|
+
if (matchedValue) {
|
|
24
|
+
value = matchedValue[0];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return ts.factory.createPropertySignature(
|
|
28
|
+
/* modifiers */
|
|
29
|
+
tsModifiers({
|
|
30
|
+
readonly
|
|
31
|
+
}),
|
|
32
|
+
/* name */
|
|
33
|
+
tsPropertyIndex(discriminator.propertyName),
|
|
34
|
+
/* questionToken */
|
|
35
|
+
void 0,
|
|
36
|
+
/* type */
|
|
37
|
+
tsLiteral(value)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
function createRef(parts) {
|
|
41
|
+
let pointer = "#";
|
|
42
|
+
for (const part of parts) {
|
|
43
|
+
if (part === void 0 || part === null || part === "") {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const maybeRef = parseRef(String(part)).pointer;
|
|
47
|
+
if (maybeRef.length) {
|
|
48
|
+
for (const refPart of maybeRef) {
|
|
49
|
+
pointer += `/${escapePointer(refPart)}`;
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
pointer += `/${escapePointer(part)}`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return pointer;
|
|
56
|
+
}
|
|
57
|
+
function debug(msg, group, time) {
|
|
58
|
+
if (process.env.DEBUG && (!group || process.env.DEBUG === "*" || process.env.DEBUG === "openapi-ts:*" || process.env.DEBUG.toLocaleLowerCase() === `openapi-ts:${group.toLocaleLowerCase()}`)) {
|
|
59
|
+
const groupColor = group && DEBUG_GROUPS[group] || c.whiteBright;
|
|
60
|
+
const groupName = groupColor(`openapi-ts:${group ?? "info"}`);
|
|
61
|
+
let timeFormatted = "";
|
|
62
|
+
if (typeof time === "number") {
|
|
63
|
+
timeFormatted = c.green(` ${formatTime(time)} `);
|
|
64
|
+
}
|
|
65
|
+
console.debug(` ${c.bold(groupName)}${timeFormatted}${msg}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function error(msg) {
|
|
69
|
+
console.error(c.red(` \u2718 ${msg}`));
|
|
70
|
+
}
|
|
71
|
+
function formatTime(t) {
|
|
72
|
+
if (typeof t === "number") {
|
|
73
|
+
if (t < 1e3) {
|
|
74
|
+
return `${Math.round(10 * t) / 10}ms`;
|
|
75
|
+
}
|
|
76
|
+
if (t < 6e4) {
|
|
77
|
+
return `${Math.round(t / 100) / 10}s`;
|
|
78
|
+
}
|
|
79
|
+
return `${Math.round(t / 6e3) / 10}m`;
|
|
80
|
+
}
|
|
81
|
+
return t;
|
|
82
|
+
}
|
|
83
|
+
function getEntries(obj, options) {
|
|
84
|
+
let entries = Object.entries(obj);
|
|
85
|
+
if (options?.alphabetize) {
|
|
86
|
+
entries.sort(([a], [b]) => a.localeCompare(b, "en-us", { numeric: true }));
|
|
87
|
+
}
|
|
88
|
+
if (options?.excludeDeprecated) {
|
|
89
|
+
entries = entries.filter(([, v]) => !(v && typeof v === "object" && "deprecated" in v && v.deprecated));
|
|
90
|
+
}
|
|
91
|
+
return entries;
|
|
92
|
+
}
|
|
93
|
+
function resolveRef(schema, $ref, { silent = false, visited = [] }) {
|
|
94
|
+
const { pointer } = parseRef($ref);
|
|
95
|
+
if (!pointer.length) {
|
|
96
|
+
return void 0;
|
|
97
|
+
}
|
|
98
|
+
let node = schema;
|
|
99
|
+
for (const key of pointer) {
|
|
100
|
+
if (node && typeof node === "object" && node[key]) {
|
|
101
|
+
node = node[key];
|
|
102
|
+
} else {
|
|
103
|
+
warn(`Could not resolve $ref "${$ref}"`, silent);
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (node && typeof node === "object" && node.$ref) {
|
|
108
|
+
if (visited.includes(node.$ref)) {
|
|
109
|
+
warn(`Could not resolve circular $ref "${$ref}"`, silent);
|
|
110
|
+
return void 0;
|
|
111
|
+
}
|
|
112
|
+
return resolveRef(schema, node.$ref, {
|
|
113
|
+
silent,
|
|
114
|
+
visited: [...visited, node.$ref]
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return node;
|
|
118
|
+
}
|
|
119
|
+
function createDiscriminatorEnum(values, prevSchema) {
|
|
120
|
+
return {
|
|
121
|
+
type: "string",
|
|
122
|
+
enum: values,
|
|
123
|
+
description: prevSchema?.description ? `${prevSchema.description} (enum property replaced by openapi-typescript)` : "discriminator enum property added by openapi-typescript"
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function patchDiscriminatorEnum(schema, ref, values, discriminator, discriminatorRef, options) {
|
|
127
|
+
const resolvedSchema = resolveRef(schema, ref, {
|
|
128
|
+
silent: options.silent ?? false
|
|
129
|
+
});
|
|
130
|
+
if (resolvedSchema?.allOf) {
|
|
131
|
+
resolvedSchema.allOf.push({
|
|
132
|
+
type: "object",
|
|
133
|
+
// discriminator enum properties always need to be required
|
|
134
|
+
required: [discriminator.propertyName],
|
|
135
|
+
properties: {
|
|
136
|
+
[discriminator.propertyName]: createDiscriminatorEnum(values)
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return true;
|
|
140
|
+
} else if (typeof resolvedSchema === "object" && "type" in resolvedSchema && resolvedSchema.type === "object") {
|
|
141
|
+
if (!resolvedSchema.properties) {
|
|
142
|
+
resolvedSchema.properties = {};
|
|
143
|
+
}
|
|
144
|
+
if (!resolvedSchema.required) {
|
|
145
|
+
resolvedSchema.required = [discriminator.propertyName];
|
|
146
|
+
} else if (!resolvedSchema.required.includes(discriminator.propertyName)) {
|
|
147
|
+
resolvedSchema.required.push(discriminator.propertyName);
|
|
148
|
+
}
|
|
149
|
+
resolvedSchema.properties[discriminator.propertyName] = createDiscriminatorEnum(
|
|
150
|
+
values,
|
|
151
|
+
resolvedSchema.properties[discriminator.propertyName]
|
|
152
|
+
);
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
warn(
|
|
156
|
+
`Discriminator mapping has an invalid schema (neither an object schema nor an allOf array): ${ref} => ${values.join(
|
|
157
|
+
", "
|
|
158
|
+
)} (Discriminator: ${discriminatorRef})`,
|
|
159
|
+
options.silent
|
|
160
|
+
);
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
function scanDiscriminators(schema, options) {
|
|
164
|
+
const objects = {};
|
|
165
|
+
const refsHandled = [];
|
|
166
|
+
walk(schema, (obj, path) => {
|
|
167
|
+
const discriminator = obj?.discriminator;
|
|
168
|
+
if (!discriminator?.propertyName) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const ref = createRef(path);
|
|
172
|
+
objects[ref] = discriminator;
|
|
173
|
+
if (!obj?.oneOf || !Array.isArray(obj.oneOf)) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const oneOf = obj.oneOf;
|
|
177
|
+
const mapping = {};
|
|
178
|
+
for (const item of oneOf) {
|
|
179
|
+
if ("$ref" in item) {
|
|
180
|
+
const value = item.$ref.split("/").pop();
|
|
181
|
+
if (value) {
|
|
182
|
+
if (!mapping[item.$ref]) {
|
|
183
|
+
mapping[item.$ref] = { inferred: value };
|
|
184
|
+
} else {
|
|
185
|
+
mapping[item.$ref].inferred = value;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (discriminator.mapping) {
|
|
191
|
+
for (const mappedValue in discriminator.mapping) {
|
|
192
|
+
const mappedRef = discriminator.mapping[mappedValue];
|
|
193
|
+
if (!mappedRef) {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (!mapping[mappedRef]?.defined) {
|
|
197
|
+
mapping[mappedRef] = { defined: [] };
|
|
198
|
+
}
|
|
199
|
+
mapping[mappedRef].defined?.push(mappedValue);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
for (const [mappedRef, { inferred, defined }] of Object.entries(mapping)) {
|
|
203
|
+
if (refsHandled.includes(mappedRef)) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (!inferred && !defined) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const mappedValues = defined ?? [inferred];
|
|
210
|
+
if (patchDiscriminatorEnum(schema, mappedRef, mappedValues, discriminator, ref, options)) {
|
|
211
|
+
refsHandled.push(mappedRef);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
walk(schema, (obj, path) => {
|
|
216
|
+
if (!obj || !Array.isArray(obj.allOf)) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
for (const item of obj.allOf) {
|
|
220
|
+
if ("$ref" in item) {
|
|
221
|
+
if (!objects[item.$ref]) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const ref = createRef(path);
|
|
225
|
+
const discriminator = objects[item.$ref];
|
|
226
|
+
const mappedValues = [];
|
|
227
|
+
if (discriminator.mapping) {
|
|
228
|
+
for (const mappedValue in discriminator.mapping) {
|
|
229
|
+
if (discriminator.mapping[mappedValue] === ref) {
|
|
230
|
+
mappedValues.push(mappedValue);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (mappedValues.length > 0) {
|
|
234
|
+
if (patchDiscriminatorEnum(
|
|
235
|
+
schema,
|
|
236
|
+
ref,
|
|
237
|
+
mappedValues,
|
|
238
|
+
discriminator,
|
|
239
|
+
item.$ref,
|
|
240
|
+
options
|
|
241
|
+
)) {
|
|
242
|
+
refsHandled.push(ref);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
objects[ref] = {
|
|
247
|
+
...objects[item.$ref]
|
|
248
|
+
};
|
|
249
|
+
} else if (item.discriminator?.propertyName) {
|
|
250
|
+
objects[createRef(path)] = { ...item.discriminator };
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
return { objects, refsHandled };
|
|
255
|
+
}
|
|
256
|
+
function walk(obj, cb, path = []) {
|
|
257
|
+
if (!obj || typeof obj !== "object") {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (Array.isArray(obj)) {
|
|
261
|
+
for (let i = 0; i < obj.length; i++) {
|
|
262
|
+
walk(obj[i], cb, path.concat(i));
|
|
263
|
+
}
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
cb(obj, path);
|
|
267
|
+
for (const k of Object.keys(obj)) {
|
|
268
|
+
walk(obj[k], cb, path.concat(k));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function warn(msg, silent = false) {
|
|
272
|
+
if (!silent) {
|
|
273
|
+
console.warn(c.yellow(` \u26A0 ${msg}`));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export { createDiscriminatorProperty, createRef, debug, error, formatTime, getEntries, resolveRef, scanDiscriminators, walk, warn };
|
|
278
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../src/lib/utils.ts"],"sourcesContent":["import { escapePointer, parseRef } from \"@redocly/openapi-core/lib/ref-utils.js\";\nimport c from \"ansi-colors\";\nimport supportsColor from \"supports-color\";\nimport ts from \"typescript\";\nimport type { DiscriminatorObject, OpenAPI3, OpenAPITSOptions, ReferenceObject, SchemaObject } from \"../types.js\";\nimport { tsLiteral, tsModifiers, tsPropertyIndex } from \"./ts.js\";\n\nif (!supportsColor.stdout || supportsColor.stdout.hasBasic === false) {\n c.enabled = false;\n}\n\nconst DEBUG_GROUPS: Record<string, c.StyleFunction | undefined> = {\n redoc: c.cyanBright,\n lint: c.yellowBright,\n bundle: c.magentaBright,\n ts: c.blueBright,\n};\n\nexport { c };\n\n/** Given a discriminator object, get the property name */\nexport function createDiscriminatorProperty(\n discriminator: DiscriminatorObject,\n { path, readonly = false }: { path: string; readonly?: boolean },\n): ts.TypeElement {\n // get the inferred propertyName value from the last section of the path (as the spec suggests to do)\n let value = parseRef(path).pointer.pop();\n // if mapping, and there’s a match, use this rather than the inferred name\n if (discriminator.mapping) {\n // Mapping value can either be a fully-qualified ref (#/components/schemas/XYZ) or a schema name (XYZ)\n const matchedValue = Object.entries(discriminator.mapping).find(\n ([, v]) => (!v.startsWith(\"#\") && v === value) || (v.startsWith(\"#\") && parseRef(v).pointer.pop() === value),\n );\n if (matchedValue) {\n value = matchedValue[0]; // why was this designed backwards!?\n }\n }\n return ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({\n readonly,\n }),\n /* name */ tsPropertyIndex(discriminator.propertyName),\n /* questionToken */ undefined,\n /* type */ tsLiteral(value),\n );\n}\n\n/** Create a $ref pointer (even from other $refs) */\nexport function createRef(parts: (number | string | undefined | null)[]): string {\n let pointer = \"#\";\n for (const part of parts) {\n if (part === undefined || part === null || part === \"\") {\n continue;\n }\n const maybeRef = parseRef(String(part)).pointer;\n if (maybeRef.length) {\n for (const refPart of maybeRef) {\n pointer += `/${escapePointer(refPart)}`;\n }\n } else {\n pointer += `/${escapePointer(part)}`;\n }\n }\n return pointer;\n}\n\n/** Print debug message (cribbed from the `debug` package, but without all the bells & whistles */\nexport function debug(msg: string, group?: string, time?: number) {\n if (\n process.env.DEBUG &&\n (!group ||\n process.env.DEBUG === \"*\" ||\n process.env.DEBUG === \"openapi-ts:*\" ||\n process.env.DEBUG.toLocaleLowerCase() === `openapi-ts:${group.toLocaleLowerCase()}`)\n ) {\n const groupColor = (group && DEBUG_GROUPS[group]) || c.whiteBright;\n const groupName = groupColor(`openapi-ts:${group ?? \"info\"}`);\n let timeFormatted = \"\";\n if (typeof time === \"number\") {\n timeFormatted = c.green(` ${formatTime(time)} `);\n }\n // biome-ignore lint/suspicious/noConsole: this is a CLI\n console.debug(` ${c.bold(groupName)}${timeFormatted}${msg}`);\n }\n}\n\n/** Print error message */\nexport function error(msg: string) {\n // biome-ignore lint/suspicious/noConsole: this is a CLI\n console.error(c.red(` ✘ ${msg}`));\n}\n\n/** Format a performance log in a friendly format */\nexport function formatTime(t: number) {\n if (typeof t === \"number\") {\n if (t < 1000) {\n return `${Math.round(10 * t) / 10}ms`;\n }\n if (t < 60000) {\n return `${Math.round(t / 100) / 10}s`;\n }\n return `${Math.round(t / 6000) / 10}m`;\n }\n return t;\n}\n\n/** Call Object.entries() and optionally sort */\nexport function getEntries<T>(\n obj: ArrayLike<T> | Record<string, T>,\n options?: {\n alphabetize?: boolean;\n excludeDeprecated?: boolean;\n },\n) {\n let entries = Object.entries(obj);\n if (options?.alphabetize) {\n entries.sort(([a], [b]) => a.localeCompare(b, \"en-us\", { numeric: true }));\n }\n if (options?.excludeDeprecated) {\n entries = entries.filter(([, v]) => !(v && typeof v === \"object\" && \"deprecated\" in v && v.deprecated));\n }\n return entries;\n}\n\n/** resolve a $ref in a schema */\nexport function resolveRef<T>(\n schema: any,\n $ref: string,\n { silent = false, visited = [] }: { silent: boolean; visited?: string[] },\n): T | undefined {\n const { pointer } = parseRef($ref);\n if (!pointer.length) {\n return undefined;\n }\n let node = schema;\n for (const key of pointer) {\n if (node && typeof node === \"object\" && node[key]) {\n node = node[key];\n } else {\n warn(`Could not resolve $ref \"${$ref}\"`, silent);\n return undefined;\n }\n }\n\n // if this is also a $ref, keep tracing\n if (node && typeof node === \"object\" && node.$ref) {\n if (visited.includes(node.$ref)) {\n warn(`Could not resolve circular $ref \"${$ref}\"`, silent);\n return undefined;\n }\n return resolveRef(schema, node.$ref, {\n silent,\n visited: [...visited, node.$ref],\n });\n }\n\n return node;\n}\n\nfunction createDiscriminatorEnum(values: string[], prevSchema?: SchemaObject): SchemaObject {\n return {\n type: \"string\",\n enum: values,\n description: prevSchema?.description\n ? `${prevSchema.description} (enum property replaced by openapi-typescript)`\n : \"discriminator enum property added by openapi-typescript\",\n };\n}\n\n/** Adds or replaces the discriminator enum with the passed `values` in a schema defined by `ref` */\nfunction patchDiscriminatorEnum(\n schema: SchemaObject,\n ref: string,\n values: string[],\n discriminator: DiscriminatorObject,\n discriminatorRef: string,\n options: OpenAPITSOptions,\n): boolean {\n const resolvedSchema = resolveRef<SchemaObject>(schema, ref, {\n silent: options.silent ?? false,\n });\n\n if (resolvedSchema?.allOf) {\n // if the schema is an allOf, we can append a new schema object to the allOf array\n resolvedSchema.allOf.push({\n type: \"object\",\n // discriminator enum properties always need to be required\n required: [discriminator.propertyName],\n properties: {\n [discriminator.propertyName]: createDiscriminatorEnum(values),\n },\n });\n\n return true;\n } else if (typeof resolvedSchema === \"object\" && \"type\" in resolvedSchema && resolvedSchema.type === \"object\") {\n // if the schema is an object, we can apply the discriminator enums to its properties\n if (!resolvedSchema.properties) {\n resolvedSchema.properties = {};\n }\n\n // discriminator enum properties always need to be required\n if (!resolvedSchema.required) {\n resolvedSchema.required = [discriminator.propertyName];\n } else if (!resolvedSchema.required.includes(discriminator.propertyName)) {\n resolvedSchema.required.push(discriminator.propertyName);\n }\n\n // add/replace the discriminator enum property\n resolvedSchema.properties[discriminator.propertyName] = createDiscriminatorEnum(\n values,\n resolvedSchema.properties[discriminator.propertyName] as SchemaObject,\n );\n\n return true;\n }\n\n warn(\n `Discriminator mapping has an invalid schema (neither an object schema nor an allOf array): ${ref} => ${values.join(\n \", \",\n )} (Discriminator: ${discriminatorRef})`,\n options.silent,\n );\n\n return false;\n}\n\ntype InternalDiscriminatorMapping = Record<string, { inferred?: string; defined?: string[] }>;\n\n/** Return a key–value map of discriminator objects found in a schema */\nexport function scanDiscriminators(schema: OpenAPI3, options: OpenAPITSOptions) {\n // all discriminator objects found in the schema\n const objects: Record<string, DiscriminatorObject> = {};\n\n // refs of all mapped schema objects we have successfully handled to infer the discriminator enum value\n const refsHandled: string[] = [];\n\n // perform 2 passes: first, collect all discriminator definitions and handle oneOf and mappings\n walk(schema, (obj, path) => {\n const discriminator = obj?.discriminator as DiscriminatorObject | undefined;\n if (!discriminator?.propertyName) {\n return;\n }\n\n // collect discriminator object for later usage\n const ref = createRef(path);\n\n objects[ref] = discriminator;\n\n // if a mapping is available we will help Typescript to infer properties by adding the discriminator enum with its single mapped value to each schema\n // we only handle the mapping in advance for discriminator + oneOf compositions right now\n if (!obj?.oneOf || !Array.isArray(obj.oneOf)) {\n return;\n }\n\n const oneOf: (SchemaObject | ReferenceObject)[] = obj.oneOf;\n const mapping: InternalDiscriminatorMapping = {};\n\n // the mapping can be inferred from the oneOf refs next to the discriminator object\n for (const item of oneOf) {\n if (\"$ref\" in item) {\n // the name of the schema is the inferred discriminator enum value\n const value = item.$ref.split(\"/\").pop();\n\n if (value) {\n if (!mapping[item.$ref]) {\n mapping[item.$ref] = { inferred: value };\n } else {\n mapping[item.$ref].inferred = value;\n }\n }\n }\n }\n\n // the mapping can be defined in the discriminator object itself\n if (discriminator.mapping) {\n for (const mappedValue in discriminator.mapping) {\n const mappedRef = discriminator.mapping[mappedValue];\n if (!mappedRef) {\n continue;\n }\n\n if (!mapping[mappedRef]?.defined) {\n // this overrides inferred values, but we don't need them anymore as soon as we have a defined value\n mapping[mappedRef] = { defined: [] };\n }\n\n mapping[mappedRef].defined?.push(mappedValue);\n }\n }\n\n for (const [mappedRef, { inferred, defined }] of Object.entries(mapping)) {\n if (refsHandled.includes(mappedRef)) {\n continue;\n }\n\n if (!inferred && !defined) {\n continue;\n }\n\n // prefer defined values over automatically inferred ones\n // the inferred enum values from the schema might not represent the actual enum values of the discriminator,\n // so if we have defined values, use them instead\n // biome-ignore lint/style/noNonNullAssertion: we just checked for this\n const mappedValues = defined ?? [inferred!];\n\n if (\n patchDiscriminatorEnum(schema as unknown as SchemaObject, mappedRef, mappedValues, discriminator, ref, options)\n ) {\n refsHandled.push(mappedRef);\n }\n }\n });\n\n // second, collect the schema objects that inherit from discriminators\n // (sometimes this mapping is implicit, so it can’t be done until we know\n // about every discriminator in the document)\n walk(schema, (obj, path) => {\n if (!obj || !Array.isArray(obj.allOf)) {\n return;\n }\n\n for (const item of (obj as any).allOf) {\n if (\"$ref\" in item) {\n if (!objects[item.$ref]) {\n return;\n }\n\n const ref = createRef(path);\n const discriminator = objects[item.$ref];\n const mappedValues: string[] = [];\n\n if (discriminator.mapping) {\n for (const mappedValue in discriminator.mapping) {\n if (discriminator.mapping[mappedValue] === ref) {\n mappedValues.push(mappedValue);\n }\n }\n\n if (mappedValues.length > 0) {\n if (\n patchDiscriminatorEnum(\n schema as unknown as SchemaObject,\n ref,\n mappedValues,\n discriminator,\n item.$ref,\n options,\n )\n ) {\n refsHandled.push(ref);\n }\n }\n }\n\n objects[ref] = {\n ...objects[item.$ref],\n };\n } else if (item.discriminator?.propertyName) {\n objects[createRef(path)] = { ...item.discriminator };\n }\n }\n });\n\n return { objects, refsHandled };\n}\n\n/** Walk through any JSON-serializable (i.e. non-circular) object */\nexport function walk(\n obj: unknown,\n cb: (value: Record<string, unknown>, path: (string | number)[]) => void,\n path: (string | number)[] = [],\n): void {\n if (!obj || typeof obj !== \"object\") {\n return;\n }\n if (Array.isArray(obj)) {\n for (let i = 0; i < obj.length; i++) {\n walk(obj[i], cb, path.concat(i));\n }\n return;\n }\n cb(obj as Record<string, unknown>, path);\n for (const k of Object.keys(obj)) {\n walk((obj as Record<string, unknown>)[k], cb, path.concat(k));\n }\n}\n\n/** Print warning message */\nexport function warn(msg: string, silent = false) {\n if (!silent) {\n // biome-ignore lint/suspicious/noConsole: this is a CLI\n console.warn(c.yellow(` ⚠ ${msg}`));\n }\n}\n"],"names":[],"mappings":";;;;;;;AAOA,IAAI,CAAC,aAAA,CAAc,MAAA,IAAU,aAAA,CAAc,MAAA,CAAO,aAAa,KAAA,EAAO;AACpE,EAAA,CAAA,CAAE,OAAA,GAAU,KAAA;AACd;AAEA,MAAM,YAAA,GAA4D;AAAA,EAChE,OAAO,CAAA,CAAE,UAAA;AAAA,EACT,MAAM,CAAA,CAAE,YAAA;AAAA,EACR,QAAQ,CAAA,CAAE,aAAA;AAAA,EACV,IAAI,CAAA,CAAE;AACR,CAAA;AAKO,SAAS,4BACd,aAAA,EACA,EAAE,IAAA,EAAM,QAAA,GAAW,OAAM,EACT;AAEhB,EAAA,IAAI,KAAA,GAAQ,QAAA,CAAS,IAAI,CAAA,CAAE,QAAQ,GAAA,EAAI;AAEvC,EAAA,IAAI,cAAc,OAAA,EAAS;AAEzB,IAAA,MAAM,YAAA,GAAe,MAAA,CAAO,OAAA,CAAQ,aAAA,CAAc,OAAO,CAAA,CAAE,IAAA;AAAA,MACzD,CAAC,GAAG,CAAC,MAAO,CAAC,CAAA,CAAE,WAAW,GAAG,CAAA,IAAK,MAAM,KAAA,IAAW,CAAA,CAAE,WAAW,GAAG,CAAA,IAAK,SAAS,CAAC,CAAA,CAAE,OAAA,CAAQ,GAAA,EAAI,KAAM;AAAA,KACxG;AACA,IAAA,IAAI,YAAA,EAAc;AAChB,MAAA,KAAA,GAAQ,aAAa,CAAC,CAAA;AAAA,IACxB;AAAA,EACF;AACA,EAAA,OAAO,GAAG,OAAA,CAAQ,uBAAA;AAAA;AAAA,IACI,WAAA,CAAY;AAAA,MAC9B;AAAA,KACD,CAAA;AAAA;AAAA,IACmB,eAAA,CAAgB,cAAc,YAAY,CAAA;AAAA;AAAA,IAC1C,MAAA;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