@elysiajs/openapi 1.3.3 → 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.
@@ -59,10 +59,11 @@ var fromTypes = (targetFilePath, {
59
59
  "lib": ["ESNext"],
60
60
  "module": "ESNext",
61
61
  "noEmit": false,
62
+ "declaration": true,
63
+ "emitDeclarationOnly": true,
62
64
  "moduleResolution": "bundler",
63
65
  "skipLibCheck": true,
64
66
  "skipDefaultLibCheck": true,
65
- "emitDeclarationOnly": true,
66
67
  "outDir": "./dist"
67
68
  },
68
69
  "include": ["${(0, import_path.join)(projectRoot, targetFilePath)}"]
@@ -72,12 +73,14 @@ var fromTypes = (targetFilePath, {
72
73
  try {
73
74
  const fileName = targetFilePath.replace(/.tsx$/, ".ts").replace(/.ts$/, ".d.ts");
74
75
  let targetFile = overrideOutputPath?.(tmpRoot) ?? (0, import_path.join)(tmpRoot, "dist", fileName);
75
- if (!(0, import_fs.existsSync)(targetFile))
76
- targetFile = (0, import_path.join)(
76
+ {
77
+ const _targetFile = (0, import_path.join)(
77
78
  tmpRoot,
78
79
  "dist",
79
80
  fileName.slice(fileName.indexOf("/") + 1)
80
81
  );
82
+ if ((0, import_fs.existsSync)(_targetFile)) targetFile = _targetFile;
83
+ }
81
84
  const declaration = (0, import_fs.readFileSync)(targetFile, "utf8");
82
85
  if ((0, import_fs.existsSync)(tmpRoot))
83
86
  (0, import_fs.rmSync)(tmpRoot, { recursive: true, force: true });
@@ -118,7 +121,9 @@ var fromTypes = (targetFilePath, {
118
121
  }
119
122
  return routes;
120
123
  } catch (error) {
121
- console.warn("[@elysiajs/openapi/gen] Failed to generate OpenAPI schema");
124
+ console.warn(
125
+ "[@elysiajs/openapi/gen] Failed to generate OpenAPI schema"
126
+ );
122
127
  console.warn(error);
123
128
  return;
124
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) hooks.params = refer.params;
340
- if (!hooks.headers && refer.headers)
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 = {};
@@ -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) hooks.params = refer.params;
81
- if (!hooks.headers && refer.headers)
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 = {};
@@ -41,10 +41,11 @@ var fromTypes = (targetFilePath, {
41
41
  "lib": ["ESNext"],
42
42
  "module": "ESNext",
43
43
  "noEmit": false,
44
+ "declaration": true,
45
+ "emitDeclarationOnly": true,
44
46
  "moduleResolution": "bundler",
45
47
  "skipLibCheck": true,
46
48
  "skipDefaultLibCheck": true,
47
- "emitDeclarationOnly": true,
48
49
  "outDir": "./dist"
49
50
  },
50
51
  "include": ["${join(projectRoot, targetFilePath)}"]
@@ -54,12 +55,14 @@ var fromTypes = (targetFilePath, {
54
55
  try {
55
56
  const fileName = targetFilePath.replace(/.tsx$/, ".ts").replace(/.ts$/, ".d.ts");
56
57
  let targetFile = overrideOutputPath?.(tmpRoot) ?? join(tmpRoot, "dist", fileName);
57
- if (!existsSync(targetFile))
58
- targetFile = join(
58
+ {
59
+ const _targetFile = join(
59
60
  tmpRoot,
60
61
  "dist",
61
62
  fileName.slice(fileName.indexOf("/") + 1)
62
63
  );
64
+ if (existsSync(_targetFile)) targetFile = _targetFile;
65
+ }
63
66
  const declaration = readFileSync(targetFile, "utf8");
64
67
  if (existsSync(tmpRoot))
65
68
  rmSync(tmpRoot, { recursive: true, force: true });
@@ -100,7 +103,9 @@ var fromTypes = (targetFilePath, {
100
103
  }
101
104
  return routes;
102
105
  } catch (error) {
103
- console.warn("[@elysiajs/openapi/gen] Failed to generate OpenAPI schema");
106
+ console.warn(
107
+ "[@elysiajs/openapi/gen] Failed to generate OpenAPI schema"
108
+ );
104
109
  console.warn(error);
105
110
  return;
106
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) hooks.params = refer.params;
313
- if (!hooks.headers && refer.headers)
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) hooks.params = refer.params;
54
- if (!hooks.headers && refer.headers)
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 = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elysiajs/openapi",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "Plugin for Elysia to auto-generate API documentation",
5
5
  "author": {
6
6
  "name": "saltyAom",