next-openapi-gen 1.2.3 → 1.4.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/README.md +36 -33
- package/dist/cli.js +319 -143
- package/dist/index.js +319 -143
- package/dist/next/index.js +204 -28
- package/dist/react-router/index.js +204 -28
- package/dist/vite/index.js +204 -28
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -132,121 +132,6 @@ var FrameworkKind;
|
|
|
132
132
|
FrameworkKind2["ReactRouter"] = "reactrouter";
|
|
133
133
|
})(FrameworkKind || (FrameworkKind = {}));
|
|
134
134
|
|
|
135
|
-
// ../openapi-core/dist/config/normalize.js
|
|
136
|
-
function normalizeRouterType(routerType) {
|
|
137
|
-
return routerType ?? DEFAULT_ROUTER_TYPE;
|
|
138
|
-
}
|
|
139
|
-
function normalizeSchemaTypes(schemaType) {
|
|
140
|
-
const schemaBackends = Array.isArray(schemaType) ? schemaType : [schemaType ?? DEFAULT_RUNTIME_SCHEMA_TYPE];
|
|
141
|
-
return [...new Set(schemaBackends)];
|
|
142
|
-
}
|
|
143
|
-
function normalizeOpenApiVersion(template) {
|
|
144
|
-
if (template.openapi.startsWith("3.2")) {
|
|
145
|
-
return "3.2";
|
|
146
|
-
}
|
|
147
|
-
if (template.openapi.startsWith("3.1")) {
|
|
148
|
-
return "3.1";
|
|
149
|
-
}
|
|
150
|
-
if (template.openapi.startsWith("4.")) {
|
|
151
|
-
return "4.0";
|
|
152
|
-
}
|
|
153
|
-
return DEFAULT_OPENAPI_VERSION;
|
|
154
|
-
}
|
|
155
|
-
function normalizeFrameworkKind(kind) {
|
|
156
|
-
switch (kind) {
|
|
157
|
-
case FrameworkKind.Nextjs:
|
|
158
|
-
case "next":
|
|
159
|
-
return FrameworkKind.Nextjs;
|
|
160
|
-
case FrameworkKind.Tanstack:
|
|
161
|
-
case "tanstack":
|
|
162
|
-
return FrameworkKind.Tanstack;
|
|
163
|
-
case FrameworkKind.ReactRouter:
|
|
164
|
-
case "react-router":
|
|
165
|
-
return FrameworkKind.ReactRouter;
|
|
166
|
-
default:
|
|
167
|
-
return FrameworkKind.Nextjs;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function normalizeFramework(config2, routerType) {
|
|
171
|
-
if (config2.framework) {
|
|
172
|
-
const frameworkKind = normalizeFrameworkKind(config2.framework.kind);
|
|
173
|
-
switch (frameworkKind) {
|
|
174
|
-
case FrameworkKind.Nextjs:
|
|
175
|
-
return {
|
|
176
|
-
...config2.framework,
|
|
177
|
-
kind: frameworkKind,
|
|
178
|
-
router: config2.framework.router || routerType,
|
|
179
|
-
modulePath: config2.framework.modulePath || config2.framework.adapterPath || config2.next?.adapterPath,
|
|
180
|
-
adapterPath: config2.framework.adapterPath || config2.next?.adapterPath
|
|
181
|
-
};
|
|
182
|
-
case FrameworkKind.Tanstack:
|
|
183
|
-
case FrameworkKind.ReactRouter:
|
|
184
|
-
return {
|
|
185
|
-
...config2.framework,
|
|
186
|
-
kind: frameworkKind,
|
|
187
|
-
modulePath: config2.framework.modulePath || config2.framework.adapterPath
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return {
|
|
192
|
-
kind: FrameworkKind.Nextjs,
|
|
193
|
-
router: routerType,
|
|
194
|
-
modulePath: config2.next?.adapterPath,
|
|
195
|
-
adapterPath: config2.next?.adapterPath
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
function normalizeOpenApiConfig(template) {
|
|
199
|
-
const routerType = normalizeRouterType(template.routerType);
|
|
200
|
-
const schemaBackends = normalizeSchemaTypes(template.schemaType);
|
|
201
|
-
const openapiVersion = normalizeOpenApiVersion({
|
|
202
|
-
openapi: "openapi" in template ? template.openapi || "3.0.0" : "3.0.0"
|
|
203
|
-
});
|
|
204
|
-
return {
|
|
205
|
-
apiDir: template.apiDir ?? DEFAULT_API_DIR,
|
|
206
|
-
routerType,
|
|
207
|
-
schemaDir: template.schemaDir ?? DEFAULT_SCHEMA_DIR,
|
|
208
|
-
docsUrl: template.docsUrl ?? DEFAULT_DOCS_URL,
|
|
209
|
-
ui: template.ui ?? DEFAULT_UI,
|
|
210
|
-
outputFile: template.outputFile ?? DEFAULT_GENERATED_OPENAPI_FILENAME,
|
|
211
|
-
outputDir: template.outputDir ?? DEFAULT_OUTPUT_DIR,
|
|
212
|
-
includeOpenApiRoutes: template.includeOpenApiRoutes ?? DEFAULT_INCLUDE_OPENAPI_ROUTES,
|
|
213
|
-
ignoreRoutes: template.ignoreRoutes ?? [],
|
|
214
|
-
schemaType: template.schemaType ?? DEFAULT_RUNTIME_SCHEMA_TYPE,
|
|
215
|
-
schemaBackends,
|
|
216
|
-
schemaFiles: template.schemaFiles ?? [],
|
|
217
|
-
defaultResponseSet: template.defaultResponseSet,
|
|
218
|
-
responseSets: template.responseSets,
|
|
219
|
-
errorConfig: template.errorConfig,
|
|
220
|
-
errorDefinitions: template.errorDefinitions,
|
|
221
|
-
openapiVersion,
|
|
222
|
-
framework: normalizeFramework(template, routerType),
|
|
223
|
-
next: {
|
|
224
|
-
adapterPath: template.next?.adapterPath
|
|
225
|
-
},
|
|
226
|
-
diagnostics: template.diagnostics ?? { enabled: DEFAULT_DIAGNOSTICS_ENABLED },
|
|
227
|
-
debug: template.debug ?? DEFAULT_DEBUG
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// ../openapi-core/dist/diagnostics/collector.js
|
|
232
|
-
var DiagnosticsCollector = class {
|
|
233
|
-
diagnostics = [];
|
|
234
|
-
add(diagnostic) {
|
|
235
|
-
this.diagnostics.push(diagnostic);
|
|
236
|
-
}
|
|
237
|
-
getAll() {
|
|
238
|
-
return [...this.diagnostics];
|
|
239
|
-
}
|
|
240
|
-
hasAny() {
|
|
241
|
-
return this.diagnostics.length > 0;
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
// ../openapi-core/dist/openapi/document.js
|
|
246
|
-
function createDocumentFromTemplate(template) {
|
|
247
|
-
return structuredClone(template);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
135
|
// ../openapi-core/dist/shared/utils.js
|
|
251
136
|
import { parse } from "@babel/parser";
|
|
252
137
|
import * as t from "@babel/types";
|
|
@@ -582,7 +467,7 @@ function parseJSDocBlock(commentValue, filePath) {
|
|
|
582
467
|
result.cookieType = extractTypeFromComment(normalizedComment, "@cookie");
|
|
583
468
|
const authValue = extractLineValue(normalizedComment, "@auth");
|
|
584
469
|
if (authValue) {
|
|
585
|
-
result.auth =
|
|
470
|
+
result.auth = authValue;
|
|
586
471
|
}
|
|
587
472
|
const querystring = parseQuerystringTag(normalizedComment);
|
|
588
473
|
if (querystring) {
|
|
@@ -950,6 +835,17 @@ function mergeJSDocData(target, source) {
|
|
|
950
835
|
function cleanComment(commentValue) {
|
|
951
836
|
return commentValue.replace(/\*\s*/g, "").trim();
|
|
952
837
|
}
|
|
838
|
+
function extractInternalFlagFromComments(comments) {
|
|
839
|
+
if (!comments)
|
|
840
|
+
return false;
|
|
841
|
+
for (const comment of comments) {
|
|
842
|
+
const cleaned = cleanComment(comment.value);
|
|
843
|
+
if (/@internal\b/.test(cleaned) || /@schema\s+false\b/.test(cleaned)) {
|
|
844
|
+
return true;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
return false;
|
|
848
|
+
}
|
|
953
849
|
function extractSchemaIdFromComments(comments) {
|
|
954
850
|
if (!comments)
|
|
955
851
|
return null;
|
|
@@ -1246,16 +1142,18 @@ var INTERNAL_OPENAPI_CONFIG_KEYS = [
|
|
|
1246
1142
|
"framework",
|
|
1247
1143
|
"next",
|
|
1248
1144
|
"diagnostics",
|
|
1249
|
-
"debug"
|
|
1145
|
+
"debug",
|
|
1146
|
+
"authPresets",
|
|
1147
|
+
"excludeSchemas"
|
|
1250
1148
|
];
|
|
1251
|
-
var
|
|
1149
|
+
var DEFAULT_AUTH_PRESET_REPLACEMENTS = {
|
|
1252
1150
|
bearer: "BearerAuth",
|
|
1253
1151
|
basic: "BasicAuth",
|
|
1254
1152
|
apikey: "ApiKeyAuth"
|
|
1255
1153
|
};
|
|
1256
|
-
function performAuthPresetReplacements(authValue) {
|
|
1154
|
+
function performAuthPresetReplacements(authValue, presets = DEFAULT_AUTH_PRESET_REPLACEMENTS) {
|
|
1257
1155
|
const authParts = authValue.split(",").map((part) => part.trim());
|
|
1258
|
-
const mappedParts = authParts.map((part) =>
|
|
1156
|
+
const mappedParts = authParts.map((part) => presets[part.toLowerCase()] || part);
|
|
1259
1157
|
return mappedParts.join(",");
|
|
1260
1158
|
}
|
|
1261
1159
|
function getOperationId(routePath, method) {
|
|
@@ -1273,6 +1171,123 @@ function parseTypeScriptFile(content, options) {
|
|
|
1273
1171
|
});
|
|
1274
1172
|
}
|
|
1275
1173
|
|
|
1174
|
+
// ../openapi-core/dist/config/normalize.js
|
|
1175
|
+
function normalizeRouterType(routerType) {
|
|
1176
|
+
return routerType ?? DEFAULT_ROUTER_TYPE;
|
|
1177
|
+
}
|
|
1178
|
+
function normalizeSchemaTypes(schemaType) {
|
|
1179
|
+
const schemaBackends = Array.isArray(schemaType) ? schemaType : [schemaType ?? DEFAULT_RUNTIME_SCHEMA_TYPE];
|
|
1180
|
+
return [...new Set(schemaBackends)];
|
|
1181
|
+
}
|
|
1182
|
+
function normalizeOpenApiVersion(template) {
|
|
1183
|
+
if (template.openapi.startsWith("3.2")) {
|
|
1184
|
+
return "3.2";
|
|
1185
|
+
}
|
|
1186
|
+
if (template.openapi.startsWith("3.1")) {
|
|
1187
|
+
return "3.1";
|
|
1188
|
+
}
|
|
1189
|
+
if (template.openapi.startsWith("4.")) {
|
|
1190
|
+
return "4.0";
|
|
1191
|
+
}
|
|
1192
|
+
return DEFAULT_OPENAPI_VERSION;
|
|
1193
|
+
}
|
|
1194
|
+
function normalizeFrameworkKind(kind) {
|
|
1195
|
+
switch (kind) {
|
|
1196
|
+
case FrameworkKind.Nextjs:
|
|
1197
|
+
case "next":
|
|
1198
|
+
return FrameworkKind.Nextjs;
|
|
1199
|
+
case FrameworkKind.Tanstack:
|
|
1200
|
+
case "tanstack":
|
|
1201
|
+
return FrameworkKind.Tanstack;
|
|
1202
|
+
case FrameworkKind.ReactRouter:
|
|
1203
|
+
case "react-router":
|
|
1204
|
+
return FrameworkKind.ReactRouter;
|
|
1205
|
+
default:
|
|
1206
|
+
return FrameworkKind.Nextjs;
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
function normalizeFramework(config2, routerType) {
|
|
1210
|
+
if (config2.framework) {
|
|
1211
|
+
const frameworkKind = normalizeFrameworkKind(config2.framework.kind);
|
|
1212
|
+
switch (frameworkKind) {
|
|
1213
|
+
case FrameworkKind.Nextjs:
|
|
1214
|
+
return {
|
|
1215
|
+
...config2.framework,
|
|
1216
|
+
kind: frameworkKind,
|
|
1217
|
+
router: config2.framework.router || routerType,
|
|
1218
|
+
modulePath: config2.framework.modulePath || config2.framework.adapterPath || config2.next?.adapterPath,
|
|
1219
|
+
adapterPath: config2.framework.adapterPath || config2.next?.adapterPath
|
|
1220
|
+
};
|
|
1221
|
+
case FrameworkKind.Tanstack:
|
|
1222
|
+
case FrameworkKind.ReactRouter:
|
|
1223
|
+
return {
|
|
1224
|
+
...config2.framework,
|
|
1225
|
+
kind: frameworkKind,
|
|
1226
|
+
modulePath: config2.framework.modulePath || config2.framework.adapterPath
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
return {
|
|
1231
|
+
kind: FrameworkKind.Nextjs,
|
|
1232
|
+
router: routerType,
|
|
1233
|
+
modulePath: config2.next?.adapterPath,
|
|
1234
|
+
adapterPath: config2.next?.adapterPath
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
function normalizeOpenApiConfig(template) {
|
|
1238
|
+
const routerType = normalizeRouterType(template.routerType);
|
|
1239
|
+
const schemaBackends = normalizeSchemaTypes(template.schemaType);
|
|
1240
|
+
const openapiVersion = normalizeOpenApiVersion({
|
|
1241
|
+
openapi: "openapi" in template ? template.openapi || "3.0.0" : "3.0.0"
|
|
1242
|
+
});
|
|
1243
|
+
return {
|
|
1244
|
+
apiDir: template.apiDir ?? DEFAULT_API_DIR,
|
|
1245
|
+
routerType,
|
|
1246
|
+
schemaDir: template.schemaDir ?? DEFAULT_SCHEMA_DIR,
|
|
1247
|
+
docsUrl: template.docsUrl ?? DEFAULT_DOCS_URL,
|
|
1248
|
+
ui: template.ui ?? DEFAULT_UI,
|
|
1249
|
+
outputFile: template.outputFile ?? DEFAULT_GENERATED_OPENAPI_FILENAME,
|
|
1250
|
+
outputDir: template.outputDir ?? DEFAULT_OUTPUT_DIR,
|
|
1251
|
+
includeOpenApiRoutes: template.includeOpenApiRoutes ?? DEFAULT_INCLUDE_OPENAPI_ROUTES,
|
|
1252
|
+
ignoreRoutes: template.ignoreRoutes ?? [],
|
|
1253
|
+
excludeSchemas: template.excludeSchemas ?? [],
|
|
1254
|
+
schemaType: template.schemaType ?? DEFAULT_RUNTIME_SCHEMA_TYPE,
|
|
1255
|
+
schemaBackends,
|
|
1256
|
+
schemaFiles: template.schemaFiles ?? [],
|
|
1257
|
+
defaultResponseSet: template.defaultResponseSet,
|
|
1258
|
+
responseSets: template.responseSets,
|
|
1259
|
+
errorConfig: template.errorConfig,
|
|
1260
|
+
errorDefinitions: template.errorDefinitions,
|
|
1261
|
+
openapiVersion,
|
|
1262
|
+
framework: normalizeFramework(template, routerType),
|
|
1263
|
+
next: {
|
|
1264
|
+
adapterPath: template.next?.adapterPath
|
|
1265
|
+
},
|
|
1266
|
+
diagnostics: template.diagnostics ?? { enabled: DEFAULT_DIAGNOSTICS_ENABLED },
|
|
1267
|
+
authPresets: { ...DEFAULT_AUTH_PRESET_REPLACEMENTS, ...template.authPresets },
|
|
1268
|
+
debug: template.debug ?? DEFAULT_DEBUG
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
// ../openapi-core/dist/diagnostics/collector.js
|
|
1273
|
+
var DiagnosticsCollector = class {
|
|
1274
|
+
diagnostics = [];
|
|
1275
|
+
add(diagnostic) {
|
|
1276
|
+
this.diagnostics.push(diagnostic);
|
|
1277
|
+
}
|
|
1278
|
+
getAll() {
|
|
1279
|
+
return [...this.diagnostics];
|
|
1280
|
+
}
|
|
1281
|
+
hasAny() {
|
|
1282
|
+
return this.diagnostics.length > 0;
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
|
|
1286
|
+
// ../openapi-core/dist/openapi/document.js
|
|
1287
|
+
function createDocumentFromTemplate(template) {
|
|
1288
|
+
return structuredClone(template);
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1276
1291
|
// ../openapi-core/dist/openapi/version-processor.js
|
|
1277
1292
|
var DefaultOpenApiVersionProcessor = class {
|
|
1278
1293
|
id;
|
|
@@ -1731,8 +1746,10 @@ function downgradeSchemaForOpenApi30(schema, mediaTypeName) {
|
|
|
1731
1746
|
const nullableBranch = nextSchema.anyOf.find((item) => item.type === "null");
|
|
1732
1747
|
const baseBranch = nextSchema.anyOf.find((item) => item.type !== "null");
|
|
1733
1748
|
if (nullableBranch && baseBranch) {
|
|
1749
|
+
const { anyOf: _anyOf, ...outerMeta } = nextSchema;
|
|
1734
1750
|
nextSchema = {
|
|
1735
1751
|
...structuredClone(baseBranch),
|
|
1752
|
+
...outerMeta,
|
|
1736
1753
|
nullable: true
|
|
1737
1754
|
};
|
|
1738
1755
|
}
|
|
@@ -3652,7 +3669,7 @@ function processZodLiteral(node, context) {
|
|
|
3652
3669
|
return { type: "string", enum: [arg.value] };
|
|
3653
3670
|
}
|
|
3654
3671
|
if (t8.isNumericLiteral(arg)) {
|
|
3655
|
-
return { type: "number", enum: [arg.value] };
|
|
3672
|
+
return { type: Number.isInteger(arg.value) ? "integer" : "number", enum: [arg.value] };
|
|
3656
3673
|
}
|
|
3657
3674
|
if (t8.isBooleanLiteral(arg)) {
|
|
3658
3675
|
return { type: "boolean", enum: [arg.value] };
|
|
@@ -3668,7 +3685,7 @@ function processZodLiteral(node, context) {
|
|
|
3668
3685
|
if (typeof value === "string")
|
|
3669
3686
|
return { type: "string", enum: [value] };
|
|
3670
3687
|
if (typeof value === "number")
|
|
3671
|
-
return { type: "number", enum: [value] };
|
|
3688
|
+
return { type: Number.isInteger(value) ? "integer" : "number", enum: [value] };
|
|
3672
3689
|
if (typeof value === "boolean")
|
|
3673
3690
|
return { type: "boolean", enum: [value] };
|
|
3674
3691
|
if (value === null)
|
|
@@ -3763,7 +3780,7 @@ function processZodTuple(node, processNode, context) {
|
|
|
3763
3780
|
if (t8.isIdentifier(node.arguments[0]) && context?.resolveConstArrayValues) {
|
|
3764
3781
|
const values = context.resolveConstArrayValues(node.arguments[0].name);
|
|
3765
3782
|
if (values && values.length > 0) {
|
|
3766
|
-
const prefixItems = values.map((value) => typeof value === "number" ? { type: "number", enum: [value] } : { type: "string", enum: [value] });
|
|
3783
|
+
const prefixItems = values.map((value) => typeof value === "number" ? { type: Number.isInteger(value) ? "integer" : "number", enum: [value] } : { type: "string", enum: [value] });
|
|
3767
3784
|
return {
|
|
3768
3785
|
type: "array",
|
|
3769
3786
|
prefixItems,
|
|
@@ -3807,7 +3824,7 @@ function processZodUnion(node, processNode, context) {
|
|
|
3807
3824
|
if (t8.isIdentifier(node.arguments[0]) && context?.resolveConstArrayValues) {
|
|
3808
3825
|
const values = context.resolveConstArrayValues(node.arguments[0].name);
|
|
3809
3826
|
if (values && values.length > 0) {
|
|
3810
|
-
const type = typeof values[0] === "number" ? "number" : "string";
|
|
3827
|
+
const type = typeof values[0] === "number" ? Number.isInteger(values[0]) ? "integer" : "number" : "string";
|
|
3811
3828
|
return { type, enum: values };
|
|
3812
3829
|
}
|
|
3813
3830
|
}
|
|
@@ -11254,8 +11271,17 @@ var ZodRuntimeExporter = class {
|
|
|
11254
11271
|
return node.arguments[0] ? literal(this.buildLiteralValue(node.arguments[0])) : null;
|
|
11255
11272
|
case "enum":
|
|
11256
11273
|
return this.buildEnum(node);
|
|
11257
|
-
case "array":
|
|
11258
|
-
|
|
11274
|
+
case "array": {
|
|
11275
|
+
const arg = node.arguments[0];
|
|
11276
|
+
if (!arg || !isProcessableNode(arg)) {
|
|
11277
|
+
return array(unknown());
|
|
11278
|
+
}
|
|
11279
|
+
const itemSchema = this.buildSchema(arg);
|
|
11280
|
+
if (!itemSchema) {
|
|
11281
|
+
return null;
|
|
11282
|
+
}
|
|
11283
|
+
return array(itemSchema);
|
|
11284
|
+
}
|
|
11259
11285
|
case "strictObject": {
|
|
11260
11286
|
const base = this.buildObject(node);
|
|
11261
11287
|
return base && typeof base.strict === "function" ? base.strict() : base;
|
|
@@ -11387,13 +11413,17 @@ var ZodRuntimeExporter = class {
|
|
|
11387
11413
|
if (node.arguments.length === 0 || !t9.isArrayExpression(node.arguments[0])) {
|
|
11388
11414
|
return tuple([]);
|
|
11389
11415
|
}
|
|
11390
|
-
const items =
|
|
11416
|
+
const items = [];
|
|
11417
|
+
for (const element of node.arguments[0].elements) {
|
|
11391
11418
|
if (!isProcessableNode(element)) {
|
|
11392
|
-
return
|
|
11419
|
+
return null;
|
|
11393
11420
|
}
|
|
11394
11421
|
const schema = this.buildSchema(element);
|
|
11395
|
-
|
|
11396
|
-
|
|
11422
|
+
if (!schema) {
|
|
11423
|
+
return null;
|
|
11424
|
+
}
|
|
11425
|
+
items.push(schema);
|
|
11426
|
+
}
|
|
11397
11427
|
return tuple(items);
|
|
11398
11428
|
}
|
|
11399
11429
|
buildTemplateLiteral(node) {
|
|
@@ -11694,6 +11724,8 @@ var ZodSchemaConverter = class {
|
|
|
11694
11724
|
/** Schema variable names whose component name was overridden via .meta({ id }). These must
|
|
11695
11725
|
* NOT be copied back under the original variable name in the OpenAPI components object. */
|
|
11696
11726
|
metaIdSchemaNames = /* @__PURE__ */ new Set();
|
|
11727
|
+
/** Schema variable names marked @internal — excluded from components/schemas output. */
|
|
11728
|
+
internalSchemaNames = /* @__PURE__ */ new Set();
|
|
11697
11729
|
// Current processing context (set during file processing)
|
|
11698
11730
|
currentFilePath;
|
|
11699
11731
|
currentAST;
|
|
@@ -12003,7 +12035,12 @@ var ZodSchemaConverter = class {
|
|
|
12003
12035
|
if (this.isZodSchema(path25.node.init)) {
|
|
12004
12036
|
const schema = this.processZodNode(path25.node.init);
|
|
12005
12037
|
if (schema) {
|
|
12006
|
-
this.
|
|
12038
|
+
const overrideId = this.extractMetaIdFromNode(path25.node.init);
|
|
12039
|
+
if (overrideId) {
|
|
12040
|
+
this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
|
|
12041
|
+
} else {
|
|
12042
|
+
this.storeResolvedSchema(schemaName, schema);
|
|
12043
|
+
}
|
|
12007
12044
|
}
|
|
12008
12045
|
return;
|
|
12009
12046
|
}
|
|
@@ -12346,8 +12383,15 @@ var ZodSchemaConverter = class {
|
|
|
12346
12383
|
};
|
|
12347
12384
|
switch (methodName) {
|
|
12348
12385
|
case "optional":
|
|
12386
|
+
break;
|
|
12349
12387
|
case "nullable":
|
|
12350
12388
|
case "nullish":
|
|
12389
|
+
schema = {
|
|
12390
|
+
anyOf: [
|
|
12391
|
+
{ $ref: `#/components/schemas/${this.getSchemaReferenceName(schemaName)}` },
|
|
12392
|
+
{ type: "null" }
|
|
12393
|
+
]
|
|
12394
|
+
};
|
|
12351
12395
|
break;
|
|
12352
12396
|
case "describe":
|
|
12353
12397
|
if (node.arguments.length > 0 && t10.isStringLiteral(node.arguments[0])) {
|
|
@@ -12865,12 +12909,16 @@ var ZodSchemaConverter = class {
|
|
|
12865
12909
|
case "optional":
|
|
12866
12910
|
break;
|
|
12867
12911
|
case "nullable":
|
|
12868
|
-
if (
|
|
12912
|
+
if (schema.allOf) {
|
|
12913
|
+
schema = { anyOf: [...schema.allOf, { type: "null" }] };
|
|
12914
|
+
} else {
|
|
12869
12915
|
schema.nullable = true;
|
|
12870
12916
|
}
|
|
12871
12917
|
break;
|
|
12872
12918
|
case "nullish":
|
|
12873
|
-
if (
|
|
12919
|
+
if (schema.allOf) {
|
|
12920
|
+
schema = { anyOf: [...schema.allOf, { type: "null" }] };
|
|
12921
|
+
} else {
|
|
12874
12922
|
schema.nullable = true;
|
|
12875
12923
|
}
|
|
12876
12924
|
break;
|
|
@@ -13315,7 +13363,13 @@ var ZodSchemaConverter = class {
|
|
|
13315
13363
|
* Get all processed Zod schemas
|
|
13316
13364
|
*/
|
|
13317
13365
|
getProcessedSchemas() {
|
|
13318
|
-
|
|
13366
|
+
const result = {};
|
|
13367
|
+
for (const [name, schema] of Object.entries(this.zodSchemas)) {
|
|
13368
|
+
if (!this.internalSchemaNames.has(name)) {
|
|
13369
|
+
result[name] = schema;
|
|
13370
|
+
}
|
|
13371
|
+
}
|
|
13372
|
+
return result;
|
|
13319
13373
|
}
|
|
13320
13374
|
/**
|
|
13321
13375
|
* Pre-scan all files to build type mappings
|
|
@@ -13367,9 +13421,21 @@ var ZodSchemaConverter = class {
|
|
|
13367
13421
|
if (t10.isIdentifier(declaration.id) && declaration.init) {
|
|
13368
13422
|
const schemaName = declaration.id.name;
|
|
13369
13423
|
if (this.isZodSchema(declaration.init)) {
|
|
13424
|
+
const decl = path25.node.declaration;
|
|
13425
|
+
const allComments = [
|
|
13426
|
+
...path25.node.leadingComments ?? [],
|
|
13427
|
+
...decl?.leadingComments ?? [],
|
|
13428
|
+
...declaration.leadingComments ?? []
|
|
13429
|
+
];
|
|
13430
|
+
if (extractInternalFlagFromComments(allComments)) {
|
|
13431
|
+
this.internalSchemaNames.add(schemaName);
|
|
13432
|
+
}
|
|
13370
13433
|
if (!this.getStoredSchema(schemaName)) {
|
|
13371
13434
|
logger.debug(`Pre-processing Zod schema: ${schemaName}`);
|
|
13372
13435
|
this.processingSchemas.add(schemaName);
|
|
13436
|
+
this.currentFilePath = filePath;
|
|
13437
|
+
this.currentAST = ast;
|
|
13438
|
+
this.currentImports = importedModules;
|
|
13373
13439
|
const schema = this.processZodNode(declaration.init);
|
|
13374
13440
|
this.processingSchemas.delete(schemaName);
|
|
13375
13441
|
if (schema) {
|
|
@@ -13392,9 +13458,19 @@ var ZodSchemaConverter = class {
|
|
|
13392
13458
|
if (t10.isIdentifier(declaration.id) && declaration.init) {
|
|
13393
13459
|
const schemaName = declaration.id.name;
|
|
13394
13460
|
if (this.isZodSchema(declaration.init)) {
|
|
13461
|
+
const allComments = [
|
|
13462
|
+
...path25.node.leadingComments ?? [],
|
|
13463
|
+
...declaration.leadingComments ?? []
|
|
13464
|
+
];
|
|
13465
|
+
if (extractInternalFlagFromComments(allComments)) {
|
|
13466
|
+
this.internalSchemaNames.add(schemaName);
|
|
13467
|
+
}
|
|
13395
13468
|
if (!this.getStoredSchema(schemaName) && !this.processingSchemas.has(schemaName)) {
|
|
13396
13469
|
logger.debug(`Pre-processing Zod schema: ${schemaName}`);
|
|
13397
13470
|
this.processingSchemas.add(schemaName);
|
|
13471
|
+
this.currentFilePath = filePath;
|
|
13472
|
+
this.currentAST = ast;
|
|
13473
|
+
this.currentImports = importedModules;
|
|
13398
13474
|
const schema = this.processZodNode(declaration.init);
|
|
13399
13475
|
this.processingSchemas.delete(schemaName);
|
|
13400
13476
|
if (schema) {
|
|
@@ -14126,7 +14202,7 @@ function collectFirstMemberLeadingComments(interfaceDecl) {
|
|
|
14126
14202
|
const firstMember = body.body?.[0];
|
|
14127
14203
|
return firstMember?.leadingComments ?? [];
|
|
14128
14204
|
}
|
|
14129
|
-
function collectAllExportedDefinitions(ast, typeDefinitions, currentFile, schemaIdAliases) {
|
|
14205
|
+
function collectAllExportedDefinitions(ast, typeDefinitions, currentFile, schemaIdAliases, internalSchemaNames) {
|
|
14130
14206
|
function registerDefinition(name, entry, allComments) {
|
|
14131
14207
|
if (!typeDefinitions[name]) {
|
|
14132
14208
|
typeDefinitions[name] = entry;
|
|
@@ -14138,6 +14214,9 @@ function collectAllExportedDefinitions(ast, typeDefinitions, currentFile, schema
|
|
|
14138
14214
|
typeDefinitions[overrideId] = entry;
|
|
14139
14215
|
}
|
|
14140
14216
|
}
|
|
14217
|
+
if (internalSchemaNames && extractInternalFlagFromComments(allComments)) {
|
|
14218
|
+
internalSchemaNames.add(name);
|
|
14219
|
+
}
|
|
14141
14220
|
}
|
|
14142
14221
|
resolvedTraverse(ast, {
|
|
14143
14222
|
TSTypeAliasDeclaration: (path25) => {
|
|
@@ -14617,6 +14696,7 @@ var SchemaProcessor = class {
|
|
|
14617
14696
|
schemaTypes;
|
|
14618
14697
|
isResolvingPickOmitBase = false;
|
|
14619
14698
|
schemaIdAliases = {};
|
|
14699
|
+
internalSchemaNames = /* @__PURE__ */ new Set();
|
|
14620
14700
|
fileAccess;
|
|
14621
14701
|
symbolResolver;
|
|
14622
14702
|
// Track imports per file for resolving ReturnType<typeof func>
|
|
@@ -14657,7 +14737,7 @@ var SchemaProcessor = class {
|
|
|
14657
14737
|
getDefinedSchemas() {
|
|
14658
14738
|
const filteredSchemas = {};
|
|
14659
14739
|
Object.entries(this.openapiDefinitions).forEach(([key, value]) => {
|
|
14660
|
-
if (!this.schemaIdAliases[key] && !this.isGenericTypeParameter(key) && !this.isInvalidSchemaName(key) && !this.isBuiltInUtilityType(key) && !this.isFunctionSchema(key)) {
|
|
14740
|
+
if (!this.schemaIdAliases[key] && !this.isGenericTypeParameter(key) && !this.isInvalidSchemaName(key) && !this.isBuiltInUtilityType(key) && !this.isFunctionSchema(key) && !this.internalSchemaNames.has(key)) {
|
|
14661
14741
|
filteredSchemas[key] = value;
|
|
14662
14742
|
}
|
|
14663
14743
|
});
|
|
@@ -14667,6 +14747,22 @@ var SchemaProcessor = class {
|
|
|
14667
14747
|
this.customSchemaProcessor.getDefinedSchemas()
|
|
14668
14748
|
]);
|
|
14669
14749
|
}
|
|
14750
|
+
getInternalSchemas() {
|
|
14751
|
+
const result = {};
|
|
14752
|
+
for (const name of this.internalSchemaNames) {
|
|
14753
|
+
const def = this.openapiDefinitions[name];
|
|
14754
|
+
if (def)
|
|
14755
|
+
result[name] = def;
|
|
14756
|
+
}
|
|
14757
|
+
if (this.zodSchemaConverter) {
|
|
14758
|
+
for (const name of this.zodSchemaConverter.internalSchemaNames) {
|
|
14759
|
+
const schema = this.zodSchemaConverter.zodSchemas[name];
|
|
14760
|
+
if (schema)
|
|
14761
|
+
result[name] = schema;
|
|
14762
|
+
}
|
|
14763
|
+
}
|
|
14764
|
+
return result;
|
|
14765
|
+
}
|
|
14670
14766
|
findSchemaDefinition(schemaName, contentType) {
|
|
14671
14767
|
this.contentType = contentType;
|
|
14672
14768
|
if (schemaName.includes("<") && schemaName.includes(">")) {
|
|
@@ -14817,7 +14913,7 @@ var SchemaProcessor = class {
|
|
|
14817
14913
|
* Used when processing imported files to ensure all referenced types are available
|
|
14818
14914
|
*/
|
|
14819
14915
|
collectAllExportedDefinitions(ast, filePath) {
|
|
14820
|
-
collectAllExportedDefinitions(ast, this.typeDefinitions, filePath || this.currentFilePath, this.schemaIdAliases);
|
|
14916
|
+
collectAllExportedDefinitions(ast, this.typeDefinitions, filePath || this.currentFilePath, this.schemaIdAliases, this.internalSchemaNames);
|
|
14821
14917
|
}
|
|
14822
14918
|
collectTypeDefinitions(ast, schemaName, filePath) {
|
|
14823
14919
|
collectTypeDefinitions(ast, schemaName, this.typeDefinitions, filePath || this.currentFilePath);
|
|
@@ -16245,11 +16341,16 @@ var ResponseProcessor = class {
|
|
|
16245
16341
|
var OperationProcessor = class {
|
|
16246
16342
|
schemaProcessor;
|
|
16247
16343
|
responseProcessor;
|
|
16344
|
+
authPresets;
|
|
16248
16345
|
performanceProfile;
|
|
16249
|
-
constructor(schemaProcessor, responseProcessor,
|
|
16346
|
+
constructor(schemaProcessor, responseProcessor, options = {}) {
|
|
16250
16347
|
this.schemaProcessor = schemaProcessor;
|
|
16251
16348
|
this.responseProcessor = responseProcessor;
|
|
16252
|
-
this.
|
|
16349
|
+
this.authPresets = {
|
|
16350
|
+
...DEFAULT_AUTH_PRESET_REPLACEMENTS,
|
|
16351
|
+
...options.authPresets
|
|
16352
|
+
};
|
|
16353
|
+
this.performanceProfile = options.performanceProfile;
|
|
16253
16354
|
}
|
|
16254
16355
|
processOperation(varName, routePath, dataTypes, pathParamNames = []) {
|
|
16255
16356
|
const method = varName.toLowerCase();
|
|
@@ -16274,9 +16375,10 @@ var OperationProcessor = class {
|
|
|
16274
16375
|
definition.deprecated = true;
|
|
16275
16376
|
}
|
|
16276
16377
|
if (explicitSecurity && explicitSecurity.length > 0) {
|
|
16277
|
-
definition.security = explicitSecurity;
|
|
16378
|
+
definition.security = explicitSecurity.map((req) => Object.fromEntries(Object.entries(req).map(([scheme, scopes]) => [this.applyPreset(scheme), scopes])));
|
|
16278
16379
|
} else if (auth) {
|
|
16279
|
-
const
|
|
16380
|
+
const mapped = performAuthPresetReplacements(auth, this.authPresets);
|
|
16381
|
+
const authItems = mapped.split(",").map((item) => item.trim());
|
|
16280
16382
|
definition.security = authItems.map((authItem) => ({
|
|
16281
16383
|
[authItem]: []
|
|
16282
16384
|
}));
|
|
@@ -16489,6 +16591,9 @@ ${suffix}`;
|
|
|
16489
16591
|
response.links[link.name] = linkObject;
|
|
16490
16592
|
}
|
|
16491
16593
|
}
|
|
16594
|
+
applyPreset(scheme) {
|
|
16595
|
+
return this.authPresets[scheme.toLowerCase()] ?? scheme;
|
|
16596
|
+
}
|
|
16492
16597
|
createQuerystringParameter(dataTypes) {
|
|
16493
16598
|
if (!dataTypes.querystringType) {
|
|
16494
16599
|
return void 0;
|
|
@@ -16577,7 +16682,10 @@ var RouteProcessor = class {
|
|
|
16577
16682
|
return new RegExp(`^${regexPattern}$`);
|
|
16578
16683
|
});
|
|
16579
16684
|
this.responseProcessor = new ResponseProcessor(this.config, this.schemaProcessor);
|
|
16580
|
-
this.operationProcessor = new OperationProcessor(this.schemaProcessor, this.responseProcessor,
|
|
16685
|
+
this.operationProcessor = new OperationProcessor(this.schemaProcessor, this.responseProcessor, {
|
|
16686
|
+
authPresets: this.config.authPresets,
|
|
16687
|
+
performanceProfile: this.performanceProfile
|
|
16688
|
+
});
|
|
16581
16689
|
}
|
|
16582
16690
|
processResponsesFromConfig(dataTypes, method) {
|
|
16583
16691
|
return this.responseProcessor.processResponses(dataTypes, method);
|
|
@@ -16803,6 +16911,64 @@ function generateErrorResponsesFromConfig(document, errorConfig) {
|
|
|
16803
16911
|
});
|
|
16804
16912
|
}
|
|
16805
16913
|
|
|
16914
|
+
// ../openapi-core/dist/core/exclude-schemas.js
|
|
16915
|
+
function patternToRegExp(pattern) {
|
|
16916
|
+
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
16917
|
+
return new RegExp(`^${escaped.replace(/\*/g, ".*")}$`);
|
|
16918
|
+
}
|
|
16919
|
+
function matchExcludePatterns(names, patterns) {
|
|
16920
|
+
if (patterns.length === 0)
|
|
16921
|
+
return [];
|
|
16922
|
+
const regexes = patterns.map(patternToRegExp);
|
|
16923
|
+
return names.filter((name) => regexes.some((re) => re.test(name)));
|
|
16924
|
+
}
|
|
16925
|
+
function applyExcludeSchemas(document, mergedSchemas, excludedSchemas) {
|
|
16926
|
+
const excludedNames = new Set(Object.keys(excludedSchemas));
|
|
16927
|
+
if (excludedNames.size === 0)
|
|
16928
|
+
return;
|
|
16929
|
+
walkAndInline(document, excludedSchemas, excludedNames, /* @__PURE__ */ new Set());
|
|
16930
|
+
for (const name of excludedNames) {
|
|
16931
|
+
delete mergedSchemas[name];
|
|
16932
|
+
}
|
|
16933
|
+
}
|
|
16934
|
+
function walkAndInline(obj, excluded, excludedNames, visiting) {
|
|
16935
|
+
if (!obj || typeof obj !== "object")
|
|
16936
|
+
return;
|
|
16937
|
+
if (Array.isArray(obj)) {
|
|
16938
|
+
for (const item of obj) {
|
|
16939
|
+
walkAndInline(item, excluded, excludedNames, visiting);
|
|
16940
|
+
}
|
|
16941
|
+
return;
|
|
16942
|
+
}
|
|
16943
|
+
const rec = obj;
|
|
16944
|
+
const ref = rec["$ref"];
|
|
16945
|
+
if (typeof ref === "string") {
|
|
16946
|
+
const match = ref.match(/^#\/components\/schemas\/(.+)$/);
|
|
16947
|
+
const name = match?.[1];
|
|
16948
|
+
if (name && excludedNames.has(name)) {
|
|
16949
|
+
if (visiting.has(name)) {
|
|
16950
|
+
logger.warn(`Circular reference to internal schema "${name}", keeping $ref`);
|
|
16951
|
+
return;
|
|
16952
|
+
}
|
|
16953
|
+
const schemaDef = excluded[name];
|
|
16954
|
+
if (schemaDef) {
|
|
16955
|
+
const cloned = JSON.parse(JSON.stringify(schemaDef));
|
|
16956
|
+
delete rec["$ref"];
|
|
16957
|
+
Object.assign(rec, cloned);
|
|
16958
|
+
const newVisiting = new Set(visiting);
|
|
16959
|
+
newVisiting.add(name);
|
|
16960
|
+
for (const key of Object.keys(rec)) {
|
|
16961
|
+
walkAndInline(rec[key], excluded, excludedNames, newVisiting);
|
|
16962
|
+
}
|
|
16963
|
+
return;
|
|
16964
|
+
}
|
|
16965
|
+
}
|
|
16966
|
+
}
|
|
16967
|
+
for (const key of Object.keys(rec)) {
|
|
16968
|
+
walkAndInline(rec[key], excluded, excludedNames, visiting);
|
|
16969
|
+
}
|
|
16970
|
+
}
|
|
16971
|
+
|
|
16806
16972
|
// ../openapi-core/dist/core/orchestrator.js
|
|
16807
16973
|
function runGenerationOrchestrator({ config: config2, template, hooks, runtime, createFrameworkSource }) {
|
|
16808
16974
|
const diagnostics = new DiagnosticsCollector();
|
|
@@ -16873,11 +17039,21 @@ function runGenerationOrchestrator({ config: config2, template, hooks, runtime,
|
|
|
16873
17039
|
}
|
|
16874
17040
|
profile.defaultComponentsAndErrorsMs = performance.now() - phaseStartedAt;
|
|
16875
17041
|
phaseStartedAt = performance.now();
|
|
16876
|
-
const
|
|
17042
|
+
const schemaProcessor = routeProcessor.getSchemaProcessor();
|
|
17043
|
+
const definedSchemas = schemaProcessor.getDefinedSchemas();
|
|
16877
17044
|
const mergedSchemas = {
|
|
16878
17045
|
...document.components.schemas,
|
|
16879
17046
|
...definedSchemas
|
|
16880
17047
|
};
|
|
17048
|
+
const internalSchemas = schemaProcessor.getInternalSchemas();
|
|
17049
|
+
const patternExcludedNames = matchExcludePatterns(Object.keys(mergedSchemas), config2.excludeSchemas ?? []);
|
|
17050
|
+
const allExcludedSchemas = {
|
|
17051
|
+
...internalSchemas,
|
|
17052
|
+
...Object.fromEntries(patternExcludedNames.map((name) => [name, mergedSchemas[name]]))
|
|
17053
|
+
};
|
|
17054
|
+
if (Object.keys(allExcludedSchemas).length > 0) {
|
|
17055
|
+
applyExcludeSchemas(document, mergedSchemas, allExcludedSchemas);
|
|
17056
|
+
}
|
|
16881
17057
|
if (Object.keys(mergedSchemas).length > 0) {
|
|
16882
17058
|
document.components.schemas = Object.fromEntries(Object.entries(mergedSchemas).sort(([a], [b]) => a.localeCompare(b, "en", { sensitivity: "base" })));
|
|
16883
17059
|
}
|