@kozojs/core 0.3.4 → 0.3.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/lib/index.js +2 -103
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -2389,110 +2389,9 @@ function buildNativeContext(req, res, params, body, services, serialize) {
|
|
|
2389
2389
|
import { z } from "zod";
|
|
2390
2390
|
|
|
2391
2391
|
// src/openapi.ts
|
|
2392
|
+
import { zodToJsonSchema as _zodToJsonSchema } from "zod-to-json-schema";
|
|
2392
2393
|
function zodToJsonSchema2(zodSchema) {
|
|
2393
|
-
|
|
2394
|
-
const def = schema._def;
|
|
2395
|
-
if (!def) {
|
|
2396
|
-
return { type: "object" };
|
|
2397
|
-
}
|
|
2398
|
-
const typeName = def.typeName;
|
|
2399
|
-
switch (typeName) {
|
|
2400
|
-
case "ZodString": {
|
|
2401
|
-
const result = { type: "string" };
|
|
2402
|
-
for (const check of def.checks || []) {
|
|
2403
|
-
if (check.kind === "min") result.minLength = check.value;
|
|
2404
|
-
if (check.kind === "max") result.maxLength = check.value;
|
|
2405
|
-
if (check.kind === "email") result.format = "email";
|
|
2406
|
-
if (check.kind === "url") result.format = "uri";
|
|
2407
|
-
if (check.kind === "uuid") result.format = "uuid";
|
|
2408
|
-
if (check.kind === "regex") result.pattern = check.regex.source;
|
|
2409
|
-
}
|
|
2410
|
-
return result;
|
|
2411
|
-
}
|
|
2412
|
-
case "ZodNumber": {
|
|
2413
|
-
const result = { type: "number" };
|
|
2414
|
-
for (const check of def.checks || []) {
|
|
2415
|
-
if (check.kind === "min") result.minimum = check.value;
|
|
2416
|
-
if (check.kind === "max") result.maximum = check.value;
|
|
2417
|
-
if (check.kind === "int") result.type = "integer";
|
|
2418
|
-
}
|
|
2419
|
-
return result;
|
|
2420
|
-
}
|
|
2421
|
-
case "ZodBoolean":
|
|
2422
|
-
return { type: "boolean" };
|
|
2423
|
-
case "ZodNull":
|
|
2424
|
-
return { type: "null" };
|
|
2425
|
-
case "ZodArray":
|
|
2426
|
-
return {
|
|
2427
|
-
type: "array",
|
|
2428
|
-
items: zodToJsonSchema2(def.type)
|
|
2429
|
-
};
|
|
2430
|
-
case "ZodObject": {
|
|
2431
|
-
const properties = {};
|
|
2432
|
-
const required = [];
|
|
2433
|
-
const shape = def.shape?.() || def.shape;
|
|
2434
|
-
if (shape) {
|
|
2435
|
-
for (const [key, value] of Object.entries(shape)) {
|
|
2436
|
-
properties[key] = zodToJsonSchema2(value);
|
|
2437
|
-
const fieldDef = value._def;
|
|
2438
|
-
if (fieldDef?.typeName !== "ZodOptional" && fieldDef?.typeName !== "ZodDefault") {
|
|
2439
|
-
required.push(key);
|
|
2440
|
-
}
|
|
2441
|
-
}
|
|
2442
|
-
}
|
|
2443
|
-
return {
|
|
2444
|
-
type: "object",
|
|
2445
|
-
properties,
|
|
2446
|
-
...required.length > 0 ? { required } : {}
|
|
2447
|
-
};
|
|
2448
|
-
}
|
|
2449
|
-
case "ZodEnum":
|
|
2450
|
-
return {
|
|
2451
|
-
type: "string",
|
|
2452
|
-
enum: def.values
|
|
2453
|
-
};
|
|
2454
|
-
case "ZodNativeEnum":
|
|
2455
|
-
return {
|
|
2456
|
-
type: "string",
|
|
2457
|
-
enum: Object.values(def.values)
|
|
2458
|
-
};
|
|
2459
|
-
case "ZodLiteral":
|
|
2460
|
-
return {
|
|
2461
|
-
type: typeof def.value,
|
|
2462
|
-
enum: [def.value]
|
|
2463
|
-
};
|
|
2464
|
-
case "ZodUnion":
|
|
2465
|
-
return {
|
|
2466
|
-
oneOf: def.options.map((opt) => zodToJsonSchema2(opt))
|
|
2467
|
-
};
|
|
2468
|
-
case "ZodOptional":
|
|
2469
|
-
return {
|
|
2470
|
-
...zodToJsonSchema2(def.innerType),
|
|
2471
|
-
nullable: true
|
|
2472
|
-
};
|
|
2473
|
-
case "ZodNullable":
|
|
2474
|
-
return {
|
|
2475
|
-
...zodToJsonSchema2(def.innerType),
|
|
2476
|
-
nullable: true
|
|
2477
|
-
};
|
|
2478
|
-
case "ZodDefault":
|
|
2479
|
-
return {
|
|
2480
|
-
...zodToJsonSchema2(def.innerType),
|
|
2481
|
-
default: def.defaultValue()
|
|
2482
|
-
};
|
|
2483
|
-
case "ZodRecord":
|
|
2484
|
-
return {
|
|
2485
|
-
type: "object",
|
|
2486
|
-
additionalProperties: zodToJsonSchema2(def.valueType)
|
|
2487
|
-
};
|
|
2488
|
-
case "ZodDate":
|
|
2489
|
-
return { type: "string", format: "date-time" };
|
|
2490
|
-
case "ZodAny":
|
|
2491
|
-
case "ZodUnknown":
|
|
2492
|
-
return {};
|
|
2493
|
-
default:
|
|
2494
|
-
return { type: "object" };
|
|
2495
|
-
}
|
|
2394
|
+
return _zodToJsonSchema(zodSchema, { $refStrategy: "none" });
|
|
2496
2395
|
}
|
|
2497
2396
|
var OpenAPIGenerator = class {
|
|
2498
2397
|
config;
|