@elysiajs/openapi 1.4.4 → 1.4.6

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
@@ -358,9 +358,10 @@ openapi({
358
358
  };
359
359
  var warned = {};
360
360
  var unwrapReference = (schema, definitions) => {
361
- if (!schema?.$ref) return schema;
362
- const name = schema.$ref.slice(schema.$ref.lastIndexOf("/") + 1);
363
- if (schema.$ref && definitions[name]) schema = definitions[name];
361
+ const ref = schema?.$ref;
362
+ if (!ref) return schema;
363
+ const name = ref.slice(ref.lastIndexOf("/") + 1);
364
+ if (ref && definitions[name]) schema = definitions[name];
364
365
  return schema;
365
366
  };
366
367
  var unwrapSchema = (schema, mapJsonSchema) => {
@@ -442,9 +443,6 @@ function toOpenAPISchema(app, exclude, references, vendors) {
442
443
  if (excludeStaticFile && route.path.includes(".") || excludePaths.includes(route.path) || excludeMethods.includes(method))
443
444
  continue;
444
445
  const hooks = route.hooks ?? {};
445
- if (route.path === "/a") {
446
- console.log("H");
447
- }
448
446
  if (references?.length)
449
447
  for (const reference of references) {
450
448
  if (!reference) continue;
@@ -464,8 +462,19 @@ function toOpenAPISchema(app, exclude, references, vendors) {
464
462
  ))
465
463
  if (isValidSchema(schema)) {
466
464
  if (!hooks.response) hooks.response = {};
465
+ else if (typeof hooks.response !== "object" || hooks.response.type || hooks.response.$ref || hooks.response["~standard"])
466
+ hooks.response = {
467
+ 200: hooks.response
468
+ };
467
469
  if (!hooks.response[status])
468
- hooks.response[status] = schema;
470
+ try {
471
+ hooks.response[status] = schema;
472
+ } catch (error) {
473
+ console.log(
474
+ "[@elysiajs/openapi/gen] Failed to assigned response schema"
475
+ );
476
+ console.log(error);
477
+ }
469
478
  }
470
479
  }
471
480
  }
@@ -550,8 +559,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
550
559
  if (hooks.body && method !== "get" && method !== "head") {
551
560
  const body = unwrapSchema(hooks.body, vendors);
552
561
  if (body) {
553
- const { type: _type, description, ...options } = body;
554
- const type = _type;
562
+ const { type, description, $ref, ...options } = unwrapReference(
563
+ body,
564
+ definitions
565
+ );
555
566
  if (hooks.parse) {
556
567
  const content = {};
557
568
  const parsers = hooks.parse;
@@ -589,7 +600,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
589
600
  operation.requestBody = {
590
601
  description,
591
602
  content: type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
592
- "text/plain": body
603
+ "text/plain": {
604
+ schema: body
605
+ }
593
606
  } : {
594
607
  "application/json": {
595
608
  schema: body
@@ -608,15 +621,14 @@ function toOpenAPISchema(app, exclude, references, vendors) {
608
621
  }
609
622
  if (hooks.response) {
610
623
  operation.responses = {};
611
- if (typeof hooks.response === "object" && !hooks.response.type && !hooks.response.$ref) {
624
+ if (typeof hooks.response === "object" && // TypeBox
625
+ !hooks.response.type && !hooks.response.$ref && !hooks.response["~standard"]) {
612
626
  for (let [status, schema] of Object.entries(hooks.response)) {
613
627
  const response = unwrapSchema(schema, vendors);
614
628
  if (!response) continue;
615
- const { type: _type, description, ...options } = response;
616
- const type = _type;
629
+ const { type, description, $ref, ...options } = unwrapReference(response, definitions);
617
630
  operation.responses[status] = {
618
631
  description: description ?? `Response for status ${status}`,
619
- ...options,
620
632
  content: type === "void" || type === "null" || type === "undefined" ? response : type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
621
633
  "text/plain": {
622
634
  schema: response
@@ -631,7 +643,11 @@ function toOpenAPISchema(app, exclude, references, vendors) {
631
643
  } else {
632
644
  const response = unwrapSchema(hooks.response, vendors);
633
645
  if (response) {
634
- const { type: _type, description, ...options } = response;
646
+ const {
647
+ type: _type,
648
+ description,
649
+ ...options
650
+ } = unwrapReference(response, definitions);
635
651
  const type = _type;
636
652
  operation.responses["200"] = {
637
653
  description: description ?? `Response for status 200`,
@@ -101,9 +101,10 @@ openapi({
101
101
  };
102
102
  var warned = {};
103
103
  var unwrapReference = (schema, definitions) => {
104
- if (!schema?.$ref) return schema;
105
- const name = schema.$ref.slice(schema.$ref.lastIndexOf("/") + 1);
106
- if (schema.$ref && definitions[name]) schema = definitions[name];
104
+ const ref = schema?.$ref;
105
+ if (!ref) return schema;
106
+ const name = ref.slice(ref.lastIndexOf("/") + 1);
107
+ if (ref && definitions[name]) schema = definitions[name];
107
108
  return schema;
108
109
  };
109
110
  var unwrapSchema = (schema, mapJsonSchema) => {
@@ -185,9 +186,6 @@ function toOpenAPISchema(app, exclude, references, vendors) {
185
186
  if (excludeStaticFile && route.path.includes(".") || excludePaths.includes(route.path) || excludeMethods.includes(method))
186
187
  continue;
187
188
  const hooks = route.hooks ?? {};
188
- if (route.path === "/a") {
189
- console.log("H");
190
- }
191
189
  if (references?.length)
192
190
  for (const reference of references) {
193
191
  if (!reference) continue;
@@ -207,8 +205,19 @@ function toOpenAPISchema(app, exclude, references, vendors) {
207
205
  ))
208
206
  if (isValidSchema(schema)) {
209
207
  if (!hooks.response) hooks.response = {};
208
+ else if (typeof hooks.response !== "object" || hooks.response.type || hooks.response.$ref || hooks.response["~standard"])
209
+ hooks.response = {
210
+ 200: hooks.response
211
+ };
210
212
  if (!hooks.response[status])
211
- hooks.response[status] = schema;
213
+ try {
214
+ hooks.response[status] = schema;
215
+ } catch (error) {
216
+ console.log(
217
+ "[@elysiajs/openapi/gen] Failed to assigned response schema"
218
+ );
219
+ console.log(error);
220
+ }
212
221
  }
213
222
  }
214
223
  }
@@ -293,8 +302,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
293
302
  if (hooks.body && method !== "get" && method !== "head") {
294
303
  const body = unwrapSchema(hooks.body, vendors);
295
304
  if (body) {
296
- const { type: _type, description, ...options } = body;
297
- const type = _type;
305
+ const { type, description, $ref, ...options } = unwrapReference(
306
+ body,
307
+ definitions
308
+ );
298
309
  if (hooks.parse) {
299
310
  const content = {};
300
311
  const parsers = hooks.parse;
@@ -332,7 +343,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
332
343
  operation.requestBody = {
333
344
  description,
334
345
  content: type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
335
- "text/plain": body
346
+ "text/plain": {
347
+ schema: body
348
+ }
336
349
  } : {
337
350
  "application/json": {
338
351
  schema: body
@@ -351,15 +364,14 @@ function toOpenAPISchema(app, exclude, references, vendors) {
351
364
  }
352
365
  if (hooks.response) {
353
366
  operation.responses = {};
354
- if (typeof hooks.response === "object" && !hooks.response.type && !hooks.response.$ref) {
367
+ if (typeof hooks.response === "object" && // TypeBox
368
+ !hooks.response.type && !hooks.response.$ref && !hooks.response["~standard"]) {
355
369
  for (let [status, schema] of Object.entries(hooks.response)) {
356
370
  const response = unwrapSchema(schema, vendors);
357
371
  if (!response) continue;
358
- const { type: _type, description, ...options } = response;
359
- const type = _type;
372
+ const { type, description, $ref, ...options } = unwrapReference(response, definitions);
360
373
  operation.responses[status] = {
361
374
  description: description ?? `Response for status ${status}`,
362
- ...options,
363
375
  content: type === "void" || type === "null" || type === "undefined" ? response : type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
364
376
  "text/plain": {
365
377
  schema: response
@@ -374,7 +386,11 @@ function toOpenAPISchema(app, exclude, references, vendors) {
374
386
  } else {
375
387
  const response = unwrapSchema(hooks.response, vendors);
376
388
  if (response) {
377
- const { type: _type, description, ...options } = response;
389
+ const {
390
+ type: _type,
391
+ description,
392
+ ...options
393
+ } = unwrapReference(response, definitions);
378
394
  const type = _type;
379
395
  operation.responses["200"] = {
380
396
  description: description ?? `Response for status 200`,
package/dist/index.mjs CHANGED
@@ -331,9 +331,10 @@ openapi({
331
331
  };
332
332
  var warned = {};
333
333
  var unwrapReference = (schema, definitions) => {
334
- if (!schema?.$ref) return schema;
335
- const name = schema.$ref.slice(schema.$ref.lastIndexOf("/") + 1);
336
- if (schema.$ref && definitions[name]) schema = definitions[name];
334
+ const ref = schema?.$ref;
335
+ if (!ref) return schema;
336
+ const name = ref.slice(ref.lastIndexOf("/") + 1);
337
+ if (ref && definitions[name]) schema = definitions[name];
337
338
  return schema;
338
339
  };
339
340
  var unwrapSchema = (schema, mapJsonSchema) => {
@@ -415,9 +416,6 @@ function toOpenAPISchema(app, exclude, references, vendors) {
415
416
  if (excludeStaticFile && route.path.includes(".") || excludePaths.includes(route.path) || excludeMethods.includes(method))
416
417
  continue;
417
418
  const hooks = route.hooks ?? {};
418
- if (route.path === "/a") {
419
- console.log("H");
420
- }
421
419
  if (references?.length)
422
420
  for (const reference of references) {
423
421
  if (!reference) continue;
@@ -437,8 +435,19 @@ function toOpenAPISchema(app, exclude, references, vendors) {
437
435
  ))
438
436
  if (isValidSchema(schema)) {
439
437
  if (!hooks.response) hooks.response = {};
438
+ else if (typeof hooks.response !== "object" || hooks.response.type || hooks.response.$ref || hooks.response["~standard"])
439
+ hooks.response = {
440
+ 200: hooks.response
441
+ };
440
442
  if (!hooks.response[status])
441
- hooks.response[status] = schema;
443
+ try {
444
+ hooks.response[status] = schema;
445
+ } catch (error) {
446
+ console.log(
447
+ "[@elysiajs/openapi/gen] Failed to assigned response schema"
448
+ );
449
+ console.log(error);
450
+ }
442
451
  }
443
452
  }
444
453
  }
@@ -523,8 +532,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
523
532
  if (hooks.body && method !== "get" && method !== "head") {
524
533
  const body = unwrapSchema(hooks.body, vendors);
525
534
  if (body) {
526
- const { type: _type, description, ...options } = body;
527
- const type = _type;
535
+ const { type, description, $ref, ...options } = unwrapReference(
536
+ body,
537
+ definitions
538
+ );
528
539
  if (hooks.parse) {
529
540
  const content = {};
530
541
  const parsers = hooks.parse;
@@ -562,7 +573,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
562
573
  operation.requestBody = {
563
574
  description,
564
575
  content: type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
565
- "text/plain": body
576
+ "text/plain": {
577
+ schema: body
578
+ }
566
579
  } : {
567
580
  "application/json": {
568
581
  schema: body
@@ -581,15 +594,14 @@ function toOpenAPISchema(app, exclude, references, vendors) {
581
594
  }
582
595
  if (hooks.response) {
583
596
  operation.responses = {};
584
- if (typeof hooks.response === "object" && !hooks.response.type && !hooks.response.$ref) {
597
+ if (typeof hooks.response === "object" && // TypeBox
598
+ !hooks.response.type && !hooks.response.$ref && !hooks.response["~standard"]) {
585
599
  for (let [status, schema] of Object.entries(hooks.response)) {
586
600
  const response = unwrapSchema(schema, vendors);
587
601
  if (!response) continue;
588
- const { type: _type, description, ...options } = response;
589
- const type = _type;
602
+ const { type, description, $ref, ...options } = unwrapReference(response, definitions);
590
603
  operation.responses[status] = {
591
604
  description: description ?? `Response for status ${status}`,
592
- ...options,
593
605
  content: type === "void" || type === "null" || type === "undefined" ? response : type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
594
606
  "text/plain": {
595
607
  schema: response
@@ -604,7 +616,11 @@ function toOpenAPISchema(app, exclude, references, vendors) {
604
616
  } else {
605
617
  const response = unwrapSchema(hooks.response, vendors);
606
618
  if (response) {
607
- const { type: _type, description, ...options } = response;
619
+ const {
620
+ type: _type,
621
+ description,
622
+ ...options
623
+ } = unwrapReference(response, definitions);
608
624
  const type = _type;
609
625
  operation.responses["200"] = {
610
626
  description: description ?? `Response for status 200`,
package/dist/openapi.mjs CHANGED
@@ -72,9 +72,10 @@ openapi({
72
72
  };
73
73
  var warned = {};
74
74
  var unwrapReference = (schema, definitions) => {
75
- if (!schema?.$ref) return schema;
76
- const name = schema.$ref.slice(schema.$ref.lastIndexOf("/") + 1);
77
- if (schema.$ref && definitions[name]) schema = definitions[name];
75
+ const ref = schema?.$ref;
76
+ if (!ref) return schema;
77
+ const name = ref.slice(ref.lastIndexOf("/") + 1);
78
+ if (ref && definitions[name]) schema = definitions[name];
78
79
  return schema;
79
80
  };
80
81
  var unwrapSchema = (schema, mapJsonSchema) => {
@@ -156,9 +157,6 @@ function toOpenAPISchema(app, exclude, references, vendors) {
156
157
  if (excludeStaticFile && route.path.includes(".") || excludePaths.includes(route.path) || excludeMethods.includes(method))
157
158
  continue;
158
159
  const hooks = route.hooks ?? {};
159
- if (route.path === "/a") {
160
- console.log("H");
161
- }
162
160
  if (references?.length)
163
161
  for (const reference of references) {
164
162
  if (!reference) continue;
@@ -178,8 +176,19 @@ function toOpenAPISchema(app, exclude, references, vendors) {
178
176
  ))
179
177
  if (isValidSchema(schema)) {
180
178
  if (!hooks.response) hooks.response = {};
179
+ else if (typeof hooks.response !== "object" || hooks.response.type || hooks.response.$ref || hooks.response["~standard"])
180
+ hooks.response = {
181
+ 200: hooks.response
182
+ };
181
183
  if (!hooks.response[status])
182
- hooks.response[status] = schema;
184
+ try {
185
+ hooks.response[status] = schema;
186
+ } catch (error) {
187
+ console.log(
188
+ "[@elysiajs/openapi/gen] Failed to assigned response schema"
189
+ );
190
+ console.log(error);
191
+ }
183
192
  }
184
193
  }
185
194
  }
@@ -264,8 +273,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
264
273
  if (hooks.body && method !== "get" && method !== "head") {
265
274
  const body = unwrapSchema(hooks.body, vendors);
266
275
  if (body) {
267
- const { type: _type, description, ...options } = body;
268
- const type = _type;
276
+ const { type, description, $ref, ...options } = unwrapReference(
277
+ body,
278
+ definitions
279
+ );
269
280
  if (hooks.parse) {
270
281
  const content = {};
271
282
  const parsers = hooks.parse;
@@ -303,7 +314,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
303
314
  operation.requestBody = {
304
315
  description,
305
316
  content: type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
306
- "text/plain": body
317
+ "text/plain": {
318
+ schema: body
319
+ }
307
320
  } : {
308
321
  "application/json": {
309
322
  schema: body
@@ -322,15 +335,14 @@ function toOpenAPISchema(app, exclude, references, vendors) {
322
335
  }
323
336
  if (hooks.response) {
324
337
  operation.responses = {};
325
- if (typeof hooks.response === "object" && !hooks.response.type && !hooks.response.$ref) {
338
+ if (typeof hooks.response === "object" && // TypeBox
339
+ !hooks.response.type && !hooks.response.$ref && !hooks.response["~standard"]) {
326
340
  for (let [status, schema] of Object.entries(hooks.response)) {
327
341
  const response = unwrapSchema(schema, vendors);
328
342
  if (!response) continue;
329
- const { type: _type, description, ...options } = response;
330
- const type = _type;
343
+ const { type, description, $ref, ...options } = unwrapReference(response, definitions);
331
344
  operation.responses[status] = {
332
345
  description: description ?? `Response for status ${status}`,
333
- ...options,
334
346
  content: type === "void" || type === "null" || type === "undefined" ? response : type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
335
347
  "text/plain": {
336
348
  schema: response
@@ -345,7 +357,11 @@ function toOpenAPISchema(app, exclude, references, vendors) {
345
357
  } else {
346
358
  const response = unwrapSchema(hooks.response, vendors);
347
359
  if (response) {
348
- const { type: _type, description, ...options } = response;
360
+ const {
361
+ type: _type,
362
+ description,
363
+ ...options
364
+ } = unwrapReference(response, definitions);
349
365
  const type = _type;
350
366
  operation.responses["200"] = {
351
367
  description: description ?? `Response for status 200`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elysiajs/openapi",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "description": "Plugin for Elysia to auto-generate API documentation",
5
5
  "author": {
6
6
  "name": "saltyAom",