hono-takibi 0.22.0 → 0.23.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.js +1 -2
- package/dist/core/hooks/index.d.ts +2 -1
- package/dist/core/hooks/index.js +1 -2
- package/dist/{core-DmIVe-SP.js → core-BhMCMrQ6.js} +6 -7
- package/dist/{docs-CtXltNLT.js → docs-C5t1NRQ8.js} +61 -89
- package/dist/generator/zod-openapi-hono/openapi/index.js +1 -2
- package/dist/{openapi-OxNU2RgN.js → openapi-KOHVzQbz.js} +3 -4
- package/dist/{shared-C9-30gJ4.js → shared-BxcbHfBt.js} +2 -2
- package/dist/vite-plugin/index.js +2 -2
- 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.23.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-BxcbHfBt.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-BxcbHfBt.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-BhMCMrQ6.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;
|
package/dist/core/docs/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { docs };
|
|
1
|
+
export { t as docs } from "../../docs-C5t1NRQ8.js";
|
|
@@ -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-CR7angVC.js";
|
|
@@ -2,12 +2,12 @@ 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
4
|
import { $ as isSchemaObject, B as isParameter, D as isCallbacks, F as isMediaWithSchema, G as isPathItemEntry, J as isRefObject, K as isPathItemRef, L as isOpenAPIPaths, N as isInlineMedia, Q as isSchemaArray, R as isOperation, T as hasRequestBodyContent, W as isPathItem, _ as toIdentifierPascalCase, at as isValidIdent, b as zodToOpenAPISchema, c as makeBarrel, d as makeStringLiteral, f as methodPath, g as statusCodeToNumber, i as ensureSuffix, j as isHttpMethod, m as renderNamedImport, nt as isSecurityScheme, p as normalizeTypes, r as cyclicNodes, s as escapeRegexLiteral, tt as isSecurityArray, u as makeSafeKey, v as uncapitalize, w as hasNumericConstraint, y as uncapitalizeWord } from "./utils-vw99OasL.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-
|
|
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-KOHVzQbz.js";
|
|
6
6
|
import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-Bgtv3nGI.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
9
|
import { t as hooks } from "./hooks-CR7angVC.js";
|
|
10
|
-
import { t as docs } from "./docs-
|
|
10
|
+
import { t as docs } from "./docs-C5t1NRQ8.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)) {
|
|
@@ -5,26 +5,6 @@ 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);
|
|
@@ -107,13 +87,14 @@ function resolveRef(ref, doc) {
|
|
|
107
87
|
return value;
|
|
108
88
|
}
|
|
109
89
|
/**
|
|
110
|
-
* Follows a Reference Object until it reaches a value
|
|
111
|
-
*
|
|
90
|
+
* Follows a Reference Object until it reaches a value, or comes back to a reference it
|
|
91
|
+
* has followed: a cycle of references names nothing. Schemas go through `derefSchema`
|
|
92
|
+
* instead, which tracks cycles the same way.
|
|
112
93
|
*/
|
|
113
|
-
function resolveRefDeep(value, doc,
|
|
94
|
+
function resolveRefDeep(value, doc, seen = /* @__PURE__ */ new Set()) {
|
|
114
95
|
if (!isRefObject(value)) return value;
|
|
115
|
-
if (
|
|
116
|
-
return resolveRefDeep(resolveRef(value.$ref, doc), doc,
|
|
96
|
+
if (seen.has(value.$ref)) return void 0;
|
|
97
|
+
return resolveRefDeep(resolveRef(value.$ref, doc), doc, /* @__PURE__ */ new Set([...seen, value.$ref]));
|
|
117
98
|
}
|
|
118
99
|
/**
|
|
119
100
|
* Name of the schema a `$ref` points at, when it points at `components.schemas`.
|
|
@@ -267,27 +248,19 @@ function isRecursiveRef(ref, doc) {
|
|
|
267
248
|
recursive.set(ref, result);
|
|
268
249
|
return result;
|
|
269
250
|
}
|
|
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
251
|
/**
|
|
284
|
-
* `derefSchema` for a schema that is about to be expanded:
|
|
285
|
-
*
|
|
252
|
+
* `derefSchema` for a schema that is about to be expanded: a `$ref` to a schema that
|
|
253
|
+
* reaches itself is followed unless the walk is already inside such a schema, and what
|
|
254
|
+
* it opens is inside one.
|
|
286
255
|
*/
|
|
287
|
-
function expandSchema(schema, doc,
|
|
288
|
-
|
|
289
|
-
if (
|
|
290
|
-
|
|
256
|
+
function expandSchema(schema, doc, inside) {
|
|
257
|
+
const recursive = schema.$ref !== void 0 && isRecursiveRef(schema.$ref, doc);
|
|
258
|
+
if (recursive && inside) return void 0;
|
|
259
|
+
const target = derefSchema(schema, doc, /* @__PURE__ */ new Set());
|
|
260
|
+
return target && {
|
|
261
|
+
schema: target.schema,
|
|
262
|
+
inside: inside || recursive
|
|
263
|
+
};
|
|
291
264
|
}
|
|
292
265
|
function primaryType(schema) {
|
|
293
266
|
return Array.isArray(schema.type) ? schema.type.find((t) => t !== "null") : schema.type;
|
|
@@ -323,12 +296,12 @@ function inferType(value) {
|
|
|
323
296
|
if (typeof value === "string" || typeof value === "boolean") return typeof value;
|
|
324
297
|
return "object";
|
|
325
298
|
}
|
|
326
|
-
function baseTypeOf(schema, doc, visited
|
|
299
|
+
function baseTypeOf(schema, doc, visited) {
|
|
327
300
|
if (Array.isArray(schema.type)) return schema.type.join(" | ");
|
|
328
301
|
if (schema.type !== void 0) return schema.type;
|
|
329
302
|
if (isRecord(schema.properties)) return "object";
|
|
330
303
|
const variants = variantsOf(schema);
|
|
331
|
-
if (variants.length > 0) return [...new Set(variants.map((variant) => formatSchemaType(variant.schema, doc, visited
|
|
304
|
+
if (variants.length > 0) return [...new Set(variants.map((variant) => formatSchemaType(variant.schema, doc, visited)))].join(" | ");
|
|
332
305
|
if (schema.const !== void 0) return inferType(schema.const);
|
|
333
306
|
if (schema.enum && schema.enum.length > 0) return inferType(schema.enum[0]);
|
|
334
307
|
return "object";
|
|
@@ -337,21 +310,21 @@ function baseTypeOf(schema, doc, visited, depth) {
|
|
|
337
310
|
* Formats a schema type string as widdershins does.
|
|
338
311
|
* Examples: "string(email)", "integer(int64)", "[User](#schemauser)", "[[User](#schemauser)]"
|
|
339
312
|
*/
|
|
340
|
-
function formatSchemaType(schema, doc, visited = /* @__PURE__ */ new Set()
|
|
341
|
-
if (!isSchemaLike(schema)
|
|
313
|
+
function formatSchemaType(schema, doc, visited = /* @__PURE__ */ new Set()) {
|
|
314
|
+
if (!isSchemaLike(schema)) return "object";
|
|
342
315
|
if (schema.$ref) {
|
|
343
316
|
const name = componentSchemaName(schema.$ref);
|
|
344
317
|
if (name) return makeSchemaLink(name, doc);
|
|
345
318
|
const target = derefSchema(schema, doc, visited);
|
|
346
|
-
return target ? formatSchemaType(target.schema, doc, target.visited
|
|
319
|
+
return target ? formatSchemaType(target.schema, doc, target.visited) : "object";
|
|
347
320
|
}
|
|
348
321
|
if (isArraySchema(schema)) {
|
|
349
322
|
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
|
|
323
|
+
if (item) return `[${formatSchemaType(item, doc, visited)}]`;
|
|
324
|
+
if (schema.prefixItems && schema.prefixItems.length > 0) return `[${schema.prefixItems.map((entry) => formatSchemaType(entry, doc, visited)).join(", ")}]`;
|
|
352
325
|
return "array";
|
|
353
326
|
}
|
|
354
|
-
const baseType = baseTypeOf(schema, doc, visited
|
|
327
|
+
const baseType = baseTypeOf(schema, doc, visited);
|
|
355
328
|
const formatted = schema.format ? `${baseType}(${schema.format})` : baseType;
|
|
356
329
|
return schema.nullable === true && !baseType.split(" | ").includes("null") ? `${formatted} | null` : formatted;
|
|
357
330
|
}
|
|
@@ -432,7 +405,7 @@ function isHidden(schema, direction) {
|
|
|
432
405
|
if (direction === "response") return schema.writeOnly === true;
|
|
433
406
|
return false;
|
|
434
407
|
}
|
|
435
|
-
function isHiddenProperty(schema, doc, direction, visited) {
|
|
408
|
+
function isHiddenProperty(schema, doc, direction, visited = /* @__PURE__ */ new Set()) {
|
|
436
409
|
if (!isSchemaLike(schema)) return false;
|
|
437
410
|
if (isHidden(schema, direction)) return true;
|
|
438
411
|
const target = derefSchema(schema, doc, visited);
|
|
@@ -441,14 +414,13 @@ function isHiddenProperty(schema, doc, direction, visited) {
|
|
|
441
414
|
function isNullSchema(schema) {
|
|
442
415
|
return schema.type === "null" || Array.isArray(schema.type) && primaryType(schema) === void 0;
|
|
443
416
|
}
|
|
444
|
-
function makeExampleFromSchema(schema, doc, direction = "schema",
|
|
445
|
-
if (depth > MAX_SCHEMA_DEPTH) return {};
|
|
417
|
+
function makeExampleFromSchema(schema, doc, direction = "schema", inside = false) {
|
|
446
418
|
if (!isSchemaLike(schema)) return null;
|
|
447
419
|
if (schema.example !== void 0) return schema.example;
|
|
448
420
|
if (schema.$ref) {
|
|
449
|
-
const target = expandSchema(schema, doc,
|
|
421
|
+
const target = expandSchema(schema, doc, inside);
|
|
450
422
|
if (!target) return {};
|
|
451
|
-
return makeExampleFromSchema(target.schema, doc, direction, target.
|
|
423
|
+
return makeExampleFromSchema(target.schema, doc, direction, target.inside);
|
|
452
424
|
}
|
|
453
425
|
const listed = firstExampleValue(schema.examples, doc);
|
|
454
426
|
if (listed !== void 0) return listed;
|
|
@@ -461,15 +433,15 @@ function makeExampleFromSchema(schema, doc, direction = "schema", visited = /* @
|
|
|
461
433
|
const result = {};
|
|
462
434
|
const parts = [...schema.allOf ?? [], ...variant ? [variant.schema] : []];
|
|
463
435
|
for (const part of parts) {
|
|
464
|
-
const example = makeExampleFromSchema(part, doc, direction,
|
|
436
|
+
const example = makeExampleFromSchema(part, doc, direction, inside);
|
|
465
437
|
if (isRecord(example)) Object.assign(result, example);
|
|
466
438
|
}
|
|
467
439
|
for (const [key, propSchema] of Object.entries(schema.properties ?? {})) {
|
|
468
|
-
if (isHiddenProperty(propSchema, doc, direction
|
|
469
|
-
result[key] = makeExampleFromSchema(propSchema, doc, direction,
|
|
440
|
+
if (isHiddenProperty(propSchema, doc, direction)) continue;
|
|
441
|
+
result[key] = makeExampleFromSchema(propSchema, doc, direction, inside);
|
|
470
442
|
}
|
|
471
443
|
if (isSchemaLike(extra)) {
|
|
472
|
-
const value = makeExampleFromSchema(extra, doc, direction,
|
|
444
|
+
const value = makeExampleFromSchema(extra, doc, direction, inside);
|
|
473
445
|
result.property1 = value;
|
|
474
446
|
result.property2 = value;
|
|
475
447
|
}
|
|
@@ -479,13 +451,13 @@ function makeExampleFromSchema(schema, doc, direction = "schema", visited = /* @
|
|
|
479
451
|
if (schema.maxItems === 0) return [];
|
|
480
452
|
const item = arrayItemSchema(schema);
|
|
481
453
|
if (item) {
|
|
482
|
-
const value = makeExampleFromSchema(item, doc, direction,
|
|
483
|
-
const count = Math.
|
|
454
|
+
const value = makeExampleFromSchema(item, doc, direction, inside);
|
|
455
|
+
const count = Math.max(schema.minItems ?? 1, 1);
|
|
484
456
|
return Array.from({ length: count }, () => value);
|
|
485
457
|
}
|
|
486
|
-
return (schema.prefixItems ?? []).map((entry) => makeExampleFromSchema(entry, doc, direction,
|
|
458
|
+
return (schema.prefixItems ?? []).map((entry) => makeExampleFromSchema(entry, doc, direction, inside));
|
|
487
459
|
}
|
|
488
|
-
if (variant) return makeExampleFromSchema(variant.schema, doc, direction,
|
|
460
|
+
if (variant) return makeExampleFromSchema(variant.schema, doc, direction, inside);
|
|
489
461
|
return makeDefaultValue(schema);
|
|
490
462
|
}
|
|
491
463
|
function extractMediaExample(media, doc) {
|
|
@@ -920,13 +892,13 @@ function makeBodyParameterBlock(operation, doc) {
|
|
|
920
892
|
/**
|
|
921
893
|
* Enum values of a schema, following `$ref` and looking into array items.
|
|
922
894
|
*/
|
|
923
|
-
function enumValuesOf(schema, doc, visited = /* @__PURE__ */ new Set()
|
|
924
|
-
if (!isSchemaLike(schema)
|
|
895
|
+
function enumValuesOf(schema, doc, visited = /* @__PURE__ */ new Set()) {
|
|
896
|
+
if (!isSchemaLike(schema)) return [];
|
|
925
897
|
const target = derefSchema(schema, doc, visited);
|
|
926
898
|
if (!target) return [];
|
|
927
899
|
if (Array.isArray(target.schema.enum)) return target.schema.enum;
|
|
928
900
|
const item = isArraySchema(target.schema) ? arrayItemSchema(target.schema) : void 0;
|
|
929
|
-
return item ? enumValuesOf(item, doc, target.visited
|
|
901
|
+
return item ? enumValuesOf(item, doc, target.visited) : [];
|
|
930
902
|
}
|
|
931
903
|
function formatEnumValue(value) {
|
|
932
904
|
if (typeof value === "string") return value === "" ? "\"\"" : value;
|
|
@@ -946,47 +918,47 @@ function describe(description, deprecated) {
|
|
|
946
918
|
* `required` of a schema together with that of its `allOf` parts: a part often
|
|
947
919
|
* carries only `required` for properties another part declares.
|
|
948
920
|
*/
|
|
949
|
-
function collectRequired(schema, doc, visited
|
|
950
|
-
if (!isSchemaLike(schema)
|
|
921
|
+
function collectRequired(schema, doc, visited = /* @__PURE__ */ new Set()) {
|
|
922
|
+
if (!isSchemaLike(schema)) return [];
|
|
951
923
|
const target = derefSchema(schema, doc, visited);
|
|
952
924
|
if (!target) return [];
|
|
953
|
-
return [...target.schema.required ?? [], ...(target.schema.allOf ?? []).flatMap((part) => collectRequired(part, doc, target.visited
|
|
925
|
+
return [...target.schema.required ?? [], ...(target.schema.allOf ?? []).flatMap((part) => collectRequired(part, doc, target.visited))];
|
|
954
926
|
}
|
|
955
|
-
function flattenFields(schema, doc, prefix, options,
|
|
956
|
-
if (
|
|
957
|
-
const target = expandSchema(schema, doc,
|
|
927
|
+
function flattenFields(schema, doc, prefix, options, inheritedRequired = [], inside = false) {
|
|
928
|
+
if (!isSchemaLike(schema)) return [];
|
|
929
|
+
const target = expandSchema(schema, doc, inside);
|
|
958
930
|
if (!target) return [];
|
|
959
931
|
const current = target.schema;
|
|
960
|
-
const
|
|
932
|
+
const within = target.inside;
|
|
961
933
|
const nestedPrefix = prefix ? `${prefix} »` : "»";
|
|
962
934
|
const named = (name) => prefix ? `${prefix} ${name}` : name;
|
|
963
|
-
const required = [...inheritedRequired, ...collectRequired(current, doc
|
|
935
|
+
const required = [...inheritedRequired, ...collectRequired(current, doc)];
|
|
964
936
|
const requiredSet = new Set(required);
|
|
965
937
|
const nestedRows = (propSchema) => {
|
|
966
938
|
if (!options.deep) return [];
|
|
967
|
-
const prop = expandSchema(propSchema, doc,
|
|
939
|
+
const prop = expandSchema(propSchema, doc, within);
|
|
968
940
|
if (!prop) return [];
|
|
969
|
-
if (hasFields(prop.schema)) return flattenFields(prop.schema, doc, nestedPrefix, options,
|
|
941
|
+
if (hasFields(prop.schema)) return flattenFields(prop.schema, doc, nestedPrefix, options, [], prop.inside);
|
|
970
942
|
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,
|
|
943
|
+
const resolvedItem = item ? expandSchema(item, doc, prop.inside) : void 0;
|
|
944
|
+
if (resolvedItem && hasFields(resolvedItem.schema)) return flattenFields(resolvedItem.schema, doc, nestedPrefix, options, [], resolvedItem.inside);
|
|
973
945
|
return [];
|
|
974
946
|
};
|
|
975
947
|
const makeRow = (name, propSchema, isRequired) => {
|
|
976
|
-
const resolved = derefSchema(propSchema, doc,
|
|
948
|
+
const resolved = derefSchema(propSchema, doc, /* @__PURE__ */ new Set())?.schema;
|
|
977
949
|
return {
|
|
978
950
|
name: named(name),
|
|
979
|
-
type: formatSchemaType(propSchema, doc
|
|
951
|
+
type: formatSchemaType(propSchema, doc),
|
|
980
952
|
required: isRequired,
|
|
981
953
|
restrictions: restrictionsOf(resolved ?? propSchema),
|
|
982
954
|
description: describe(propSchema.description ?? resolved?.description, propSchema.deprecated ?? resolved?.deprecated),
|
|
983
|
-
enums: enumValuesOf(propSchema, doc
|
|
955
|
+
enums: enumValuesOf(propSchema, doc)
|
|
984
956
|
};
|
|
985
957
|
};
|
|
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
|
|
958
|
+
const inherited = (current.allOf ?? []).flatMap((part) => flattenFields(part, doc, prefix, options, required, within));
|
|
959
|
+
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
960
|
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,
|
|
961
|
+
const variants = variantsOf(current).flatMap((variant) => [makeRow(`*${variant.keyword}*`, variant.schema, false), ...flattenFields(variant.schema, doc, prefix, options, required, within)]);
|
|
990
962
|
const rows = [
|
|
991
963
|
...inherited,
|
|
992
964
|
...own,
|
|
@@ -998,18 +970,18 @@ function flattenFields(schema, doc, prefix, options, visited = /* @__PURE__ */ n
|
|
|
998
970
|
if (!item) return [];
|
|
999
971
|
const anonymous = options.anonymous ? [{
|
|
1000
972
|
name: "*anonymous*",
|
|
1001
|
-
type: `[${formatSchemaType(item, doc
|
|
973
|
+
type: `[${formatSchemaType(item, doc)}]`,
|
|
1002
974
|
required: false,
|
|
1003
975
|
restrictions: "none",
|
|
1004
976
|
description: "none",
|
|
1005
977
|
enums: []
|
|
1006
978
|
}] : [];
|
|
1007
|
-
const resolvedItem = expandSchema(item, doc,
|
|
979
|
+
const resolvedItem = expandSchema(item, doc, within);
|
|
1008
980
|
if (!(resolvedItem && hasFields(resolvedItem.schema))) return anonymous;
|
|
1009
981
|
return [...anonymous, ...flattenFields(resolvedItem.schema, doc, "»", {
|
|
1010
982
|
...options,
|
|
1011
983
|
anonymous: false
|
|
1012
|
-
},
|
|
984
|
+
}, [], resolvedItem.inside)];
|
|
1013
985
|
}
|
|
1014
986
|
function makeFieldTable(fields) {
|
|
1015
987
|
return [
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { zodOpenAPIHono };
|
|
1
|
+
export { t as zodOpenAPIHono } from "../../../openapi-KOHVzQbz.js";
|
|
@@ -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])"
|
|
@@ -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-BhMCMrQ6.js";
|
|
5
5
|
import { a as unlink, i as readdir, t as exists } from "./file-K6j5IJXi.js";
|
|
6
6
|
import { t as hooks } from "./hooks-CR7angVC.js";
|
|
7
|
-
import { t as docs } from "./docs-
|
|
7
|
+
import { t as docs } from "./docs-C5t1NRQ8.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";
|
|
@@ -2,9 +2,9 @@ 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
4
|
import { q as isRecord } from "../utils-vw99OasL.js";
|
|
5
|
-
import { C as isInsideDirectory, S as appEntryOutput } from "../core-
|
|
5
|
+
import { C as isInsideDirectory, S as appEntryOutput } from "../core-BhMCMrQ6.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-BxcbHfBt.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.23.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",
|