@elysiajs/openapi 1.4.3 → 1.4.4
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/cjs/gen/index.js +37 -6
- package/dist/cjs/index.js +20 -6
- package/dist/cjs/openapi.js +20 -6
- package/dist/gen/index.d.ts +6 -1
- package/dist/gen/index.mjs +37 -6
- package/dist/index.mjs +20 -6
- package/dist/openapi.mjs +20 -6
- package/package.json +1 -1
package/dist/cjs/gen/index.js
CHANGED
|
@@ -8315,6 +8315,35 @@ var import_child_process = require("child_process");
|
|
|
8315
8315
|
var matchRoute = /: Elysia<(.*)>/gs;
|
|
8316
8316
|
var matchStatus = /(\d{3}):/g;
|
|
8317
8317
|
var wrapStatusInQuote = (value) => value.replace(matchStatus, '"$1":');
|
|
8318
|
+
function extractRootObjects(code) {
|
|
8319
|
+
const results = [];
|
|
8320
|
+
let i = 0;
|
|
8321
|
+
while (i < code.length) {
|
|
8322
|
+
const colonIdx = code.indexOf(":", i);
|
|
8323
|
+
if (colonIdx === -1) break;
|
|
8324
|
+
let keyEnd = colonIdx - 1;
|
|
8325
|
+
while (keyEnd >= 0 && /\s/.test(code[keyEnd])) keyEnd--;
|
|
8326
|
+
let keyStart = keyEnd;
|
|
8327
|
+
while (keyStart >= 0 && /\w/.test(code[keyStart])) keyStart--;
|
|
8328
|
+
const braceIdx = code.indexOf("{", colonIdx);
|
|
8329
|
+
if (braceIdx === -1) break;
|
|
8330
|
+
let depth = 0;
|
|
8331
|
+
let end = braceIdx;
|
|
8332
|
+
for (; end < code.length; end++) {
|
|
8333
|
+
if (code[end] === "{") depth++;
|
|
8334
|
+
else if (code[end] === "}") {
|
|
8335
|
+
depth--;
|
|
8336
|
+
if (depth === 0) {
|
|
8337
|
+
end++;
|
|
8338
|
+
break;
|
|
8339
|
+
}
|
|
8340
|
+
}
|
|
8341
|
+
}
|
|
8342
|
+
results.push(`{${code.slice(keyStart + 1, end)};}`);
|
|
8343
|
+
i = end;
|
|
8344
|
+
}
|
|
8345
|
+
return results;
|
|
8346
|
+
}
|
|
8318
8347
|
var fromTypes = (targetFilePath, {
|
|
8319
8348
|
tsconfigPath = "tsconfig.json",
|
|
8320
8349
|
instanceName,
|
|
@@ -8322,7 +8351,8 @@ var fromTypes = (targetFilePath, {
|
|
|
8322
8351
|
overrideOutputPath,
|
|
8323
8352
|
debug = false,
|
|
8324
8353
|
compilerOptions,
|
|
8325
|
-
tmpRoot = (0, import_path2.join)((0, import_os.tmpdir)(), ".ElysiaAutoOpenAPI")
|
|
8354
|
+
tmpRoot = (0, import_path2.join)((0, import_os.tmpdir)(), ".ElysiaAutoOpenAPI"),
|
|
8355
|
+
silent = false
|
|
8326
8356
|
} = {}) => () => {
|
|
8327
8357
|
try {
|
|
8328
8358
|
if (!targetFilePath.endsWith(".ts") && !targetFilePath.endsWith(".tsx"))
|
|
@@ -8369,7 +8399,7 @@ var fromTypes = (targetFilePath, {
|
|
|
8369
8399
|
(0, import_child_process.spawnSync)(`tsc`, {
|
|
8370
8400
|
shell: true,
|
|
8371
8401
|
cwd: tmpRoot,
|
|
8372
|
-
stdio:
|
|
8402
|
+
stdio: silent ? void 0 : "inherit"
|
|
8373
8403
|
});
|
|
8374
8404
|
const fileName = targetFilePath.replace(/.tsx$/, ".ts").replace(/.ts$/, ".d.ts");
|
|
8375
8405
|
targetFile = (overrideOutputPath ? typeof overrideOutputPath === "string" ? overrideOutputPath.startsWith("/") ? overrideOutputPath : (0, import_path2.join)(tmpRoot, "dist", overrideOutputPath) : overrideOutputPath(tmpRoot) : void 0) ?? (0, import_path2.join)(
|
|
@@ -8405,7 +8435,7 @@ var fromTypes = (targetFilePath, {
|
|
|
8405
8435
|
console.warn(tempFiles);
|
|
8406
8436
|
}
|
|
8407
8437
|
} else {
|
|
8408
|
-
console.
|
|
8438
|
+
console.warn(
|
|
8409
8439
|
"reason: root folder doesn't exists",
|
|
8410
8440
|
(0, import_path2.join)(tmpRoot, "dist")
|
|
8411
8441
|
);
|
|
@@ -8414,7 +8444,7 @@ var fromTypes = (targetFilePath, {
|
|
|
8414
8444
|
}
|
|
8415
8445
|
}
|
|
8416
8446
|
const declaration = (0, import_fs.readFileSync)(targetFile, "utf8");
|
|
8417
|
-
if ((0, import_fs.existsSync)(tmpRoot))
|
|
8447
|
+
if (!debug && (0, import_fs.existsSync)(tmpRoot))
|
|
8418
8448
|
(0, import_fs.rmSync)(tmpRoot, { recursive: true, force: true });
|
|
8419
8449
|
let instance = declaration.match(
|
|
8420
8450
|
instanceName ? new RegExp(`${instanceName}: Elysia<(.*)`, "gs") : matchRoute
|
|
@@ -8434,8 +8464,8 @@ var fromTypes = (targetFilePath, {
|
|
|
8434
8464
|
instance.slice(3, instance.indexOf("}, {", 4))
|
|
8435
8465
|
);
|
|
8436
8466
|
const routes = {};
|
|
8437
|
-
for (const route of routesString
|
|
8438
|
-
let schema = TypeBox(
|
|
8467
|
+
for (const route of extractRootObjects(routesString)) {
|
|
8468
|
+
let schema = TypeBox(route);
|
|
8439
8469
|
if (schema.type !== "object") continue;
|
|
8440
8470
|
const paths = [];
|
|
8441
8471
|
while (true) {
|
|
@@ -8446,6 +8476,7 @@ var fromTypes = (targetFilePath, {
|
|
|
8446
8476
|
if (!schema?.properties) break;
|
|
8447
8477
|
}
|
|
8448
8478
|
const method = paths.pop();
|
|
8479
|
+
if (!method) continue;
|
|
8449
8480
|
const path = "/" + paths.join("/");
|
|
8450
8481
|
schema = schema.properties;
|
|
8451
8482
|
if (schema?.response?.type === "object") {
|
package/dist/cjs/index.js
CHANGED
|
@@ -340,7 +340,8 @@ openapi({
|
|
|
340
340
|
zod: zodToJsonSchema
|
|
341
341
|
}
|
|
342
342
|
})`,
|
|
343
|
-
valibot: `import
|
|
343
|
+
valibot: `import openapi from '@elysiajs/openapi'
|
|
344
|
+
import { toJsonSchema } from '@valibot/to-json-schema'
|
|
344
345
|
|
|
345
346
|
openapi({
|
|
346
347
|
mapJsonSchema: {
|
|
@@ -418,11 +419,12 @@ var unwrapSchema = (schema, mapJsonSchema) => {
|
|
|
418
419
|
return schema.toJSONSchema?.() ?? schema?.toJsonSchema?.();
|
|
419
420
|
};
|
|
420
421
|
function toOpenAPISchema(app, exclude, references, vendors) {
|
|
421
|
-
|
|
422
|
-
methods: excludeMethods = ["
|
|
422
|
+
let {
|
|
423
|
+
methods: excludeMethods = ["options"],
|
|
423
424
|
staticFile: excludeStaticFile = true,
|
|
424
425
|
tags: excludeTags
|
|
425
426
|
} = exclude ?? {};
|
|
427
|
+
excludeMethods = excludeMethods.map((method) => method.toLowerCase());
|
|
426
428
|
const excludePaths = Array.isArray(exclude?.paths) ? exclude.paths : typeof exclude?.paths !== "undefined" ? [exclude.paths] : [];
|
|
427
429
|
const paths = /* @__PURE__ */ Object.create(null);
|
|
428
430
|
const definitions = app.getGlobalDefinitions?.().type;
|
|
@@ -440,6 +442,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
440
442
|
if (excludeStaticFile && route.path.includes(".") || excludePaths.includes(route.path) || excludeMethods.includes(method))
|
|
441
443
|
continue;
|
|
442
444
|
const hooks = route.hooks ?? {};
|
|
445
|
+
if (route.path === "/a") {
|
|
446
|
+
console.log("H");
|
|
447
|
+
}
|
|
443
448
|
if (references?.length)
|
|
444
449
|
for (const reference of references) {
|
|
445
450
|
if (!reference) continue;
|
|
@@ -488,7 +493,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
488
493
|
});
|
|
489
494
|
}
|
|
490
495
|
if (hooks.query) {
|
|
491
|
-
const query = unwrapReference(
|
|
496
|
+
const query = unwrapReference(
|
|
497
|
+
unwrapSchema(hooks.query, vendors),
|
|
498
|
+
definitions
|
|
499
|
+
);
|
|
492
500
|
if (query && query.type === "object" && query.properties) {
|
|
493
501
|
const required = query.required || [];
|
|
494
502
|
for (const [queryName, querySchema] of Object.entries(
|
|
@@ -503,7 +511,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
503
511
|
}
|
|
504
512
|
}
|
|
505
513
|
if (hooks.headers) {
|
|
506
|
-
const headers = unwrapReference(
|
|
514
|
+
const headers = unwrapReference(
|
|
515
|
+
unwrapSchema(hooks.query, vendors),
|
|
516
|
+
definitions
|
|
517
|
+
);
|
|
507
518
|
if (headers && headers.type === "object" && headers.properties) {
|
|
508
519
|
const required = headers.required || [];
|
|
509
520
|
for (const [headerName, headerSchema] of Object.entries(
|
|
@@ -518,7 +529,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
518
529
|
}
|
|
519
530
|
}
|
|
520
531
|
if (hooks.cookie) {
|
|
521
|
-
const cookie = unwrapReference(
|
|
532
|
+
const cookie = unwrapReference(
|
|
533
|
+
unwrapSchema(hooks.cookie, vendors),
|
|
534
|
+
definitions
|
|
535
|
+
);
|
|
522
536
|
if (cookie && cookie.type === "object" && cookie.properties) {
|
|
523
537
|
const required = cookie.required || [];
|
|
524
538
|
for (const [cookieName, cookieSchema] of Object.entries(
|
package/dist/cjs/openapi.js
CHANGED
|
@@ -83,7 +83,8 @@ openapi({
|
|
|
83
83
|
zod: zodToJsonSchema
|
|
84
84
|
}
|
|
85
85
|
})`,
|
|
86
|
-
valibot: `import
|
|
86
|
+
valibot: `import openapi from '@elysiajs/openapi'
|
|
87
|
+
import { toJsonSchema } from '@valibot/to-json-schema'
|
|
87
88
|
|
|
88
89
|
openapi({
|
|
89
90
|
mapJsonSchema: {
|
|
@@ -161,11 +162,12 @@ var unwrapSchema = (schema, mapJsonSchema) => {
|
|
|
161
162
|
return schema.toJSONSchema?.() ?? schema?.toJsonSchema?.();
|
|
162
163
|
};
|
|
163
164
|
function toOpenAPISchema(app, exclude, references, vendors) {
|
|
164
|
-
|
|
165
|
-
methods: excludeMethods = ["
|
|
165
|
+
let {
|
|
166
|
+
methods: excludeMethods = ["options"],
|
|
166
167
|
staticFile: excludeStaticFile = true,
|
|
167
168
|
tags: excludeTags
|
|
168
169
|
} = exclude ?? {};
|
|
170
|
+
excludeMethods = excludeMethods.map((method) => method.toLowerCase());
|
|
169
171
|
const excludePaths = Array.isArray(exclude?.paths) ? exclude.paths : typeof exclude?.paths !== "undefined" ? [exclude.paths] : [];
|
|
170
172
|
const paths = /* @__PURE__ */ Object.create(null);
|
|
171
173
|
const definitions = app.getGlobalDefinitions?.().type;
|
|
@@ -183,6 +185,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
183
185
|
if (excludeStaticFile && route.path.includes(".") || excludePaths.includes(route.path) || excludeMethods.includes(method))
|
|
184
186
|
continue;
|
|
185
187
|
const hooks = route.hooks ?? {};
|
|
188
|
+
if (route.path === "/a") {
|
|
189
|
+
console.log("H");
|
|
190
|
+
}
|
|
186
191
|
if (references?.length)
|
|
187
192
|
for (const reference of references) {
|
|
188
193
|
if (!reference) continue;
|
|
@@ -231,7 +236,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
231
236
|
});
|
|
232
237
|
}
|
|
233
238
|
if (hooks.query) {
|
|
234
|
-
const query = unwrapReference(
|
|
239
|
+
const query = unwrapReference(
|
|
240
|
+
unwrapSchema(hooks.query, vendors),
|
|
241
|
+
definitions
|
|
242
|
+
);
|
|
235
243
|
if (query && query.type === "object" && query.properties) {
|
|
236
244
|
const required = query.required || [];
|
|
237
245
|
for (const [queryName, querySchema] of Object.entries(
|
|
@@ -246,7 +254,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
246
254
|
}
|
|
247
255
|
}
|
|
248
256
|
if (hooks.headers) {
|
|
249
|
-
const headers = unwrapReference(
|
|
257
|
+
const headers = unwrapReference(
|
|
258
|
+
unwrapSchema(hooks.query, vendors),
|
|
259
|
+
definitions
|
|
260
|
+
);
|
|
250
261
|
if (headers && headers.type === "object" && headers.properties) {
|
|
251
262
|
const required = headers.required || [];
|
|
252
263
|
for (const [headerName, headerSchema] of Object.entries(
|
|
@@ -261,7 +272,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
261
272
|
}
|
|
262
273
|
}
|
|
263
274
|
if (hooks.cookie) {
|
|
264
|
-
const cookie = unwrapReference(
|
|
275
|
+
const cookie = unwrapReference(
|
|
276
|
+
unwrapSchema(hooks.cookie, vendors),
|
|
277
|
+
definitions
|
|
278
|
+
);
|
|
265
279
|
if (cookie && cookie.type === "object" && cookie.properties) {
|
|
266
280
|
const required = cookie.required || [];
|
|
267
281
|
for (const [cookieName, cookieSchema] of Object.entries(
|
package/dist/gen/index.d.ts
CHANGED
|
@@ -46,6 +46,11 @@ interface OpenAPIGeneratorOptions {
|
|
|
46
46
|
* ! be careful that the folder will be removed after the process ends
|
|
47
47
|
*/
|
|
48
48
|
tmpRoot?: string;
|
|
49
|
+
/**
|
|
50
|
+
* disable log
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
silent?: boolean;
|
|
49
54
|
}
|
|
50
55
|
/**
|
|
51
56
|
* Auto generate OpenAPI schema from Elysia instance
|
|
@@ -60,5 +65,5 @@ export declare const fromTypes: (
|
|
|
60
65
|
*
|
|
61
66
|
* The path must export an Elysia instance
|
|
62
67
|
*/
|
|
63
|
-
targetFilePath: string, { tsconfigPath, instanceName, projectRoot, overrideOutputPath, debug, compilerOptions, tmpRoot }?: OpenAPIGeneratorOptions) => () => AdditionalReference | undefined;
|
|
68
|
+
targetFilePath: string, { tsconfigPath, instanceName, projectRoot, overrideOutputPath, debug, compilerOptions, tmpRoot, silent }?: OpenAPIGeneratorOptions) => () => AdditionalReference | undefined;
|
|
64
69
|
export {};
|
package/dist/gen/index.mjs
CHANGED
|
@@ -8304,6 +8304,35 @@ import { spawnSync } from "child_process";
|
|
|
8304
8304
|
var matchRoute = /: Elysia<(.*)>/gs;
|
|
8305
8305
|
var matchStatus = /(\d{3}):/g;
|
|
8306
8306
|
var wrapStatusInQuote = (value) => value.replace(matchStatus, '"$1":');
|
|
8307
|
+
function extractRootObjects(code) {
|
|
8308
|
+
const results = [];
|
|
8309
|
+
let i = 0;
|
|
8310
|
+
while (i < code.length) {
|
|
8311
|
+
const colonIdx = code.indexOf(":", i);
|
|
8312
|
+
if (colonIdx === -1) break;
|
|
8313
|
+
let keyEnd = colonIdx - 1;
|
|
8314
|
+
while (keyEnd >= 0 && /\s/.test(code[keyEnd])) keyEnd--;
|
|
8315
|
+
let keyStart = keyEnd;
|
|
8316
|
+
while (keyStart >= 0 && /\w/.test(code[keyStart])) keyStart--;
|
|
8317
|
+
const braceIdx = code.indexOf("{", colonIdx);
|
|
8318
|
+
if (braceIdx === -1) break;
|
|
8319
|
+
let depth = 0;
|
|
8320
|
+
let end = braceIdx;
|
|
8321
|
+
for (; end < code.length; end++) {
|
|
8322
|
+
if (code[end] === "{") depth++;
|
|
8323
|
+
else if (code[end] === "}") {
|
|
8324
|
+
depth--;
|
|
8325
|
+
if (depth === 0) {
|
|
8326
|
+
end++;
|
|
8327
|
+
break;
|
|
8328
|
+
}
|
|
8329
|
+
}
|
|
8330
|
+
}
|
|
8331
|
+
results.push(`{${code.slice(keyStart + 1, end)};}`);
|
|
8332
|
+
i = end;
|
|
8333
|
+
}
|
|
8334
|
+
return results;
|
|
8335
|
+
}
|
|
8307
8336
|
var fromTypes = (targetFilePath, {
|
|
8308
8337
|
tsconfigPath = "tsconfig.json",
|
|
8309
8338
|
instanceName,
|
|
@@ -8311,7 +8340,8 @@ var fromTypes = (targetFilePath, {
|
|
|
8311
8340
|
overrideOutputPath,
|
|
8312
8341
|
debug = false,
|
|
8313
8342
|
compilerOptions,
|
|
8314
|
-
tmpRoot = join(tmpdir(), ".ElysiaAutoOpenAPI")
|
|
8343
|
+
tmpRoot = join(tmpdir(), ".ElysiaAutoOpenAPI"),
|
|
8344
|
+
silent = false
|
|
8315
8345
|
} = {}) => () => {
|
|
8316
8346
|
try {
|
|
8317
8347
|
if (!targetFilePath.endsWith(".ts") && !targetFilePath.endsWith(".tsx"))
|
|
@@ -8358,7 +8388,7 @@ var fromTypes = (targetFilePath, {
|
|
|
8358
8388
|
spawnSync(`tsc`, {
|
|
8359
8389
|
shell: true,
|
|
8360
8390
|
cwd: tmpRoot,
|
|
8361
|
-
stdio:
|
|
8391
|
+
stdio: silent ? void 0 : "inherit"
|
|
8362
8392
|
});
|
|
8363
8393
|
const fileName = targetFilePath.replace(/.tsx$/, ".ts").replace(/.ts$/, ".d.ts");
|
|
8364
8394
|
targetFile = (overrideOutputPath ? typeof overrideOutputPath === "string" ? overrideOutputPath.startsWith("/") ? overrideOutputPath : join(tmpRoot, "dist", overrideOutputPath) : overrideOutputPath(tmpRoot) : void 0) ?? join(
|
|
@@ -8394,7 +8424,7 @@ var fromTypes = (targetFilePath, {
|
|
|
8394
8424
|
console.warn(tempFiles);
|
|
8395
8425
|
}
|
|
8396
8426
|
} else {
|
|
8397
|
-
console.
|
|
8427
|
+
console.warn(
|
|
8398
8428
|
"reason: root folder doesn't exists",
|
|
8399
8429
|
join(tmpRoot, "dist")
|
|
8400
8430
|
);
|
|
@@ -8403,7 +8433,7 @@ var fromTypes = (targetFilePath, {
|
|
|
8403
8433
|
}
|
|
8404
8434
|
}
|
|
8405
8435
|
const declaration = readFileSync(targetFile, "utf8");
|
|
8406
|
-
if (existsSync(tmpRoot))
|
|
8436
|
+
if (!debug && existsSync(tmpRoot))
|
|
8407
8437
|
rmSync(tmpRoot, { recursive: true, force: true });
|
|
8408
8438
|
let instance = declaration.match(
|
|
8409
8439
|
instanceName ? new RegExp(`${instanceName}: Elysia<(.*)`, "gs") : matchRoute
|
|
@@ -8423,8 +8453,8 @@ var fromTypes = (targetFilePath, {
|
|
|
8423
8453
|
instance.slice(3, instance.indexOf("}, {", 4))
|
|
8424
8454
|
);
|
|
8425
8455
|
const routes = {};
|
|
8426
|
-
for (const route of routesString
|
|
8427
|
-
let schema = TypeBox(
|
|
8456
|
+
for (const route of extractRootObjects(routesString)) {
|
|
8457
|
+
let schema = TypeBox(route);
|
|
8428
8458
|
if (schema.type !== "object") continue;
|
|
8429
8459
|
const paths = [];
|
|
8430
8460
|
while (true) {
|
|
@@ -8435,6 +8465,7 @@ var fromTypes = (targetFilePath, {
|
|
|
8435
8465
|
if (!schema?.properties) break;
|
|
8436
8466
|
}
|
|
8437
8467
|
const method = paths.pop();
|
|
8468
|
+
if (!method) continue;
|
|
8438
8469
|
const path = "/" + paths.join("/");
|
|
8439
8470
|
schema = schema.properties;
|
|
8440
8471
|
if (schema?.response?.type === "object") {
|
package/dist/index.mjs
CHANGED
|
@@ -313,7 +313,8 @@ openapi({
|
|
|
313
313
|
zod: zodToJsonSchema
|
|
314
314
|
}
|
|
315
315
|
})`,
|
|
316
|
-
valibot: `import
|
|
316
|
+
valibot: `import openapi from '@elysiajs/openapi'
|
|
317
|
+
import { toJsonSchema } from '@valibot/to-json-schema'
|
|
317
318
|
|
|
318
319
|
openapi({
|
|
319
320
|
mapJsonSchema: {
|
|
@@ -391,11 +392,12 @@ var unwrapSchema = (schema, mapJsonSchema) => {
|
|
|
391
392
|
return schema.toJSONSchema?.() ?? schema?.toJsonSchema?.();
|
|
392
393
|
};
|
|
393
394
|
function toOpenAPISchema(app, exclude, references, vendors) {
|
|
394
|
-
|
|
395
|
-
methods: excludeMethods = ["
|
|
395
|
+
let {
|
|
396
|
+
methods: excludeMethods = ["options"],
|
|
396
397
|
staticFile: excludeStaticFile = true,
|
|
397
398
|
tags: excludeTags
|
|
398
399
|
} = exclude ?? {};
|
|
400
|
+
excludeMethods = excludeMethods.map((method) => method.toLowerCase());
|
|
399
401
|
const excludePaths = Array.isArray(exclude?.paths) ? exclude.paths : typeof exclude?.paths !== "undefined" ? [exclude.paths] : [];
|
|
400
402
|
const paths = /* @__PURE__ */ Object.create(null);
|
|
401
403
|
const definitions = app.getGlobalDefinitions?.().type;
|
|
@@ -413,6 +415,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
413
415
|
if (excludeStaticFile && route.path.includes(".") || excludePaths.includes(route.path) || excludeMethods.includes(method))
|
|
414
416
|
continue;
|
|
415
417
|
const hooks = route.hooks ?? {};
|
|
418
|
+
if (route.path === "/a") {
|
|
419
|
+
console.log("H");
|
|
420
|
+
}
|
|
416
421
|
if (references?.length)
|
|
417
422
|
for (const reference of references) {
|
|
418
423
|
if (!reference) continue;
|
|
@@ -461,7 +466,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
461
466
|
});
|
|
462
467
|
}
|
|
463
468
|
if (hooks.query) {
|
|
464
|
-
const query = unwrapReference(
|
|
469
|
+
const query = unwrapReference(
|
|
470
|
+
unwrapSchema(hooks.query, vendors),
|
|
471
|
+
definitions
|
|
472
|
+
);
|
|
465
473
|
if (query && query.type === "object" && query.properties) {
|
|
466
474
|
const required = query.required || [];
|
|
467
475
|
for (const [queryName, querySchema] of Object.entries(
|
|
@@ -476,7 +484,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
476
484
|
}
|
|
477
485
|
}
|
|
478
486
|
if (hooks.headers) {
|
|
479
|
-
const headers = unwrapReference(
|
|
487
|
+
const headers = unwrapReference(
|
|
488
|
+
unwrapSchema(hooks.query, vendors),
|
|
489
|
+
definitions
|
|
490
|
+
);
|
|
480
491
|
if (headers && headers.type === "object" && headers.properties) {
|
|
481
492
|
const required = headers.required || [];
|
|
482
493
|
for (const [headerName, headerSchema] of Object.entries(
|
|
@@ -491,7 +502,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
491
502
|
}
|
|
492
503
|
}
|
|
493
504
|
if (hooks.cookie) {
|
|
494
|
-
const cookie = unwrapReference(
|
|
505
|
+
const cookie = unwrapReference(
|
|
506
|
+
unwrapSchema(hooks.cookie, vendors),
|
|
507
|
+
definitions
|
|
508
|
+
);
|
|
495
509
|
if (cookie && cookie.type === "object" && cookie.properties) {
|
|
496
510
|
const required = cookie.required || [];
|
|
497
511
|
for (const [cookieName, cookieSchema] of Object.entries(
|
package/dist/openapi.mjs
CHANGED
|
@@ -54,7 +54,8 @@ openapi({
|
|
|
54
54
|
zod: zodToJsonSchema
|
|
55
55
|
}
|
|
56
56
|
})`,
|
|
57
|
-
valibot: `import
|
|
57
|
+
valibot: `import openapi from '@elysiajs/openapi'
|
|
58
|
+
import { toJsonSchema } from '@valibot/to-json-schema'
|
|
58
59
|
|
|
59
60
|
openapi({
|
|
60
61
|
mapJsonSchema: {
|
|
@@ -132,11 +133,12 @@ var unwrapSchema = (schema, mapJsonSchema) => {
|
|
|
132
133
|
return schema.toJSONSchema?.() ?? schema?.toJsonSchema?.();
|
|
133
134
|
};
|
|
134
135
|
function toOpenAPISchema(app, exclude, references, vendors) {
|
|
135
|
-
|
|
136
|
-
methods: excludeMethods = ["
|
|
136
|
+
let {
|
|
137
|
+
methods: excludeMethods = ["options"],
|
|
137
138
|
staticFile: excludeStaticFile = true,
|
|
138
139
|
tags: excludeTags
|
|
139
140
|
} = exclude ?? {};
|
|
141
|
+
excludeMethods = excludeMethods.map((method) => method.toLowerCase());
|
|
140
142
|
const excludePaths = Array.isArray(exclude?.paths) ? exclude.paths : typeof exclude?.paths !== "undefined" ? [exclude.paths] : [];
|
|
141
143
|
const paths = /* @__PURE__ */ Object.create(null);
|
|
142
144
|
const definitions = app.getGlobalDefinitions?.().type;
|
|
@@ -154,6 +156,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
154
156
|
if (excludeStaticFile && route.path.includes(".") || excludePaths.includes(route.path) || excludeMethods.includes(method))
|
|
155
157
|
continue;
|
|
156
158
|
const hooks = route.hooks ?? {};
|
|
159
|
+
if (route.path === "/a") {
|
|
160
|
+
console.log("H");
|
|
161
|
+
}
|
|
157
162
|
if (references?.length)
|
|
158
163
|
for (const reference of references) {
|
|
159
164
|
if (!reference) continue;
|
|
@@ -202,7 +207,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
202
207
|
});
|
|
203
208
|
}
|
|
204
209
|
if (hooks.query) {
|
|
205
|
-
const query = unwrapReference(
|
|
210
|
+
const query = unwrapReference(
|
|
211
|
+
unwrapSchema(hooks.query, vendors),
|
|
212
|
+
definitions
|
|
213
|
+
);
|
|
206
214
|
if (query && query.type === "object" && query.properties) {
|
|
207
215
|
const required = query.required || [];
|
|
208
216
|
for (const [queryName, querySchema] of Object.entries(
|
|
@@ -217,7 +225,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
217
225
|
}
|
|
218
226
|
}
|
|
219
227
|
if (hooks.headers) {
|
|
220
|
-
const headers = unwrapReference(
|
|
228
|
+
const headers = unwrapReference(
|
|
229
|
+
unwrapSchema(hooks.query, vendors),
|
|
230
|
+
definitions
|
|
231
|
+
);
|
|
221
232
|
if (headers && headers.type === "object" && headers.properties) {
|
|
222
233
|
const required = headers.required || [];
|
|
223
234
|
for (const [headerName, headerSchema] of Object.entries(
|
|
@@ -232,7 +243,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
|
|
|
232
243
|
}
|
|
233
244
|
}
|
|
234
245
|
if (hooks.cookie) {
|
|
235
|
-
const cookie = unwrapReference(
|
|
246
|
+
const cookie = unwrapReference(
|
|
247
|
+
unwrapSchema(hooks.cookie, vendors),
|
|
248
|
+
definitions
|
|
249
|
+
);
|
|
236
250
|
if (cookie && cookie.type === "object" && cookie.properties) {
|
|
237
251
|
const required = cookie.required || [];
|
|
238
252
|
for (const [cookieName, cookieSchema] of Object.entries(
|