@elysiajs/openapi 1.3.2 → 1.3.3

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.
@@ -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");
@@ -69,14 +70,15 @@ var fromTypes = (targetFilePath, {
69
70
  );
70
71
  exec(`tsc`, tmpRoot);
71
72
  try {
72
- const declaration = (0, import_fs.readFileSync)(
73
- (0, import_path.join)(
73
+ const fileName = targetFilePath.replace(/.tsx$/, ".ts").replace(/.ts$/, ".d.ts");
74
+ let targetFile = overrideOutputPath?.(tmpRoot) ?? (0, import_path.join)(tmpRoot, "dist", fileName);
75
+ if (!(0, import_fs.existsSync)(targetFile))
76
+ targetFile = (0, import_path.join)(
74
77
  tmpRoot,
75
78
  "dist",
76
- targetFilePath.replace(/.tsx$/, ".ts").replace(/.ts$/, ".d.ts")
77
- ),
78
- "utf8"
79
- );
79
+ fileName.slice(fileName.indexOf("/") + 1)
80
+ );
81
+ const declaration = (0, import_fs.readFileSync)(targetFile, "utf8");
80
82
  if ((0, import_fs.existsSync)(tmpRoot))
81
83
  (0, import_fs.rmSync)(tmpRoot, { recursive: true, force: true });
82
84
  let instance = declaration.match(
@@ -116,7 +118,7 @@ var fromTypes = (targetFilePath, {
116
118
  }
117
119
  return routes;
118
120
  } catch (error) {
119
- console.warn("Failed to generate OpenAPI schema");
121
+ console.warn("[@elysiajs/openapi/gen] Failed to generate OpenAPI schema");
120
122
  console.warn(error);
121
123
  return;
122
124
  }
@@ -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 {};
@@ -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");
@@ -51,14 +52,15 @@ var fromTypes = (targetFilePath, {
51
52
  );
52
53
  exec(`tsc`, tmpRoot);
53
54
  try {
54
- const declaration = readFileSync(
55
- join(
55
+ const fileName = targetFilePath.replace(/.tsx$/, ".ts").replace(/.ts$/, ".d.ts");
56
+ let targetFile = overrideOutputPath?.(tmpRoot) ?? join(tmpRoot, "dist", fileName);
57
+ if (!existsSync(targetFile))
58
+ targetFile = join(
56
59
  tmpRoot,
57
60
  "dist",
58
- targetFilePath.replace(/.tsx$/, ".ts").replace(/.ts$/, ".d.ts")
59
- ),
60
- "utf8"
61
- );
61
+ fileName.slice(fileName.indexOf("/") + 1)
62
+ );
63
+ const declaration = readFileSync(targetFile, "utf8");
62
64
  if (existsSync(tmpRoot))
63
65
  rmSync(tmpRoot, { recursive: true, force: true });
64
66
  let instance = declaration.match(
@@ -98,7 +100,7 @@ var fromTypes = (targetFilePath, {
98
100
  }
99
101
  return routes;
100
102
  } catch (error) {
101
- console.warn("Failed to generate OpenAPI schema");
103
+ console.warn("[@elysiajs/openapi/gen] Failed to generate OpenAPI schema");
102
104
  console.warn(error);
103
105
  return;
104
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elysiajs/openapi",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Plugin for Elysia to auto-generate API documentation",
5
5
  "author": {
6
6
  "name": "saltyAom",