hono-takibi 0.9.99997 → 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 +4 -2
- package/dist/cli.js +8 -4
- package/dist/core/docs/index.d.ts +1 -1
- package/dist/core/docs/index.js +1 -1
- package/dist/core/hooks/index.d.ts +1 -1
- package/dist/core/hooks/index.js +1 -1
- package/dist/core/rpc/index.d.ts +1 -1
- package/dist/core/rpc/index.js +11 -11
- package/dist/core/type/index.d.ts +1 -1
- package/dist/core/type/index.js +9 -8
- package/dist/{docs-D6-_1ql4.js → docs-D0ZoEuTk.js} +20 -20
- package/dist/{emit-CFR63U4L.js → emit-rUfH9f6q.js} +1 -1
- package/dist/{fsp-BXry-Hx5.js → fsp-BxW8iutq.js} +1 -19
- package/dist/generator/zod-openapi-hono/openapi/index.d.ts +1 -1
- package/dist/generator/zod-openapi-hono/openapi/index.js +1 -1
- package/dist/{hooks-qJjGH61L.js → hooks-BMBBxGkd.js} +12 -21
- package/dist/{index-CQcc43cH.d.ts → index-BDBsbJIq.d.ts} +16 -20
- package/dist/index.js +2 -3
- package/dist/{openapi-QvfGV6Gp.js → openapi-DvDCtFfn.js} +150 -165
- package/dist/{rpc-BDZmSva1.js → rpc-BefI0iar.js} +6 -6
- package/dist/{shared-66qmwvRi.js → shared-Zyc06ZL_.js} +311 -200
- package/dist/{guard-C_eRJ0au.js → utils-D1npWaGs.js} +132 -95
- package/dist/vite-plugin/index.js +14 -10
- package/package.json +6 -4
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
|
|
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-
|
|
4
|
-
import { n as parseOpenAPI, r as takibi, t as makeJob } from "./shared-
|
|
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
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../index-
|
|
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;
|
package/dist/core/docs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as docs } from "../../docs-
|
|
1
|
+
import { t as docs } from "../../docs-D0ZoEuTk.js";
|
|
2
2
|
export { docs };
|
package/dist/core/hooks/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as hooks } from "../../hooks-
|
|
1
|
+
import { t as hooks } from "../../hooks-BMBBxGkd.js";
|
|
2
2
|
export { hooks };
|
package/dist/core/rpc/index.d.ts
CHANGED
package/dist/core/rpc/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as emit } from "../../emit-
|
|
2
|
-
import {
|
|
3
|
-
import { a as parsePathItem, i as operationHasArgs, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "../../rpc-
|
|
4
|
-
import
|
|
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
|
|
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];
|
|
@@ -83,8 +83,8 @@ async function rpc(openAPI, output, importPath, split, clientName = "client", us
|
|
|
83
83
|
const operationCodes = makeOperationCodes(paths, makeOperationDeps(clientName, componentsParameters, componentsRequestBodies), useParseResponse, hasBasePath, docs);
|
|
84
84
|
if (!split) {
|
|
85
85
|
const body = operationCodes.map(({ code }) => code).join("\n\n");
|
|
86
|
-
const code = `${makeHeader(importPath, operationCodes.some(({ hasArgs }) => hasArgs), clientName, useParseResponse)}${body}${operationCodes.length ? "\n" : ""}`;
|
|
87
|
-
const emitResult = await emit(code,
|
|
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);
|
|
88
88
|
if (!emitResult.ok) return {
|
|
89
89
|
ok: false,
|
|
90
90
|
error: emitResult.error
|
|
@@ -95,12 +95,12 @@ async function rpc(openAPI, output, importPath, split, clientName = "client", us
|
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
const { outDir, indexPath } = resolveSplitOutDir(output);
|
|
98
|
-
const index = `${
|
|
98
|
+
const index = `${[...new Set(operationCodes.map(({ funcName }) => `export * from './${funcName}'`))].join("\n")}\n`;
|
|
99
99
|
const e = (await Promise.all([...operationCodes.map(({ funcName, code, hasArgs }) => {
|
|
100
100
|
const fileSrc = `${makeHeader(importPath, hasArgs, clientName, useParseResponse)}${code}\n`;
|
|
101
|
-
const filePath =
|
|
102
|
-
return emit(fileSrc,
|
|
103
|
-
}), emit(index,
|
|
101
|
+
const filePath = join(outDir, `${funcName}.ts`);
|
|
102
|
+
return emit(fileSrc, dirname(filePath), filePath);
|
|
103
|
+
}), emit(index, dirname(indexPath), indexPath)])).find((result) => !result.ok);
|
|
104
104
|
if (e) return e;
|
|
105
105
|
return {
|
|
106
106
|
ok: true,
|
package/dist/core/type/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as emit } from "../../emit-
|
|
2
|
-
import {
|
|
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
|
/**
|
|
@@ -28,7 +28,8 @@ async function type(openAPI, output, readonly) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
function makeHonoSchemaType(openAPI) {
|
|
31
|
-
const {
|
|
31
|
+
const { components } = openAPI;
|
|
32
|
+
const paths = isOpenAPIPaths(openAPI.paths) ? openAPI.paths : {};
|
|
32
33
|
const pathEntries = Object.entries(paths).flatMap(([openApiPath, pathItem]) => {
|
|
33
34
|
const honoPath = makeHonoPath(openApiPath);
|
|
34
35
|
const pathLevelParams = isParameterArray(pathItem.parameters) ? pathItem.parameters : [];
|
|
@@ -47,7 +48,7 @@ function makeHonoSchemaType(openAPI) {
|
|
|
47
48
|
return pathEntries.length === 0 ? "{}" : pathEntries.map(({ path: p, methods }) => `{'${p}':{${methods}}}`).join("&");
|
|
48
49
|
}
|
|
49
50
|
function makeHonoPath(openApiPath) {
|
|
50
|
-
return openApiPath.
|
|
51
|
+
return openApiPath.replaceAll(/\{([^}]+)\}/g, ":$1");
|
|
51
52
|
}
|
|
52
53
|
function makeMethodType(operation, openApiPath, components, pathLevelParams) {
|
|
53
54
|
const inputType = makeInputType(operation, openApiPath, components, pathLevelParams);
|
|
@@ -69,7 +70,7 @@ function makeInputType(operation, openApiPath, components, pathLevelParams) {
|
|
|
69
70
|
return parts.length === 0 ? "{}" : parts.join("&");
|
|
70
71
|
}
|
|
71
72
|
function makePathParams(openApiPath) {
|
|
72
|
-
return
|
|
73
|
+
return [...openApiPath.matchAll(/\{([^}]+)\}/g)].map((m) => m[1]);
|
|
73
74
|
}
|
|
74
75
|
function makeParamPart(params, components) {
|
|
75
76
|
const props = params.map((p) => {
|
|
@@ -168,9 +169,9 @@ function makeSchemaTypeString(schema, components, visited) {
|
|
|
168
169
|
if (schema.oneOf && schema.oneOf.length > 0) return schema.oneOf.map((s) => makeSchemaTypeString(s, components, visited)).join("|");
|
|
169
170
|
if (schema.anyOf && schema.anyOf.length > 0) return schema.anyOf.map((s) => makeSchemaTypeString(s, components, visited)).join("|");
|
|
170
171
|
if (schema.allOf && schema.allOf.length > 0) return makeAllOfTypeString(schema.allOf, components, visited);
|
|
171
|
-
if (schema.enum && schema.enum.length > 0) return schema.enum.map((v) => typeof v === "string" ? `'${v.
|
|
172
|
+
if (schema.enum && schema.enum.length > 0) return schema.enum.map((v) => typeof v === "string" ? `'${v.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'` : String(v)).join("|");
|
|
172
173
|
if (schema.const !== void 0) {
|
|
173
|
-
if (typeof schema.const === "string") return `'${schema.const.
|
|
174
|
+
if (typeof schema.const === "string") return `'${schema.const.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
|
|
174
175
|
if (typeof schema.const === "number" || typeof schema.const === "boolean") return String(schema.const);
|
|
175
176
|
return JSON.stringify(schema.const);
|
|
176
177
|
}
|
|
@@ -222,7 +223,7 @@ function makeAllOfTypeString(allOf, components, visited) {
|
|
|
222
223
|
return result;
|
|
223
224
|
}, /* @__PURE__ */ new Map());
|
|
224
225
|
if (mergedProps.size === 0) return "{}";
|
|
225
|
-
return `{${
|
|
226
|
+
return `{${[...mergedProps.entries()].map(([key, { type, required }]) => {
|
|
226
227
|
const safeKey = makeSafeKey(key);
|
|
227
228
|
return required ? `${safeKey}:${type}` : `${safeKey}?:${type}|undefined`;
|
|
228
229
|
}).join(";")}}`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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 ?? "")).
|
|
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().
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
|
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
|
|
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}»` : "»»").
|
|
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}»` : "»»").
|
|
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,7 +495,7 @@ function flattenResponseSchemaFields(schema, components, prefix, visited = /* @_
|
|
|
495
495
|
restrictions: "none",
|
|
496
496
|
description: propSchema.description ?? "none"
|
|
497
497
|
};
|
|
498
|
-
const nestedPrefix = (prefix ? `${prefix}»` : "»").
|
|
498
|
+
const nestedPrefix = (prefix ? `${prefix}»` : "»").replaceAll("»", "» ").trimEnd();
|
|
499
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];
|
|
@@ -504,8 +504,8 @@ function flattenResponseSchemaFields(schema, components, prefix, visited = /* @_
|
|
|
504
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 =
|
|
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
510
|
if (resolvedItem.type === "object" && resolvedItem.properties) return [row, ...flattenResponseSchemaFields(resolvedItem, components, nestedPrefix, visited, depth + 1)];
|
|
511
511
|
}
|
|
@@ -514,8 +514,8 @@ function flattenResponseSchemaFields(schema, components, prefix, visited = /* @_
|
|
|
514
514
|
});
|
|
515
515
|
}
|
|
516
516
|
if (schema.type === "array" && schema.items) {
|
|
517
|
-
const itemSchema =
|
|
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
|
-
|
|
656
|
-
return Object.entries(
|
|
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,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
|
|
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-
|
|
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-
|
|
1
|
+
import { t as zodOpenAPIHono } from "../../../openapi-DvDCtFfn.js";
|
|
2
2
|
export { zodOpenAPIHono };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as emit } from "./emit-
|
|
2
|
-
import {
|
|
3
|
-
import { a as parsePathItem, i as operationHasArgs, n as hasNoContentResponse, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "./rpc-
|
|
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) {
|
|
@@ -28,15 +28,6 @@ function makeInfiniteQueryKeyGetterName(method, pathStr, isSWR) {
|
|
|
28
28
|
if (isSWR) return `get${capitalize(methodPath(method, pathStr))}InfiniteKey`;
|
|
29
29
|
return `get${capitalize(methodPath("", pathStr))}InfiniteQueryKey`;
|
|
30
30
|
}
|
|
31
|
-
function makeQueryOptionsGetterName(pathStr) {
|
|
32
|
-
return `get${capitalize(methodPath("", pathStr))}QueryOptions`;
|
|
33
|
-
}
|
|
34
|
-
function makeInfiniteQueryOptionsGetterName(pathStr) {
|
|
35
|
-
return `get${capitalize(methodPath("", pathStr))}InfiniteQueryOptions`;
|
|
36
|
-
}
|
|
37
|
-
function makeMutationOptionsGetterName(method, pathStr) {
|
|
38
|
-
return `get${capitalize(methodPath(method, pathStr))}MutationOptions`;
|
|
39
|
-
}
|
|
40
31
|
function makeQueryKeyGetterCode(keyGetterName, hasArgs, argsType, honoPath, config, hasHeader = false) {
|
|
41
32
|
const prefix = honoPath.replace(/^\//, "").split("/")[0];
|
|
42
33
|
if (config.isVueQuery) {
|
|
@@ -360,7 +351,7 @@ function makeHookCode(pathStr, method, item, deps, config, clientName) {
|
|
|
360
351
|
const runtimeAccess = makeRuntimeAccess(clientName, method, pathStr);
|
|
361
352
|
const responseType = makeResponseTypeFromClient(clientName, method, pathStr);
|
|
362
353
|
const hasNoContent = hasNoContentResponse(op);
|
|
363
|
-
const honoPath = pathStr.
|
|
354
|
+
const honoPath = pathStr.replaceAll(/\{([^}]+)\}/g, ":$1");
|
|
364
355
|
if (config.isSWR) {
|
|
365
356
|
if (isQuery) {
|
|
366
357
|
const keyGetterName = makeQueryKeyGetterName(method, pathStr, true);
|
|
@@ -397,12 +388,12 @@ function makeHookCode(pathStr, method, item, deps, config, clientName) {
|
|
|
397
388
|
const queryHookName = makeHookName("", pathStr, config.hookPrefix);
|
|
398
389
|
const pathFuncName = methodPath("", pathStr);
|
|
399
390
|
const keyGetterName = makeQueryKeyGetterName(method, pathStr);
|
|
400
|
-
const optionsGetterName =
|
|
391
|
+
const optionsGetterName = `get${capitalize(methodPath("", pathStr))}QueryOptions`;
|
|
401
392
|
const keyGetterCode = makeQueryKeyGetterCode(keyGetterName, hasArgs, argsType, honoPath, config, hasHeaderArgs);
|
|
402
393
|
const optionsGetterCode = makeQueryOptionsGetterCode(optionsGetterName, keyGetterName, hasArgs, argsType, runtimeAccess, config);
|
|
403
394
|
const hookCode = makeQueryHookCode(queryHookName, keyGetterName, runtimeAccess, hasArgs, argsType, responseType, config);
|
|
404
395
|
const infiniteKeyGetterName = makeInfiniteQueryKeyGetterName(method, pathStr);
|
|
405
|
-
const infiniteOptionsGetterName =
|
|
396
|
+
const infiniteOptionsGetterName = `get${capitalize(methodPath("", pathStr))}InfiniteQueryOptions`;
|
|
406
397
|
const { infiniteQueryFn, useInfiniteQueryOptionsType } = config;
|
|
407
398
|
const hasInfinite = !!(infiniteQueryFn && useInfiniteQueryOptionsType) && hasPagination;
|
|
408
399
|
const infiniteKeyGetterCode = hasInfinite ? makeInfiniteQueryKeyGetterCode(infiniteKeyGetterName, hasArgs, argsType, honoPath, config, hasHeaderArgs) : null;
|
|
@@ -452,7 +443,7 @@ function makeHookCode(pathStr, method, item, deps, config, clientName) {
|
|
|
452
443
|
operationFileName
|
|
453
444
|
};
|
|
454
445
|
}
|
|
455
|
-
const optionsGetterName =
|
|
446
|
+
const optionsGetterName = `get${capitalize(methodPath(method, pathStr))}MutationOptions`;
|
|
456
447
|
return {
|
|
457
448
|
code: `${makeMutationOptionsGetterCode(optionsGetterName, hasArgs, argsType, runtimeAccess, method, honoPath, responseType, hasNoContent, config)}\n\n${makeMutationHookCode(hookName, optionsGetterName, hasArgs, argsType, responseType, config, hasNoContent)}`,
|
|
458
449
|
isQuery: false,
|
|
@@ -555,7 +546,7 @@ async function makeQueryHooks(openAPI, output, importPath, config, split, client
|
|
|
555
546
|
const prefixBody = prefixKeyCodes.join("\n\n");
|
|
556
547
|
const hookBody = hookCodes.map(({ code }) => code).join("\n\n");
|
|
557
548
|
const body = prefixBody + (prefixBody && hookBody ? "\n\n" : "") + hookBody;
|
|
558
|
-
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 ? "\n" : ""}`;
|
|
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" : ""}`;
|
|
559
550
|
const emitResult = await emit(code, path.dirname(output), output);
|
|
560
551
|
if (!emitResult.ok) return {
|
|
561
552
|
ok: false,
|
|
@@ -563,12 +554,12 @@ async function makeQueryHooks(openAPI, output, importPath, config, split, client
|
|
|
563
554
|
};
|
|
564
555
|
return {
|
|
565
556
|
ok: true,
|
|
566
|
-
value: `Generated ${config.frameworkName.toLowerCase().
|
|
557
|
+
value: `Generated ${config.frameworkName.toLowerCase().replaceAll(" ", "-")} hooks written to ${output}`
|
|
567
558
|
};
|
|
568
559
|
}
|
|
569
560
|
const { outDir, indexPath } = resolveSplitOutDir(output);
|
|
570
|
-
const keysCode = prefixKeyCodes.length ? `${prefixKeyCodes.join("\n\n")}\n` : "";
|
|
571
|
-
const exportLines =
|
|
561
|
+
const keysCode = prefixKeyCodes.length > 0 ? `${prefixKeyCodes.join("\n\n")}\n` : "";
|
|
562
|
+
const exportLines = [...new Set(hookCodes.map(({ operationFileName }) => `export * from './${operationFileName}'`))];
|
|
572
563
|
const index = `${(keysCode ? [`export * from './keys'`, ...exportLines] : exportLines).join("\n")}\n`;
|
|
573
564
|
const e = (await Promise.all([
|
|
574
565
|
...hookCodes.map(({ operationFileName, code, isQuery, hasArgs, hasInfinite }) => {
|
|
@@ -582,7 +573,7 @@ async function makeQueryHooks(openAPI, output, importPath, config, split, client
|
|
|
582
573
|
if (e) return e;
|
|
583
574
|
return {
|
|
584
575
|
ok: true,
|
|
585
|
-
value: `Generated ${config.frameworkName.toLowerCase().
|
|
576
|
+
value: `Generated ${config.frameworkName.toLowerCase().replaceAll(" ", "-")} hooks written to ${outDir}/*.ts (index.ts included)`
|
|
586
577
|
};
|
|
587
578
|
}
|
|
588
579
|
//#endregion
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
2
1
|
//#region src/openapi/index.d.ts
|
|
3
|
-
type
|
|
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
|
|
104
|
-
readonly
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
readonly
|
|
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
|
|
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
|
|
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 =
|
|
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`;
|