hono-takibi 0.9.99996 → 0.9.99998

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/README.md CHANGED
@@ -135,10 +135,10 @@ export default defineConfig({
135
135
  This generates:
136
136
 
137
137
  - `src/index.ts` - App entry point with route registrations
138
- - `src/handlers/*.ts` - Handler stubs for each resource
138
+ - `src/handlers/*.ts` - Handler stubs, one file per tag (the first `tags` entry of each operation, lower camel case; the first path segment when an operation has no tag)
139
139
  - `src/handlers/*.test.ts` - Test files with `@faker-js/faker` mock data (imports from `vitest`, `vite-plus/test`, or `bun:test`)
140
140
 
141
- Re-running after updating your OpenAPI spec is safe — your hand-written handler logic and test customizations are preserved. Only new routes are added as stubs.
141
+ Re-running after updating your OpenAPI spec is safe — your hand-written handler logic and test customizations are preserved. Only new routes are added as stubs. The generator never deletes a file under `handlers/` and never re-stubs a handler that already exists in that directory: a handler you moved into another file (e.g. split by concern) is regenerated in place, files that hold no `*RouteHandler` export / `.openapi(xxxRoute)` registration / `*Route` export stay untouched, and their `export * from` lines in `handlers/index.ts` are kept. When a route leaves the spec, its handler declaration and route import are removed from whichever file holds them, but the file itself — and anything hand-written in it — remains; delete it by hand once nothing else is in it. Only top-level files in `handlers/` are scanned, not subdirectories.
142
142
 
143
143
  ### Handler Generation Modes
144
144
 
@@ -170,6 +170,8 @@ export const api = app.route('/', healthHandler)
170
170
  export default app
171
171
  ```
172
172
 
173
+ If you split routes into hand-written files in this mode, name each sub-router export `<fileBasename>Handler` (e.g. `export const sharesHandler = ...` in `shares.ts`) — that is the name the generator merges into and the app mounts.
174
+
173
175
  #### `routeHandler: true`
174
176
 
175
177
  Handlers export typed `RouteHandler` functions, and `index.ts` centralizes route registration:
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { readConfig } from "./index.js";
3
- import { r as setFormatOptions } from "./emit-CFR63U4L.js";
4
- import { n as parseOpenAPI, r as takibi, t as makeJob } from "./shared-DnibnCI5.js";
3
+ import { r as setFormatOptions } from "./emit-rUfH9f6q.js";
4
+ import { n as parseOpenAPI, r as takibi, t as makeJob } from "./shared-Zyc06ZL_.js";
5
5
  import { existsSync } from "node:fs";
6
6
  import { resolve } from "node:path";
7
7
  //#region src/cli/index.ts
@@ -9,12 +9,16 @@ const HELP_TEXT = `Usage: hono-takibi <input.{yaml,json,tsp}> -o <output.ts>
9
9
 
10
10
  Options:
11
11
  -h, --help display help for command`;
12
+ function isYamlOrJsonOrTsp(i) {
13
+ return i.endsWith(".yaml") || i.endsWith(".json") || i.endsWith(".tsp");
14
+ }
15
+ function isTs(o) {
16
+ return o.endsWith(".ts");
17
+ }
12
18
  function parseCli(args) {
13
19
  const input = args[0];
14
20
  const oIdx = args.indexOf("-o");
15
21
  const output = oIdx !== -1 ? args[oIdx + 1] : void 0;
16
- const isYamlOrJsonOrTsp = (i) => i.endsWith(".yaml") || i.endsWith(".json") || i.endsWith(".tsp");
17
- const isTs = (o) => o.endsWith(".ts");
18
22
  if (!(input && output && isYamlOrJsonOrTsp(input) && isTs(output))) return {
19
23
  ok: false,
20
24
  error: HELP_TEXT
@@ -33,7 +37,8 @@ async function honoTakibi() {
33
37
  ok: true,
34
38
  value: HELP_TEXT
35
39
  };
36
- if (!existsSync(resolve(process.cwd(), "hono-takibi.config.ts"))) {
40
+ const abs = resolve(process.cwd(), "hono-takibi.config.ts");
41
+ if (!existsSync(abs)) {
37
42
  const cliResult = parseCli(args);
38
43
  if (!cliResult.ok) return {
39
44
  ok: false,
@@ -1,4 +1,4 @@
1
- import { t as OpenAPI } from "../../index-CQcc43cH.js";
1
+ import { t as OpenAPI } from "../../index-BDBsbJIq.js";
2
2
  //#region src/core/docs/index.d.ts
3
3
  declare function docs(openAPI: OpenAPI, output: string, entry?: string, basePath?: string, curl?: boolean, baseUrl?: string): Promise<{
4
4
  readonly value?: never;
@@ -1,2 +1,2 @@
1
- import { t as docs } from "../../docs-DJEuJ8Cn.js";
1
+ import { t as docs } from "../../docs-D0ZoEuTk.js";
2
2
  export { docs };
@@ -1,4 +1,4 @@
1
- import { t as OpenAPI } from "../../index-CQcc43cH.js";
1
+ import { t as OpenAPI } from "../../index-BDBsbJIq.js";
2
2
  //#region src/core/hooks/index.d.ts
3
3
  declare const HOOK_CONFIGS: {
4
4
  readonly swr: {
@@ -1,2 +1,2 @@
1
- import { t as hooks } from "../../hooks-BfmklyQ_.js";
1
+ import { t as hooks } from "../../hooks-BMBBxGkd.js";
2
2
  export { hooks };
@@ -1,4 +1,4 @@
1
- import { t as OpenAPI } from "../../index-CQcc43cH.js";
1
+ import { t as OpenAPI } from "../../index-BDBsbJIq.js";
2
2
  //#region src/core/rpc/index.d.ts
3
3
  /**
4
4
  * Generates RPC client wrapper functions from OpenAPI specification.
@@ -1,7 +1,7 @@
1
- import { t as emit } from "../../emit-CFR63U4L.js";
2
- import { N as methodPath, c as isOperationLike, f as isRecord, j as makeInferRequestType, o as isOpenAPIPaths } from "../../guard-B2ZfZYyO.js";
3
- import { a as parsePathItem, i as operationHasArgs, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "../../rpc-vbCXB2S_.js";
4
- import path from "node:path";
1
+ import { t as emit } from "../../emit-rUfH9f6q.js";
2
+ import { D as isOpenAPIPaths, L as isRecord, d as methodPath, k as isOperationLike, l as makeInferRequestType } from "../../utils-D1npWaGs.js";
3
+ import { a as parsePathItem, i as operationHasArgs, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "../../rpc-BefI0iar.js";
4
+ import { dirname, join } from "node:path";
5
5
  //#region src/core/rpc/index.ts
6
6
  /**
7
7
  * Builds a JSDoc block from operation `summary` / `description` plus the HTTP route line.
@@ -16,7 +16,7 @@ function makeJsDoc(operation, method, path) {
16
16
  if (summary) sections.push([summary]);
17
17
  if (description) sections.push(description.split("\n"));
18
18
  sections.push([`${method.toUpperCase()} ${path}`]);
19
- return `/**\n${sections.map((lines, i) => i === 0 ? lines : ["", ...lines]).flat().map((line) => line ? ` * ${line}` : " *").join("\n")}\n */\n`;
19
+ return `/**\n${sections.map((lines) => lines.join("\n")).join("\n\n").split("\n").map((line) => line ? ` * ${line}` : " *").join("\n")}\n */\n`;
20
20
  }
21
21
  function makeOperationCode(path, method, item, deps, useParseResponse, hasBasePath, docs) {
22
22
  const operation = item[method];
@@ -78,10 +78,13 @@ async function rpc(openAPI, output, importPath, split, clientName = "client", us
78
78
  error: "Invalid OpenAPI paths"
79
79
  };
80
80
  const hasBasePath = basePath !== void 0 && basePath !== "/";
81
- const operationCodes = makeOperationCodes(paths, makeOperationDeps(clientName, openAPI.components?.parameters ?? {}, openAPI.components?.requestBodies ?? {}), useParseResponse, hasBasePath, docs);
81
+ const componentsParameters = openAPI.components?.parameters ?? {};
82
+ const componentsRequestBodies = openAPI.components?.requestBodies ?? {};
83
+ const operationCodes = makeOperationCodes(paths, makeOperationDeps(clientName, componentsParameters, componentsRequestBodies), useParseResponse, hasBasePath, docs);
82
84
  if (!split) {
83
85
  const body = operationCodes.map(({ code }) => code).join("\n\n");
84
- const emitResult = await emit(`${makeHeader(importPath, operationCodes.some(({ hasArgs }) => hasArgs), clientName, useParseResponse)}${body}${operationCodes.length ? "\n" : ""}`, path.dirname(output), output);
86
+ const code = `${makeHeader(importPath, operationCodes.some(({ hasArgs }) => hasArgs), clientName, useParseResponse)}${body}${operationCodes.length > 0 ? "\n" : ""}`;
87
+ const emitResult = await emit(code, dirname(output), output);
85
88
  if (!emitResult.ok) return {
86
89
  ok: false,
87
90
  error: emitResult.error
@@ -92,12 +95,12 @@ async function rpc(openAPI, output, importPath, split, clientName = "client", us
92
95
  };
93
96
  }
94
97
  const { outDir, indexPath } = resolveSplitOutDir(output);
95
- const index = `${Array.from(new Set(operationCodes.map(({ funcName }) => `export * from './${funcName}'`))).join("\n")}\n`;
98
+ const index = `${[...new Set(operationCodes.map(({ funcName }) => `export * from './${funcName}'`))].join("\n")}\n`;
96
99
  const e = (await Promise.all([...operationCodes.map(({ funcName, code, hasArgs }) => {
97
100
  const fileSrc = `${makeHeader(importPath, hasArgs, clientName, useParseResponse)}${code}\n`;
98
- const filePath = path.join(outDir, `${funcName}.ts`);
99
- return emit(fileSrc, path.dirname(filePath), filePath);
100
- }), emit(index, path.dirname(indexPath), indexPath)])).find((result) => !result.ok);
101
+ const filePath = join(outDir, `${funcName}.ts`);
102
+ return emit(fileSrc, dirname(filePath), filePath);
103
+ }), emit(index, dirname(indexPath), indexPath)])).find((result) => !result.ok);
101
104
  if (e) return e;
102
105
  return {
103
106
  ok: true,
@@ -1,4 +1,4 @@
1
- import { t as OpenAPI } from "../../index-CQcc43cH.js";
1
+ import { t as OpenAPI } from "../../index-BDBsbJIq.js";
2
2
  //#region src/core/type/index.d.ts
3
3
  /**
4
4
  * Generates TypeScript type declarations from OpenAPI specification.
@@ -1,5 +1,5 @@
1
- import { t as emit } from "../../emit-CFR63U4L.js";
2
- import { L as statusCodeToNumber, M as makeSafeKey, g as isSchemaArray, i as isMediaWithSchema, l as isParameter, m as isRequestBody, n as isHttpMethod, s as isOperation, u as isParameterArray, x as isStringRef } from "../../guard-B2ZfZYyO.js";
1
+ import { t as emit } from "../../emit-rUfH9f6q.js";
2
+ import { A as isParameter, C as isHttpMethod, D as isOpenAPIPaths, O as isOperation, T as isMediaWithSchema, V as isSchemaArray, h as statusCodeToNumber, j as isParameterArray, q as isStringRef, u as makeSafeKey, z as isRequestBody } from "../../utils-D1npWaGs.js";
3
3
  import path from "node:path";
4
4
  //#region src/core/type/index.ts
5
5
  /**
@@ -17,7 +17,8 @@ const DEEP_READONLY_TYPE = "type DeepReadonly<T>=T extends(infer R)[]?readonly D
17
17
  async function type(openAPI, output, readonly) {
18
18
  const schemaType = makeHonoSchemaType(openAPI);
19
19
  const wrappedType = readonly ? `DeepReadonly<${schemaType}>` : schemaType;
20
- const emitResult = await emit(`${readonly ? DEEP_READONLY_TYPE : ""}declare const routes:import('@hono/zod-openapi').OpenAPIHono<import('hono/types').Env,${wrappedType},'/'>\nexport default routes\n`, path.dirname(output), output);
20
+ const dts = `${readonly ? DEEP_READONLY_TYPE : ""}declare const routes:import('@hono/zod-openapi').OpenAPIHono<import('hono/types').Env,${wrappedType},'/'>\nexport default routes\n`;
21
+ const emitResult = await emit(dts, path.dirname(output), output);
21
22
  return emitResult.ok ? {
22
23
  ok: true,
23
24
  value: `Generated type code written to ${output}`
@@ -27,7 +28,8 @@ async function type(openAPI, output, readonly) {
27
28
  };
28
29
  }
29
30
  function makeHonoSchemaType(openAPI) {
30
- const { paths, components } = openAPI;
31
+ const { components } = openAPI;
32
+ const paths = isOpenAPIPaths(openAPI.paths) ? openAPI.paths : {};
31
33
  const pathEntries = Object.entries(paths).flatMap(([openApiPath, pathItem]) => {
32
34
  const honoPath = makeHonoPath(openApiPath);
33
35
  const pathLevelParams = isParameterArray(pathItem.parameters) ? pathItem.parameters : [];
@@ -46,7 +48,7 @@ function makeHonoSchemaType(openAPI) {
46
48
  return pathEntries.length === 0 ? "{}" : pathEntries.map(({ path: p, methods }) => `{'${p}':{${methods}}}`).join("&");
47
49
  }
48
50
  function makeHonoPath(openApiPath) {
49
- return openApiPath.replace(/\{([^}]+)\}/g, ":$1");
51
+ return openApiPath.replaceAll(/\{([^}]+)\}/g, ":$1");
50
52
  }
51
53
  function makeMethodType(operation, openApiPath, components, pathLevelParams) {
52
54
  const inputType = makeInputType(operation, openApiPath, components, pathLevelParams);
@@ -68,7 +70,7 @@ function makeInputType(operation, openApiPath, components, pathLevelParams) {
68
70
  return parts.length === 0 ? "{}" : parts.join("&");
69
71
  }
70
72
  function makePathParams(openApiPath) {
71
- return Array.from(openApiPath.matchAll(/\{([^}]+)\}/g)).map((m) => m[1]);
73
+ return [...openApiPath.matchAll(/\{([^}]+)\}/g)].map((m) => m[1]);
72
74
  }
73
75
  function makeParamPart(params, components) {
74
76
  const props = params.map((p) => {
@@ -167,9 +169,9 @@ function makeSchemaTypeString(schema, components, visited) {
167
169
  if (schema.oneOf && schema.oneOf.length > 0) return schema.oneOf.map((s) => makeSchemaTypeString(s, components, visited)).join("|");
168
170
  if (schema.anyOf && schema.anyOf.length > 0) return schema.anyOf.map((s) => makeSchemaTypeString(s, components, visited)).join("|");
169
171
  if (schema.allOf && schema.allOf.length > 0) return makeAllOfTypeString(schema.allOf, components, visited);
170
- if (schema.enum && schema.enum.length > 0) return schema.enum.map((v) => typeof v === "string" ? `'${v.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'` : String(v)).join("|");
172
+ if (schema.enum && schema.enum.length > 0) return schema.enum.map((v) => typeof v === "string" ? `'${v.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'` : String(v)).join("|");
171
173
  if (schema.const !== void 0) {
172
- if (typeof schema.const === "string") return `'${schema.const.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
174
+ if (typeof schema.const === "string") return `'${schema.const.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
173
175
  if (typeof schema.const === "number" || typeof schema.const === "boolean") return String(schema.const);
174
176
  return JSON.stringify(schema.const);
175
177
  }
@@ -221,7 +223,7 @@ function makeAllOfTypeString(allOf, components, visited) {
221
223
  return result;
222
224
  }, /* @__PURE__ */ new Map());
223
225
  if (mergedProps.size === 0) return "{}";
224
- return `{${Array.from(mergedProps.entries()).map(([key, { type, required }]) => {
226
+ return `{${[...mergedProps.entries()].map(([key, { type, required }]) => {
225
227
  const safeKey = makeSafeKey(key);
226
228
  return required ? `${safeKey}:${type}` : `${safeKey}?:${type}|undefined`;
227
229
  }).join(";")}}`;
@@ -1,5 +1,5 @@
1
- import { a as writeFile, t as mkdir } from "./fsp-BXry-Hx5.js";
2
- import { O as escapeHtml, a as isOAuthFlowValue, b as isSecurityScheme, f as isRecord, h as isResponses, m as isRequestBody, p as isRefObject, r as isMedia, y as isSecurityArray } from "./guard-B2ZfZYyO.js";
1
+ import { i as writeFile, t as mkdir } from "./fsp-BxW8iutq.js";
2
+ import { B as isResponses, D as isOpenAPIPaths, E as isOAuthFlowValue, G as isSecurityScheme, H as isSchemaObject, L as isRecord, R as isRefObject, V as isSchemaArray, W as isSecurityArray, o as escapeHtml, w as isMedia, z as isRequestBody } from "./utils-D1npWaGs.js";
3
3
  import path from "node:path";
4
4
  import { STATUS_CODES } from "node:http";
5
5
  //#region src/generator/docs/index.ts
@@ -15,10 +15,10 @@ const HTTP_METHODS = [
15
15
  ];
16
16
  const MAX_SCHEMA_DEPTH = 50;
17
17
  function toSlug(text) {
18
- return (typeof text === "string" ? text : String(text ?? "")).replace(/[A-Z]/g, (c) => c.toLowerCase()).replace(/[^a-z0-9\u3000-\u9fff\uff00-\uffef -]/g, "").replace(/\s+/g, "-");
18
+ return (typeof text === "string" ? text : String(text ?? "")).replaceAll(/[A-Z]/g, (c) => c.toLowerCase()).replaceAll(/[^a-z0-9\u3000-\u9fff\uff00-\uffef -]/g, "").replaceAll(/\s+/g, "-");
19
19
  }
20
20
  function toTitleSlug(title) {
21
- return (typeof title === "string" ? title : String(title ?? "")).toLowerCase().replace(/[^a-z0-9 -]/g, "").replace(/\s+/g, "-");
21
+ return (typeof title === "string" ? title : String(title ?? "")).toLowerCase().replaceAll(/[^a-z0-9 -]/g, "").replaceAll(/\s+/g, "-");
22
22
  }
23
23
  function lookupComponentSection(components, section) {
24
24
  switch (section) {
@@ -65,8 +65,8 @@ function formatSchemaType(schema) {
65
65
  return `[${name}](#schema${name.toLowerCase()})`;
66
66
  }
67
67
  if (schema.type === "array" && schema.items) {
68
- const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
69
- if (itemSchema) return `[${formatSchemaType(itemSchema)}]`;
68
+ const itemSchema = isSchemaArray(schema.items) ? schema.items[0] : schema.items;
69
+ if (isSchemaObject(itemSchema)) return `[${formatSchemaType(itemSchema)}]`;
70
70
  return "array";
71
71
  }
72
72
  const baseType = Array.isArray(schema.type) ? schema.type.join(" | ") : schema.type ?? "object";
@@ -103,7 +103,7 @@ function makeDefaultValue(schema) {
103
103
  switch (schema.type) {
104
104
  case "string": return makeDefaultString(schema.format);
105
105
  case "number":
106
- case "integer": return schema.minimum !== void 0 ? schema.minimum : 0;
106
+ case "integer": return schema.minimum ?? 0;
107
107
  case "boolean": return true;
108
108
  default: return null;
109
109
  }
@@ -126,8 +126,8 @@ function makeExampleFromSchema(schema, components, visited = /* @__PURE__ */ new
126
126
  return result;
127
127
  }
128
128
  if (schema.type === "array" && schema.items) {
129
- const item = Array.isArray(schema.items) ? schema.items[0] : schema.items;
130
- if (item) return [makeExampleFromSchema(item, components, visited, depth + 1)];
129
+ const item = isSchemaArray(schema.items) ? schema.items[0] : schema.items;
130
+ if (isSchemaObject(item)) return [makeExampleFromSchema(item, components, visited, depth + 1)];
131
131
  return [];
132
132
  }
133
133
  if (schema.allOf?.length) {
@@ -326,7 +326,7 @@ function makeCodeSampleCurl(method, pathStr, basePath, operation, securityScheme
326
326
  [
327
327
  `curl ${url} \\`,
328
328
  ...remaining.slice(0, -1).map((r) => `${r} \\`),
329
- remaining[remaining.length - 1]
329
+ remaining.at(-1)
330
330
  ].join("\n"),
331
331
  "```"
332
332
  ];
@@ -346,7 +346,7 @@ function resolveOperationParameters(operation, components) {
346
346
  });
347
347
  }
348
348
  function getPathParameters(openAPI, pathStr) {
349
- const pathItem = openAPI.paths?.[pathStr];
349
+ const pathItem = (isOpenAPIPaths(openAPI.paths) ? openAPI.paths : {})[pathStr];
350
350
  if (!pathItem?.parameters) return [];
351
351
  return pathItem.parameters.flatMap((parameter) => {
352
352
  if ("$ref" in parameter && parameter.$ref) {
@@ -388,12 +388,12 @@ function flattenBodyParams(schema, components, prefix, visited = /* @__PURE__ */
388
388
  required: requiredSet.has(key),
389
389
  description: propSchema.description ?? "none"
390
390
  };
391
- if (propSchema.type === "object" && propSchema.properties) return [row, ...flattenBodyParams(propSchema, components, (prefix ? `${prefix}»` : "»»").replace(/»/g, "» "), visited, depth + 1)];
391
+ if (propSchema.type === "object" && propSchema.properties) return [row, ...flattenBodyParams(propSchema, components, (prefix ? `${prefix}»` : "»»").replaceAll("»", "» "), visited, depth + 1)];
392
392
  if (propSchema.$ref) {
393
393
  if (visited.has(propSchema.$ref)) return [row];
394
394
  visited.add(propSchema.$ref);
395
395
  const innerResolved = resolveRef(propSchema.$ref, components);
396
- if (isSchemaLike(innerResolved) && innerResolved.type === "object") return [row, ...flattenBodyParams(innerResolved, components, (prefix ? `${prefix}»` : "»»").replace(/»/g, "» "), visited, depth + 1)];
396
+ if (isSchemaLike(innerResolved) && innerResolved.type === "object") return [row, ...flattenBodyParams(innerResolved, components, (prefix ? `${prefix}»` : "»»").replaceAll("»", "» "), visited, depth + 1)];
397
397
  }
398
398
  return [row];
399
399
  });
@@ -495,27 +495,27 @@ function flattenResponseSchemaFields(schema, components, prefix, visited = /* @_
495
495
  restrictions: "none",
496
496
  description: propSchema.description ?? "none"
497
497
  };
498
- const nestedPrefix = (prefix ? `${prefix}»` : "»").replace(/»/g, "» ").trimEnd();
499
- if (propSchema.type === "object" && propSchema.properties) return [row, ...flattenResponseSchemaFields(propSchema, components, `${nestedPrefix}`, visited, depth + 1)];
498
+ const nestedPrefix = (prefix ? `${prefix}»` : "»").replaceAll("»", "» ").trimEnd();
499
+ if (propSchema.type === "object" && propSchema.properties) return [row, ...flattenResponseSchemaFields(propSchema, components, nestedPrefix, visited, depth + 1)];
500
500
  if (propSchema.$ref) {
501
501
  if (visited.has(propSchema.$ref)) return [row];
502
502
  visited.add(propSchema.$ref);
503
503
  const innerResolved = resolveRef(propSchema.$ref, components);
504
- if (isSchemaLike(innerResolved) && innerResolved.type === "object") return [row, ...flattenResponseSchemaFields(innerResolved, components, `${nestedPrefix}`, visited, depth + 1)];
504
+ if (isSchemaLike(innerResolved) && innerResolved.type === "object") return [row, ...flattenResponseSchemaFields(innerResolved, components, nestedPrefix, visited, depth + 1)];
505
505
  }
506
506
  if (propSchema.type === "array" && propSchema.items) {
507
- const itemSchema = Array.isArray(propSchema.items) ? propSchema.items[0] : propSchema.items;
508
- if (itemSchema) {
507
+ const itemSchema = isSchemaArray(propSchema.items) ? propSchema.items[0] : propSchema.items;
508
+ if (isSchemaObject(itemSchema)) {
509
509
  const resolvedItem = resolveArrayItem(itemSchema, components, visited);
510
- if (resolvedItem.type === "object" && resolvedItem.properties) return [row, ...flattenResponseSchemaFields(resolvedItem, components, `${nestedPrefix}`, visited, depth + 1)];
510
+ if (resolvedItem.type === "object" && resolvedItem.properties) return [row, ...flattenResponseSchemaFields(resolvedItem, components, nestedPrefix, visited, depth + 1)];
511
511
  }
512
512
  }
513
513
  return [row];
514
514
  });
515
515
  }
516
516
  if (schema.type === "array" && schema.items) {
517
- const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
518
- if (itemSchema) {
517
+ const itemSchema = isSchemaArray(schema.items) ? schema.items[0] : schema.items;
518
+ if (isSchemaObject(itemSchema)) {
519
519
  const anonRow = {
520
520
  name: "*anonymous*",
521
521
  type: `[${formatSchemaType(itemSchema)}]`,
@@ -652,8 +652,8 @@ function makeSchemasSection(schemas, components) {
652
652
  return lines;
653
653
  }
654
654
  function collectEndpoints(openAPI) {
655
- if (!openAPI.paths) return [];
656
- return Object.entries(openAPI.paths).flatMap(([pathStr, pathItem]) => {
655
+ const paths = isOpenAPIPaths(openAPI.paths) ? openAPI.paths : {};
656
+ return Object.entries(paths).flatMap(([pathStr, pathItem]) => {
657
657
  if (!pathItem) return [];
658
658
  return HTTP_METHODS.flatMap((method) => {
659
659
  const operation = pathItem[method];
@@ -1,4 +1,4 @@
1
- import { a as writeFile, t as mkdir } from "./fsp-BXry-Hx5.js";
1
+ import { i as writeFile, t as mkdir } from "./fsp-BxW8iutq.js";
2
2
  import { format } from "oxfmt";
3
3
  //#region src/format/index.ts
4
4
  const defaultConfig = {
@@ -1,23 +1,5 @@
1
1
  import fsp from "node:fs/promises";
2
2
  //#region src/fsp/index.ts
3
- async function unlink(path) {
4
- try {
5
- await fsp.unlink(path);
6
- return {
7
- ok: true,
8
- value: void 0
9
- };
10
- } catch (e) {
11
- if (e instanceof Error && "code" in e && e.code === "ENOENT") return {
12
- ok: true,
13
- value: void 0
14
- };
15
- return {
16
- ok: false,
17
- error: e instanceof Error ? e.message : String(e)
18
- };
19
- }
20
- }
21
3
  async function mkdir(dir) {
22
4
  try {
23
5
  await fsp.mkdir(dir, { recursive: true });
@@ -86,4 +68,4 @@ async function writeFile(path, data) {
86
68
  }
87
69
  }
88
70
  //#endregion
89
- export { writeFile as a, unlink as i, readFile as n, readdir as r, mkdir as t };
71
+ export { writeFile as i, readFile as n, readdir as r, mkdir as t };
@@ -1,4 +1,4 @@
1
- import { t as OpenAPI } from "../../../index-CQcc43cH.js";
1
+ import { t as OpenAPI } from "../../../index-BDBsbJIq.js";
2
2
  //#region src/generator/zod-openapi-hono/openapi/index.d.ts
3
3
  declare function zodOpenAPIHono(openapi: OpenAPI, options: {
4
4
  readonly readonly?: boolean;
@@ -1,2 +1,2 @@
1
- import { t as zodOpenAPIHono } from "../../../openapi-CmhbPLWG.js";
1
+ import { t as zodOpenAPIHono } from "../../../openapi-DvDCtFfn.js";
2
2
  export { zodOpenAPIHono };
@@ -1,10 +1,11 @@
1
- import { t as emit } from "./emit-CFR63U4L.js";
2
- import { N as methodPath, R as toIdentifierPascalCase, c as isOperationLike, f as isRecord, o as isOpenAPIPaths, w as capitalize } from "./guard-B2ZfZYyO.js";
3
- import { a as parsePathItem, i as operationHasArgs, n as hasNoContentResponse, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "./rpc-vbCXB2S_.js";
1
+ import { t as emit } from "./emit-rUfH9f6q.js";
2
+ import { D as isOpenAPIPaths, L as isRecord, d as methodPath, g as toIdentifierPascalCase, k as isOperationLike, n as capitalize } from "./utils-D1npWaGs.js";
3
+ import { a as parsePathItem, i as operationHasArgs, n as hasNoContentResponse, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "./rpc-BefI0iar.js";
4
4
  import path from "node:path";
5
5
  //#region src/helper/query.ts
6
6
  function makeHookName(method, pathStr, prefix) {
7
- return `${prefix}${capitalize(methodPath(method, pathStr))}`;
7
+ const funcName = methodPath(method, pathStr);
8
+ return `${prefix}${capitalize(funcName)}`;
8
9
  }
9
10
  function makeRuntimeAccess(clientName, method, pathStr) {
10
11
  return `${clientName}${formatPath(pathStr).runtimePath}.$${method}`;
@@ -27,15 +28,6 @@ function makeInfiniteQueryKeyGetterName(method, pathStr, isSWR) {
27
28
  if (isSWR) return `get${capitalize(methodPath(method, pathStr))}InfiniteKey`;
28
29
  return `get${capitalize(methodPath("", pathStr))}InfiniteQueryKey`;
29
30
  }
30
- function makeQueryOptionsGetterName(pathStr) {
31
- return `get${capitalize(methodPath("", pathStr))}QueryOptions`;
32
- }
33
- function makeInfiniteQueryOptionsGetterName(pathStr) {
34
- return `get${capitalize(methodPath("", pathStr))}InfiniteQueryOptions`;
35
- }
36
- function makeMutationOptionsGetterName(method, pathStr) {
37
- return `get${capitalize(methodPath(method, pathStr))}MutationOptions`;
38
- }
39
31
  function makeQueryKeyGetterCode(keyGetterName, hasArgs, argsType, honoPath, config, hasHeader = false) {
40
32
  const prefix = honoPath.replace(/^\//, "").split("/")[0];
41
33
  if (config.isVueQuery) {
@@ -359,7 +351,7 @@ function makeHookCode(pathStr, method, item, deps, config, clientName) {
359
351
  const runtimeAccess = makeRuntimeAccess(clientName, method, pathStr);
360
352
  const responseType = makeResponseTypeFromClient(clientName, method, pathStr);
361
353
  const hasNoContent = hasNoContentResponse(op);
362
- const honoPath = pathStr.replace(/\{([^}]+)\}/g, ":$1");
354
+ const honoPath = pathStr.replaceAll(/\{([^}]+)\}/g, ":$1");
363
355
  if (config.isSWR) {
364
356
  if (isQuery) {
365
357
  const keyGetterName = makeQueryKeyGetterName(method, pathStr, true);
@@ -396,12 +388,12 @@ function makeHookCode(pathStr, method, item, deps, config, clientName) {
396
388
  const queryHookName = makeHookName("", pathStr, config.hookPrefix);
397
389
  const pathFuncName = methodPath("", pathStr);
398
390
  const keyGetterName = makeQueryKeyGetterName(method, pathStr);
399
- const optionsGetterName = makeQueryOptionsGetterName(pathStr);
391
+ const optionsGetterName = `get${capitalize(methodPath("", pathStr))}QueryOptions`;
400
392
  const keyGetterCode = makeQueryKeyGetterCode(keyGetterName, hasArgs, argsType, honoPath, config, hasHeaderArgs);
401
393
  const optionsGetterCode = makeQueryOptionsGetterCode(optionsGetterName, keyGetterName, hasArgs, argsType, runtimeAccess, config);
402
394
  const hookCode = makeQueryHookCode(queryHookName, keyGetterName, runtimeAccess, hasArgs, argsType, responseType, config);
403
395
  const infiniteKeyGetterName = makeInfiniteQueryKeyGetterName(method, pathStr);
404
- const infiniteOptionsGetterName = makeInfiniteQueryOptionsGetterName(pathStr);
396
+ const infiniteOptionsGetterName = `get${capitalize(methodPath("", pathStr))}InfiniteQueryOptions`;
405
397
  const { infiniteQueryFn, useInfiniteQueryOptionsType } = config;
406
398
  const hasInfinite = !!(infiniteQueryFn && useInfiniteQueryOptionsType) && hasPagination;
407
399
  const infiniteKeyGetterCode = hasInfinite ? makeInfiniteQueryKeyGetterCode(infiniteKeyGetterName, hasArgs, argsType, honoPath, config, hasHeaderArgs) : null;
@@ -451,7 +443,7 @@ function makeHookCode(pathStr, method, item, deps, config, clientName) {
451
443
  operationFileName
452
444
  };
453
445
  }
454
- const optionsGetterName = makeMutationOptionsGetterName(method, pathStr);
446
+ const optionsGetterName = `get${capitalize(methodPath(method, pathStr))}MutationOptions`;
455
447
  return {
456
448
  code: `${makeMutationOptionsGetterCode(optionsGetterName, hasArgs, argsType, runtimeAccess, method, honoPath, responseType, hasNoContent, config)}\n\n${makeMutationHookCode(hookName, optionsGetterName, hasArgs, argsType, responseType, config, hasNoContent)}`,
457
449
  isQuery: false,
@@ -545,26 +537,29 @@ async function makeQueryHooks(openAPI, output, importPath, config, split, client
545
537
  ok: false,
546
538
  error: "Invalid OpenAPI paths"
547
539
  };
548
- const hookCodes = makeHookCodes(pathsMaybe, makeOperationDeps(clientName, openAPI.components?.parameters ?? {}, openAPI.components?.requestBodies ?? {}), config, clientName);
540
+ const componentsParameters = openAPI.components?.parameters ?? {};
541
+ const componentsRequestBodies = openAPI.components?.requestBodies ?? {};
542
+ const hookCodes = makeHookCodes(pathsMaybe, makeOperationDeps(clientName, componentsParameters, componentsRequestBodies), config, clientName);
549
543
  const prefixKeyCodes = makePrefixKeyCodes(pathsMaybe);
550
544
  const hasAnyArgs = hookCodes.some(({ hasArgs }) => hasArgs);
551
545
  if (!split) {
552
546
  const prefixBody = prefixKeyCodes.join("\n\n");
553
547
  const hookBody = hookCodes.map(({ code }) => code).join("\n\n");
554
548
  const body = prefixBody + (prefixBody && hookBody ? "\n\n" : "") + hookBody;
555
- const emitResult = await emit(`${makeHeader(importPath, clientName, hookCodes.some(({ isQuery }) => isQuery), hookCodes.some(({ isQuery }) => !isQuery), hasAnyArgs, config, hookCodes.some(({ isQuery, hasArgs }) => isQuery && hasArgs), hookCodes.some(({ hasInfinite }) => hasInfinite))}${body}${hookCodes.length ? "\n" : ""}`, path.dirname(output), output);
549
+ const code = `${makeHeader(importPath, clientName, hookCodes.some(({ isQuery }) => isQuery), hookCodes.some(({ isQuery }) => !isQuery), hasAnyArgs, config, hookCodes.some(({ isQuery, hasArgs }) => isQuery && hasArgs), hookCodes.some(({ hasInfinite }) => hasInfinite))}${body}${hookCodes.length > 0 ? "\n" : ""}`;
550
+ const emitResult = await emit(code, path.dirname(output), output);
556
551
  if (!emitResult.ok) return {
557
552
  ok: false,
558
553
  error: emitResult.error
559
554
  };
560
555
  return {
561
556
  ok: true,
562
- value: `Generated ${config.frameworkName.toLowerCase().replace(/ /g, "-")} hooks written to ${output}`
557
+ value: `Generated ${config.frameworkName.toLowerCase().replaceAll(" ", "-")} hooks written to ${output}`
563
558
  };
564
559
  }
565
560
  const { outDir, indexPath } = resolveSplitOutDir(output);
566
- const keysCode = prefixKeyCodes.length ? `${prefixKeyCodes.join("\n\n")}\n` : "";
567
- const exportLines = Array.from(new Set(hookCodes.map(({ operationFileName }) => `export * from './${operationFileName}'`)));
561
+ const keysCode = prefixKeyCodes.length > 0 ? `${prefixKeyCodes.join("\n\n")}\n` : "";
562
+ const exportLines = [...new Set(hookCodes.map(({ operationFileName }) => `export * from './${operationFileName}'`))];
568
563
  const index = `${(keysCode ? [`export * from './keys'`, ...exportLines] : exportLines).join("\n")}\n`;
569
564
  const e = (await Promise.all([
570
565
  ...hookCodes.map(({ operationFileName, code, isQuery, hasArgs, hasInfinite }) => {
@@ -578,7 +573,7 @@ async function makeQueryHooks(openAPI, output, importPath, config, split, client
578
573
  if (e) return e;
579
574
  return {
580
575
  ok: true,
581
- value: `Generated ${config.frameworkName.toLowerCase().replace(/ /g, "-")} hooks written to ${outDir}/*.ts (index.ts included)`
576
+ value: `Generated ${config.frameworkName.toLowerCase().replaceAll(" ", "-")} hooks written to ${outDir}/*.ts (index.ts included)`
582
577
  };
583
578
  }
584
579
  //#endregion
@@ -1,7 +1,5 @@
1
- import SwaggerParser from "@apidevtools/swagger-parser";
2
1
  //#region src/openapi/index.d.ts
3
- type BaseOpenAPI = Awaited<ReturnType<typeof SwaggerParser.bundle>>;
4
- type OpenAPI = BaseOpenAPI & {
2
+ type OpenAPI = {
5
3
  readonly openapi?: string;
6
4
  readonly $self?: string;
7
5
  readonly info?: {
@@ -40,8 +38,6 @@ type OpenAPI = BaseOpenAPI & {
40
38
  readonly kind?: string;
41
39
  }[];
42
40
  readonly externalDocs?: ExternalDocs;
43
- } & {
44
- paths: OpenAPIPaths;
45
41
  };
46
42
  type Components = {
47
43
  readonly schemas?: {
@@ -100,18 +96,22 @@ type Components = {
100
96
  readonly [k: string]: Media | Reference;
101
97
  };
102
98
  };
103
- type OAuthFlow = {
104
- readonly implicit?: {
105
- readonly authorizationUrl: string;
106
- readonly deviceAuthorizationUrl: string;
107
- readonly tokenUrl: string;
108
- readonly refreshUrl: string;
109
- readonly scopes: {
110
- readonly [k: string]: string;
111
- };
99
+ type OAuthFlowDetail = {
100
+ readonly authorizationUrl?: string;
101
+ readonly deviceAuthorizationUrl?: string;
102
+ readonly tokenUrl?: string;
103
+ readonly refreshUrl?: string;
104
+ readonly scopes: {
105
+ readonly [k: string]: string;
112
106
  };
113
107
  };
114
- type OpenAPIPaths = { readonly [P in keyof NonNullable<BaseOpenAPI['paths']>]: PathItem; };
108
+ type OAuthFlow = {
109
+ readonly implicit?: OAuthFlowDetail;
110
+ readonly password?: OAuthFlowDetail;
111
+ readonly clientCredentials?: OAuthFlowDetail;
112
+ readonly authorizationCode?: OAuthFlowDetail;
113
+ readonly deviceAuthorization?: OAuthFlowDetail;
114
+ };
115
115
  type Type = 'string' | 'number' | 'integer' | 'date' | 'boolean' | 'array' | 'object' | 'null';
116
116
  type Format = FormatString | FormatNumber;
117
117
  type FormatString = 'email' | 'uuid' | 'uuidv4' | 'uuidv6' | 'uuidv7' | 'url' | 'uri' | 'httpUrl' | 'hostname' | 'hex' | 'jwt' | 'emoji' | 'base64' | 'base64url' | 'nanoid' | 'cuid' | 'cuid2' | 'ulid' | 'ipv4' | 'ipv6' | 'cidrv4' | 'cidrv6' | 'date' | 'time' | 'date-time' | 'duration' | 'binary' | 'byte' | 'password' | 'mac' | 'hash' | 'e164' | 'guid' | 'toLowerCase' | 'toUpperCase' | 'trim';
@@ -213,11 +213,7 @@ type Operation = {
213
213
  readonly [k: string]: Responses;
214
214
  };
215
215
  readonly callbacks?: {
216
- readonly [k: string]: {
217
- readonly $ref?: string;
218
- readonly summary?: string;
219
- readonly description?: string;
220
- };
216
+ readonly [k: string]: Callbacks | Reference;
221
217
  };
222
218
  readonly deprecated?: boolean;
223
219
  readonly security?: readonly {
package/dist/index.js CHANGED
@@ -186,11 +186,10 @@ const ConfigSchema = z.object({
186
186
  "mediaTypes"
187
187
  ].some((k) => v.components?.[k] !== void 0)), { message: "with template.define, per-type component outputs (components.schemas, components.responses, ...) are not supported. Use components.output for a single components file." }).refine((v) => {
188
188
  if (v.template?.define !== true || v.components?.output === void 0) return true;
189
- const normalize = (p) => p.replace(/^\.\//, "");
190
- const componentsOutput = normalize(v.components.output);
189
+ const componentsOutput = v.components.output.replace(/^\.\//, "");
191
190
  const container = componentsOutput.endsWith("/index.ts") ? componentsOutput.slice(0, -9) : componentsOutput;
192
191
  const anchor = container.includes("/") ? container.slice(0, container.lastIndexOf("/")) : "";
193
- const appEntry = normalize(v.output ?? (anchor === "" || anchor === "." ? "index.ts" : `${anchor}/index.ts`));
192
+ const appEntry = (v.output ?? (anchor === "" || anchor === "." ? "index.ts" : `${anchor}/index.ts`)).replace(/^\.\//, "");
194
193
  if (!appEntry.endsWith("index.ts")) return true;
195
194
  const baseDir = appEntry === "index.ts" ? "" : appEntry.slice(0, -9);
196
195
  const routesDir = baseDir === "" ? "routes" : `${baseDir}/routes`;