@elysiajs/openapi 1.4.4 → 1.4.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
@@ -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;
@@ -550,8 +548,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
550
548
  if (hooks.body && method !== "get" && method !== "head") {
551
549
  const body = unwrapSchema(hooks.body, vendors);
552
550
  if (body) {
553
- const { type: _type, description, ...options } = body;
554
- const type = _type;
551
+ const { type, description, $ref, ...options } = unwrapReference(
552
+ body,
553
+ definitions
554
+ );
555
555
  if (hooks.parse) {
556
556
  const content = {};
557
557
  const parsers = hooks.parse;
@@ -589,7 +589,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
589
589
  operation.requestBody = {
590
590
  description,
591
591
  content: type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
592
- "text/plain": body
592
+ "text/plain": {
593
+ schema: body
594
+ }
593
595
  } : {
594
596
  "application/json": {
595
597
  schema: body
@@ -612,11 +614,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
612
614
  for (let [status, schema] of Object.entries(hooks.response)) {
613
615
  const response = unwrapSchema(schema, vendors);
614
616
  if (!response) continue;
615
- const { type: _type, description, ...options } = response;
616
- const type = _type;
617
+ const { type, description, $ref, ...options } = unwrapReference(response, definitions);
617
618
  operation.responses[status] = {
618
619
  description: description ?? `Response for status ${status}`,
619
- ...options,
620
620
  content: type === "void" || type === "null" || type === "undefined" ? response : type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
621
621
  "text/plain": {
622
622
  schema: response
@@ -631,7 +631,11 @@ function toOpenAPISchema(app, exclude, references, vendors) {
631
631
  } else {
632
632
  const response = unwrapSchema(hooks.response, vendors);
633
633
  if (response) {
634
- const { type: _type, description, ...options } = response;
634
+ const {
635
+ type: _type,
636
+ description,
637
+ ...options
638
+ } = unwrapReference(response, definitions);
635
639
  const type = _type;
636
640
  operation.responses["200"] = {
637
641
  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;
@@ -293,8 +291,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
293
291
  if (hooks.body && method !== "get" && method !== "head") {
294
292
  const body = unwrapSchema(hooks.body, vendors);
295
293
  if (body) {
296
- const { type: _type, description, ...options } = body;
297
- const type = _type;
294
+ const { type, description, $ref, ...options } = unwrapReference(
295
+ body,
296
+ definitions
297
+ );
298
298
  if (hooks.parse) {
299
299
  const content = {};
300
300
  const parsers = hooks.parse;
@@ -332,7 +332,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
332
332
  operation.requestBody = {
333
333
  description,
334
334
  content: type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
335
- "text/plain": body
335
+ "text/plain": {
336
+ schema: body
337
+ }
336
338
  } : {
337
339
  "application/json": {
338
340
  schema: body
@@ -355,11 +357,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
355
357
  for (let [status, schema] of Object.entries(hooks.response)) {
356
358
  const response = unwrapSchema(schema, vendors);
357
359
  if (!response) continue;
358
- const { type: _type, description, ...options } = response;
359
- const type = _type;
360
+ const { type, description, $ref, ...options } = unwrapReference(response, definitions);
360
361
  operation.responses[status] = {
361
362
  description: description ?? `Response for status ${status}`,
362
- ...options,
363
363
  content: type === "void" || type === "null" || type === "undefined" ? response : type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
364
364
  "text/plain": {
365
365
  schema: response
@@ -374,7 +374,11 @@ function toOpenAPISchema(app, exclude, references, vendors) {
374
374
  } else {
375
375
  const response = unwrapSchema(hooks.response, vendors);
376
376
  if (response) {
377
- const { type: _type, description, ...options } = response;
377
+ const {
378
+ type: _type,
379
+ description,
380
+ ...options
381
+ } = unwrapReference(response, definitions);
378
382
  const type = _type;
379
383
  operation.responses["200"] = {
380
384
  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;
@@ -523,8 +521,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
523
521
  if (hooks.body && method !== "get" && method !== "head") {
524
522
  const body = unwrapSchema(hooks.body, vendors);
525
523
  if (body) {
526
- const { type: _type, description, ...options } = body;
527
- const type = _type;
524
+ const { type, description, $ref, ...options } = unwrapReference(
525
+ body,
526
+ definitions
527
+ );
528
528
  if (hooks.parse) {
529
529
  const content = {};
530
530
  const parsers = hooks.parse;
@@ -562,7 +562,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
562
562
  operation.requestBody = {
563
563
  description,
564
564
  content: type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
565
- "text/plain": body
565
+ "text/plain": {
566
+ schema: body
567
+ }
566
568
  } : {
567
569
  "application/json": {
568
570
  schema: body
@@ -585,11 +587,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
585
587
  for (let [status, schema] of Object.entries(hooks.response)) {
586
588
  const response = unwrapSchema(schema, vendors);
587
589
  if (!response) continue;
588
- const { type: _type, description, ...options } = response;
589
- const type = _type;
590
+ const { type, description, $ref, ...options } = unwrapReference(response, definitions);
590
591
  operation.responses[status] = {
591
592
  description: description ?? `Response for status ${status}`,
592
- ...options,
593
593
  content: type === "void" || type === "null" || type === "undefined" ? response : type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
594
594
  "text/plain": {
595
595
  schema: response
@@ -604,7 +604,11 @@ function toOpenAPISchema(app, exclude, references, vendors) {
604
604
  } else {
605
605
  const response = unwrapSchema(hooks.response, vendors);
606
606
  if (response) {
607
- const { type: _type, description, ...options } = response;
607
+ const {
608
+ type: _type,
609
+ description,
610
+ ...options
611
+ } = unwrapReference(response, definitions);
608
612
  const type = _type;
609
613
  operation.responses["200"] = {
610
614
  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;
@@ -264,8 +262,10 @@ function toOpenAPISchema(app, exclude, references, vendors) {
264
262
  if (hooks.body && method !== "get" && method !== "head") {
265
263
  const body = unwrapSchema(hooks.body, vendors);
266
264
  if (body) {
267
- const { type: _type, description, ...options } = body;
268
- const type = _type;
265
+ const { type, description, $ref, ...options } = unwrapReference(
266
+ body,
267
+ definitions
268
+ );
269
269
  if (hooks.parse) {
270
270
  const content = {};
271
271
  const parsers = hooks.parse;
@@ -303,7 +303,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
303
303
  operation.requestBody = {
304
304
  description,
305
305
  content: type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
306
- "text/plain": body
306
+ "text/plain": {
307
+ schema: body
308
+ }
307
309
  } : {
308
310
  "application/json": {
309
311
  schema: body
@@ -326,11 +328,9 @@ function toOpenAPISchema(app, exclude, references, vendors) {
326
328
  for (let [status, schema] of Object.entries(hooks.response)) {
327
329
  const response = unwrapSchema(schema, vendors);
328
330
  if (!response) continue;
329
- const { type: _type, description, ...options } = response;
330
- const type = _type;
331
+ const { type, description, $ref, ...options } = unwrapReference(response, definitions);
331
332
  operation.responses[status] = {
332
333
  description: description ?? `Response for status ${status}`,
333
- ...options,
334
334
  content: type === "void" || type === "null" || type === "undefined" ? response : type === "string" || type === "number" || type === "integer" || type === "boolean" ? {
335
335
  "text/plain": {
336
336
  schema: response
@@ -345,7 +345,11 @@ function toOpenAPISchema(app, exclude, references, vendors) {
345
345
  } else {
346
346
  const response = unwrapSchema(hooks.response, vendors);
347
347
  if (response) {
348
- const { type: _type, description, ...options } = response;
348
+ const {
349
+ type: _type,
350
+ description,
351
+ ...options
352
+ } = unwrapReference(response, definitions);
349
353
  const type = _type;
350
354
  operation.responses["200"] = {
351
355
  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.5",
4
4
  "description": "Plugin for Elysia to auto-generate API documentation",
5
5
  "author": {
6
6
  "name": "saltyAom",