@elysiajs/openapi 1.3.12 → 1.4.0-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/bun.lock +545 -537
- package/dist/cjs/gen/index.js +1 -1
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +122 -81
- package/dist/cjs/openapi.d.ts +7 -4
- package/dist/cjs/openapi.js +122 -79
- package/dist/gen/index.mjs +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +122 -81
- package/dist/openapi.d.ts +7 -4
- package/dist/openapi.mjs +121 -79
- package/package.json +92 -88
- package/bunfig.toml +0 -2
package/dist/cjs/gen/index.js
CHANGED
package/dist/cjs/index.d.ts
CHANGED
|
@@ -19,16 +19,19 @@ export declare const openapi: <const Enabled extends boolean = true, const Path
|
|
|
19
19
|
macro: {};
|
|
20
20
|
macroFn: {};
|
|
21
21
|
parser: {};
|
|
22
|
+
response: {};
|
|
22
23
|
}, {}, {
|
|
23
24
|
derive: {};
|
|
24
25
|
resolve: {};
|
|
25
26
|
schema: {};
|
|
26
27
|
standaloneSchema: {};
|
|
28
|
+
response: {};
|
|
27
29
|
}, {
|
|
28
30
|
derive: {};
|
|
29
31
|
resolve: {};
|
|
30
32
|
schema: {};
|
|
31
33
|
standaloneSchema: {};
|
|
34
|
+
response: {};
|
|
32
35
|
}>;
|
|
33
36
|
export { toOpenAPISchema, withHeaders } from './openapi';
|
|
34
37
|
export type { ElysiaOpenAPIConfig };
|
package/dist/cjs/index.js
CHANGED
|
@@ -295,6 +295,7 @@ var Hint = Symbol.for("TypeBox.Hint");
|
|
|
295
295
|
var Kind = Symbol.for("TypeBox.Kind");
|
|
296
296
|
|
|
297
297
|
// src/openapi.ts
|
|
298
|
+
var import_xsschema = require("xsschema");
|
|
298
299
|
var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
|
|
299
300
|
var toRef = (name) => import_elysia.t.Ref(`#/components/schemas/${name}`);
|
|
300
301
|
var toOperationId = (method, paths) => {
|
|
@@ -323,7 +324,14 @@ var getLoosePath = (path) => {
|
|
|
323
324
|
return path.slice(0, path.length - 1);
|
|
324
325
|
return path + "/";
|
|
325
326
|
};
|
|
326
|
-
|
|
327
|
+
var unwrapSchema = (schema) => {
|
|
328
|
+
if (!schema) return;
|
|
329
|
+
if (typeof schema === "string") schema = toRef(schema);
|
|
330
|
+
if (Kind in schema) return schema;
|
|
331
|
+
if (Kind in schema === false && schema["~standard"])
|
|
332
|
+
return (0, import_xsschema.toJsonSchema)(schema);
|
|
333
|
+
};
|
|
334
|
+
async function toOpenAPISchema(app, exclude, references) {
|
|
327
335
|
const {
|
|
328
336
|
methods: excludeMethods = ["OPTIONS"],
|
|
329
337
|
staticFile: excludeStaticFile = true,
|
|
@@ -376,11 +384,11 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
376
384
|
};
|
|
377
385
|
const parameters = [];
|
|
378
386
|
if (hooks.params) {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
if (
|
|
387
|
+
let params = unwrapSchema(hooks.params);
|
|
388
|
+
if (params) params = await params;
|
|
389
|
+
if (params && params.type === "object" && params.properties)
|
|
382
390
|
for (const [paramName, paramSchema] of Object.entries(
|
|
383
|
-
|
|
391
|
+
params.properties
|
|
384
392
|
))
|
|
385
393
|
parameters.push({
|
|
386
394
|
name: paramName,
|
|
@@ -389,15 +397,14 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
389
397
|
// Path parameters are always required
|
|
390
398
|
schema: paramSchema
|
|
391
399
|
});
|
|
392
|
-
}
|
|
393
400
|
}
|
|
394
401
|
if (hooks.query) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
if (
|
|
398
|
-
const required =
|
|
402
|
+
let query = unwrapSchema(hooks.query);
|
|
403
|
+
if (query) query = await query;
|
|
404
|
+
if (query && query.type === "object" && query.properties) {
|
|
405
|
+
const required = query.required || [];
|
|
399
406
|
for (const [queryName, querySchema] of Object.entries(
|
|
400
|
-
|
|
407
|
+
query.properties
|
|
401
408
|
))
|
|
402
409
|
parameters.push({
|
|
403
410
|
name: queryName,
|
|
@@ -408,12 +415,12 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
408
415
|
}
|
|
409
416
|
}
|
|
410
417
|
if (hooks.headers) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
if (
|
|
414
|
-
const required =
|
|
418
|
+
let headers = unwrapSchema(hooks.query);
|
|
419
|
+
if (headers) headers = await headers;
|
|
420
|
+
if (headers && headers.type === "object" && headers.properties) {
|
|
421
|
+
const required = headers.required || [];
|
|
415
422
|
for (const [headerName, headerSchema] of Object.entries(
|
|
416
|
-
|
|
423
|
+
headers.properties
|
|
417
424
|
))
|
|
418
425
|
parameters.push({
|
|
419
426
|
name: headerName,
|
|
@@ -424,12 +431,12 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
424
431
|
}
|
|
425
432
|
}
|
|
426
433
|
if (hooks.cookie) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
if (
|
|
430
|
-
const required =
|
|
434
|
+
let cookie = unwrapSchema(hooks.cookie);
|
|
435
|
+
if (cookie) cookie = await cookie;
|
|
436
|
+
if (cookie && cookie.type === "object" && cookie.properties) {
|
|
437
|
+
const required = cookie.required || [];
|
|
431
438
|
for (const [cookieName, cookieSchema] of Object.entries(
|
|
432
|
-
|
|
439
|
+
cookie.properties
|
|
433
440
|
))
|
|
434
441
|
parameters.push({
|
|
435
442
|
name: cookieName,
|
|
@@ -441,80 +448,107 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
441
448
|
}
|
|
442
449
|
if (parameters.length > 0) operation.parameters = parameters;
|
|
443
450
|
if (hooks.body && method !== "get" && method !== "head") {
|
|
444
|
-
|
|
445
|
-
if (
|
|
446
|
-
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
451
|
+
let body = unwrapSchema(hooks.body);
|
|
452
|
+
if (body) body = await body;
|
|
453
|
+
if (body) {
|
|
454
|
+
const { type: _type, description, ...options } = body;
|
|
455
|
+
const type = _type;
|
|
456
|
+
if (hooks.parse) {
|
|
457
|
+
const content = {};
|
|
458
|
+
const parsers = hooks.parse;
|
|
459
|
+
for (const parser of parsers) {
|
|
460
|
+
if (typeof parser.fn === "function") continue;
|
|
461
|
+
switch (parser.fn) {
|
|
462
|
+
case "text":
|
|
463
|
+
case "text/plain":
|
|
464
|
+
content["text/plain"] = { schema: body };
|
|
465
|
+
continue;
|
|
466
|
+
case "urlencoded":
|
|
467
|
+
case "application/x-www-form-urlencoded":
|
|
468
|
+
content["application/x-www-form-urlencoded"] = {
|
|
469
|
+
schema: body
|
|
470
|
+
};
|
|
471
|
+
continue;
|
|
472
|
+
case "json":
|
|
473
|
+
case "application/json":
|
|
474
|
+
content["application/json"] = { schema: body };
|
|
475
|
+
continue;
|
|
476
|
+
case "formdata":
|
|
477
|
+
case "multipart/form-data":
|
|
478
|
+
content["multipart/form-data"] = {
|
|
479
|
+
schema: body
|
|
480
|
+
};
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
471
483
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
"
|
|
481
|
-
|
|
484
|
+
operation.requestBody = {
|
|
485
|
+
description,
|
|
486
|
+
content,
|
|
487
|
+
required: true
|
|
488
|
+
};
|
|
489
|
+
} else {
|
|
490
|
+
operation.requestBody = {
|
|
491
|
+
description,
|
|
492
|
+
content: type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
|
|
493
|
+
"text/plain": body
|
|
494
|
+
} : {
|
|
495
|
+
"application/json": {
|
|
496
|
+
schema: body
|
|
497
|
+
},
|
|
498
|
+
"application/x-www-form-urlencoded": {
|
|
499
|
+
schema: body
|
|
500
|
+
},
|
|
501
|
+
"multipart/form-data": {
|
|
502
|
+
schema: body
|
|
503
|
+
}
|
|
482
504
|
},
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
},
|
|
487
|
-
required: true
|
|
488
|
-
};
|
|
505
|
+
required: true
|
|
506
|
+
};
|
|
507
|
+
}
|
|
489
508
|
}
|
|
490
509
|
}
|
|
491
510
|
if (hooks.response) {
|
|
492
511
|
operation.responses = {};
|
|
493
512
|
if (typeof hooks.response === "object" && !hooks.response.type && !hooks.response.$ref) {
|
|
494
513
|
for (let [status, schema] of Object.entries(hooks.response)) {
|
|
495
|
-
|
|
496
|
-
|
|
514
|
+
let response = unwrapSchema(schema);
|
|
515
|
+
if (response) response = await response;
|
|
516
|
+
if (!response) continue;
|
|
517
|
+
const { type: _type, description, ...options } = response;
|
|
518
|
+
const type = _type;
|
|
497
519
|
operation.responses[status] = {
|
|
498
|
-
description: `Response for status ${status}`,
|
|
520
|
+
description: description ?? `Response for status ${status}`,
|
|
499
521
|
...options,
|
|
500
|
-
content: type === "void" || type === "null" || type === "undefined" ?
|
|
522
|
+
content: type === "void" || type === "null" || type === "undefined" ? response : type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
|
|
523
|
+
"text/plain": {
|
|
524
|
+
schema: response
|
|
525
|
+
}
|
|
526
|
+
} : {
|
|
501
527
|
"application/json": {
|
|
502
|
-
schema
|
|
528
|
+
schema: response
|
|
503
529
|
}
|
|
504
530
|
}
|
|
505
531
|
};
|
|
506
532
|
}
|
|
507
533
|
} else {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
534
|
+
let response = unwrapSchema(hooks.response);
|
|
535
|
+
if (response) response = await response;
|
|
536
|
+
if (response) {
|
|
537
|
+
const { type: _type, description, ...options } = response;
|
|
538
|
+
const type = _type;
|
|
539
|
+
operation.responses["200"] = {
|
|
540
|
+
description: description ?? `Response for status 200`,
|
|
541
|
+
content: type === "void" || type === "null" || type === "undefined" ? response : type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
|
|
542
|
+
"text/plain": {
|
|
543
|
+
schema: response
|
|
544
|
+
}
|
|
545
|
+
} : {
|
|
546
|
+
"application/json": {
|
|
547
|
+
schema: response
|
|
548
|
+
}
|
|
515
549
|
}
|
|
516
|
-
}
|
|
517
|
-
}
|
|
550
|
+
};
|
|
551
|
+
}
|
|
518
552
|
}
|
|
519
553
|
}
|
|
520
554
|
for (let path of getPossiblePath(route.path)) {
|
|
@@ -545,7 +579,14 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
545
579
|
};
|
|
546
580
|
}
|
|
547
581
|
}
|
|
548
|
-
const
|
|
582
|
+
const _schemas = app.getGlobalDefinitions?.().type;
|
|
583
|
+
const schemas = /* @__PURE__ */ Object.create(null);
|
|
584
|
+
if (_schemas)
|
|
585
|
+
for (const [name, schema] of Object.entries(_schemas)) {
|
|
586
|
+
let jsonSchema = unwrapSchema(schema);
|
|
587
|
+
if (jsonSchema instanceof Promise) jsonSchema = await jsonSchema;
|
|
588
|
+
if (jsonSchema) schemas[name] = jsonSchema;
|
|
589
|
+
}
|
|
549
590
|
return {
|
|
550
591
|
components: {
|
|
551
592
|
schemas
|
|
@@ -611,13 +652,13 @@ var openapi = ({
|
|
|
611
652
|
);
|
|
612
653
|
}).get(
|
|
613
654
|
specPath,
|
|
614
|
-
function openAPISchema() {
|
|
655
|
+
async function openAPISchema() {
|
|
615
656
|
if (totalRoutes === app.routes.length) return cachedSchema;
|
|
616
657
|
totalRoutes = app.routes.length;
|
|
617
658
|
const {
|
|
618
659
|
paths,
|
|
619
660
|
components: { schemas }
|
|
620
|
-
} = toOpenAPISchema(app, exclude, references);
|
|
661
|
+
} = await toOpenAPISchema(app, exclude, references);
|
|
621
662
|
return cachedSchema = {
|
|
622
663
|
openapi: "3.0.3",
|
|
623
664
|
...documentation,
|
package/dist/cjs/openapi.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AnyElysia, type TSchema } from 'elysia';
|
|
1
|
+
import { type AnyElysia, type TSchema, type InputSchema } from 'elysia';
|
|
2
2
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
3
3
|
import { type TProperties } from '@sinclair/typebox';
|
|
4
4
|
import type { AdditionalReferences, ElysiaOpenAPIConfig } from './types';
|
|
@@ -10,17 +10,20 @@ export declare const capitalize: (word: string) => string;
|
|
|
10
10
|
*/
|
|
11
11
|
export declare const getPossiblePath: (path: string) => string[];
|
|
12
12
|
export declare const getLoosePath: (path: string) => string;
|
|
13
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
14
|
+
export declare const unwrapSchema: (schema: InputSchema["body"]) => MaybePromise<OpenAPIV3.SchemaObject | undefined>;
|
|
13
15
|
/**
|
|
14
16
|
* Converts Elysia routes to OpenAPI 3.0.3 paths schema
|
|
15
17
|
* @param routes Array of Elysia route objects
|
|
16
18
|
* @returns OpenAPI paths object
|
|
17
19
|
*/
|
|
18
|
-
export declare function toOpenAPISchema(app: AnyElysia, exclude?: ElysiaOpenAPIConfig['exclude'], references?: AdditionalReferences): {
|
|
20
|
+
export declare function toOpenAPISchema(app: AnyElysia, exclude?: ElysiaOpenAPIConfig['exclude'], references?: AdditionalReferences): Promise<{
|
|
19
21
|
components: {
|
|
20
|
-
schemas:
|
|
22
|
+
schemas: any;
|
|
21
23
|
};
|
|
22
24
|
paths: OpenAPIV3.PathsObject<{}, {}>;
|
|
23
|
-
}
|
|
25
|
+
}>;
|
|
24
26
|
export declare const withHeaders: (schema: TSchema, headers: TProperties) => TSchema & {
|
|
25
27
|
headers: TProperties;
|
|
26
28
|
};
|
|
29
|
+
export {};
|
package/dist/cjs/openapi.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(openapi_exports, {
|
|
|
24
24
|
getLoosePath: () => getLoosePath,
|
|
25
25
|
getPossiblePath: () => getPossiblePath,
|
|
26
26
|
toOpenAPISchema: () => toOpenAPISchema,
|
|
27
|
+
unwrapSchema: () => unwrapSchema,
|
|
27
28
|
withHeaders: () => withHeaders
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(openapi_exports);
|
|
@@ -37,6 +38,7 @@ var Hint = Symbol.for("TypeBox.Hint");
|
|
|
37
38
|
var Kind = Symbol.for("TypeBox.Kind");
|
|
38
39
|
|
|
39
40
|
// src/openapi.ts
|
|
41
|
+
var import_xsschema = require("xsschema");
|
|
40
42
|
var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
|
|
41
43
|
var toRef = (name) => import_elysia.t.Ref(`#/components/schemas/${name}`);
|
|
42
44
|
var toOperationId = (method, paths) => {
|
|
@@ -65,7 +67,14 @@ var getLoosePath = (path) => {
|
|
|
65
67
|
return path.slice(0, path.length - 1);
|
|
66
68
|
return path + "/";
|
|
67
69
|
};
|
|
68
|
-
|
|
70
|
+
var unwrapSchema = (schema) => {
|
|
71
|
+
if (!schema) return;
|
|
72
|
+
if (typeof schema === "string") schema = toRef(schema);
|
|
73
|
+
if (Kind in schema) return schema;
|
|
74
|
+
if (Kind in schema === false && schema["~standard"])
|
|
75
|
+
return (0, import_xsschema.toJsonSchema)(schema);
|
|
76
|
+
};
|
|
77
|
+
async function toOpenAPISchema(app, exclude, references) {
|
|
69
78
|
const {
|
|
70
79
|
methods: excludeMethods = ["OPTIONS"],
|
|
71
80
|
staticFile: excludeStaticFile = true,
|
|
@@ -118,11 +127,11 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
118
127
|
};
|
|
119
128
|
const parameters = [];
|
|
120
129
|
if (hooks.params) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (
|
|
130
|
+
let params = unwrapSchema(hooks.params);
|
|
131
|
+
if (params) params = await params;
|
|
132
|
+
if (params && params.type === "object" && params.properties)
|
|
124
133
|
for (const [paramName, paramSchema] of Object.entries(
|
|
125
|
-
|
|
134
|
+
params.properties
|
|
126
135
|
))
|
|
127
136
|
parameters.push({
|
|
128
137
|
name: paramName,
|
|
@@ -131,15 +140,14 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
131
140
|
// Path parameters are always required
|
|
132
141
|
schema: paramSchema
|
|
133
142
|
});
|
|
134
|
-
}
|
|
135
143
|
}
|
|
136
144
|
if (hooks.query) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (
|
|
140
|
-
const required =
|
|
145
|
+
let query = unwrapSchema(hooks.query);
|
|
146
|
+
if (query) query = await query;
|
|
147
|
+
if (query && query.type === "object" && query.properties) {
|
|
148
|
+
const required = query.required || [];
|
|
141
149
|
for (const [queryName, querySchema] of Object.entries(
|
|
142
|
-
|
|
150
|
+
query.properties
|
|
143
151
|
))
|
|
144
152
|
parameters.push({
|
|
145
153
|
name: queryName,
|
|
@@ -150,12 +158,12 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
150
158
|
}
|
|
151
159
|
}
|
|
152
160
|
if (hooks.headers) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (
|
|
156
|
-
const required =
|
|
161
|
+
let headers = unwrapSchema(hooks.query);
|
|
162
|
+
if (headers) headers = await headers;
|
|
163
|
+
if (headers && headers.type === "object" && headers.properties) {
|
|
164
|
+
const required = headers.required || [];
|
|
157
165
|
for (const [headerName, headerSchema] of Object.entries(
|
|
158
|
-
|
|
166
|
+
headers.properties
|
|
159
167
|
))
|
|
160
168
|
parameters.push({
|
|
161
169
|
name: headerName,
|
|
@@ -166,12 +174,12 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
166
174
|
}
|
|
167
175
|
}
|
|
168
176
|
if (hooks.cookie) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (
|
|
172
|
-
const required =
|
|
177
|
+
let cookie = unwrapSchema(hooks.cookie);
|
|
178
|
+
if (cookie) cookie = await cookie;
|
|
179
|
+
if (cookie && cookie.type === "object" && cookie.properties) {
|
|
180
|
+
const required = cookie.required || [];
|
|
173
181
|
for (const [cookieName, cookieSchema] of Object.entries(
|
|
174
|
-
|
|
182
|
+
cookie.properties
|
|
175
183
|
))
|
|
176
184
|
parameters.push({
|
|
177
185
|
name: cookieName,
|
|
@@ -183,80 +191,107 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
183
191
|
}
|
|
184
192
|
if (parameters.length > 0) operation.parameters = parameters;
|
|
185
193
|
if (hooks.body && method !== "get" && method !== "head") {
|
|
186
|
-
|
|
187
|
-
if (
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
194
|
+
let body = unwrapSchema(hooks.body);
|
|
195
|
+
if (body) body = await body;
|
|
196
|
+
if (body) {
|
|
197
|
+
const { type: _type, description, ...options } = body;
|
|
198
|
+
const type = _type;
|
|
199
|
+
if (hooks.parse) {
|
|
200
|
+
const content = {};
|
|
201
|
+
const parsers = hooks.parse;
|
|
202
|
+
for (const parser of parsers) {
|
|
203
|
+
if (typeof parser.fn === "function") continue;
|
|
204
|
+
switch (parser.fn) {
|
|
205
|
+
case "text":
|
|
206
|
+
case "text/plain":
|
|
207
|
+
content["text/plain"] = { schema: body };
|
|
208
|
+
continue;
|
|
209
|
+
case "urlencoded":
|
|
210
|
+
case "application/x-www-form-urlencoded":
|
|
211
|
+
content["application/x-www-form-urlencoded"] = {
|
|
212
|
+
schema: body
|
|
213
|
+
};
|
|
214
|
+
continue;
|
|
215
|
+
case "json":
|
|
216
|
+
case "application/json":
|
|
217
|
+
content["application/json"] = { schema: body };
|
|
218
|
+
continue;
|
|
219
|
+
case "formdata":
|
|
220
|
+
case "multipart/form-data":
|
|
221
|
+
content["multipart/form-data"] = {
|
|
222
|
+
schema: body
|
|
223
|
+
};
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
213
226
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
"
|
|
223
|
-
|
|
227
|
+
operation.requestBody = {
|
|
228
|
+
description,
|
|
229
|
+
content,
|
|
230
|
+
required: true
|
|
231
|
+
};
|
|
232
|
+
} else {
|
|
233
|
+
operation.requestBody = {
|
|
234
|
+
description,
|
|
235
|
+
content: type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
|
|
236
|
+
"text/plain": body
|
|
237
|
+
} : {
|
|
238
|
+
"application/json": {
|
|
239
|
+
schema: body
|
|
240
|
+
},
|
|
241
|
+
"application/x-www-form-urlencoded": {
|
|
242
|
+
schema: body
|
|
243
|
+
},
|
|
244
|
+
"multipart/form-data": {
|
|
245
|
+
schema: body
|
|
246
|
+
}
|
|
224
247
|
},
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
},
|
|
229
|
-
required: true
|
|
230
|
-
};
|
|
248
|
+
required: true
|
|
249
|
+
};
|
|
250
|
+
}
|
|
231
251
|
}
|
|
232
252
|
}
|
|
233
253
|
if (hooks.response) {
|
|
234
254
|
operation.responses = {};
|
|
235
255
|
if (typeof hooks.response === "object" && !hooks.response.type && !hooks.response.$ref) {
|
|
236
256
|
for (let [status, schema] of Object.entries(hooks.response)) {
|
|
237
|
-
|
|
238
|
-
|
|
257
|
+
let response = unwrapSchema(schema);
|
|
258
|
+
if (response) response = await response;
|
|
259
|
+
if (!response) continue;
|
|
260
|
+
const { type: _type, description, ...options } = response;
|
|
261
|
+
const type = _type;
|
|
239
262
|
operation.responses[status] = {
|
|
240
|
-
description: `Response for status ${status}`,
|
|
263
|
+
description: description ?? `Response for status ${status}`,
|
|
241
264
|
...options,
|
|
242
|
-
content: type === "void" || type === "null" || type === "undefined" ?
|
|
265
|
+
content: type === "void" || type === "null" || type === "undefined" ? response : type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
|
|
266
|
+
"text/plain": {
|
|
267
|
+
schema: response
|
|
268
|
+
}
|
|
269
|
+
} : {
|
|
243
270
|
"application/json": {
|
|
244
|
-
schema
|
|
271
|
+
schema: response
|
|
245
272
|
}
|
|
246
273
|
}
|
|
247
274
|
};
|
|
248
275
|
}
|
|
249
276
|
} else {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
277
|
+
let response = unwrapSchema(hooks.response);
|
|
278
|
+
if (response) response = await response;
|
|
279
|
+
if (response) {
|
|
280
|
+
const { type: _type, description, ...options } = response;
|
|
281
|
+
const type = _type;
|
|
282
|
+
operation.responses["200"] = {
|
|
283
|
+
description: description ?? `Response for status 200`,
|
|
284
|
+
content: type === "void" || type === "null" || type === "undefined" ? response : type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
|
|
285
|
+
"text/plain": {
|
|
286
|
+
schema: response
|
|
287
|
+
}
|
|
288
|
+
} : {
|
|
289
|
+
"application/json": {
|
|
290
|
+
schema: response
|
|
291
|
+
}
|
|
257
292
|
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
260
295
|
}
|
|
261
296
|
}
|
|
262
297
|
for (let path of getPossiblePath(route.path)) {
|
|
@@ -287,7 +322,14 @@ function toOpenAPISchema(app, exclude, references) {
|
|
|
287
322
|
};
|
|
288
323
|
}
|
|
289
324
|
}
|
|
290
|
-
const
|
|
325
|
+
const _schemas = app.getGlobalDefinitions?.().type;
|
|
326
|
+
const schemas = /* @__PURE__ */ Object.create(null);
|
|
327
|
+
if (_schemas)
|
|
328
|
+
for (const [name, schema] of Object.entries(_schemas)) {
|
|
329
|
+
let jsonSchema = unwrapSchema(schema);
|
|
330
|
+
if (jsonSchema instanceof Promise) jsonSchema = await jsonSchema;
|
|
331
|
+
if (jsonSchema) schemas[name] = jsonSchema;
|
|
332
|
+
}
|
|
291
333
|
return {
|
|
292
334
|
components: {
|
|
293
335
|
schemas
|
|
@@ -304,5 +346,6 @@ var withHeaders = (schema, headers) => Object.assign(schema, {
|
|
|
304
346
|
getLoosePath,
|
|
305
347
|
getPossiblePath,
|
|
306
348
|
toOpenAPISchema,
|
|
349
|
+
unwrapSchema,
|
|
307
350
|
withHeaders
|
|
308
351
|
});
|