@elysiajs/openapi 1.3.3 → 1.3.5

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
@@ -286,6 +286,15 @@ var ScalarRender = (info, config) => `<!doctype html>
286
286
 
287
287
  // src/openapi.ts
288
288
  var import_elysia = require("elysia");
289
+
290
+ // node_modules/@sinclair/typebox/build/esm/type/symbols/symbols.mjs
291
+ var TransformKind = Symbol.for("TypeBox.Transform");
292
+ var ReadonlyKind = Symbol.for("TypeBox.Readonly");
293
+ var OptionalKind = Symbol.for("TypeBox.Optional");
294
+ var Hint = Symbol.for("TypeBox.Hint");
295
+ var Kind = Symbol.for("TypeBox.Kind");
296
+
297
+ // src/openapi.ts
289
298
  var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
290
299
  var toRef = (name) => import_elysia.t.Ref(`#/components/schemas/${name}`);
291
300
  var toOperationId = (method, paths) => {
@@ -308,6 +317,7 @@ var getPossiblePath = (path) => {
308
317
  }
309
318
  return paths;
310
319
  };
320
+ var isValidSchema = (schema) => typeof schema === "object" && (Kind in schema && schema[Kind] !== "Unknown" || schema.type || schema.properties || schema.items);
311
321
  function toOpenAPISchema(app, exclude, references) {
312
322
  const {
313
323
  methods: excludeMethods = ["OPTIONS"],
@@ -334,18 +344,23 @@ function toOpenAPISchema(app, exclude, references) {
334
344
  for (const reference of references) {
335
345
  const refer = reference[route.path]?.[method];
336
346
  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)
347
+ if (!hooks.body && isValidSchema(refer.body))
348
+ hooks.body = refer.body;
349
+ if (!hooks.query && isValidSchema(refer.query))
350
+ hooks.query = refer.query;
351
+ if (!hooks.params && isValidSchema(refer.params))
352
+ hooks.params = refer.params;
353
+ if (!hooks.headers && isValidSchema(refer.headers))
341
354
  hooks.headers = refer.headers;
342
- if (!hooks.response && refer.response) {
343
- hooks.response = {};
355
+ if (refer.response) {
344
356
  for (const [status, schema] of Object.entries(
345
357
  refer.response
346
358
  ))
347
- if (!hooks.response[status])
348
- hooks.response[status] = schema;
359
+ if (isValidSchema(schema)) {
360
+ if (!hooks.response) hooks.response = {};
361
+ if (!hooks.response[status])
362
+ hooks.response[status] = schema;
363
+ }
349
364
  }
350
365
  }
351
366
  if (excludeTags && hooks.detail.tags?.some((tag) => excludeTags?.includes(tag)))
@@ -419,7 +434,7 @@ function toOpenAPISchema(app, exclude, references) {
419
434
  }
420
435
  }
421
436
  if (parameters.length > 0) operation.parameters = parameters;
422
- if (hooks.body) {
437
+ if (hooks.body && method !== "get" && method !== "head") {
423
438
  if (typeof hooks.body === "string") hooks.body = toRef(hooks.body);
424
439
  if (hooks.parse) {
425
440
  const content = {};
@@ -1,6 +1,6 @@
1
1
  import { type AnyElysia, type TSchema } from 'elysia';
2
2
  import type { OpenAPIV3 } from 'openapi-types';
3
- import type { TProperties } from '@sinclair/typebox';
3
+ import { type TProperties } from '@sinclair/typebox';
4
4
  import type { AdditionalReferences, ElysiaOpenAPIConfig } from './types';
5
5
  export declare const capitalize: (word: string) => string;
6
6
  /**
@@ -27,6 +27,15 @@ __export(openapi_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(openapi_exports);
29
29
  var import_elysia = require("elysia");
30
+
31
+ // node_modules/@sinclair/typebox/build/esm/type/symbols/symbols.mjs
32
+ var TransformKind = Symbol.for("TypeBox.Transform");
33
+ var ReadonlyKind = Symbol.for("TypeBox.Readonly");
34
+ var OptionalKind = Symbol.for("TypeBox.Optional");
35
+ var Hint = Symbol.for("TypeBox.Hint");
36
+ var Kind = Symbol.for("TypeBox.Kind");
37
+
38
+ // src/openapi.ts
30
39
  var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
31
40
  var toRef = (name) => import_elysia.t.Ref(`#/components/schemas/${name}`);
32
41
  var toOperationId = (method, paths) => {
@@ -49,6 +58,7 @@ var getPossiblePath = (path) => {
49
58
  }
50
59
  return paths;
51
60
  };
61
+ var isValidSchema = (schema) => typeof schema === "object" && (Kind in schema && schema[Kind] !== "Unknown" || schema.type || schema.properties || schema.items);
52
62
  function toOpenAPISchema(app, exclude, references) {
53
63
  const {
54
64
  methods: excludeMethods = ["OPTIONS"],
@@ -75,18 +85,23 @@ function toOpenAPISchema(app, exclude, references) {
75
85
  for (const reference of references) {
76
86
  const refer = reference[route.path]?.[method];
77
87
  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)
88
+ if (!hooks.body && isValidSchema(refer.body))
89
+ hooks.body = refer.body;
90
+ if (!hooks.query && isValidSchema(refer.query))
91
+ hooks.query = refer.query;
92
+ if (!hooks.params && isValidSchema(refer.params))
93
+ hooks.params = refer.params;
94
+ if (!hooks.headers && isValidSchema(refer.headers))
82
95
  hooks.headers = refer.headers;
83
- if (!hooks.response && refer.response) {
84
- hooks.response = {};
96
+ if (refer.response) {
85
97
  for (const [status, schema] of Object.entries(
86
98
  refer.response
87
99
  ))
88
- if (!hooks.response[status])
89
- hooks.response[status] = schema;
100
+ if (isValidSchema(schema)) {
101
+ if (!hooks.response) hooks.response = {};
102
+ if (!hooks.response[status])
103
+ hooks.response[status] = schema;
104
+ }
90
105
  }
91
106
  }
92
107
  if (excludeTags && hooks.detail.tags?.some((tag) => excludeTags?.includes(tag)))
@@ -160,7 +175,7 @@ function toOpenAPISchema(app, exclude, references) {
160
175
  }
161
176
  }
162
177
  if (parameters.length > 0) operation.parameters = parameters;
163
- if (hooks.body) {
178
+ if (hooks.body && method !== "get" && method !== "head") {
164
179
  if (typeof hooks.body === "string") hooks.body = toRef(hooks.body);
165
180
  if (hooks.parse) {
166
181
  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
@@ -259,6 +259,15 @@ var ScalarRender = (info, config) => `<!doctype html>
259
259
 
260
260
  // src/openapi.ts
261
261
  import { t } from "elysia";
262
+
263
+ // node_modules/@sinclair/typebox/build/esm/type/symbols/symbols.mjs
264
+ var TransformKind = Symbol.for("TypeBox.Transform");
265
+ var ReadonlyKind = Symbol.for("TypeBox.Readonly");
266
+ var OptionalKind = Symbol.for("TypeBox.Optional");
267
+ var Hint = Symbol.for("TypeBox.Hint");
268
+ var Kind = Symbol.for("TypeBox.Kind");
269
+
270
+ // src/openapi.ts
262
271
  var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
263
272
  var toRef = (name) => t.Ref(`#/components/schemas/${name}`);
264
273
  var toOperationId = (method, paths) => {
@@ -281,6 +290,7 @@ var getPossiblePath = (path) => {
281
290
  }
282
291
  return paths;
283
292
  };
293
+ var isValidSchema = (schema) => typeof schema === "object" && (Kind in schema && schema[Kind] !== "Unknown" || schema.type || schema.properties || schema.items);
284
294
  function toOpenAPISchema(app, exclude, references) {
285
295
  const {
286
296
  methods: excludeMethods = ["OPTIONS"],
@@ -307,18 +317,23 @@ function toOpenAPISchema(app, exclude, references) {
307
317
  for (const reference of references) {
308
318
  const refer = reference[route.path]?.[method];
309
319
  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)
320
+ if (!hooks.body && isValidSchema(refer.body))
321
+ hooks.body = refer.body;
322
+ if (!hooks.query && isValidSchema(refer.query))
323
+ hooks.query = refer.query;
324
+ if (!hooks.params && isValidSchema(refer.params))
325
+ hooks.params = refer.params;
326
+ if (!hooks.headers && isValidSchema(refer.headers))
314
327
  hooks.headers = refer.headers;
315
- if (!hooks.response && refer.response) {
316
- hooks.response = {};
328
+ if (refer.response) {
317
329
  for (const [status, schema] of Object.entries(
318
330
  refer.response
319
331
  ))
320
- if (!hooks.response[status])
321
- hooks.response[status] = schema;
332
+ if (isValidSchema(schema)) {
333
+ if (!hooks.response) hooks.response = {};
334
+ if (!hooks.response[status])
335
+ hooks.response[status] = schema;
336
+ }
322
337
  }
323
338
  }
324
339
  if (excludeTags && hooks.detail.tags?.some((tag) => excludeTags?.includes(tag)))
@@ -392,7 +407,7 @@ function toOpenAPISchema(app, exclude, references) {
392
407
  }
393
408
  }
394
409
  if (parameters.length > 0) operation.parameters = parameters;
395
- if (hooks.body) {
410
+ if (hooks.body && method !== "get" && method !== "head") {
396
411
  if (typeof hooks.body === "string") hooks.body = toRef(hooks.body);
397
412
  if (hooks.parse) {
398
413
  const content = {};
package/dist/openapi.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type AnyElysia, type TSchema } from 'elysia';
2
2
  import type { OpenAPIV3 } from 'openapi-types';
3
- import type { TProperties } from '@sinclair/typebox';
3
+ import { type TProperties } from '@sinclair/typebox';
4
4
  import type { AdditionalReferences, ElysiaOpenAPIConfig } from './types';
5
5
  export declare const capitalize: (word: string) => string;
6
6
  /**
package/dist/openapi.mjs CHANGED
@@ -1,5 +1,14 @@
1
1
  // src/openapi.ts
2
2
  import { t } from "elysia";
3
+
4
+ // node_modules/@sinclair/typebox/build/esm/type/symbols/symbols.mjs
5
+ var TransformKind = Symbol.for("TypeBox.Transform");
6
+ var ReadonlyKind = Symbol.for("TypeBox.Readonly");
7
+ var OptionalKind = Symbol.for("TypeBox.Optional");
8
+ var Hint = Symbol.for("TypeBox.Hint");
9
+ var Kind = Symbol.for("TypeBox.Kind");
10
+
11
+ // src/openapi.ts
3
12
  var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
4
13
  var toRef = (name) => t.Ref(`#/components/schemas/${name}`);
5
14
  var toOperationId = (method, paths) => {
@@ -22,6 +31,7 @@ var getPossiblePath = (path) => {
22
31
  }
23
32
  return paths;
24
33
  };
34
+ var isValidSchema = (schema) => typeof schema === "object" && (Kind in schema && schema[Kind] !== "Unknown" || schema.type || schema.properties || schema.items);
25
35
  function toOpenAPISchema(app, exclude, references) {
26
36
  const {
27
37
  methods: excludeMethods = ["OPTIONS"],
@@ -48,18 +58,23 @@ function toOpenAPISchema(app, exclude, references) {
48
58
  for (const reference of references) {
49
59
  const refer = reference[route.path]?.[method];
50
60
  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)
61
+ if (!hooks.body && isValidSchema(refer.body))
62
+ hooks.body = refer.body;
63
+ if (!hooks.query && isValidSchema(refer.query))
64
+ hooks.query = refer.query;
65
+ if (!hooks.params && isValidSchema(refer.params))
66
+ hooks.params = refer.params;
67
+ if (!hooks.headers && isValidSchema(refer.headers))
55
68
  hooks.headers = refer.headers;
56
- if (!hooks.response && refer.response) {
57
- hooks.response = {};
69
+ if (refer.response) {
58
70
  for (const [status, schema] of Object.entries(
59
71
  refer.response
60
72
  ))
61
- if (!hooks.response[status])
62
- hooks.response[status] = schema;
73
+ if (isValidSchema(schema)) {
74
+ if (!hooks.response) hooks.response = {};
75
+ if (!hooks.response[status])
76
+ hooks.response[status] = schema;
77
+ }
63
78
  }
64
79
  }
65
80
  if (excludeTags && hooks.detail.tags?.some((tag) => excludeTags?.includes(tag)))
@@ -133,7 +148,7 @@ function toOpenAPISchema(app, exclude, references) {
133
148
  }
134
149
  }
135
150
  if (parameters.length > 0) operation.parameters = parameters;
136
- if (hooks.body) {
151
+ if (hooks.body && method !== "get" && method !== "head") {
137
152
  if (typeof hooks.body === "string") hooks.body = toRef(hooks.body);
138
153
  if (hooks.parse) {
139
154
  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.5",
4
4
  "description": "Plugin for Elysia to auto-generate API documentation",
5
5
  "author": {
6
6
  "name": "saltyAom",