@elysiajs/openapi 1.3.2 → 1.3.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 +16 -9
- package/dist/cjs/index.js +7 -6
- package/dist/cjs/openapi.js +7 -6
- package/dist/gen/index.d.ts +8 -1
- package/dist/gen/index.mjs +16 -9
- package/dist/index.mjs +7 -6
- package/dist/openapi.mjs +7 -6
- package/package.json +1 -1
package/dist/cjs/gen/index.js
CHANGED
|
@@ -39,7 +39,8 @@ var exec = (command, cwd) => (0, import_child_process.spawnSync)(command, {
|
|
|
39
39
|
var fromTypes = (targetFilePath, {
|
|
40
40
|
tsconfigPath = "tsconfig.json",
|
|
41
41
|
instanceName,
|
|
42
|
-
projectRoot = process.cwd()
|
|
42
|
+
projectRoot = process.cwd(),
|
|
43
|
+
overrideOutputPath
|
|
43
44
|
} = {}) => () => {
|
|
44
45
|
if (!targetFilePath.endsWith(".ts") && !targetFilePath.endsWith(".tsx"))
|
|
45
46
|
throw new Error("Only .ts files are supported");
|
|
@@ -58,10 +59,11 @@ var fromTypes = (targetFilePath, {
|
|
|
58
59
|
"lib": ["ESNext"],
|
|
59
60
|
"module": "ESNext",
|
|
60
61
|
"noEmit": false,
|
|
62
|
+
"declaration": true,
|
|
63
|
+
"emitDeclarationOnly": true,
|
|
61
64
|
"moduleResolution": "bundler",
|
|
62
65
|
"skipLibCheck": true,
|
|
63
66
|
"skipDefaultLibCheck": true,
|
|
64
|
-
"emitDeclarationOnly": true,
|
|
65
67
|
"outDir": "./dist"
|
|
66
68
|
},
|
|
67
69
|
"include": ["${(0, import_path.join)(projectRoot, targetFilePath)}"]
|
|
@@ -69,14 +71,17 @@ var fromTypes = (targetFilePath, {
|
|
|
69
71
|
);
|
|
70
72
|
exec(`tsc`, tmpRoot);
|
|
71
73
|
try {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
+
const fileName = targetFilePath.replace(/.tsx$/, ".ts").replace(/.ts$/, ".d.ts");
|
|
75
|
+
let targetFile = overrideOutputPath?.(tmpRoot) ?? (0, import_path.join)(tmpRoot, "dist", fileName);
|
|
76
|
+
{
|
|
77
|
+
const _targetFile = (0, import_path.join)(
|
|
74
78
|
tmpRoot,
|
|
75
79
|
"dist",
|
|
76
|
-
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
fileName.slice(fileName.indexOf("/") + 1)
|
|
81
|
+
);
|
|
82
|
+
if ((0, import_fs.existsSync)(_targetFile)) targetFile = _targetFile;
|
|
83
|
+
}
|
|
84
|
+
const declaration = (0, import_fs.readFileSync)(targetFile, "utf8");
|
|
80
85
|
if ((0, import_fs.existsSync)(tmpRoot))
|
|
81
86
|
(0, import_fs.rmSync)(tmpRoot, { recursive: true, force: true });
|
|
82
87
|
let instance = declaration.match(
|
|
@@ -116,7 +121,9 @@ var fromTypes = (targetFilePath, {
|
|
|
116
121
|
}
|
|
117
122
|
return routes;
|
|
118
123
|
} catch (error) {
|
|
119
|
-
console.warn(
|
|
124
|
+
console.warn(
|
|
125
|
+
"[@elysiajs/openapi/gen] Failed to generate OpenAPI schema"
|
|
126
|
+
);
|
|
120
127
|
console.warn(error);
|
|
121
128
|
return;
|
|
122
129
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -334,17 +334,18 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
334
334
|
for (const reference of references) {
|
|
335
335
|
const refer = reference[route.path]?.[method];
|
|
336
336
|
if (!refer) continue;
|
|
337
|
-
if (!hooks.body && refer.body) hooks.body = refer.body;
|
|
338
|
-
if (!hooks.query && refer.query) hooks.query = refer.query;
|
|
339
|
-
if (!hooks.params && refer.params)
|
|
340
|
-
|
|
337
|
+
if (!hooks.body && refer.body?.type) hooks.body = refer.body;
|
|
338
|
+
if (!hooks.query && refer.query?.type) hooks.query = refer.query;
|
|
339
|
+
if (!hooks.params && refer.params?.type)
|
|
340
|
+
hooks.params = refer.params;
|
|
341
|
+
if (!hooks.headers && refer.headers?.type)
|
|
341
342
|
hooks.headers = refer.headers;
|
|
342
343
|
if (!hooks.response && refer.response) {
|
|
343
344
|
hooks.response = {};
|
|
344
345
|
for (const [status, schema] of Object.entries(
|
|
345
346
|
refer.response
|
|
346
347
|
))
|
|
347
|
-
if (!hooks.response[status])
|
|
348
|
+
if (!hooks.response[status] && schema?.type)
|
|
348
349
|
hooks.response[status] = schema;
|
|
349
350
|
}
|
|
350
351
|
}
|
|
@@ -419,7 +420,7 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
419
420
|
}
|
|
420
421
|
}
|
|
421
422
|
if (parameters.length > 0) operation.parameters = parameters;
|
|
422
|
-
if (hooks.body) {
|
|
423
|
+
if (hooks.body && method !== "get" && method !== "head") {
|
|
423
424
|
if (typeof hooks.body === "string") hooks.body = toRef(hooks.body);
|
|
424
425
|
if (hooks.parse) {
|
|
425
426
|
const content = {};
|
package/dist/cjs/openapi.js
CHANGED
|
@@ -75,17 +75,18 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
75
75
|
for (const reference of references) {
|
|
76
76
|
const refer = reference[route.path]?.[method];
|
|
77
77
|
if (!refer) continue;
|
|
78
|
-
if (!hooks.body && refer.body) hooks.body = refer.body;
|
|
79
|
-
if (!hooks.query && refer.query) hooks.query = refer.query;
|
|
80
|
-
if (!hooks.params && refer.params)
|
|
81
|
-
|
|
78
|
+
if (!hooks.body && refer.body?.type) hooks.body = refer.body;
|
|
79
|
+
if (!hooks.query && refer.query?.type) hooks.query = refer.query;
|
|
80
|
+
if (!hooks.params && refer.params?.type)
|
|
81
|
+
hooks.params = refer.params;
|
|
82
|
+
if (!hooks.headers && refer.headers?.type)
|
|
82
83
|
hooks.headers = refer.headers;
|
|
83
84
|
if (!hooks.response && refer.response) {
|
|
84
85
|
hooks.response = {};
|
|
85
86
|
for (const [status, schema] of Object.entries(
|
|
86
87
|
refer.response
|
|
87
88
|
))
|
|
88
|
-
if (!hooks.response[status])
|
|
89
|
+
if (!hooks.response[status] && schema?.type)
|
|
89
90
|
hooks.response[status] = schema;
|
|
90
91
|
}
|
|
91
92
|
}
|
|
@@ -160,7 +161,7 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
if (parameters.length > 0) operation.parameters = parameters;
|
|
163
|
-
if (hooks.body) {
|
|
164
|
+
if (hooks.body && method !== "get" && method !== "head") {
|
|
164
165
|
if (typeof hooks.body === "string") hooks.body = toRef(hooks.body);
|
|
165
166
|
if (hooks.parse) {
|
|
166
167
|
const content = {};
|
package/dist/gen/index.d.ts
CHANGED
|
@@ -18,6 +18,13 @@ interface OpenAPIGeneratorOptions {
|
|
|
18
18
|
* @default process.cwd()
|
|
19
19
|
*/
|
|
20
20
|
projectRoot?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Override output path
|
|
23
|
+
*
|
|
24
|
+
* Under any circumstance, that Elysia failed to find a correct schema,
|
|
25
|
+
* Put your own schema in this path
|
|
26
|
+
*/
|
|
27
|
+
overrideOutputPath?(tempDir: string): string;
|
|
21
28
|
}
|
|
22
29
|
/**
|
|
23
30
|
* Auto generate OpenAPI schema from Elysia instance
|
|
@@ -32,5 +39,5 @@ export declare const fromTypes: (
|
|
|
32
39
|
*
|
|
33
40
|
* The path must export an Elysia instance
|
|
34
41
|
*/
|
|
35
|
-
targetFilePath: string, { tsconfigPath, instanceName, projectRoot }?: OpenAPIGeneratorOptions) => () => AdditionalReference | undefined;
|
|
42
|
+
targetFilePath: string, { tsconfigPath, instanceName, projectRoot, overrideOutputPath }?: OpenAPIGeneratorOptions) => () => AdditionalReference | undefined;
|
|
36
43
|
export {};
|
package/dist/gen/index.mjs
CHANGED
|
@@ -21,7 +21,8 @@ var exec = (command, cwd) => spawnSync(command, {
|
|
|
21
21
|
var fromTypes = (targetFilePath, {
|
|
22
22
|
tsconfigPath = "tsconfig.json",
|
|
23
23
|
instanceName,
|
|
24
|
-
projectRoot = process.cwd()
|
|
24
|
+
projectRoot = process.cwd(),
|
|
25
|
+
overrideOutputPath
|
|
25
26
|
} = {}) => () => {
|
|
26
27
|
if (!targetFilePath.endsWith(".ts") && !targetFilePath.endsWith(".tsx"))
|
|
27
28
|
throw new Error("Only .ts files are supported");
|
|
@@ -40,10 +41,11 @@ var fromTypes = (targetFilePath, {
|
|
|
40
41
|
"lib": ["ESNext"],
|
|
41
42
|
"module": "ESNext",
|
|
42
43
|
"noEmit": false,
|
|
44
|
+
"declaration": true,
|
|
45
|
+
"emitDeclarationOnly": true,
|
|
43
46
|
"moduleResolution": "bundler",
|
|
44
47
|
"skipLibCheck": true,
|
|
45
48
|
"skipDefaultLibCheck": true,
|
|
46
|
-
"emitDeclarationOnly": true,
|
|
47
49
|
"outDir": "./dist"
|
|
48
50
|
},
|
|
49
51
|
"include": ["${join(projectRoot, targetFilePath)}"]
|
|
@@ -51,14 +53,17 @@ var fromTypes = (targetFilePath, {
|
|
|
51
53
|
);
|
|
52
54
|
exec(`tsc`, tmpRoot);
|
|
53
55
|
try {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
+
const fileName = targetFilePath.replace(/.tsx$/, ".ts").replace(/.ts$/, ".d.ts");
|
|
57
|
+
let targetFile = overrideOutputPath?.(tmpRoot) ?? join(tmpRoot, "dist", fileName);
|
|
58
|
+
{
|
|
59
|
+
const _targetFile = join(
|
|
56
60
|
tmpRoot,
|
|
57
61
|
"dist",
|
|
58
|
-
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
fileName.slice(fileName.indexOf("/") + 1)
|
|
63
|
+
);
|
|
64
|
+
if (existsSync(_targetFile)) targetFile = _targetFile;
|
|
65
|
+
}
|
|
66
|
+
const declaration = readFileSync(targetFile, "utf8");
|
|
62
67
|
if (existsSync(tmpRoot))
|
|
63
68
|
rmSync(tmpRoot, { recursive: true, force: true });
|
|
64
69
|
let instance = declaration.match(
|
|
@@ -98,7 +103,9 @@ var fromTypes = (targetFilePath, {
|
|
|
98
103
|
}
|
|
99
104
|
return routes;
|
|
100
105
|
} catch (error) {
|
|
101
|
-
console.warn(
|
|
106
|
+
console.warn(
|
|
107
|
+
"[@elysiajs/openapi/gen] Failed to generate OpenAPI schema"
|
|
108
|
+
);
|
|
102
109
|
console.warn(error);
|
|
103
110
|
return;
|
|
104
111
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -307,17 +307,18 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
307
307
|
for (const reference of references) {
|
|
308
308
|
const refer = reference[route.path]?.[method];
|
|
309
309
|
if (!refer) continue;
|
|
310
|
-
if (!hooks.body && refer.body) hooks.body = refer.body;
|
|
311
|
-
if (!hooks.query && refer.query) hooks.query = refer.query;
|
|
312
|
-
if (!hooks.params && refer.params)
|
|
313
|
-
|
|
310
|
+
if (!hooks.body && refer.body?.type) hooks.body = refer.body;
|
|
311
|
+
if (!hooks.query && refer.query?.type) hooks.query = refer.query;
|
|
312
|
+
if (!hooks.params && refer.params?.type)
|
|
313
|
+
hooks.params = refer.params;
|
|
314
|
+
if (!hooks.headers && refer.headers?.type)
|
|
314
315
|
hooks.headers = refer.headers;
|
|
315
316
|
if (!hooks.response && refer.response) {
|
|
316
317
|
hooks.response = {};
|
|
317
318
|
for (const [status, schema] of Object.entries(
|
|
318
319
|
refer.response
|
|
319
320
|
))
|
|
320
|
-
if (!hooks.response[status])
|
|
321
|
+
if (!hooks.response[status] && schema?.type)
|
|
321
322
|
hooks.response[status] = schema;
|
|
322
323
|
}
|
|
323
324
|
}
|
|
@@ -392,7 +393,7 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
392
393
|
}
|
|
393
394
|
}
|
|
394
395
|
if (parameters.length > 0) operation.parameters = parameters;
|
|
395
|
-
if (hooks.body) {
|
|
396
|
+
if (hooks.body && method !== "get" && method !== "head") {
|
|
396
397
|
if (typeof hooks.body === "string") hooks.body = toRef(hooks.body);
|
|
397
398
|
if (hooks.parse) {
|
|
398
399
|
const content = {};
|
package/dist/openapi.mjs
CHANGED
|
@@ -48,17 +48,18 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
48
48
|
for (const reference of references) {
|
|
49
49
|
const refer = reference[route.path]?.[method];
|
|
50
50
|
if (!refer) continue;
|
|
51
|
-
if (!hooks.body && refer.body) hooks.body = refer.body;
|
|
52
|
-
if (!hooks.query && refer.query) hooks.query = refer.query;
|
|
53
|
-
if (!hooks.params && refer.params)
|
|
54
|
-
|
|
51
|
+
if (!hooks.body && refer.body?.type) hooks.body = refer.body;
|
|
52
|
+
if (!hooks.query && refer.query?.type) hooks.query = refer.query;
|
|
53
|
+
if (!hooks.params && refer.params?.type)
|
|
54
|
+
hooks.params = refer.params;
|
|
55
|
+
if (!hooks.headers && refer.headers?.type)
|
|
55
56
|
hooks.headers = refer.headers;
|
|
56
57
|
if (!hooks.response && refer.response) {
|
|
57
58
|
hooks.response = {};
|
|
58
59
|
for (const [status, schema] of Object.entries(
|
|
59
60
|
refer.response
|
|
60
61
|
))
|
|
61
|
-
if (!hooks.response[status])
|
|
62
|
+
if (!hooks.response[status] && schema?.type)
|
|
62
63
|
hooks.response[status] = schema;
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -133,7 +134,7 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
if (parameters.length > 0) operation.parameters = parameters;
|
|
136
|
-
if (hooks.body) {
|
|
137
|
+
if (hooks.body && method !== "get" && method !== "head") {
|
|
137
138
|
if (typeof hooks.body === "string") hooks.body = toRef(hooks.body);
|
|
138
139
|
if (hooks.parse) {
|
|
139
140
|
const content = {};
|