@elysiajs/openapi 1.3.4 → 1.3.6-exp.0
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 +28 -9
- package/dist/cjs/openapi.d.ts +2 -1
- package/dist/cjs/openapi.js +30 -9
- package/dist/index.mjs +28 -9
- package/dist/openapi.d.ts +2 -1
- package/dist/openapi.mjs +29 -9
- package/package.json +1 -1
- package/bunfig.toml +0 -2
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,12 @@ 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);
|
|
321
|
+
var getLoosePath = (path) => {
|
|
322
|
+
if (path.charCodeAt(path.length - 1) === 47)
|
|
323
|
+
return path.slice(0, path.length - 1);
|
|
324
|
+
return path + "/";
|
|
325
|
+
};
|
|
311
326
|
function toOpenAPISchema(app, exclude, references) {
|
|
312
327
|
const {
|
|
313
328
|
methods: excludeMethods = ["OPTIONS"],
|
|
@@ -332,21 +347,25 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
332
347
|
const hooks = route.hooks ?? {};
|
|
333
348
|
if (references)
|
|
334
349
|
for (const reference of references) {
|
|
335
|
-
const refer = reference[route.path]?.[method];
|
|
350
|
+
const refer = reference[route.path]?.[method] ?? reference[getLoosePath(route.path)]?.[method];
|
|
336
351
|
if (!refer) continue;
|
|
337
|
-
if (!hooks.body && refer.body
|
|
338
|
-
|
|
339
|
-
if (!hooks.
|
|
352
|
+
if (!hooks.body && isValidSchema(refer.body))
|
|
353
|
+
hooks.body = refer.body;
|
|
354
|
+
if (!hooks.query && isValidSchema(refer.query))
|
|
355
|
+
hooks.query = refer.query;
|
|
356
|
+
if (!hooks.params && isValidSchema(refer.params))
|
|
340
357
|
hooks.params = refer.params;
|
|
341
|
-
if (!hooks.headers && refer.headers
|
|
358
|
+
if (!hooks.headers && isValidSchema(refer.headers))
|
|
342
359
|
hooks.headers = refer.headers;
|
|
343
|
-
if (
|
|
344
|
-
hooks.response = {};
|
|
360
|
+
if (refer.response) {
|
|
345
361
|
for (const [status, schema] of Object.entries(
|
|
346
362
|
refer.response
|
|
347
363
|
))
|
|
348
|
-
if (
|
|
349
|
-
hooks.response
|
|
364
|
+
if (isValidSchema(schema)) {
|
|
365
|
+
if (!hooks.response) hooks.response = {};
|
|
366
|
+
if (!hooks.response[status])
|
|
367
|
+
hooks.response[status] = schema;
|
|
368
|
+
}
|
|
350
369
|
}
|
|
351
370
|
}
|
|
352
371
|
if (excludeTags && hooks.detail.tags?.some((tag) => excludeTags?.includes(tag)))
|
package/dist/cjs/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
|
|
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
|
/**
|
|
@@ -9,6 +9,7 @@ export declare const capitalize: (word: string) => string;
|
|
|
9
9
|
* @returns {string[]} paths
|
|
10
10
|
*/
|
|
11
11
|
export declare const getPossiblePath: (path: string) => string[];
|
|
12
|
+
export declare const getLoosePath: (path: string) => string;
|
|
12
13
|
/**
|
|
13
14
|
* Converts Elysia routes to OpenAPI 3.0.3 paths schema
|
|
14
15
|
* @param routes Array of Elysia route objects
|
package/dist/cjs/openapi.js
CHANGED
|
@@ -21,12 +21,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var openapi_exports = {};
|
|
22
22
|
__export(openapi_exports, {
|
|
23
23
|
capitalize: () => capitalize,
|
|
24
|
+
getLoosePath: () => getLoosePath,
|
|
24
25
|
getPossiblePath: () => getPossiblePath,
|
|
25
26
|
toOpenAPISchema: () => toOpenAPISchema,
|
|
26
27
|
withHeaders: () => withHeaders
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(openapi_exports);
|
|
29
30
|
var import_elysia = require("elysia");
|
|
31
|
+
|
|
32
|
+
// node_modules/@sinclair/typebox/build/esm/type/symbols/symbols.mjs
|
|
33
|
+
var TransformKind = Symbol.for("TypeBox.Transform");
|
|
34
|
+
var ReadonlyKind = Symbol.for("TypeBox.Readonly");
|
|
35
|
+
var OptionalKind = Symbol.for("TypeBox.Optional");
|
|
36
|
+
var Hint = Symbol.for("TypeBox.Hint");
|
|
37
|
+
var Kind = Symbol.for("TypeBox.Kind");
|
|
38
|
+
|
|
39
|
+
// src/openapi.ts
|
|
30
40
|
var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
|
|
31
41
|
var toRef = (name) => import_elysia.t.Ref(`#/components/schemas/${name}`);
|
|
32
42
|
var toOperationId = (method, paths) => {
|
|
@@ -49,6 +59,12 @@ var getPossiblePath = (path) => {
|
|
|
49
59
|
}
|
|
50
60
|
return paths;
|
|
51
61
|
};
|
|
62
|
+
var isValidSchema = (schema) => typeof schema === "object" && (Kind in schema && schema[Kind] !== "Unknown" || schema.type || schema.properties || schema.items);
|
|
63
|
+
var getLoosePath = (path) => {
|
|
64
|
+
if (path.charCodeAt(path.length - 1) === 47)
|
|
65
|
+
return path.slice(0, path.length - 1);
|
|
66
|
+
return path + "/";
|
|
67
|
+
};
|
|
52
68
|
function toOpenAPISchema(app, exclude, references) {
|
|
53
69
|
const {
|
|
54
70
|
methods: excludeMethods = ["OPTIONS"],
|
|
@@ -73,21 +89,25 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
73
89
|
const hooks = route.hooks ?? {};
|
|
74
90
|
if (references)
|
|
75
91
|
for (const reference of references) {
|
|
76
|
-
const refer = reference[route.path]?.[method];
|
|
92
|
+
const refer = reference[route.path]?.[method] ?? reference[getLoosePath(route.path)]?.[method];
|
|
77
93
|
if (!refer) continue;
|
|
78
|
-
if (!hooks.body && refer.body
|
|
79
|
-
|
|
80
|
-
if (!hooks.
|
|
94
|
+
if (!hooks.body && isValidSchema(refer.body))
|
|
95
|
+
hooks.body = refer.body;
|
|
96
|
+
if (!hooks.query && isValidSchema(refer.query))
|
|
97
|
+
hooks.query = refer.query;
|
|
98
|
+
if (!hooks.params && isValidSchema(refer.params))
|
|
81
99
|
hooks.params = refer.params;
|
|
82
|
-
if (!hooks.headers && refer.headers
|
|
100
|
+
if (!hooks.headers && isValidSchema(refer.headers))
|
|
83
101
|
hooks.headers = refer.headers;
|
|
84
|
-
if (
|
|
85
|
-
hooks.response = {};
|
|
102
|
+
if (refer.response) {
|
|
86
103
|
for (const [status, schema] of Object.entries(
|
|
87
104
|
refer.response
|
|
88
105
|
))
|
|
89
|
-
if (
|
|
90
|
-
hooks.response
|
|
106
|
+
if (isValidSchema(schema)) {
|
|
107
|
+
if (!hooks.response) hooks.response = {};
|
|
108
|
+
if (!hooks.response[status])
|
|
109
|
+
hooks.response[status] = schema;
|
|
110
|
+
}
|
|
91
111
|
}
|
|
92
112
|
}
|
|
93
113
|
if (excludeTags && hooks.detail.tags?.some((tag) => excludeTags?.includes(tag)))
|
|
@@ -280,6 +300,7 @@ var withHeaders = (schema, headers) => Object.assign(schema, {
|
|
|
280
300
|
// Annotate the CommonJS export names for ESM import in node:
|
|
281
301
|
0 && (module.exports = {
|
|
282
302
|
capitalize,
|
|
303
|
+
getLoosePath,
|
|
283
304
|
getPossiblePath,
|
|
284
305
|
toOpenAPISchema,
|
|
285
306
|
withHeaders
|
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,12 @@ 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);
|
|
294
|
+
var getLoosePath = (path) => {
|
|
295
|
+
if (path.charCodeAt(path.length - 1) === 47)
|
|
296
|
+
return path.slice(0, path.length - 1);
|
|
297
|
+
return path + "/";
|
|
298
|
+
};
|
|
284
299
|
function toOpenAPISchema(app, exclude, references) {
|
|
285
300
|
const {
|
|
286
301
|
methods: excludeMethods = ["OPTIONS"],
|
|
@@ -305,21 +320,25 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
305
320
|
const hooks = route.hooks ?? {};
|
|
306
321
|
if (references)
|
|
307
322
|
for (const reference of references) {
|
|
308
|
-
const refer = reference[route.path]?.[method];
|
|
323
|
+
const refer = reference[route.path]?.[method] ?? reference[getLoosePath(route.path)]?.[method];
|
|
309
324
|
if (!refer) continue;
|
|
310
|
-
if (!hooks.body && refer.body
|
|
311
|
-
|
|
312
|
-
if (!hooks.
|
|
325
|
+
if (!hooks.body && isValidSchema(refer.body))
|
|
326
|
+
hooks.body = refer.body;
|
|
327
|
+
if (!hooks.query && isValidSchema(refer.query))
|
|
328
|
+
hooks.query = refer.query;
|
|
329
|
+
if (!hooks.params && isValidSchema(refer.params))
|
|
313
330
|
hooks.params = refer.params;
|
|
314
|
-
if (!hooks.headers && refer.headers
|
|
331
|
+
if (!hooks.headers && isValidSchema(refer.headers))
|
|
315
332
|
hooks.headers = refer.headers;
|
|
316
|
-
if (
|
|
317
|
-
hooks.response = {};
|
|
333
|
+
if (refer.response) {
|
|
318
334
|
for (const [status, schema] of Object.entries(
|
|
319
335
|
refer.response
|
|
320
336
|
))
|
|
321
|
-
if (
|
|
322
|
-
hooks.response
|
|
337
|
+
if (isValidSchema(schema)) {
|
|
338
|
+
if (!hooks.response) hooks.response = {};
|
|
339
|
+
if (!hooks.response[status])
|
|
340
|
+
hooks.response[status] = schema;
|
|
341
|
+
}
|
|
323
342
|
}
|
|
324
343
|
}
|
|
325
344
|
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
|
|
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
|
/**
|
|
@@ -9,6 +9,7 @@ export declare const capitalize: (word: string) => string;
|
|
|
9
9
|
* @returns {string[]} paths
|
|
10
10
|
*/
|
|
11
11
|
export declare const getPossiblePath: (path: string) => string[];
|
|
12
|
+
export declare const getLoosePath: (path: string) => string;
|
|
12
13
|
/**
|
|
13
14
|
* Converts Elysia routes to OpenAPI 3.0.3 paths schema
|
|
14
15
|
* @param routes Array of Elysia route objects
|
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,12 @@ 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);
|
|
35
|
+
var getLoosePath = (path) => {
|
|
36
|
+
if (path.charCodeAt(path.length - 1) === 47)
|
|
37
|
+
return path.slice(0, path.length - 1);
|
|
38
|
+
return path + "/";
|
|
39
|
+
};
|
|
25
40
|
function toOpenAPISchema(app, exclude, references) {
|
|
26
41
|
const {
|
|
27
42
|
methods: excludeMethods = ["OPTIONS"],
|
|
@@ -46,21 +61,25 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
46
61
|
const hooks = route.hooks ?? {};
|
|
47
62
|
if (references)
|
|
48
63
|
for (const reference of references) {
|
|
49
|
-
const refer = reference[route.path]?.[method];
|
|
64
|
+
const refer = reference[route.path]?.[method] ?? reference[getLoosePath(route.path)]?.[method];
|
|
50
65
|
if (!refer) continue;
|
|
51
|
-
if (!hooks.body && refer.body
|
|
52
|
-
|
|
53
|
-
if (!hooks.
|
|
66
|
+
if (!hooks.body && isValidSchema(refer.body))
|
|
67
|
+
hooks.body = refer.body;
|
|
68
|
+
if (!hooks.query && isValidSchema(refer.query))
|
|
69
|
+
hooks.query = refer.query;
|
|
70
|
+
if (!hooks.params && isValidSchema(refer.params))
|
|
54
71
|
hooks.params = refer.params;
|
|
55
|
-
if (!hooks.headers && refer.headers
|
|
72
|
+
if (!hooks.headers && isValidSchema(refer.headers))
|
|
56
73
|
hooks.headers = refer.headers;
|
|
57
|
-
if (
|
|
58
|
-
hooks.response = {};
|
|
74
|
+
if (refer.response) {
|
|
59
75
|
for (const [status, schema] of Object.entries(
|
|
60
76
|
refer.response
|
|
61
77
|
))
|
|
62
|
-
if (
|
|
63
|
-
hooks.response
|
|
78
|
+
if (isValidSchema(schema)) {
|
|
79
|
+
if (!hooks.response) hooks.response = {};
|
|
80
|
+
if (!hooks.response[status])
|
|
81
|
+
hooks.response[status] = schema;
|
|
82
|
+
}
|
|
64
83
|
}
|
|
65
84
|
}
|
|
66
85
|
if (excludeTags && hooks.detail.tags?.some((tag) => excludeTags?.includes(tag)))
|
|
@@ -252,6 +271,7 @@ var withHeaders = (schema, headers) => Object.assign(schema, {
|
|
|
252
271
|
});
|
|
253
272
|
export {
|
|
254
273
|
capitalize,
|
|
274
|
+
getLoosePath,
|
|
255
275
|
getPossiblePath,
|
|
256
276
|
toOpenAPISchema,
|
|
257
277
|
withHeaders
|
package/package.json
CHANGED
package/bunfig.toml
DELETED