@elysiajs/openapi 1.3.4 → 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.
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,19 +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?.type) hooks.body = refer.body;
338
- if (!hooks.query && refer.query?.type) hooks.query = refer.query;
339
- if (!hooks.params && refer.params?.type)
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))
340
352
  hooks.params = refer.params;
341
- if (!hooks.headers && refer.headers?.type)
353
+ if (!hooks.headers && isValidSchema(refer.headers))
342
354
  hooks.headers = refer.headers;
343
- if (!hooks.response && refer.response) {
344
- hooks.response = {};
355
+ if (refer.response) {
345
356
  for (const [status, schema] of Object.entries(
346
357
  refer.response
347
358
  ))
348
- if (!hooks.response[status] && schema?.type)
349
- 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
+ }
350
364
  }
351
365
  }
352
366
  if (excludeTags && hooks.detail.tags?.some((tag) => excludeTags?.includes(tag)))
@@ -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,19 +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?.type) hooks.body = refer.body;
79
- if (!hooks.query && refer.query?.type) hooks.query = refer.query;
80
- if (!hooks.params && refer.params?.type)
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))
81
93
  hooks.params = refer.params;
82
- if (!hooks.headers && refer.headers?.type)
94
+ if (!hooks.headers && isValidSchema(refer.headers))
83
95
  hooks.headers = refer.headers;
84
- if (!hooks.response && refer.response) {
85
- hooks.response = {};
96
+ if (refer.response) {
86
97
  for (const [status, schema] of Object.entries(
87
98
  refer.response
88
99
  ))
89
- if (!hooks.response[status] && schema?.type)
90
- 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
+ }
91
105
  }
92
106
  }
93
107
  if (excludeTags && hooks.detail.tags?.some((tag) => excludeTags?.includes(tag)))
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,19 +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?.type) hooks.body = refer.body;
311
- if (!hooks.query && refer.query?.type) hooks.query = refer.query;
312
- if (!hooks.params && refer.params?.type)
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))
313
325
  hooks.params = refer.params;
314
- if (!hooks.headers && refer.headers?.type)
326
+ if (!hooks.headers && isValidSchema(refer.headers))
315
327
  hooks.headers = refer.headers;
316
- if (!hooks.response && refer.response) {
317
- hooks.response = {};
328
+ if (refer.response) {
318
329
  for (const [status, schema] of Object.entries(
319
330
  refer.response
320
331
  ))
321
- if (!hooks.response[status] && schema?.type)
322
- 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
+ }
323
337
  }
324
338
  }
325
339
  if (excludeTags && hooks.detail.tags?.some((tag) => excludeTags?.includes(tag)))
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,19 +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?.type) hooks.body = refer.body;
52
- if (!hooks.query && refer.query?.type) hooks.query = refer.query;
53
- if (!hooks.params && refer.params?.type)
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))
54
66
  hooks.params = refer.params;
55
- if (!hooks.headers && refer.headers?.type)
67
+ if (!hooks.headers && isValidSchema(refer.headers))
56
68
  hooks.headers = refer.headers;
57
- if (!hooks.response && refer.response) {
58
- hooks.response = {};
69
+ if (refer.response) {
59
70
  for (const [status, schema] of Object.entries(
60
71
  refer.response
61
72
  ))
62
- if (!hooks.response[status] && schema?.type)
63
- 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
+ }
64
78
  }
65
79
  }
66
80
  if (excludeTags && hooks.detail.tags?.some((tag) => excludeTags?.includes(tag)))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elysiajs/openapi",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "Plugin for Elysia to auto-generate API documentation",
5
5
  "author": {
6
6
  "name": "saltyAom",