@elysiajs/openapi 1.4.12 → 1.4.14

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
@@ -2696,7 +2696,9 @@ function Void(options) {
2696
2696
 
2697
2697
  // src/openapi.ts
2698
2698
  var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
2699
- var toRef = (name) => import_elysia.t.Ref(`#/components/schemas/${name}`);
2699
+ var toRef = (name) => import_elysia.t.Ref(
2700
+ name.startsWith("#/") ? name : `#/components/schemas/${name}`
2701
+ );
2700
2702
  var toOperationId = (method, paths) => {
2701
2703
  let operationId = method.toLowerCase();
2702
2704
  if (!paths || paths === "/") return operationId + "Index";
@@ -2828,18 +2830,21 @@ var isTSchema = (value) => {
2828
2830
  var normalizeSchemaReference = (schema) => {
2829
2831
  if (!schema) return void 0;
2830
2832
  if (typeof schema !== "string") return schema;
2831
- return import_elysia.t.Ref(schema);
2833
+ return toRef(schema);
2832
2834
  };
2833
2835
  var mergeSchemaProperty = (existing, incoming, vendors) => {
2834
2836
  if (!existing) return incoming;
2835
2837
  if (!incoming) return existing;
2836
- const existingSchema = normalizeSchemaReference(existing);
2838
+ let existingSchema = normalizeSchemaReference(existing);
2837
2839
  let incomingSchema = normalizeSchemaReference(incoming);
2838
2840
  if (!existingSchema) return incoming;
2839
2841
  if (!incomingSchema) return existing;
2840
2842
  if (!isTSchema(incomingSchema) && incomingSchema["~standard"])
2841
2843
  incomingSchema = unwrapSchema(incomingSchema, vendors);
2842
- if (!incomingSchema) return existing;
2844
+ if (!isTSchema(existingSchema) && existingSchema["~standard"])
2845
+ existingSchema = unwrapSchema(existingSchema, vendors);
2846
+ if (!incomingSchema) return existingSchema;
2847
+ if (!existingSchema) return incomingSchema;
2843
2848
  const { schema: mergedSchema, notObjects } = mergeObjectSchemas([
2844
2849
  existingSchema,
2845
2850
  incomingSchema
@@ -2855,7 +2860,11 @@ var unwrapResponseSchema = (schema, vendors) => typeof schema === "string" ? nor
2855
2860
  schema["~standard"] ? unwrapSchema(schema, vendors, "output") : Object.fromEntries(
2856
2861
  Object.entries(schema).map(([status, schema2]) => [
2857
2862
  status,
2858
- typeof schema2 === "string" ? normalizeSchemaReference(schema2) : isTSchema(schema2) ? schema2 : unwrapSchema(schema2, vendors, "output")
2863
+ typeof schema2 === "string" ? normalizeSchemaReference(schema2) : isTSchema(schema2) ? schema2 : unwrapSchema(
2864
+ schema2,
2865
+ vendors,
2866
+ "output"
2867
+ )
2859
2868
  ])
2860
2869
  )
2861
2870
  );
@@ -2974,13 +2983,18 @@ var unwrapSchema = (schema, mapJsonSchema, io = "input") => {
2974
2983
  if (!schema) return;
2975
2984
  if (typeof schema === "string") schema = toRef(schema);
2976
2985
  if (Kind in schema) return enumToOpenApi(schema);
2977
- if (Kind in schema || !schema?.["~standard"]) return;
2986
+ if (!schema?.["~standard"] && // @ts-ignore
2987
+ (schema.$schema || schema.type || schema.properties || schema.items))
2988
+ return schema;
2989
+ if (!schema?.["~standard"]) return;
2978
2990
  const vendor = schema["~standard"].vendor;
2979
2991
  try {
2980
- if (schema["~standard"]?.jsonSchema?.[io])
2981
- return schema["~standard"]?.jsonSchema?.[io]?.();
2982
2992
  if (mapJsonSchema?.[vendor] && typeof mapJsonSchema[vendor] === "function")
2983
2993
  return enumToOpenApi(mapJsonSchema[vendor](schema));
2994
+ if (schema["~standard"]?.jsonSchema?.[io])
2995
+ return enumToOpenApi(schema["~standard"].jsonSchema[io]({
2996
+ target: "draft-2020-12"
2997
+ }));
2984
2998
  switch (vendor) {
2985
2999
  case "zod":
2986
3000
  if (warned.zod4 || warned.zod3) break;
@@ -3287,7 +3301,11 @@ function toOpenAPISchema(app, exclude, references, vendors) {
3287
3301
  };
3288
3302
  }
3289
3303
  } else {
3290
- const response = unwrapSchema(hooks.response, vendors, "output");
3304
+ const response = unwrapSchema(
3305
+ hooks.response,
3306
+ vendors,
3307
+ "output"
3308
+ );
3291
3309
  if (response) {
3292
3310
  const {
3293
3311
  type: _type,
@@ -11,6 +11,11 @@ export declare const capitalize: (word: string) => string;
11
11
  export declare const getPossiblePath: (path: string) => string[];
12
12
  export declare const getLoosePath: (path: string) => string;
13
13
  export declare const unwrapSchema: (schema: InputSchema["body"], mapJsonSchema?: MapJsonSchema, io?: "input" | "output") => OpenAPIV3.SchemaObject | undefined;
14
+ /**
15
+ * Convert TypeBox enum-like Union schemas to OpenAPI enum schemas
16
+ *
17
+ * Otherwise, return the schema as is
18
+ */
14
19
  export declare const enumToOpenApi: <T extends TAnySchema | OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined>(_schema: T) => T;
15
20
  /**
16
21
  * Converts Elysia routes to OpenAPI 3.0.3 paths schema
@@ -36,7 +36,9 @@ var Kind = /* @__PURE__ */ Symbol.for("TypeBox.Kind");
36
36
 
37
37
  // src/openapi.ts
38
38
  var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
39
- var toRef = (name) => import_elysia.t.Ref(`#/components/schemas/${name}`);
39
+ var toRef = (name) => import_elysia.t.Ref(
40
+ name.startsWith("#/") ? name : `#/components/schemas/${name}`
41
+ );
40
42
  var toOperationId = (method, paths) => {
41
43
  let operationId = method.toLowerCase();
42
44
  if (!paths || paths === "/") return operationId + "Index";
@@ -168,18 +170,21 @@ var isTSchema = (value) => {
168
170
  var normalizeSchemaReference = (schema) => {
169
171
  if (!schema) return void 0;
170
172
  if (typeof schema !== "string") return schema;
171
- return import_elysia.t.Ref(schema);
173
+ return toRef(schema);
172
174
  };
173
175
  var mergeSchemaProperty = (existing, incoming, vendors) => {
174
176
  if (!existing) return incoming;
175
177
  if (!incoming) return existing;
176
- const existingSchema = normalizeSchemaReference(existing);
178
+ let existingSchema = normalizeSchemaReference(existing);
177
179
  let incomingSchema = normalizeSchemaReference(incoming);
178
180
  if (!existingSchema) return incoming;
179
181
  if (!incomingSchema) return existing;
180
182
  if (!isTSchema(incomingSchema) && incomingSchema["~standard"])
181
183
  incomingSchema = unwrapSchema(incomingSchema, vendors);
182
- if (!incomingSchema) return existing;
184
+ if (!isTSchema(existingSchema) && existingSchema["~standard"])
185
+ existingSchema = unwrapSchema(existingSchema, vendors);
186
+ if (!incomingSchema) return existingSchema;
187
+ if (!existingSchema) return incomingSchema;
183
188
  const { schema: mergedSchema, notObjects } = mergeObjectSchemas([
184
189
  existingSchema,
185
190
  incomingSchema
@@ -195,7 +200,11 @@ var unwrapResponseSchema = (schema, vendors) => typeof schema === "string" ? nor
195
200
  schema["~standard"] ? unwrapSchema(schema, vendors, "output") : Object.fromEntries(
196
201
  Object.entries(schema).map(([status, schema2]) => [
197
202
  status,
198
- typeof schema2 === "string" ? normalizeSchemaReference(schema2) : isTSchema(schema2) ? schema2 : unwrapSchema(schema2, vendors, "output")
203
+ typeof schema2 === "string" ? normalizeSchemaReference(schema2) : isTSchema(schema2) ? schema2 : unwrapSchema(
204
+ schema2,
205
+ vendors,
206
+ "output"
207
+ )
199
208
  ])
200
209
  )
201
210
  );
@@ -314,13 +323,18 @@ var unwrapSchema = (schema, mapJsonSchema, io = "input") => {
314
323
  if (!schema) return;
315
324
  if (typeof schema === "string") schema = toRef(schema);
316
325
  if (Kind in schema) return enumToOpenApi(schema);
317
- if (Kind in schema || !schema?.["~standard"]) return;
326
+ if (!schema?.["~standard"] && // @ts-ignore
327
+ (schema.$schema || schema.type || schema.properties || schema.items))
328
+ return schema;
329
+ if (!schema?.["~standard"]) return;
318
330
  const vendor = schema["~standard"].vendor;
319
331
  try {
320
- if (schema["~standard"]?.jsonSchema?.[io])
321
- return schema["~standard"]?.jsonSchema?.[io]?.();
322
332
  if (mapJsonSchema?.[vendor] && typeof mapJsonSchema[vendor] === "function")
323
333
  return enumToOpenApi(mapJsonSchema[vendor](schema));
334
+ if (schema["~standard"]?.jsonSchema?.[io])
335
+ return enumToOpenApi(schema["~standard"].jsonSchema[io]({
336
+ target: "draft-2020-12"
337
+ }));
324
338
  switch (vendor) {
325
339
  case "zod":
326
340
  if (warned.zod4 || warned.zod3) break;
@@ -627,7 +641,11 @@ function toOpenAPISchema(app, exclude, references, vendors) {
627
641
  };
628
642
  }
629
643
  } else {
630
- const response = unwrapSchema(hooks.response, vendors, "output");
644
+ const response = unwrapSchema(
645
+ hooks.response,
646
+ vendors,
647
+ "output"
648
+ );
631
649
  if (response) {
632
650
  const {
633
651
  type: _type,
package/dist/index.mjs CHANGED
@@ -2674,7 +2674,9 @@ function Void(options) {
2674
2674
 
2675
2675
  // src/openapi.ts
2676
2676
  var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
2677
- var toRef = (name) => t.Ref(`#/components/schemas/${name}`);
2677
+ var toRef = (name) => t.Ref(
2678
+ name.startsWith("#/") ? name : `#/components/schemas/${name}`
2679
+ );
2678
2680
  var toOperationId = (method, paths) => {
2679
2681
  let operationId = method.toLowerCase();
2680
2682
  if (!paths || paths === "/") return operationId + "Index";
@@ -2806,18 +2808,21 @@ var isTSchema = (value) => {
2806
2808
  var normalizeSchemaReference = (schema) => {
2807
2809
  if (!schema) return void 0;
2808
2810
  if (typeof schema !== "string") return schema;
2809
- return t.Ref(schema);
2811
+ return toRef(schema);
2810
2812
  };
2811
2813
  var mergeSchemaProperty = (existing, incoming, vendors) => {
2812
2814
  if (!existing) return incoming;
2813
2815
  if (!incoming) return existing;
2814
- const existingSchema = normalizeSchemaReference(existing);
2816
+ let existingSchema = normalizeSchemaReference(existing);
2815
2817
  let incomingSchema = normalizeSchemaReference(incoming);
2816
2818
  if (!existingSchema) return incoming;
2817
2819
  if (!incomingSchema) return existing;
2818
2820
  if (!isTSchema(incomingSchema) && incomingSchema["~standard"])
2819
2821
  incomingSchema = unwrapSchema(incomingSchema, vendors);
2820
- if (!incomingSchema) return existing;
2822
+ if (!isTSchema(existingSchema) && existingSchema["~standard"])
2823
+ existingSchema = unwrapSchema(existingSchema, vendors);
2824
+ if (!incomingSchema) return existingSchema;
2825
+ if (!existingSchema) return incomingSchema;
2821
2826
  const { schema: mergedSchema, notObjects } = mergeObjectSchemas([
2822
2827
  existingSchema,
2823
2828
  incomingSchema
@@ -2833,7 +2838,11 @@ var unwrapResponseSchema = (schema, vendors) => typeof schema === "string" ? nor
2833
2838
  schema["~standard"] ? unwrapSchema(schema, vendors, "output") : Object.fromEntries(
2834
2839
  Object.entries(schema).map(([status, schema2]) => [
2835
2840
  status,
2836
- typeof schema2 === "string" ? normalizeSchemaReference(schema2) : isTSchema(schema2) ? schema2 : unwrapSchema(schema2, vendors, "output")
2841
+ typeof schema2 === "string" ? normalizeSchemaReference(schema2) : isTSchema(schema2) ? schema2 : unwrapSchema(
2842
+ schema2,
2843
+ vendors,
2844
+ "output"
2845
+ )
2837
2846
  ])
2838
2847
  )
2839
2848
  );
@@ -2952,13 +2961,18 @@ var unwrapSchema = (schema, mapJsonSchema, io = "input") => {
2952
2961
  if (!schema) return;
2953
2962
  if (typeof schema === "string") schema = toRef(schema);
2954
2963
  if (Kind in schema) return enumToOpenApi(schema);
2955
- if (Kind in schema || !schema?.["~standard"]) return;
2964
+ if (!schema?.["~standard"] && // @ts-ignore
2965
+ (schema.$schema || schema.type || schema.properties || schema.items))
2966
+ return schema;
2967
+ if (!schema?.["~standard"]) return;
2956
2968
  const vendor = schema["~standard"].vendor;
2957
2969
  try {
2958
- if (schema["~standard"]?.jsonSchema?.[io])
2959
- return schema["~standard"]?.jsonSchema?.[io]?.();
2960
2970
  if (mapJsonSchema?.[vendor] && typeof mapJsonSchema[vendor] === "function")
2961
2971
  return enumToOpenApi(mapJsonSchema[vendor](schema));
2972
+ if (schema["~standard"]?.jsonSchema?.[io])
2973
+ return enumToOpenApi(schema["~standard"].jsonSchema[io]({
2974
+ target: "draft-2020-12"
2975
+ }));
2962
2976
  switch (vendor) {
2963
2977
  case "zod":
2964
2978
  if (warned.zod4 || warned.zod3) break;
@@ -3265,7 +3279,11 @@ function toOpenAPISchema(app, exclude, references, vendors) {
3265
3279
  };
3266
3280
  }
3267
3281
  } else {
3268
- const response = unwrapSchema(hooks.response, vendors, "output");
3282
+ const response = unwrapSchema(
3283
+ hooks.response,
3284
+ vendors,
3285
+ "output"
3286
+ );
3269
3287
  if (response) {
3270
3288
  const {
3271
3289
  type: _type,
package/dist/openapi.d.ts CHANGED
@@ -11,6 +11,11 @@ export declare const capitalize: (word: string) => string;
11
11
  export declare const getPossiblePath: (path: string) => string[];
12
12
  export declare const getLoosePath: (path: string) => string;
13
13
  export declare const unwrapSchema: (schema: InputSchema["body"], mapJsonSchema?: MapJsonSchema, io?: "input" | "output") => OpenAPIV3.SchemaObject | undefined;
14
+ /**
15
+ * Convert TypeBox enum-like Union schemas to OpenAPI enum schemas
16
+ *
17
+ * Otherwise, return the schema as is
18
+ */
14
19
  export declare const enumToOpenApi: <T extends TAnySchema | OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined>(_schema: T) => T;
15
20
  /**
16
21
  * Converts Elysia routes to OpenAPI 3.0.3 paths schema
package/dist/openapi.mjs CHANGED
@@ -6,7 +6,9 @@ var Kind = /* @__PURE__ */ Symbol.for("TypeBox.Kind");
6
6
 
7
7
  // src/openapi.ts
8
8
  var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
9
- var toRef = (name) => t.Ref(`#/components/schemas/${name}`);
9
+ var toRef = (name) => t.Ref(
10
+ name.startsWith("#/") ? name : `#/components/schemas/${name}`
11
+ );
10
12
  var toOperationId = (method, paths) => {
11
13
  let operationId = method.toLowerCase();
12
14
  if (!paths || paths === "/") return operationId + "Index";
@@ -138,18 +140,21 @@ var isTSchema = (value) => {
138
140
  var normalizeSchemaReference = (schema) => {
139
141
  if (!schema) return void 0;
140
142
  if (typeof schema !== "string") return schema;
141
- return t.Ref(schema);
143
+ return toRef(schema);
142
144
  };
143
145
  var mergeSchemaProperty = (existing, incoming, vendors) => {
144
146
  if (!existing) return incoming;
145
147
  if (!incoming) return existing;
146
- const existingSchema = normalizeSchemaReference(existing);
148
+ let existingSchema = normalizeSchemaReference(existing);
147
149
  let incomingSchema = normalizeSchemaReference(incoming);
148
150
  if (!existingSchema) return incoming;
149
151
  if (!incomingSchema) return existing;
150
152
  if (!isTSchema(incomingSchema) && incomingSchema["~standard"])
151
153
  incomingSchema = unwrapSchema(incomingSchema, vendors);
152
- if (!incomingSchema) return existing;
154
+ if (!isTSchema(existingSchema) && existingSchema["~standard"])
155
+ existingSchema = unwrapSchema(existingSchema, vendors);
156
+ if (!incomingSchema) return existingSchema;
157
+ if (!existingSchema) return incomingSchema;
153
158
  const { schema: mergedSchema, notObjects } = mergeObjectSchemas([
154
159
  existingSchema,
155
160
  incomingSchema
@@ -165,7 +170,11 @@ var unwrapResponseSchema = (schema, vendors) => typeof schema === "string" ? nor
165
170
  schema["~standard"] ? unwrapSchema(schema, vendors, "output") : Object.fromEntries(
166
171
  Object.entries(schema).map(([status, schema2]) => [
167
172
  status,
168
- typeof schema2 === "string" ? normalizeSchemaReference(schema2) : isTSchema(schema2) ? schema2 : unwrapSchema(schema2, vendors, "output")
173
+ typeof schema2 === "string" ? normalizeSchemaReference(schema2) : isTSchema(schema2) ? schema2 : unwrapSchema(
174
+ schema2,
175
+ vendors,
176
+ "output"
177
+ )
169
178
  ])
170
179
  )
171
180
  );
@@ -284,13 +293,18 @@ var unwrapSchema = (schema, mapJsonSchema, io = "input") => {
284
293
  if (!schema) return;
285
294
  if (typeof schema === "string") schema = toRef(schema);
286
295
  if (Kind in schema) return enumToOpenApi(schema);
287
- if (Kind in schema || !schema?.["~standard"]) return;
296
+ if (!schema?.["~standard"] && // @ts-ignore
297
+ (schema.$schema || schema.type || schema.properties || schema.items))
298
+ return schema;
299
+ if (!schema?.["~standard"]) return;
288
300
  const vendor = schema["~standard"].vendor;
289
301
  try {
290
- if (schema["~standard"]?.jsonSchema?.[io])
291
- return schema["~standard"]?.jsonSchema?.[io]?.();
292
302
  if (mapJsonSchema?.[vendor] && typeof mapJsonSchema[vendor] === "function")
293
303
  return enumToOpenApi(mapJsonSchema[vendor](schema));
304
+ if (schema["~standard"]?.jsonSchema?.[io])
305
+ return enumToOpenApi(schema["~standard"].jsonSchema[io]({
306
+ target: "draft-2020-12"
307
+ }));
294
308
  switch (vendor) {
295
309
  case "zod":
296
310
  if (warned.zod4 || warned.zod3) break;
@@ -597,7 +611,11 @@ function toOpenAPISchema(app, exclude, references, vendors) {
597
611
  };
598
612
  }
599
613
  } else {
600
- const response = unwrapSchema(hooks.response, vendors, "output");
614
+ const response = unwrapSchema(
615
+ hooks.response,
616
+ vendors,
617
+ "output"
618
+ );
601
619
  if (response) {
602
620
  const {
603
621
  type: _type,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elysiajs/openapi",
3
- "version": "1.4.12",
3
+ "version": "1.4.14",
4
4
  "description": "Plugin for Elysia to auto-generate API documentation",
5
5
  "author": {
6
6
  "name": "saltyAom",
@@ -73,7 +73,6 @@
73
73
  "build": "bun build.ts",
74
74
  "release": "npm run build && npm run test && npm publish --access public"
75
75
  },
76
- "dependencies": {},
77
76
  "devDependencies": {
78
77
  "@apidevtools/swagger-parser": "^12.0.0",
79
78
  "@scalar/types": "^0.2.13",