hono-takibi 0.22.0 → 0.24.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/dist/cli.js +4 -4
- package/dist/core/docs/index.d.ts +1 -1
- package/dist/core/docs/index.js +1 -2
- package/dist/core/hooks/index.d.ts +4 -3
- package/dist/core/hooks/index.js +1 -2
- package/dist/core/rpc/index.d.ts +2 -2
- package/dist/core/rpc/index.js +2 -2
- package/dist/core/type/index.d.ts +1 -1
- package/dist/core/type/index.js +1 -1
- package/dist/{core-DmIVe-SP.js → core-Bhi7NjFK.js} +9 -10
- package/dist/{docs-CtXltNLT.js → docs-DTHnPNsq.js} +62 -97
- package/dist/generator/zod-openapi-hono/openapi/index.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/openapi/index.js +1 -2
- package/dist/{hooks-CR7angVC.js → hooks-BRODO70o.js} +2 -2
- package/dist/{index-tsPqeV6H.d.ts → index-B3ze4n_I.d.ts} +2 -2
- package/dist/{index-3BQ2KpP9.d.ts → index-BtPuSeOg.d.ts} +1 -1
- package/dist/{openapi-OxNU2RgN.js → openapi-CRWQo78t.js} +16 -18
- package/dist/{rpc-Bgtv3nGI.js → rpc-CoHJtjYX.js} +1 -1
- package/dist/{shared-C9-30gJ4.js → shared-CYeurBoC.js} +3 -3
- package/dist/{utils-vw99OasL.js → utils-Dznx-EnJ.js} +13 -1
- package/dist/vite-plugin/index.js +3 -3
- package/package.json +12 -12
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
|
5
5
|
import { Console, Effect, FileSystem, Option, Path, Ref, Schema, Stream } from "effect";
|
|
6
6
|
import { Argument, CliError, Command, Flag } from "effect/cli";
|
|
7
7
|
//#region package.json
|
|
8
|
-
var version = "0.
|
|
8
|
+
var version = "0.24.0";
|
|
9
9
|
var description = "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi";
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/cli/index.ts
|
|
@@ -42,7 +42,7 @@ function runJobs(config) {
|
|
|
42
42
|
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob, packageRoots }] = yield* Effect.promise(() => Promise.all([
|
|
43
43
|
import("./openapi-DEZCoJlc.js").then((n) => n.t),
|
|
44
44
|
import("./format-CuHABcKC.js").then((n) => n.r),
|
|
45
|
-
import("./shared-
|
|
45
|
+
import("./shared-CYeurBoC.js").then((n) => n.a)
|
|
46
46
|
]));
|
|
47
47
|
const openAPI = yield* parseOpenAPI(config.input);
|
|
48
48
|
const jobs = makeJob(openAPI, config, yield* packageRoots(openAPI, config));
|
|
@@ -80,7 +80,7 @@ function reportJobs(config, previous) {
|
|
|
80
80
|
onFailure: (error) => Console.error(`❌ ${error.message}`),
|
|
81
81
|
onSuccess: (report) => Console.log(report)
|
|
82
82
|
}));
|
|
83
|
-
const { outsideSources } = yield* Effect.promise(() => import("./shared-
|
|
83
|
+
const { outsideSources } = yield* Effect.promise(() => import("./shared-CYeurBoC.js").then((n) => n.a));
|
|
84
84
|
const inputDirectory = path.dirname(path.resolve(config.input));
|
|
85
85
|
return {
|
|
86
86
|
inputDirectory,
|
|
@@ -207,7 +207,7 @@ function generate(args) {
|
|
|
207
207
|
})]
|
|
208
208
|
});
|
|
209
209
|
if (input !== void 0 && output !== void 0) {
|
|
210
|
-
const [{ parseOpenAPI }, { takibi }] = yield* Effect.promise(() => Promise.all([import("./openapi-DEZCoJlc.js").then((n) => n.t), import("./core-
|
|
210
|
+
const [{ parseOpenAPI }, { takibi }] = yield* Effect.promise(() => Promise.all([import("./openapi-DEZCoJlc.js").then((n) => n.t), import("./core-Bhi7NjFK.js").then((n) => n.t)]));
|
|
211
211
|
return yield* Console.log(yield* takibi(yield* parseOpenAPI(input), output));
|
|
212
212
|
}
|
|
213
213
|
const resolvedConfig = configPath ?? DEFAULT_CONFIG_FILE;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../index-
|
|
1
|
+
import { t as OpenAPI } from "../../index-B3ze4n_I.js";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
3
|
//#region src/core/docs/index.d.ts
|
|
4
4
|
export declare function docs(openAPI: OpenAPI, output: string, entry?: string, basePath?: string, curl?: boolean, baseUrl?: string): Effect.Effect<string, import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
package/dist/core/docs/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { docs };
|
|
1
|
+
export { t as docs } from "../../docs-DTHnPNsq.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../index-
|
|
1
|
+
import { t as OpenAPI } from "../../index-B3ze4n_I.js";
|
|
2
2
|
import { n as GenerateError, t as FormatError } from "../../index-D_gf3Xzx.js";
|
|
3
|
-
import { t as Grouping } from "../../index-
|
|
3
|
+
import { t as Grouping } from "../../index-BtPuSeOg.js";
|
|
4
4
|
//#region src/core/hooks/index.d.ts
|
|
5
5
|
declare const HOOK_CONFIGS: {
|
|
6
6
|
readonly swr: {
|
|
@@ -167,4 +167,5 @@ export declare function hooks(openAPI: OpenAPI, output: string, importPath: stri
|
|
|
167
167
|
readonly grouping?: Grouping;
|
|
168
168
|
readonly basePath?: string;
|
|
169
169
|
}): import("effect/Effect").Effect<`Generated ${string} hooks written to ${string}`, FormatError | GenerateError | import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
|
170
|
-
//#endregion
|
|
170
|
+
//#endregion
|
|
171
|
+
export {};
|
package/dist/core/hooks/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { hooks };
|
|
1
|
+
export { t as hooks } from "../../hooks-BRODO70o.js";
|
package/dist/core/rpc/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../index-
|
|
1
|
+
import { t as OpenAPI } from "../../index-B3ze4n_I.js";
|
|
2
2
|
import { n as GenerateError, t as FormatError } from "../../index-D_gf3Xzx.js";
|
|
3
|
-
import { t as Grouping } from "../../index-
|
|
3
|
+
import { t as Grouping } from "../../index-BtPuSeOg.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
//#region src/core/rpc/index.d.ts
|
|
6
6
|
/**
|
package/dist/core/rpc/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { s as HTTP_METHODS } from "../../constants-Bz8YiPum.js";
|
|
2
2
|
import { i as GenerateError } from "../../format-CuHABcKC.js";
|
|
3
|
-
import {
|
|
4
|
-
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-
|
|
3
|
+
import { B as isOperationLike, J as isRecord, R as isOpenAPIPaths, p as methodPath, u as makeInferRequestType } from "../../utils-Dznx-EnJ.js";
|
|
4
|
+
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-CoHJtjYX.js";
|
|
5
5
|
import { t as emit } from "../../emit-uwlZZeRM.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import { dirname } from "node:path";
|
package/dist/core/type/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../../constants-Bz8YiPum.js";
|
|
2
|
-
import {
|
|
2
|
+
import { $ as isSchemaArray, H as isParameterArray, I as isMediaWithSchema, M as isHttpMethod, R as isOpenAPIPaths, V as isParameter, Z as isRequestBody, _ as statusCodeToNumber, at as isStringRef, d as makeSafeKey, v as toIdentifierPascalCase, z as isOperation } from "../../utils-Dznx-EnJ.js";
|
|
3
3
|
import { t as emit } from "../../emit-uwlZZeRM.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
2
|
import { n as COMPONENT_NAMES, p as TEXT_MEDIA_TYPE, r as COMPONENT_REF_PREFIX, s as HTTP_METHODS, u as JSON_MEDIA_TYPE } from "./constants-Bz8YiPum.js";
|
|
3
3
|
import { i as GenerateError, n as fmt } from "./format-CuHABcKC.js";
|
|
4
|
-
import { $ as
|
|
5
|
-
import { A as resolvePathItem, C as makeCallback, D as makeRouteProperties, E as makeRouteEntries, O as makeWebhookEntries, S as zodToOpenAPI, T as makeRef, _ as descendantsWhere, a as responsesCode, b as parseSource, c as headersCode, d as makeExportConst, f as makeImports, g as declarationOf, h as ast, i as schemasCode, k as resolveParameter, l as makeSplitSchemaFile, m as analyzeCircularSchemas, n as routeCode, o as requestBodiesCode, p as makeModuleSpec, r as componentsCode, s as parametersCode, t as zodOpenAPIHono, u as makeConst, v as identifierNames, w as makePathItem, x as textOf, y as parseModule } from "./openapi-
|
|
6
|
-
import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-
|
|
4
|
+
import { $ as isSchemaArray, E as hasRequestBodyContent, G as isPathItem, I as isMediaWithSchema, K as isPathItemEntry, M as isHttpMethod, O as isCallbacks, P as isInlineMedia, R as isOpenAPIPaths, T as hasNumericConstraint, V as isParameter, Y as isRefObject, _ as statusCodeToNumber, a as ensureSuffix, b as uncapitalizeWord, c as escapeRegexLiteral, d as makeSafeKey, et as isSchemaObject, f as makeStringLiteral, h as renderNamedImport, l as makeBarrel, m as normalizeTypes, nt as isSecurityArray, ot as isValidIdent, p as methodPath, q as isPathItemRef, r as cyclicNodes, rt as isSecurityScheme, v as toIdentifierPascalCase, x as zodToOpenAPISchema, y as uncapitalize, z as isOperation } from "./utils-Dznx-EnJ.js";
|
|
5
|
+
import { A as resolvePathItem, C as makeCallback, D as makeRouteProperties, E as makeRouteEntries, O as makeWebhookEntries, S as zodToOpenAPI, T as makeRef, _ as descendantsWhere, a as responsesCode, b as parseSource, c as headersCode, d as makeExportConst, f as makeImports, g as declarationOf, h as ast, i as schemasCode, k as resolveParameter, l as makeSplitSchemaFile, m as analyzeCircularSchemas, n as routeCode, o as requestBodiesCode, p as makeModuleSpec, r as componentsCode, s as parametersCode, t as zodOpenAPIHono, u as makeConst, v as identifierNames, w as makePathItem, x as textOf, y as parseModule } from "./openapi-CRWQo78t.js";
|
|
6
|
+
import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-CoHJtjYX.js";
|
|
7
7
|
import { i as readdir, n as mkdir, o as writeFile, r as readFile } from "./file-K6j5IJXi.js";
|
|
8
8
|
import { t as emit } from "./emit-uwlZZeRM.js";
|
|
9
|
-
import { t as hooks } from "./hooks-
|
|
10
|
-
import { t as docs } from "./docs-
|
|
9
|
+
import { t as hooks } from "./hooks-BRODO70o.js";
|
|
10
|
+
import { t as docs } from "./docs-DTHnPNsq.js";
|
|
11
11
|
import { rpc } from "./core/rpc/index.js";
|
|
12
12
|
import { type } from "./core/type/index.js";
|
|
13
13
|
import { Effect } from "effect";
|
|
@@ -320,12 +320,12 @@ function numericRange(schema, integer) {
|
|
|
320
320
|
...schema.multipleOf !== void 0 ? { multipleOf: schema.multipleOf } : {}
|
|
321
321
|
};
|
|
322
322
|
}
|
|
323
|
-
const OPEN_RANGE_SPAN = 1e3;
|
|
324
323
|
function closedRange(range, defaultMin, defaultMax) {
|
|
325
|
-
const
|
|
324
|
+
const span = defaultMax - defaultMin;
|
|
325
|
+
const min = range.min ?? (range.max === void 0 || range.max > defaultMin ? defaultMin : range.max > 0 ? 0 : range.max - span);
|
|
326
326
|
return {
|
|
327
327
|
min,
|
|
328
|
-
max: range.max ?? (min < defaultMax ? defaultMax : min +
|
|
328
|
+
max: range.max ?? (min < defaultMax ? defaultMax : min + span)
|
|
329
329
|
};
|
|
330
330
|
}
|
|
331
331
|
function numericFaker(schema, range) {
|
|
@@ -357,7 +357,6 @@ function numericFaker(schema, range) {
|
|
|
357
357
|
]).join(", ")} })`;
|
|
358
358
|
}
|
|
359
359
|
const MAX_RECURSION_DEPTH = 2;
|
|
360
|
-
const MAX_REQUIRED_RECURSION_DEPTH = 16;
|
|
361
360
|
function containsRecursion(value) {
|
|
362
361
|
return value.includes("(depth + 1)");
|
|
363
362
|
}
|
|
@@ -475,7 +474,7 @@ function schemaValue(schema, propertyName, options = {}) {
|
|
|
475
474
|
if (schema.enum && schema.enum.length > 0) return `faker.helpers.arrayElement([${schema.enum.map((v) => JSON.stringify(v)).join(", ")}] as const)`;
|
|
476
475
|
if (schema.$ref) {
|
|
477
476
|
const call = recursiveCall(schema, options.recursive);
|
|
478
|
-
if (call !== void 0) return `(depth < ${
|
|
477
|
+
if (call !== void 0) return `(depth < ${MAX_RECURSION_DEPTH} ? ${call} : undefined)`;
|
|
479
478
|
return `${mockFunctionName(schema.$ref.split("/").pop() || "unknown")}()`;
|
|
480
479
|
}
|
|
481
480
|
if (Array.isArray(schema.type)) {
|
|
@@ -1,30 +1,10 @@
|
|
|
1
1
|
import { d as MULTIPART_MEDIA_TYPE, s as HTTP_METHODS } from "./constants-Bz8YiPum.js";
|
|
2
|
-
import { J as
|
|
2
|
+
import { $ as isSchemaArray, J as isRecord, Y as isRefObject, i as decodePercent, s as escapeHtml } from "./utils-Dznx-EnJ.js";
|
|
3
3
|
import { n as mkdir, o as writeFile } from "./file-K6j5IJXi.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { STATUS_CODES } from "node:http";
|
|
7
7
|
//#region src/generator/docs/index.ts
|
|
8
|
-
const MAX_SCHEMA_DEPTH = 50;
|
|
9
|
-
const MAX_REF_HOPS = 10;
|
|
10
|
-
const MAX_EXAMPLE_ITEMS = 10;
|
|
11
|
-
/**
|
|
12
|
-
* How many `$ref`s one table or one example may expand in total.
|
|
13
|
-
*
|
|
14
|
-
* The bound on the size of the document: every table and example of every operation
|
|
15
|
-
* expands what it refers to, so a document whose schemas all reach each other writes
|
|
16
|
-
* this many schemas into each of them. At 1000, 500 such schemas and 600 operations
|
|
17
|
-
* made a document too large for a string; a table or example that expands 50 schemas
|
|
18
|
-
* is past what anyone reads, and past that the schema is still named and linked.
|
|
19
|
-
*/
|
|
20
|
-
const MAX_REF_EXPANSIONS = 50;
|
|
21
|
-
/**
|
|
22
|
-
* How many times one table or one example expands the same recursive schema.
|
|
23
|
-
* Cycle detection works per path, so schemas that reference each other would
|
|
24
|
-
* otherwise be expanded once per path through them, which grows factorially.
|
|
25
|
-
* Past the limit the schema is still named and linked, just not expanded.
|
|
26
|
-
*/
|
|
27
|
-
const MAX_EXPANSIONS_PER_RECURSIVE_REF = 2;
|
|
28
8
|
const documentCaches = /* @__PURE__ */ new WeakMap();
|
|
29
9
|
function cacheOf(doc) {
|
|
30
10
|
const found = documentCaches.get(doc);
|
|
@@ -70,13 +50,6 @@ function toText(value) {
|
|
|
70
50
|
function toSingleLine(value) {
|
|
71
51
|
return value.replaceAll(/\s+/gu, " ").trim();
|
|
72
52
|
}
|
|
73
|
-
function decodePercent(value) {
|
|
74
|
-
try {
|
|
75
|
-
return decodeURIComponent(value);
|
|
76
|
-
} catch {
|
|
77
|
-
return value;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
53
|
/**
|
|
81
54
|
* Decodes one JSON Pointer segment of a URI fragment: percent-encoding first,
|
|
82
55
|
* then `~1` and `~0` (RFC 6901 §6).
|
|
@@ -107,13 +80,14 @@ function resolveRef(ref, doc) {
|
|
|
107
80
|
return value;
|
|
108
81
|
}
|
|
109
82
|
/**
|
|
110
|
-
* Follows a Reference Object until it reaches a value
|
|
111
|
-
*
|
|
83
|
+
* Follows a Reference Object until it reaches a value, or comes back to a reference it
|
|
84
|
+
* has followed: a cycle of references names nothing. Schemas go through `derefSchema`
|
|
85
|
+
* instead, which tracks cycles the same way.
|
|
112
86
|
*/
|
|
113
|
-
function resolveRefDeep(value, doc,
|
|
87
|
+
function resolveRefDeep(value, doc, seen = /* @__PURE__ */ new Set()) {
|
|
114
88
|
if (!isRefObject(value)) return value;
|
|
115
|
-
if (
|
|
116
|
-
return resolveRefDeep(resolveRef(value.$ref, doc), doc,
|
|
89
|
+
if (seen.has(value.$ref)) return void 0;
|
|
90
|
+
return resolveRefDeep(resolveRef(value.$ref, doc), doc, /* @__PURE__ */ new Set([...seen, value.$ref]));
|
|
117
91
|
}
|
|
118
92
|
/**
|
|
119
93
|
* Name of the schema a `$ref` points at, when it points at `components.schemas`.
|
|
@@ -267,27 +241,19 @@ function isRecursiveRef(ref, doc) {
|
|
|
267
241
|
recursive.set(ref, result);
|
|
268
242
|
return result;
|
|
269
243
|
}
|
|
270
|
-
function makeBudget(doc) {
|
|
271
|
-
const counts = /* @__PURE__ */ new Map();
|
|
272
|
-
const state = { left: MAX_REF_EXPANSIONS };
|
|
273
|
-
return { take: (ref) => {
|
|
274
|
-
const count = counts.get(ref) ?? 0;
|
|
275
|
-
const isRecursive = isRecursiveRef(ref, doc);
|
|
276
|
-
if (state.left <= 0) return false;
|
|
277
|
-
if (isRecursive && count >= MAX_EXPANSIONS_PER_RECURSIVE_REF) return false;
|
|
278
|
-
state.left -= 1;
|
|
279
|
-
counts.set(ref, count + 1);
|
|
280
|
-
return true;
|
|
281
|
-
} };
|
|
282
|
-
}
|
|
283
244
|
/**
|
|
284
|
-
* `derefSchema` for a schema that is about to be expanded:
|
|
285
|
-
*
|
|
245
|
+
* `derefSchema` for a schema that is about to be expanded: a `$ref` to a schema that
|
|
246
|
+
* reaches itself is followed unless the walk is already inside such a schema, and what
|
|
247
|
+
* it opens is inside one.
|
|
286
248
|
*/
|
|
287
|
-
function expandSchema(schema, doc,
|
|
288
|
-
|
|
289
|
-
if (
|
|
290
|
-
|
|
249
|
+
function expandSchema(schema, doc, inside) {
|
|
250
|
+
const recursive = schema.$ref !== void 0 && isRecursiveRef(schema.$ref, doc);
|
|
251
|
+
if (recursive && inside) return void 0;
|
|
252
|
+
const target = derefSchema(schema, doc, /* @__PURE__ */ new Set());
|
|
253
|
+
return target && {
|
|
254
|
+
schema: target.schema,
|
|
255
|
+
inside: inside || recursive
|
|
256
|
+
};
|
|
291
257
|
}
|
|
292
258
|
function primaryType(schema) {
|
|
293
259
|
return Array.isArray(schema.type) ? schema.type.find((t) => t !== "null") : schema.type;
|
|
@@ -323,12 +289,12 @@ function inferType(value) {
|
|
|
323
289
|
if (typeof value === "string" || typeof value === "boolean") return typeof value;
|
|
324
290
|
return "object";
|
|
325
291
|
}
|
|
326
|
-
function baseTypeOf(schema, doc, visited
|
|
292
|
+
function baseTypeOf(schema, doc, visited) {
|
|
327
293
|
if (Array.isArray(schema.type)) return schema.type.join(" | ");
|
|
328
294
|
if (schema.type !== void 0) return schema.type;
|
|
329
295
|
if (isRecord(schema.properties)) return "object";
|
|
330
296
|
const variants = variantsOf(schema);
|
|
331
|
-
if (variants.length > 0) return [...new Set(variants.map((variant) => formatSchemaType(variant.schema, doc, visited
|
|
297
|
+
if (variants.length > 0) return [...new Set(variants.map((variant) => formatSchemaType(variant.schema, doc, visited)))].join(" | ");
|
|
332
298
|
if (schema.const !== void 0) return inferType(schema.const);
|
|
333
299
|
if (schema.enum && schema.enum.length > 0) return inferType(schema.enum[0]);
|
|
334
300
|
return "object";
|
|
@@ -337,21 +303,21 @@ function baseTypeOf(schema, doc, visited, depth) {
|
|
|
337
303
|
* Formats a schema type string as widdershins does.
|
|
338
304
|
* Examples: "string(email)", "integer(int64)", "[User](#schemauser)", "[[User](#schemauser)]"
|
|
339
305
|
*/
|
|
340
|
-
function formatSchemaType(schema, doc, visited = /* @__PURE__ */ new Set()
|
|
341
|
-
if (!isSchemaLike(schema)
|
|
306
|
+
function formatSchemaType(schema, doc, visited = /* @__PURE__ */ new Set()) {
|
|
307
|
+
if (!isSchemaLike(schema)) return "object";
|
|
342
308
|
if (schema.$ref) {
|
|
343
309
|
const name = componentSchemaName(schema.$ref);
|
|
344
310
|
if (name) return makeSchemaLink(name, doc);
|
|
345
311
|
const target = derefSchema(schema, doc, visited);
|
|
346
|
-
return target ? formatSchemaType(target.schema, doc, target.visited
|
|
312
|
+
return target ? formatSchemaType(target.schema, doc, target.visited) : "object";
|
|
347
313
|
}
|
|
348
314
|
if (isArraySchema(schema)) {
|
|
349
315
|
const item = arrayItemSchema(schema);
|
|
350
|
-
if (item) return `[${formatSchemaType(item, doc, visited
|
|
351
|
-
if (schema.prefixItems && schema.prefixItems.length > 0) return `[${schema.prefixItems.map((entry) => formatSchemaType(entry, doc, visited
|
|
316
|
+
if (item) return `[${formatSchemaType(item, doc, visited)}]`;
|
|
317
|
+
if (schema.prefixItems && schema.prefixItems.length > 0) return `[${schema.prefixItems.map((entry) => formatSchemaType(entry, doc, visited)).join(", ")}]`;
|
|
352
318
|
return "array";
|
|
353
319
|
}
|
|
354
|
-
const baseType = baseTypeOf(schema, doc, visited
|
|
320
|
+
const baseType = baseTypeOf(schema, doc, visited);
|
|
355
321
|
const formatted = schema.format ? `${baseType}(${schema.format})` : baseType;
|
|
356
322
|
return schema.nullable === true && !baseType.split(" | ").includes("null") ? `${formatted} | null` : formatted;
|
|
357
323
|
}
|
|
@@ -432,7 +398,7 @@ function isHidden(schema, direction) {
|
|
|
432
398
|
if (direction === "response") return schema.writeOnly === true;
|
|
433
399
|
return false;
|
|
434
400
|
}
|
|
435
|
-
function isHiddenProperty(schema, doc, direction, visited) {
|
|
401
|
+
function isHiddenProperty(schema, doc, direction, visited = /* @__PURE__ */ new Set()) {
|
|
436
402
|
if (!isSchemaLike(schema)) return false;
|
|
437
403
|
if (isHidden(schema, direction)) return true;
|
|
438
404
|
const target = derefSchema(schema, doc, visited);
|
|
@@ -441,14 +407,13 @@ function isHiddenProperty(schema, doc, direction, visited) {
|
|
|
441
407
|
function isNullSchema(schema) {
|
|
442
408
|
return schema.type === "null" || Array.isArray(schema.type) && primaryType(schema) === void 0;
|
|
443
409
|
}
|
|
444
|
-
function makeExampleFromSchema(schema, doc, direction = "schema",
|
|
445
|
-
if (depth > MAX_SCHEMA_DEPTH) return {};
|
|
410
|
+
function makeExampleFromSchema(schema, doc, direction = "schema", inside = false) {
|
|
446
411
|
if (!isSchemaLike(schema)) return null;
|
|
447
412
|
if (schema.example !== void 0) return schema.example;
|
|
448
413
|
if (schema.$ref) {
|
|
449
|
-
const target = expandSchema(schema, doc,
|
|
414
|
+
const target = expandSchema(schema, doc, inside);
|
|
450
415
|
if (!target) return {};
|
|
451
|
-
return makeExampleFromSchema(target.schema, doc, direction, target.
|
|
416
|
+
return makeExampleFromSchema(target.schema, doc, direction, target.inside);
|
|
452
417
|
}
|
|
453
418
|
const listed = firstExampleValue(schema.examples, doc);
|
|
454
419
|
if (listed !== void 0) return listed;
|
|
@@ -461,15 +426,15 @@ function makeExampleFromSchema(schema, doc, direction = "schema", visited = /* @
|
|
|
461
426
|
const result = {};
|
|
462
427
|
const parts = [...schema.allOf ?? [], ...variant ? [variant.schema] : []];
|
|
463
428
|
for (const part of parts) {
|
|
464
|
-
const example = makeExampleFromSchema(part, doc, direction,
|
|
429
|
+
const example = makeExampleFromSchema(part, doc, direction, inside);
|
|
465
430
|
if (isRecord(example)) Object.assign(result, example);
|
|
466
431
|
}
|
|
467
432
|
for (const [key, propSchema] of Object.entries(schema.properties ?? {})) {
|
|
468
|
-
if (isHiddenProperty(propSchema, doc, direction
|
|
469
|
-
result[key] = makeExampleFromSchema(propSchema, doc, direction,
|
|
433
|
+
if (isHiddenProperty(propSchema, doc, direction)) continue;
|
|
434
|
+
result[key] = makeExampleFromSchema(propSchema, doc, direction, inside);
|
|
470
435
|
}
|
|
471
436
|
if (isSchemaLike(extra)) {
|
|
472
|
-
const value = makeExampleFromSchema(extra, doc, direction,
|
|
437
|
+
const value = makeExampleFromSchema(extra, doc, direction, inside);
|
|
473
438
|
result.property1 = value;
|
|
474
439
|
result.property2 = value;
|
|
475
440
|
}
|
|
@@ -479,13 +444,13 @@ function makeExampleFromSchema(schema, doc, direction = "schema", visited = /* @
|
|
|
479
444
|
if (schema.maxItems === 0) return [];
|
|
480
445
|
const item = arrayItemSchema(schema);
|
|
481
446
|
if (item) {
|
|
482
|
-
const value = makeExampleFromSchema(item, doc, direction,
|
|
483
|
-
const count = Math.
|
|
447
|
+
const value = makeExampleFromSchema(item, doc, direction, inside);
|
|
448
|
+
const count = Math.max(schema.minItems ?? 1, 1);
|
|
484
449
|
return Array.from({ length: count }, () => value);
|
|
485
450
|
}
|
|
486
|
-
return (schema.prefixItems ?? []).map((entry) => makeExampleFromSchema(entry, doc, direction,
|
|
451
|
+
return (schema.prefixItems ?? []).map((entry) => makeExampleFromSchema(entry, doc, direction, inside));
|
|
487
452
|
}
|
|
488
|
-
if (variant) return makeExampleFromSchema(variant.schema, doc, direction,
|
|
453
|
+
if (variant) return makeExampleFromSchema(variant.schema, doc, direction, inside);
|
|
489
454
|
return makeDefaultValue(schema);
|
|
490
455
|
}
|
|
491
456
|
function extractMediaExample(media, doc) {
|
|
@@ -920,13 +885,13 @@ function makeBodyParameterBlock(operation, doc) {
|
|
|
920
885
|
/**
|
|
921
886
|
* Enum values of a schema, following `$ref` and looking into array items.
|
|
922
887
|
*/
|
|
923
|
-
function enumValuesOf(schema, doc, visited = /* @__PURE__ */ new Set()
|
|
924
|
-
if (!isSchemaLike(schema)
|
|
888
|
+
function enumValuesOf(schema, doc, visited = /* @__PURE__ */ new Set()) {
|
|
889
|
+
if (!isSchemaLike(schema)) return [];
|
|
925
890
|
const target = derefSchema(schema, doc, visited);
|
|
926
891
|
if (!target) return [];
|
|
927
892
|
if (Array.isArray(target.schema.enum)) return target.schema.enum;
|
|
928
893
|
const item = isArraySchema(target.schema) ? arrayItemSchema(target.schema) : void 0;
|
|
929
|
-
return item ? enumValuesOf(item, doc, target.visited
|
|
894
|
+
return item ? enumValuesOf(item, doc, target.visited) : [];
|
|
930
895
|
}
|
|
931
896
|
function formatEnumValue(value) {
|
|
932
897
|
if (typeof value === "string") return value === "" ? "\"\"" : value;
|
|
@@ -946,47 +911,47 @@ function describe(description, deprecated) {
|
|
|
946
911
|
* `required` of a schema together with that of its `allOf` parts: a part often
|
|
947
912
|
* carries only `required` for properties another part declares.
|
|
948
913
|
*/
|
|
949
|
-
function collectRequired(schema, doc, visited
|
|
950
|
-
if (!isSchemaLike(schema)
|
|
914
|
+
function collectRequired(schema, doc, visited = /* @__PURE__ */ new Set()) {
|
|
915
|
+
if (!isSchemaLike(schema)) return [];
|
|
951
916
|
const target = derefSchema(schema, doc, visited);
|
|
952
917
|
if (!target) return [];
|
|
953
|
-
return [...target.schema.required ?? [], ...(target.schema.allOf ?? []).flatMap((part) => collectRequired(part, doc, target.visited
|
|
918
|
+
return [...target.schema.required ?? [], ...(target.schema.allOf ?? []).flatMap((part) => collectRequired(part, doc, target.visited))];
|
|
954
919
|
}
|
|
955
|
-
function flattenFields(schema, doc, prefix, options,
|
|
956
|
-
if (
|
|
957
|
-
const target = expandSchema(schema, doc,
|
|
920
|
+
function flattenFields(schema, doc, prefix, options, inheritedRequired = [], inside = false) {
|
|
921
|
+
if (!isSchemaLike(schema)) return [];
|
|
922
|
+
const target = expandSchema(schema, doc, inside);
|
|
958
923
|
if (!target) return [];
|
|
959
924
|
const current = target.schema;
|
|
960
|
-
const
|
|
925
|
+
const within = target.inside;
|
|
961
926
|
const nestedPrefix = prefix ? `${prefix} »` : "»";
|
|
962
927
|
const named = (name) => prefix ? `${prefix} ${name}` : name;
|
|
963
|
-
const required = [...inheritedRequired, ...collectRequired(current, doc
|
|
928
|
+
const required = [...inheritedRequired, ...collectRequired(current, doc)];
|
|
964
929
|
const requiredSet = new Set(required);
|
|
965
930
|
const nestedRows = (propSchema) => {
|
|
966
931
|
if (!options.deep) return [];
|
|
967
|
-
const prop = expandSchema(propSchema, doc,
|
|
932
|
+
const prop = expandSchema(propSchema, doc, within);
|
|
968
933
|
if (!prop) return [];
|
|
969
|
-
if (hasFields(prop.schema)) return flattenFields(prop.schema, doc, nestedPrefix, options,
|
|
934
|
+
if (hasFields(prop.schema)) return flattenFields(prop.schema, doc, nestedPrefix, options, [], prop.inside);
|
|
970
935
|
const item = isArraySchema(prop.schema) ? arrayItemSchema(prop.schema) : void 0;
|
|
971
|
-
const resolvedItem = item ? expandSchema(item, doc, prop.
|
|
972
|
-
if (resolvedItem && hasFields(resolvedItem.schema)) return flattenFields(resolvedItem.schema, doc, nestedPrefix, options,
|
|
936
|
+
const resolvedItem = item ? expandSchema(item, doc, prop.inside) : void 0;
|
|
937
|
+
if (resolvedItem && hasFields(resolvedItem.schema)) return flattenFields(resolvedItem.schema, doc, nestedPrefix, options, [], resolvedItem.inside);
|
|
973
938
|
return [];
|
|
974
939
|
};
|
|
975
940
|
const makeRow = (name, propSchema, isRequired) => {
|
|
976
|
-
const resolved = derefSchema(propSchema, doc,
|
|
941
|
+
const resolved = derefSchema(propSchema, doc, /* @__PURE__ */ new Set())?.schema;
|
|
977
942
|
return {
|
|
978
943
|
name: named(name),
|
|
979
|
-
type: formatSchemaType(propSchema, doc
|
|
944
|
+
type: formatSchemaType(propSchema, doc),
|
|
980
945
|
required: isRequired,
|
|
981
946
|
restrictions: restrictionsOf(resolved ?? propSchema),
|
|
982
947
|
description: describe(propSchema.description ?? resolved?.description, propSchema.deprecated ?? resolved?.deprecated),
|
|
983
|
-
enums: enumValuesOf(propSchema, doc
|
|
948
|
+
enums: enumValuesOf(propSchema, doc)
|
|
984
949
|
};
|
|
985
950
|
};
|
|
986
|
-
const inherited = (current.allOf ?? []).flatMap((part) => flattenFields(part, doc, prefix, options,
|
|
987
|
-
const own = isObjectSchema(current) ? Object.entries(current.properties).filter(([, propSchema]) => isSchemaLike(propSchema) && !isHiddenProperty(propSchema, doc, options.direction
|
|
951
|
+
const inherited = (current.allOf ?? []).flatMap((part) => flattenFields(part, doc, prefix, options, required, within));
|
|
952
|
+
const own = isObjectSchema(current) ? Object.entries(current.properties).filter(([, propSchema]) => isSchemaLike(propSchema) && !isHiddenProperty(propSchema, doc, options.direction)).flatMap(([key, propSchema]) => [makeRow(key, propSchema, requiredSet.has(key)), ...nestedRows(propSchema)]) : [];
|
|
988
953
|
const extra = isSchemaLike(current.additionalProperties) ? [makeRow("**additionalProperties**", current.additionalProperties, false), ...nestedRows(current.additionalProperties)] : [];
|
|
989
|
-
const variants = variantsOf(current).flatMap((variant) => [makeRow(`*${variant.keyword}*`, variant.schema, false), ...flattenFields(variant.schema, doc, prefix, options,
|
|
954
|
+
const variants = variantsOf(current).flatMap((variant) => [makeRow(`*${variant.keyword}*`, variant.schema, false), ...flattenFields(variant.schema, doc, prefix, options, required, within)]);
|
|
990
955
|
const rows = [
|
|
991
956
|
...inherited,
|
|
992
957
|
...own,
|
|
@@ -998,18 +963,18 @@ function flattenFields(schema, doc, prefix, options, visited = /* @__PURE__ */ n
|
|
|
998
963
|
if (!item) return [];
|
|
999
964
|
const anonymous = options.anonymous ? [{
|
|
1000
965
|
name: "*anonymous*",
|
|
1001
|
-
type: `[${formatSchemaType(item, doc
|
|
966
|
+
type: `[${formatSchemaType(item, doc)}]`,
|
|
1002
967
|
required: false,
|
|
1003
968
|
restrictions: "none",
|
|
1004
969
|
description: "none",
|
|
1005
970
|
enums: []
|
|
1006
971
|
}] : [];
|
|
1007
|
-
const resolvedItem = expandSchema(item, doc,
|
|
972
|
+
const resolvedItem = expandSchema(item, doc, within);
|
|
1008
973
|
if (!(resolvedItem && hasFields(resolvedItem.schema))) return anonymous;
|
|
1009
974
|
return [...anonymous, ...flattenFields(resolvedItem.schema, doc, "»", {
|
|
1010
975
|
...options,
|
|
1011
976
|
anonymous: false
|
|
1012
|
-
},
|
|
977
|
+
}, [], resolvedItem.inside)];
|
|
1013
978
|
}
|
|
1014
979
|
function makeFieldTable(fields) {
|
|
1015
980
|
return [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../../index-
|
|
1
|
+
import { t as OpenAPI } from "../../../index-B3ze4n_I.js";
|
|
2
2
|
//#region src/generator/zod-openapi-hono/openapi/index.d.ts
|
|
3
3
|
export declare function zodOpenAPIHono(openapi: OpenAPI, options?: {
|
|
4
4
|
readonly readonly?: boolean;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { zodOpenAPIHono };
|
|
1
|
+
export { t as zodOpenAPIHono } from "../../../openapi-CRWQo78t.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { s as HTTP_METHODS } from "./constants-Bz8YiPum.js";
|
|
2
2
|
import { i as GenerateError } from "./format-CuHABcKC.js";
|
|
3
|
-
import {
|
|
4
|
-
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "./rpc-
|
|
3
|
+
import { B as isOperationLike, J as isRecord, R as isOpenAPIPaths, S as hasNoContentResponse, n as capitalize, p as methodPath, v as toIdentifierPascalCase } from "./utils-Dznx-EnJ.js";
|
|
4
|
+
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "./rpc-CoHJtjYX.js";
|
|
5
5
|
import { t as emit } from "./emit-uwlZZeRM.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import path from "node:path";
|
|
@@ -418,8 +418,8 @@ type Schema$1 = {
|
|
|
418
418
|
readonly 'x-coerce'?: boolean;
|
|
419
419
|
/**
|
|
420
420
|
* Opt into `z.stringbool()` for boolean schemas. Use `true` for the default
|
|
421
|
-
* truthy/falsy lists, or pass an object to customize.
|
|
422
|
-
*
|
|
421
|
+
* truthy/falsy lists, or pass an object to customize. Beside it, `x-coerce`
|
|
422
|
+
* has nothing left to read: `z.stringbool()` is what the schema emits.
|
|
423
423
|
* @see https://zod.dev/api?id=stringbool
|
|
424
424
|
*/
|
|
425
425
|
readonly 'x-stringbool'?: true | {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as FORM_MEDIA_TYPES, r as COMPONENT_REF_PREFIX, s as HTTP_METHODS, t as ARROW_FUNCTION_PATTERN } from "./constants-Bz8YiPum.js";
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as isSchemaArray, A as isExamplesInput, C as hasNoUserChain, D as hasTypelessConstraint, F as isMedia, G as isPathItem, J as isRecord, K as isPathItemEntry, L as isOffsetTime, N as isInheritedName, O as isCallbacks, Q as isResponses, V as isParameter, W as isParameterRef, X as isRefOnly, Y as isRefObject, a as ensureSuffix, c as escapeRegexLiteral, d as makeSafeKey, et as isSchemaObject, f as makeStringLiteral, g as requestParamsArray, h as renderNamedImport, i as decodePercent, it as isSingleSchema, j as isHeader, k as isDiscriminableBranch, m as normalizeTypes, o as error, ot as isValidIdent, p as methodPath, q as isPathItemRef, r as cyclicNodes, t as baseError, v as toIdentifierPascalCase, w as hasNotProperty, x as zodToOpenAPISchema, y as uncapitalize, z as isOperation } from "./utils-Dznx-EnJ.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { parseSync, visitorKeys } from "oxc-parser";
|
|
5
5
|
//#region src/helper/wire.ts
|
|
@@ -24,7 +24,7 @@ function resolveSchemaRef(ref, schemas) {
|
|
|
24
24
|
if (!ref.startsWith(COMPONENT_REF_PREFIX.schemas)) return void 0;
|
|
25
25
|
const name = ref.slice(COMPONENT_REF_PREFIX.schemas.length);
|
|
26
26
|
if (name.includes("/")) return void 0;
|
|
27
|
-
return schemas?.[
|
|
27
|
+
return schemas?.[decodePercent(name)];
|
|
28
28
|
}
|
|
29
29
|
function primitiveKind(value) {
|
|
30
30
|
if (value === null) return null;
|
|
@@ -377,7 +377,6 @@ function wireObject(parameter, schemas) {
|
|
|
377
377
|
if (style === "matrix") return explode ? value(objectReader(";", true, false, ";")) : value(objectReader(",", false, false, `;${name}=`));
|
|
378
378
|
return value(objectReader(",", explode));
|
|
379
379
|
}
|
|
380
|
-
const DEEP_OBJECT_DEPTH = 16;
|
|
381
380
|
/**
|
|
382
381
|
* The function that gathers the keys of a query, or of the cookies, into the object
|
|
383
382
|
* parameters among them, as source, or `undefined` when none is spread over several keys.
|
|
@@ -409,14 +408,14 @@ function makeWireGather(objects, taken) {
|
|
|
409
408
|
"const lists=new WeakSet<object>()",
|
|
410
409
|
String.raw`const isIndex=(part:string|undefined)=>part!==undefined&&/^\d*$/.test(part)`,
|
|
411
410
|
"const child=(target:Record<string,unknown>,key:string,asList:boolean)=>{const held=target[key];if(isGroup(held))return held;const made:Record<string,unknown>=Object.create(null);if(asList)lists.add(made);target[key]=made;return made}",
|
|
412
|
-
"const set=(
|
|
413
|
-
"const settle=(
|
|
411
|
+
"const set=(root:Record<string,unknown>,path:readonly string[],item:unknown):void=>{const work:[Record<string,unknown>,number,unknown,boolean][]=[[root,0,item,false]];for(let job=work.pop();job!==undefined;job=work.pop()){const [target,at,value,split]=job;const head=path[at];if(head===undefined)continue;const next=path[at+1];if(head===''){if(!split&&Array.isArray(value)){for(let i=value.length-1;i>=0;i-=1)work.push([target,at,value[i],true]);continue}const size=Object.keys(target).length;if(next===undefined){target[String(size)]=value;continue}const free=next===''?-1:Object.values(target).findIndex((held)=>isGroup(held)&&!(next in held));work.push([child(target,String(free<0?size:free),isIndex(next)),at+1,value,false]);continue}if(next===undefined){target[head]=value;continue}work.push([child(target,head,isIndex(next)),at+1,value,false])}}",
|
|
412
|
+
"const settle=(root:unknown):unknown=>{if(!isGroup(root))return root;const found:[Record<string,unknown>,string,Record<string,unknown>][]=[];const queue:Record<string,unknown>[]=[root];for(const node of queue){for(const [key,inner] of Object.entries(node)){if(isGroup(inner)){found.push([node,key,inner]);queue.push(inner)}}}const finish=(group:Record<string,unknown>):unknown=>lists.has(group)?Object.entries(group).sort((a,b)=>Number(a[0])-Number(b[0])).map(([,inner])=>inner):Object.assign(Object.create(null),group);for(const [parent,key,group] of found.reverse()){parent[key]=finish(group)}return finish(root)}",
|
|
414
413
|
`const deep:string[]=${JSON.stringify(deep)}`
|
|
415
414
|
] : [],
|
|
416
415
|
...spread.length > 0 ? [`const spread=new Map<string,string[]>(${JSON.stringify(spread)})`] : [],
|
|
417
416
|
...open.length > 0 ? [`const open:string[]=${JSON.stringify(open)}`, `const taken:string[]=${JSON.stringify(taken)}`] : [],
|
|
418
417
|
`for(const [key,item] of Object.entries(val)){${[
|
|
419
|
-
...deep.length > 0 ? [String.raw`const match=/^([^\[\]]+)((?:\[[^\[\]]*\])+)$/.exec(key);const name=match?.[1];const path=match?.[2];if(name!==undefined&&path!==undefined&&deep.includes(name)){const parts=path.slice(1,-1).split('][');
|
|
418
|
+
...deep.length > 0 ? [String.raw`const match=/^([^\[\]]+)((?:\[[^\[\]]*\])+)$/.exec(key);const name=match?.[1];const path=match?.[2];if(name!==undefined&&path!==undefined&&deep.includes(name)){const parts=path.slice(1,-1).split('][');set(group(name),parts,item);continue}`] : [],
|
|
420
419
|
...spread.length > 0 ? ["const owners=spread.get(key);if(owners!==undefined){for(const owner of owners){group(owner)[key]=item}continue}"] : [],
|
|
421
420
|
...open.length > 0 ? ["if(!taken.includes(key)){for(const owner of open){group(owner)[key]=item}}"] : [],
|
|
422
421
|
"rest.push([key,item])"
|
|
@@ -546,10 +545,10 @@ function makeRef($ref) {
|
|
|
546
545
|
}
|
|
547
546
|
];
|
|
548
547
|
const propertiesMatch = $ref.match(/^#\/components\/schemas\/([^/]+)\/properties\/(.+)$/u);
|
|
549
|
-
if (propertiesMatch) return `z.lazy(()=>${toIdentifierPascalCase(ensureSuffix(
|
|
548
|
+
if (propertiesMatch) return `z.lazy(()=>${toIdentifierPascalCase(ensureSuffix(decodePercent(propertiesMatch[1]), "Schema"))})`;
|
|
550
549
|
const rawRef = $ref.split("/").at(-1);
|
|
551
550
|
if (!rawRef) return "Schema";
|
|
552
|
-
const decodedRef =
|
|
551
|
+
const decodedRef = decodePercent(rawRef);
|
|
553
552
|
const match = COMPONENT_SUFFIX_MAP.find(({ prefix }) => $ref.startsWith(prefix));
|
|
554
553
|
return toIdentifierPascalCase(ensureSuffix(decodedRef, match?.suffix ?? "Schema"));
|
|
555
554
|
}
|
|
@@ -1939,7 +1938,6 @@ function string(schema, options) {
|
|
|
1939
1938
|
//#endregion
|
|
1940
1939
|
//#region src/generator/zod-to-openapi/index.ts
|
|
1941
1940
|
function zodToOpenAPI(schema, meta, options) {
|
|
1942
|
-
if (schema === void 0) throw new Error("Schema is undefined");
|
|
1943
1941
|
if (schema === true) return wrap("z.any()", {}, meta, options);
|
|
1944
1942
|
if (schema === false) return wrap("z.never()", {}, meta, options);
|
|
1945
1943
|
const nullRead = options?.coerce === true && options.json !== true ? nullReading(schema, options.schemas) : void 0;
|
|
@@ -2076,7 +2074,7 @@ function zodToOpenAPI(schema, meta, options) {
|
|
|
2076
2074
|
const discriminator = schema.discriminator?.propertyName;
|
|
2077
2075
|
const oneOfMessage = schema["x-oneOf-message"] ?? schema["x-error-message"];
|
|
2078
2076
|
const oneOfErrorArg = oneOfMessage ? `,${error(oneOfMessage)}` : "";
|
|
2079
|
-
const branches = schema.oneOf.map((s) => s.$ref === void 0 ? s : isRefOnly(s) && s.$ref.startsWith(COMPONENT_REF_PREFIX.schemas) ? options?.schemas?.[
|
|
2077
|
+
const branches = schema.oneOf.map((s) => s.$ref === void 0 ? s : isRefOnly(s) && s.$ref.startsWith(COMPONENT_REF_PREFIX.schemas) ? options?.schemas?.[decodePercent(s.$ref.slice(COMPONENT_REF_PREFIX.schemas.length))] : void 0);
|
|
2080
2078
|
const literalsPerBranch = branches.map((branch) => {
|
|
2081
2079
|
if (discriminator === void 0 || branch === void 0) return void 0;
|
|
2082
2080
|
if (!isDiscriminableBranch(branch, discriminator)) return void 0;
|
|
@@ -2169,11 +2167,9 @@ function zodToOpenAPI(schema, meta, options) {
|
|
|
2169
2167
|
if (t.includes("boolean")) {
|
|
2170
2168
|
const errorMessage = schema["x-error-message"];
|
|
2171
2169
|
const requiredMessage = schema["x-required-message"];
|
|
2172
|
-
const xCoerce = schema["x-coerce"] === true;
|
|
2173
2170
|
const xStringbool = schema["x-stringbool"];
|
|
2174
|
-
if (xCoerce && xStringbool !== void 0) throw new Error("x-coerce and x-stringbool are mutually exclusive on a boolean schema. Remove one.");
|
|
2175
|
-
const arg = baseError(errorMessage, xCoerce ? void 0 : requiredMessage);
|
|
2176
2171
|
if (xStringbool !== void 0) {
|
|
2172
|
+
const arg = baseError(errorMessage, requiredMessage);
|
|
2177
2173
|
const opts = xStringbool === true ? null : xStringbool;
|
|
2178
2174
|
const optsObj = opts ? {
|
|
2179
2175
|
...opts.truthy !== void 0 ? { truthy: opts.truthy } : {},
|
|
@@ -2184,6 +2180,8 @@ function zodToOpenAPI(schema, meta, options) {
|
|
|
2184
2180
|
const combinedArg = optsStr && arg ? `${optsStr.slice(0, -1)},${arg.slice(1)}` : optsStr || arg;
|
|
2185
2181
|
return done(combinedArg ? `z.stringbool(${combinedArg})` : "z.stringbool()", schema);
|
|
2186
2182
|
}
|
|
2183
|
+
const xCoerce = schema["x-coerce"] === true;
|
|
2184
|
+
const arg = baseError(errorMessage, xCoerce ? void 0 : requiredMessage);
|
|
2187
2185
|
const baseFn = xCoerce ? "z.coerce.boolean" : effective?.coerce ? "z.stringbool" : "z.boolean";
|
|
2188
2186
|
return done(arg ? `${baseFn}(${arg})` : `${baseFn}()`, schema);
|
|
2189
2187
|
}
|
|
@@ -2427,7 +2425,7 @@ function findDiscriminatedBranches(schemas, schemaNames) {
|
|
|
2427
2425
|
if (discriminator === void 0 || schema?.oneOf === void 0) return [];
|
|
2428
2426
|
return schema.oneOf.flatMap((branch) => {
|
|
2429
2427
|
if (!(isRefOnly(branch) && branch.$ref?.startsWith(COMPONENT_REF_PREFIX.schemas))) return [];
|
|
2430
|
-
const name =
|
|
2428
|
+
const name = decodePercent(branch.$ref.slice(COMPONENT_REF_PREFIX.schemas.length));
|
|
2431
2429
|
const target = schemas[name];
|
|
2432
2430
|
return target && isDiscriminableBranch(target, discriminator) ? [name] : [];
|
|
2433
2431
|
});
|
|
@@ -2610,12 +2608,12 @@ function makeTypeString(schema, selfTypeName, cyclicGroup, readonly) {
|
|
|
2610
2608
|
function makeRefTypeString(ref, selfTypeName) {
|
|
2611
2609
|
const propertiesMatch = ref.match(/^#\/components\/schemas\/([^/]+)\/properties\//u);
|
|
2612
2610
|
if (propertiesMatch) {
|
|
2613
|
-
const parentName = toIdentifierPascalCase(
|
|
2611
|
+
const parentName = toIdentifierPascalCase(decodePercent(propertiesMatch[1]));
|
|
2614
2612
|
if (parentName === selfTypeName) return `${parentName}Type`;
|
|
2615
2613
|
return `z.infer<typeof ${parentName}Schema>`;
|
|
2616
2614
|
}
|
|
2617
2615
|
const rawRef = ref.split("/").at(-1) ?? "";
|
|
2618
|
-
const refName = toIdentifierPascalCase(
|
|
2616
|
+
const refName = toIdentifierPascalCase(decodePercent(rawRef));
|
|
2619
2617
|
if (refName === selfTypeName) return `${refName}Type`;
|
|
2620
2618
|
return `z.infer<typeof ${refName}Schema>`;
|
|
2621
2619
|
}
|
|
@@ -2661,12 +2659,12 @@ function makeArrayTypeString(schema, selfTypeName, cyclicGroup, readonly) {
|
|
|
2661
2659
|
if (items.$ref) {
|
|
2662
2660
|
const propertiesMatch = items.$ref.match(/^#\/components\/schemas\/([^/]+)\/properties\//u);
|
|
2663
2661
|
if (propertiesMatch) {
|
|
2664
|
-
const parentName = toIdentifierPascalCase(
|
|
2662
|
+
const parentName = toIdentifierPascalCase(decodePercent(propertiesMatch[1]));
|
|
2665
2663
|
if (parentName === selfTypeName) return `${prefix}${parentName}Type[]`;
|
|
2666
2664
|
return `${prefix}z.infer<typeof ${parentName}Schema>[]`;
|
|
2667
2665
|
}
|
|
2668
2666
|
const rawRef = items.$ref.split("/").at(-1) ?? "";
|
|
2669
|
-
const refName = toIdentifierPascalCase(
|
|
2667
|
+
const refName = toIdentifierPascalCase(decodePercent(rawRef));
|
|
2670
2668
|
if (refName === selfTypeName) return `${prefix}${refName}Type[]`;
|
|
2671
2669
|
return `${prefix}z.infer<typeof ${refName}Schema>[]`;
|
|
2672
2670
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as FORM_MEDIA_TYPES, u as JSON_MEDIA_TYPE } from "./constants-Bz8YiPum.js";
|
|
2
|
-
import {
|
|
2
|
+
import { B as isOperationLike, J as isRecord, U as isParameterObject, Y as isRefObject, ot as isValidIdent, tt as isSchemaProperty } from "./utils-Dznx-EnJ.js";
|
|
3
3
|
//#region src/helper/group.ts
|
|
4
4
|
const RESERVED = /* @__PURE__ */ new Set([
|
|
5
5
|
"arguments",
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
2
|
import { n as COMPONENT_NAMES, o as HOOK_LIBRARIES } from "./constants-Bz8YiPum.js";
|
|
3
3
|
import { i as GenerateError } from "./format-CuHABcKC.js";
|
|
4
|
-
import { C as isInsideDirectory, E as makeGeneratedImport, S as appEntryOutput, T as makeAppEntryImport, _ as headers, a as takibi, b as client, c as securitySchemes, d as requestBodies, f as pathItems, g as links, h as mediaTypes, i as defineTemplate, l as schemas, m as components, n as webhooks, o as route, p as parameters, r as template, s as mock, u as responses, v as examples, w as makeAppEntryFile, x as handlerGroupOf, y as callbacks } from "./core-
|
|
4
|
+
import { C as isInsideDirectory, E as makeGeneratedImport, S as appEntryOutput, T as makeAppEntryImport, _ as headers, a as takibi, b as client, c as securitySchemes, d as requestBodies, f as pathItems, g as links, h as mediaTypes, i as defineTemplate, l as schemas, m as components, n as webhooks, o as route, p as parameters, r as template, s as mock, u as responses, v as examples, w as makeAppEntryFile, x as handlerGroupOf, y as callbacks } from "./core-Bhi7NjFK.js";
|
|
5
5
|
import { a as unlink, i as readdir, t as exists } from "./file-K6j5IJXi.js";
|
|
6
|
-
import { t as hooks } from "./hooks-
|
|
7
|
-
import { t as docs } from "./docs-
|
|
6
|
+
import { t as hooks } from "./hooks-BRODO70o.js";
|
|
7
|
+
import { t as docs } from "./docs-DTHnPNsq.js";
|
|
8
8
|
import { rpc } from "./core/rpc/index.js";
|
|
9
9
|
import { type } from "./core/type/index.js";
|
|
10
10
|
import { Effect, FileSystem, Schema } from "effect";
|
|
@@ -424,6 +424,18 @@ function ensureSuffix(text, suffix) {
|
|
|
424
424
|
return `${text}${suffix}`;
|
|
425
425
|
}
|
|
426
426
|
/**
|
|
427
|
+
* Undoes the percent-encoding of one `$ref` segment. A segment that is not valid
|
|
428
|
+
* percent-encoding (`Foo%ZZ`) is kept as it is: no `$ref` makes the generator throw, it
|
|
429
|
+
* just names a component that is not there.
|
|
430
|
+
*/
|
|
431
|
+
function decodePercent(value) {
|
|
432
|
+
try {
|
|
433
|
+
return decodeURIComponent(value);
|
|
434
|
+
} catch {
|
|
435
|
+
return value;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
427
439
|
* Generates a Zod schema constant and optional inferred type alias.
|
|
428
440
|
*
|
|
429
441
|
*
|
|
@@ -546,4 +558,4 @@ function cyclicNodes(deps) {
|
|
|
546
558
|
return result;
|
|
547
559
|
}
|
|
548
560
|
//#endregion
|
|
549
|
-
export {
|
|
561
|
+
export { isSchemaArray as $, isExamplesInput as A, isOperationLike as B, hasNoUserChain as C, hasTypelessConstraint as D, hasRequestBodyContent as E, isMedia as F, isPathItem as G, isParameterArray as H, isMediaWithSchema as I, isRecord as J, isPathItemEntry as K, isOffsetTime as L, isHttpMethod as M, isInheritedName as N, isCallbacks as O, isInlineMedia as P, isResponses as Q, isOpenAPIPaths as R, hasNoContentResponse as S, hasNumericConstraint as T, isParameterObject as U, isParameter as V, isParameterRef as W, isRefOnly as X, isRefObject as Y, isRequestBody as Z, statusCodeToNumber as _, ensureSuffix as a, isStringRef as at, uncapitalizeWord as b, escapeRegexLiteral as c, makeSafeKey as d, isSchemaObject as et, makeStringLiteral as f, requestParamsArray as g, renderNamedImport as h, decodePercent as i, isSingleSchema as it, isHeader as j, isDiscriminableBranch as k, makeBarrel as l, normalizeTypes as m, capitalize as n, isSecurityArray as nt, error as o, isValidIdent as ot, methodPath as p, isPathItemRef as q, cyclicNodes as r, isSecurityScheme as rt, escapeHtml as s, baseError as t, isSchemaProperty as tt, makeInferRequestType as u, toIdentifierPascalCase as v, hasNotProperty as w, zodToOpenAPISchema as x, uncapitalize as y, isOperation as z };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { l as INPUT_EXTENSIONS } from "../constants-Bz8YiPum.js";
|
|
2
2
|
import { parseConfig } from "../index.js";
|
|
3
3
|
import { t as FormatOptions } from "../format-CuHABcKC.js";
|
|
4
|
-
import {
|
|
5
|
-
import { C as isInsideDirectory, S as appEntryOutput } from "../core-
|
|
4
|
+
import { J as isRecord } from "../utils-Dznx-EnJ.js";
|
|
5
|
+
import { C as isInsideDirectory, S as appEntryOutput } from "../core-Bhi7NjFK.js";
|
|
6
6
|
import { n as parseOpenAPI } from "../openapi-DEZCoJlc.js";
|
|
7
|
-
import { i as packageRoots, n as makeJob, r as outsideSources, t as cleanSplitOutputs } from "../shared-
|
|
7
|
+
import { i as packageRoots, n as makeJob, r as outsideSources, t as cleanSplitOutputs } from "../shared-CYeurBoC.js";
|
|
8
8
|
import { Effect, FileSystem, Option, Result } from "effect";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import crypto from "node:crypto";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono-takibi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hono",
|
|
@@ -55,23 +55,23 @@
|
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@apidevtools/swagger-parser": "^13.
|
|
59
|
-
"@effect/platform-node": "4.0.
|
|
60
|
-
"@typespec/compiler": "^1.
|
|
61
|
-
"@typespec/openapi3": "^1.
|
|
62
|
-
"effect": "4.0.
|
|
58
|
+
"@apidevtools/swagger-parser": "^13.1.0",
|
|
59
|
+
"@effect/platform-node": "4.0.5",
|
|
60
|
+
"@typespec/compiler": "^1.17.0",
|
|
61
|
+
"@typespec/openapi3": "^1.17.0",
|
|
62
|
+
"effect": "4.0.5",
|
|
63
63
|
"oxc-parser": "^0.154.0",
|
|
64
|
-
"oxfmt": "^0.
|
|
64
|
+
"oxfmt": "^0.73.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@faker-js/faker": "^10.6.0",
|
|
68
68
|
"@hono/zod-openapi": "^1.6.3",
|
|
69
|
-
"@types/node": "^26.6.
|
|
70
|
-
"@typespec/http": "^1.
|
|
71
|
-
"@typespec/rest": "^0.
|
|
72
|
-
"hono": "^4.13.
|
|
69
|
+
"@types/node": "^26.6.5",
|
|
70
|
+
"@typespec/http": "^1.17.0",
|
|
71
|
+
"@typespec/rest": "^0.87.0",
|
|
72
|
+
"hono": "^4.13.13",
|
|
73
73
|
"typescript": "^7.0.2",
|
|
74
|
-
"zod": "^4.6.
|
|
74
|
+
"zod": "^4.6.7"
|
|
75
75
|
},
|
|
76
76
|
"scripts": {
|
|
77
77
|
"build": "vp pack",
|