hono-takibi 0.24.0 → 0.26.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/README.md +3 -1
- package/dist/cli.js +16 -11
- package/dist/{constants-Bz8YiPum.js → constants-hwmOoQfI.js} +24 -2
- 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 +6 -6
- package/dist/core/type/index.js +2 -2
- package/dist/{core-Bhi7NjFK.js → core-FnayWJZV.js} +18 -18
- package/dist/{docs-DTHnPNsq.js → docs-D8ivFJrR.js} +10 -4
- 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-BRODO70o.js → hooks-DJHtFXnM.js} +28 -28
- package/dist/{index-DhipYt_q.d.ts → index-BNrSddFB.d.ts} +11 -4
- package/dist/{index-BtPuSeOg.d.ts → index-D3apEdjU.d.ts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -4
- package/dist/{openapi-CRWQo78t.js → openapi-CU23GKuM.js} +324 -110
- package/dist/{openapi-DEZCoJlc.js → openapi-t_u-tF52.js} +5 -1
- package/dist/{rpc-CoHJtjYX.js → rpc-CSZ3hBkn.js} +2 -2
- package/dist/{shared-CYeurBoC.js → shared-BvbKZMJK.js} +18 -5
- package/dist/{utils-Dznx-EnJ.js → utils-Bw0Q2Ozg.js} +119 -3
- package/dist/vite-plugin/index.js +12 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ From one document it can generate:
|
|
|
21
21
|
npm install -D hono-takibi
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
Pass an OpenAPI (`.yaml`, `.json`) or TypeSpec (`.tsp`) document and an output file:
|
|
24
|
+
Pass an OpenAPI (`.yaml`, `.yml`, `.json`) or TypeSpec (`.tsp`) document and an output file:
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
27
|
npx hono-takibi openapi.yaml -o src/routes.ts
|
|
@@ -38,6 +38,8 @@ export default defineConfig({
|
|
|
38
38
|
})
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
`input` also takes an `http(s)` URL, with or without a file extension: a remote document is read by its content.
|
|
42
|
+
|
|
41
43
|
```bash
|
|
42
44
|
npx hono-takibi
|
|
43
45
|
```
|
package/dist/cli.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { h as isInputPath, u as INPUT_EXTENSIONS } from "./constants-hwmOoQfI.js";
|
|
3
3
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
4
4
|
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.26.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
|
|
12
12
|
const COMMAND_NAME = "hono-takibi";
|
|
13
13
|
const DEFAULT_CONFIG_FILE = "hono-takibi.config.ts";
|
|
14
|
-
const DocumentPathSchema = Schema.String.pipe(Schema.refine(
|
|
14
|
+
const DocumentPathSchema = Schema.String.pipe(Schema.refine(isInputPath, { message: "an OpenAPI (.yaml, .yml, .json) or TypeSpec (.tsp) document" })).annotate({
|
|
15
15
|
title: "Input document",
|
|
16
16
|
description: "OpenAPI or TypeSpec document the one-shot mode generates from.",
|
|
17
17
|
examples: [
|
|
@@ -26,7 +26,7 @@ const TypeScriptPathSchema = Schema.String.pipe(Schema.refine(Schema.is(Schema.T
|
|
|
26
26
|
examples: ["./src/routes.ts", "src/api/routes.ts"]
|
|
27
27
|
});
|
|
28
28
|
const commandLine = {
|
|
29
|
-
input: Argument.File("input", { mustExist: true }).pipe(Argument.withSchema(DocumentPathSchema), Argument.withDescription("OpenAPI (.yaml, .json) or TypeSpec (.tsp) document to generate from"), Argument.withMetavar("input.{yaml,json,tsp}"), Argument.optional),
|
|
29
|
+
input: Argument.File("input", { mustExist: true }).pipe(Argument.withSchema(DocumentPathSchema), Argument.withDescription("OpenAPI (.yaml, .yml, .json) or TypeSpec (.tsp) document to generate from"), Argument.withMetavar("input.{yaml,yml,json,tsp}"), Argument.optional),
|
|
30
30
|
output: Flag.String("output").pipe(Flag.withAlias("o"), Flag.withSchema(TypeScriptPathSchema), Flag.withDescription("TypeScript file the generated routes are written to"), Flag.withMetavar("output.ts"), Flag.optional),
|
|
31
31
|
config: Flag.File("config", { mustExist: true }).pipe(Flag.withAlias("c"), Flag.withDescription(`Config file to run (default: ./${DEFAULT_CONFIG_FILE})`), Flag.withMetavar("file"), Flag.optional),
|
|
32
32
|
watch: Flag.Boolean("watch").pipe(Flag.withAlias("w"), Flag.withDescription("Rerun the config on every change to its documents or itself"), Flag.withDefault(false))
|
|
@@ -39,12 +39,12 @@ function loadConfig(configPath, reload) {
|
|
|
39
39
|
}
|
|
40
40
|
function runJobs(config) {
|
|
41
41
|
return Effect.gen(function* () {
|
|
42
|
-
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob, packageRoots }] = yield* Effect.promise(() => Promise.all([
|
|
43
|
-
import("./openapi-
|
|
42
|
+
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob, openAPI3, packageRoots }] = yield* Effect.promise(() => Promise.all([
|
|
43
|
+
import("./openapi-t_u-tF52.js").then((n) => n.t),
|
|
44
44
|
import("./format-CuHABcKC.js").then((n) => n.r),
|
|
45
|
-
import("./shared-
|
|
45
|
+
import("./shared-BvbKZMJK.js").then((n) => n.o)
|
|
46
46
|
]));
|
|
47
|
-
const openAPI = yield* parseOpenAPI(config.input);
|
|
47
|
+
const openAPI = yield* openAPI3(yield* parseOpenAPI(config.input), config.input);
|
|
48
48
|
const jobs = makeJob(openAPI, config, yield* packageRoots(openAPI, config));
|
|
49
49
|
yield* cleanSplitOutputs(jobs.filter((job) => job.split).map((job) => job.output));
|
|
50
50
|
return (yield* Effect.forEach(jobs, (job) => job.run(job.output), { concurrency: "unbounded" }).pipe(Effect.provideService(FormatOptions, config.format ?? {}))).filter((message) => message !== "").join("\n");
|
|
@@ -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-BvbKZMJK.js").then((n) => n.o));
|
|
84
84
|
const inputDirectory = path.dirname(path.resolve(config.input));
|
|
85
85
|
return {
|
|
86
86
|
inputDirectory,
|
|
@@ -207,8 +207,13 @@ 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([
|
|
211
|
-
|
|
210
|
+
const [{ parseOpenAPI }, { takibi }, { openAPI3 }] = yield* Effect.promise(() => Promise.all([
|
|
211
|
+
import("./openapi-t_u-tF52.js").then((n) => n.t),
|
|
212
|
+
import("./core-FnayWJZV.js").then((n) => n.t),
|
|
213
|
+
import("./shared-BvbKZMJK.js").then((n) => n.o)
|
|
214
|
+
]));
|
|
215
|
+
const document = yield* openAPI3(yield* parseOpenAPI(input), input);
|
|
216
|
+
return yield* Console.log(yield* takibi(document, output));
|
|
212
217
|
}
|
|
213
218
|
const resolvedConfig = configPath ?? DEFAULT_CONFIG_FILE;
|
|
214
219
|
if (args.watch) return yield* watchConfig(resolvedConfig, yield* reportConfigPass(resolvedConfig, false, void 0));
|
|
@@ -13,12 +13,34 @@ const COMPONENT_NAMES = [
|
|
|
13
13
|
"pathItems",
|
|
14
14
|
"mediaTypes"
|
|
15
15
|
];
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* What the identifier of a component is suffixed with, by section: `#/components/schemas/User`
|
|
18
|
+
* is `UserSchema`. A security scheme is named by `security` requirements, not by `$ref`.
|
|
19
|
+
*/
|
|
20
|
+
const COMPONENT_SUFFIXES = {
|
|
21
|
+
schemas: "Schema",
|
|
22
|
+
parameters: "ParamsSchema",
|
|
23
|
+
headers: "HeaderSchema",
|
|
24
|
+
securitySchemes: "SecurityScheme",
|
|
25
|
+
requestBodies: "RequestBody",
|
|
26
|
+
responses: "Response",
|
|
27
|
+
examples: "Example",
|
|
28
|
+
links: "Link",
|
|
29
|
+
callbacks: "Callback",
|
|
30
|
+
pathItems: "PathItem",
|
|
31
|
+
mediaTypes: "MediaTypeSchema"
|
|
32
|
+
};
|
|
33
|
+
/** The extensions of an input document: OpenAPI as YAML (`.yaml` or `.yml`) or JSON, or a TypeSpec entry. */
|
|
17
34
|
const INPUT_EXTENSIONS = [
|
|
18
35
|
".yaml",
|
|
36
|
+
".yml",
|
|
19
37
|
".json",
|
|
20
38
|
".tsp"
|
|
21
39
|
];
|
|
40
|
+
/** An input document by its extension, or an `http(s)` URL to one (see `InputPath`). */
|
|
41
|
+
function isInputPath(v) {
|
|
42
|
+
return typeof v === "string" && (INPUT_EXTENSIONS.some((extension) => v.endsWith(extension)) || /^https?:\/\//u.test(v));
|
|
43
|
+
}
|
|
22
44
|
/** A JavaScript identifier that can be written bare: as a binding, or a key or member access. */
|
|
23
45
|
const IDENTIFIER_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/u;
|
|
24
46
|
/**
|
|
@@ -78,4 +100,4 @@ const HTTP_METHODS = [
|
|
|
78
100
|
"query"
|
|
79
101
|
];
|
|
80
102
|
//#endregion
|
|
81
|
-
export {
|
|
103
|
+
export { FORM_MEDIA_TYPES as a, HTTP_METHODS as c, JSON_MEDIA_TYPE as d, MULTIPART_MEDIA_TYPE as f, isInputPath as h, COMPONENT_SUFFIXES as i, IDENTIFIER_PATTERN as l, TEXT_MEDIA_TYPE as m, COMPONENT_NAMES as n, FORM_URLENCODED_MEDIA_TYPE as o, OCTET_STREAM_MEDIA_TYPE as p, COMPONENT_REF_PREFIX as r, HOOK_LIBRARIES as s, ARROW_FUNCTION_PATTERN as t, INPUT_EXTENSIONS as u };
|
package/dist/core/docs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as docs } from "../../docs-
|
|
1
|
+
export { t as docs } from "../../docs-D8ivFJrR.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as OpenAPI } from "../../index-B3ze4n_I.js";
|
|
2
2
|
import { n as GenerateError, t as FormatError } from "../../index-D_gf3Xzx.js";
|
|
3
|
-
import { t as Grouping } from "../../index-
|
|
3
|
+
import { t as Grouping } from "../../index-D3apEdjU.js";
|
|
4
4
|
//#region src/core/hooks/index.d.ts
|
|
5
5
|
declare const HOOK_CONFIGS: {
|
|
6
6
|
readonly swr: {
|
package/dist/core/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as hooks } from "../../hooks-
|
|
1
|
+
export { t as hooks } from "../../hooks-DJHtFXnM.js";
|
package/dist/core/rpc/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as OpenAPI } from "../../index-B3ze4n_I.js";
|
|
2
2
|
import { n as GenerateError, t as FormatError } from "../../index-D_gf3Xzx.js";
|
|
3
|
-
import { t as Grouping } from "../../index-
|
|
3
|
+
import { t as Grouping } from "../../index-D3apEdjU.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
//#region src/core/rpc/index.d.ts
|
|
6
6
|
/**
|
package/dist/core/rpc/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as HTTP_METHODS } from "../../constants-hwmOoQfI.js";
|
|
2
2
|
import { i as GenerateError } from "../../format-CuHABcKC.js";
|
|
3
|
-
import {
|
|
4
|
-
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-
|
|
3
|
+
import { V as isOperationLike, Y as isRecord, _ as routeName, u as makeInferRequestType, z as isOpenAPIPaths } from "../../utils-Bw0Q2Ozg.js";
|
|
4
|
+
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-CSZ3hBkn.js";
|
|
5
5
|
import { t as emit } from "../../emit-uwlZZeRM.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import { dirname } from "node:path";
|
|
@@ -21,7 +21,7 @@ function makeJsDoc(operation, method, path) {
|
|
|
21
21
|
sections.push([`${method.toUpperCase()} ${path}`]);
|
|
22
22
|
return `/**\n${sections.map((lines) => lines.join("\n")).join("\n\n").split("\n").map((line) => line ? ` * ${line}` : " *").join("\n")}\n */\n`;
|
|
23
23
|
}
|
|
24
|
-
function makeOperationCode(path, method, item, base, useParseResponse, hasBasePath, docs, grouping) {
|
|
24
|
+
function makeOperationCode(paths, path, method, item, base, useParseResponse, hasBasePath, docs, grouping) {
|
|
25
25
|
const operation = item[method];
|
|
26
26
|
if (!isOperationLike(operation)) return null;
|
|
27
27
|
const group = grouping?.(path, operationTags(operation));
|
|
@@ -29,7 +29,7 @@ function makeOperationCode(path, method, item, base, useParseResponse, hasBasePa
|
|
|
29
29
|
...base,
|
|
30
30
|
client: makeGroupClientName(group)
|
|
31
31
|
};
|
|
32
|
-
const funcName =
|
|
32
|
+
const funcName = routeName(method, path, paths);
|
|
33
33
|
const pathResult = formatPath(path, hasBasePath);
|
|
34
34
|
const hasArgs = operationHasArgs(item, operation, deps);
|
|
35
35
|
const inferType = makeInferRequestType(deps.client, pathResult, method);
|
|
@@ -45,7 +45,7 @@ function makeOperationCode(path, method, item, base, useParseResponse, hasBasePa
|
|
|
45
45
|
function makeOperationCodes(paths, deps, useParseResponse, hasBasePath, docs, grouping) {
|
|
46
46
|
return Object.entries(paths).filter((entry) => isRecord(entry[1])).flatMap(([p, rawItem]) => {
|
|
47
47
|
const pathItem = parsePathItem(rawItem);
|
|
48
|
-
return HTTP_METHODS.map((method) => makeOperationCode(p, method, pathItem, deps, useParseResponse, hasBasePath, docs, grouping)).filter((item) => item !== null);
|
|
48
|
+
return HTTP_METHODS.map((method) => makeOperationCode(paths, p, method, pathItem, deps, useParseResponse, hasBasePath, docs, grouping)).filter((item) => item !== null);
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
function makeHeader(importPath, needsInferRequestType, clientNames, useParseResponse) {
|
package/dist/core/type/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../../constants-
|
|
2
|
-
import {
|
|
1
|
+
import "../../constants-hwmOoQfI.js";
|
|
2
|
+
import { B as isOperation, H as isParameter, L as isMediaWithSchema, N as isHttpMethod, Q as isRequestBody, U as isParameterArray, d as makeSafeKey, et as isSchemaArray, ot as isStringRef, v as statusCodeToNumber, y as toIdentifierPascalCase, z as isOpenAPIPaths } from "../../utils-Bw0Q2Ozg.js";
|
|
3
3
|
import { t as emit } from "../../emit-uwlZZeRM.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
-
import {
|
|
2
|
+
import { c as HTTP_METHODS, d as JSON_MEDIA_TYPE, m as TEXT_MEDIA_TYPE, n as COMPONENT_NAMES, r as COMPONENT_REF_PREFIX } from "./constants-hwmOoQfI.js";
|
|
3
3
|
import { i as GenerateError, n as fmt } from "./format-CuHABcKC.js";
|
|
4
|
-
import {
|
|
5
|
-
import { A as resolvePathItem, C as makeCallback, D as makeRouteProperties, E as makeRouteEntries, O as makeWebhookEntries, S as zodToOpenAPI, T as makeRef, _ as descendantsWhere, a as responsesCode, b as parseSource, c as headersCode, d as makeExportConst, f as makeImports, g as declarationOf, h as ast, i as schemasCode, k as resolveParameter, l as makeSplitSchemaFile, m as analyzeCircularSchemas, n as routeCode, o as requestBodiesCode, p as makeModuleSpec, r as componentsCode, s as parametersCode, t as zodOpenAPIHono, u as makeConst, v as identifierNames, w as makePathItem, x as textOf, y as parseModule } from "./openapi-
|
|
6
|
-
import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-
|
|
4
|
+
import { A as isCallbacks, B as isOperation, D as hasNumericConstraint, F as isInlineMedia, H as isParameter, J as isPathItemRef, K as isPathItem, L as isMediaWithSchema, N as isHttpMethod, O as hasRequestBodyContent, S as zodToOpenAPISchema, X as isRefObject, _ as routeName, a as ensureSuffix, b as uncapitalize, c as escapeRegexLiteral, d as makeSafeKey, et as isSchemaArray, f as makeStringLiteral, h as renderNamedImport, it as isSecurityScheme, l as makeBarrel, p as normalizeTypes, q as isPathItemEntry, r as cyclicNodes, rt as isSecurityArray, st as isValidIdent, tt as isSchemaObject, v as statusCodeToNumber, x as uncapitalizeWord, y as toIdentifierPascalCase, z as isOpenAPIPaths } from "./utils-Bw0Q2Ozg.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-CU23GKuM.js";
|
|
6
|
+
import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-CSZ3hBkn.js";
|
|
7
7
|
import { i as readdir, n as mkdir, o as writeFile, r as readFile } from "./file-K6j5IJXi.js";
|
|
8
8
|
import { t as emit } from "./emit-uwlZZeRM.js";
|
|
9
|
-
import { t as hooks } from "./hooks-
|
|
10
|
-
import { t as docs } from "./docs-
|
|
9
|
+
import { t as hooks } from "./hooks-DJHtFXnM.js";
|
|
10
|
+
import { t as docs } from "./docs-D8ivFJrR.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";
|
|
@@ -629,7 +629,7 @@ function defineEntries(openapi, readonly) {
|
|
|
629
629
|
} : operation;
|
|
630
630
|
const properties = makeRouteProperties(path, method, effective, readonly, openapi.components?.schemas);
|
|
631
631
|
const asConst = readonly ? " as const" : "";
|
|
632
|
-
const entryName =
|
|
632
|
+
const entryName = routeName(method, path, openapi.paths);
|
|
633
633
|
return [{
|
|
634
634
|
name: entryName,
|
|
635
635
|
path,
|
|
@@ -1386,24 +1386,24 @@ function makePaths(output, pathAlias, routeImport) {
|
|
|
1386
1386
|
importFrom: routeImport ?? (aliasPrefix ? `${aliasPrefix}/${routeModuleName}` : `../${routeModuleName}`)
|
|
1387
1387
|
};
|
|
1388
1388
|
}
|
|
1389
|
-
function makeHandlerInfo(path, method, operation, existing, member, body) {
|
|
1390
|
-
const routeId =
|
|
1389
|
+
function makeHandlerInfo(paths, path, method, operation, existing, member, body) {
|
|
1390
|
+
const routeId = routeName(method, path, paths);
|
|
1391
1391
|
return {
|
|
1392
1392
|
fileName: resolveHandlerFileName(makeHandlerFileName(path, operation.tags), `${routeId}${member}`, existing),
|
|
1393
1393
|
contents: [body(routeId)],
|
|
1394
1394
|
routeNames: [`${routeId}Route`]
|
|
1395
1395
|
};
|
|
1396
1396
|
}
|
|
1397
|
-
function makeInlineStubHandlerInfo(path, method, operation, existing) {
|
|
1398
|
-
return makeHandlerInfo(path, method, operation, existing, "Route", (routeId) => `.openapi(${routeId}Route,(c)=>{})`);
|
|
1397
|
+
function makeInlineStubHandlerInfo(paths, path, method, operation, existing) {
|
|
1398
|
+
return makeHandlerInfo(paths, path, method, operation, existing, "Route", (routeId) => `.openapi(${routeId}Route,(c)=>{})`);
|
|
1399
1399
|
}
|
|
1400
1400
|
function makeInlineStubFileContent(handler, importFrom) {
|
|
1401
1401
|
const exportName = `${basename(handler.fileName, ".ts")}Handler`;
|
|
1402
1402
|
const routeImports = [...new Set(handler.routeNames)].join(", ");
|
|
1403
1403
|
return `${`import { OpenAPIHono } from '@hono/zod-openapi'\n${routeImports ? `import { ${routeImports} } from '${importFrom}';` : ""}`}\n\nconst app = new OpenAPIHono()\n\nexport const ${exportName} = app\n${handler.contents.join("\n")}`;
|
|
1404
1404
|
}
|
|
1405
|
-
function makeStubHandlerInfo(path, method, operation, existing) {
|
|
1406
|
-
return makeHandlerInfo(path, method, operation, existing, "RouteHandler", (routeId) => `export const ${routeId}RouteHandler:RouteHandler<typeof ${routeId}Route>=async(c)=>{}`);
|
|
1405
|
+
function makeStubHandlerInfo(paths, path, method, operation, existing) {
|
|
1406
|
+
return makeHandlerInfo(paths, path, method, operation, existing, "RouteHandler", (routeId) => `export const ${routeId}RouteHandler:RouteHandler<typeof ${routeId}Route>=async(c)=>{}`);
|
|
1407
1407
|
}
|
|
1408
1408
|
function makeMergedHandlers(handlers) {
|
|
1409
1409
|
const handlerMap = /* @__PURE__ */ new Map();
|
|
@@ -1467,7 +1467,7 @@ function zodOpenAPIHonoHandler(openapi, output, pathAlias, routeImport, routeHan
|
|
|
1467
1467
|
const paths = openapi.paths;
|
|
1468
1468
|
const { handlerPath, importFrom } = makePaths(output, pathAlias, routeImport);
|
|
1469
1469
|
const existing = yield* scanExistingHandlerFiles(handlerPath, routeHandler ? (code) => collectExportedNames(code, "RouteHandler") : collectInlineRouteNames);
|
|
1470
|
-
const specHandlers = makeMergedHandlers(Object.entries(paths).flatMap(([path, pathItem]) => Object.entries(pathItem).filter((entry) => isHttpMethod(entry[0]) && isOperation(entry[1])).map(([method, operation]) => routeHandler ? makeStubHandlerInfo(path, method, operation, existing) : makeInlineStubHandlerInfo(path, method, operation, existing))));
|
|
1470
|
+
const specHandlers = makeMergedHandlers(Object.entries(paths).flatMap(([path, pathItem]) => Object.entries(pathItem).filter((entry) => isHttpMethod(entry[0]) && isOperation(entry[1])).map(([method, operation]) => routeHandler ? makeStubHandlerInfo(paths, path, method, operation, existing) : makeInlineStubHandlerInfo(paths, path, method, operation, existing))));
|
|
1471
1471
|
const handlers = [...specHandlers, ...makeOrphanHandlers(existing, specHandlers.map((h) => h.fileName))];
|
|
1472
1472
|
yield* mkdir(handlerPath);
|
|
1473
1473
|
yield* Effect.all([...handlers.map((handler) => writeHandler({
|
|
@@ -1487,7 +1487,7 @@ function resolveInlineHandlerFileNames(openapi, output, pathAlias, routeImport)
|
|
|
1487
1487
|
return Effect.gen(function* () {
|
|
1488
1488
|
const { handlerPath } = makePaths(output, pathAlias, routeImport);
|
|
1489
1489
|
const existing = yield* scanExistingHandlerFiles(handlerPath, collectInlineRouteNames);
|
|
1490
|
-
const fileNames = Object.entries(openapi.paths).flatMap(([path, pathItem]) => Object.entries(pathItem).filter((entry) => isHttpMethod(entry[0]) && isOperation(entry[1])).map(([method, operation]) => resolveHandlerFileName(makeHandlerFileName(path, operation.tags), `${
|
|
1490
|
+
const fileNames = Object.entries(openapi.paths).flatMap(([path, pathItem]) => Object.entries(pathItem).filter((entry) => isHttpMethod(entry[0]) && isOperation(entry[1])).map(([method, operation]) => resolveHandlerFileName(makeHandlerFileName(path, operation.tags), `${routeName(method, path, openapi.paths)}Route`, existing)));
|
|
1491
1491
|
return [...new Set(fileNames)];
|
|
1492
1492
|
});
|
|
1493
1493
|
}
|
|
@@ -2356,7 +2356,7 @@ function makeMock(openapi, basePath, options = {}) {
|
|
|
2356
2356
|
const allRefs = /* @__PURE__ */ new Set();
|
|
2357
2357
|
const processed = Object.entries(paths).flatMap(([p, pathItem]) => Object.entries(pathItem).flatMap(([method, operation]) => {
|
|
2358
2358
|
if (!(isHttpMethod(method) && isOperation(operation))) return [];
|
|
2359
|
-
const routeId =
|
|
2359
|
+
const routeId = routeName(method, p, paths);
|
|
2360
2360
|
const security = extractSecurityInfo(isSecurityArray(operation.security) ? operation.security : void 0, isSecurityArray(openapi.security) ? openapi.security : void 0, securitySchemes);
|
|
2361
2361
|
const requiresAuth = security.length > 0;
|
|
2362
2362
|
const success = resolveSuccessResponse(operation.responses, componentResponses);
|
|
@@ -2547,8 +2547,8 @@ function app(openapi, output, basePath, pathAlias, routeImport, routeHandler = f
|
|
|
2547
2547
|
return Object.entries(paths).flatMap(([path, pathItem]) => Object.entries(pathItem).flatMap(([method]) => {
|
|
2548
2548
|
if (!isHttpMethod(method)) return [];
|
|
2549
2549
|
return {
|
|
2550
|
-
routeName: `${
|
|
2551
|
-
handlerName: `${
|
|
2550
|
+
routeName: `${routeName(method, path, paths)}Route`,
|
|
2551
|
+
handlerName: `${routeName(method, path, paths)}RouteHandler`,
|
|
2552
2552
|
path
|
|
2553
2553
|
};
|
|
2554
2554
|
}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { c as HTTP_METHODS, f as MULTIPART_MEDIA_TYPE } from "./constants-hwmOoQfI.js";
|
|
2
|
+
import { X as isRefObject, Y as isRecord, et as isSchemaArray, i as decodePercent, s as escapeHtml } from "./utils-Bw0Q2Ozg.js";
|
|
3
3
|
import { n as mkdir, o as writeFile } from "./file-K6j5IJXi.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
@@ -114,6 +114,10 @@ function schemaAnchor(name, doc) {
|
|
|
114
114
|
anchors.set(name, anchor);
|
|
115
115
|
return anchor;
|
|
116
116
|
}
|
|
117
|
+
/** A `$ref` to a schema under `components.schemas`: linked in a table, listed under Schemas. */
|
|
118
|
+
function isComponentRef(schema) {
|
|
119
|
+
return schema.$ref !== void 0 && componentSchemaName(schema.$ref) !== void 0;
|
|
120
|
+
}
|
|
117
121
|
function makeSchemaLink(name, doc) {
|
|
118
122
|
return `[${name}](#schema${schemaAnchor(name, doc)})`;
|
|
119
123
|
}
|
|
@@ -928,11 +932,12 @@ function flattenFields(schema, doc, prefix, options, inheritedRequired = [], ins
|
|
|
928
932
|
const required = [...inheritedRequired, ...collectRequired(current, doc)];
|
|
929
933
|
const requiredSet = new Set(required);
|
|
930
934
|
const nestedRows = (propSchema) => {
|
|
931
|
-
if (!options.deep) return [];
|
|
935
|
+
if (!options.deep || isComponentRef(propSchema)) return [];
|
|
932
936
|
const prop = expandSchema(propSchema, doc, within);
|
|
933
937
|
if (!prop) return [];
|
|
934
938
|
if (hasFields(prop.schema)) return flattenFields(prop.schema, doc, nestedPrefix, options, [], prop.inside);
|
|
935
939
|
const item = isArraySchema(prop.schema) ? arrayItemSchema(prop.schema) : void 0;
|
|
940
|
+
if (item && isComponentRef(item)) return [];
|
|
936
941
|
const resolvedItem = item ? expandSchema(item, doc, prop.inside) : void 0;
|
|
937
942
|
if (resolvedItem && hasFields(resolvedItem.schema)) return flattenFields(resolvedItem.schema, doc, nestedPrefix, options, [], resolvedItem.inside);
|
|
938
943
|
return [];
|
|
@@ -951,7 +956,7 @@ function flattenFields(schema, doc, prefix, options, inheritedRequired = [], ins
|
|
|
951
956
|
const inherited = (current.allOf ?? []).flatMap((part) => flattenFields(part, doc, prefix, options, required, within));
|
|
952
957
|
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)]) : [];
|
|
953
958
|
const extra = isSchemaLike(current.additionalProperties) ? [makeRow("**additionalProperties**", current.additionalProperties, false), ...nestedRows(current.additionalProperties)] : [];
|
|
954
|
-
const variants = variantsOf(current).flatMap((variant) => [makeRow(`*${variant.keyword}*`, variant.schema, false), ...flattenFields(variant.schema, doc, prefix, options, required, within)]);
|
|
959
|
+
const variants = variantsOf(current).flatMap((variant) => [makeRow(`*${variant.keyword}*`, variant.schema, false), ...isComponentRef(variant.schema) ? [] : flattenFields(variant.schema, doc, prefix, options, required, within)]);
|
|
955
960
|
const rows = [
|
|
956
961
|
...inherited,
|
|
957
962
|
...own,
|
|
@@ -969,6 +974,7 @@ function flattenFields(schema, doc, prefix, options, inheritedRequired = [], ins
|
|
|
969
974
|
description: "none",
|
|
970
975
|
enums: []
|
|
971
976
|
}] : [];
|
|
977
|
+
if (isComponentRef(item)) return anonymous;
|
|
972
978
|
const resolvedItem = expandSchema(item, doc, within);
|
|
973
979
|
if (!(resolvedItem && hasFields(resolvedItem.schema))) return anonymous;
|
|
974
980
|
return [...anonymous, ...flattenFields(resolvedItem.schema, doc, "»", {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as OpenAPI } from "../../../index-B3ze4n_I.js";
|
|
2
2
|
//#region src/generator/zod-openapi-hono/openapi/index.d.ts
|
|
3
|
-
export declare function zodOpenAPIHono(
|
|
3
|
+
export declare function zodOpenAPIHono(document: OpenAPI, options?: {
|
|
4
4
|
readonly readonly?: boolean;
|
|
5
5
|
readonly exportSchemas?: boolean;
|
|
6
6
|
readonly exportSchemasTypes?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as zodOpenAPIHono } from "../../../openapi-
|
|
1
|
+
export { t as zodOpenAPIHono } from "../../../openapi-CU23GKuM.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as HTTP_METHODS } from "./constants-hwmOoQfI.js";
|
|
2
2
|
import { i as GenerateError } from "./format-CuHABcKC.js";
|
|
3
|
-
import {
|
|
4
|
-
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "./rpc-
|
|
3
|
+
import { V as isOperationLike, Y as isRecord, _ as routeName, n as capitalize, w as hasNoContentResponse, y as toIdentifierPascalCase, z as isOpenAPIPaths } from "./utils-Bw0Q2Ozg.js";
|
|
4
|
+
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "./rpc-CSZ3hBkn.js";
|
|
5
5
|
import { t as emit } from "./emit-uwlZZeRM.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import path from "node:path";
|
|
@@ -26,8 +26,8 @@ const VUE_MUTATION_MEMBER = `{mutationFn?:unknown}`;
|
|
|
26
26
|
function makeOmitInjectedKeys(optionsType, keys, vueMember) {
|
|
27
27
|
return `Omit<${vueMember ? `Extract<${optionsType},${vueMember}>` : optionsType},${keys}>`;
|
|
28
28
|
}
|
|
29
|
-
function makeHookName(method, pathStr, prefix) {
|
|
30
|
-
const funcName =
|
|
29
|
+
function makeHookName(method, pathStr, prefix, paths) {
|
|
30
|
+
const funcName = routeName(method, pathStr, paths);
|
|
31
31
|
return `${prefix}${capitalize(funcName)}`;
|
|
32
32
|
}
|
|
33
33
|
function makeRuntimeAccess(clientName, method, pathStr, hasBasePath = false) {
|
|
@@ -46,20 +46,20 @@ function makeArgsType(clientName, method, pathStr, hasBasePath = false) {
|
|
|
46
46
|
function queryNameMethod(method) {
|
|
47
47
|
return method === "get" ? "" : method;
|
|
48
48
|
}
|
|
49
|
-
function makeQueryKeyGetterName(method, pathStr, isSWR) {
|
|
50
|
-
if (isSWR) return `get${capitalize(
|
|
51
|
-
return `get${capitalize(
|
|
49
|
+
function makeQueryKeyGetterName(method, pathStr, paths, isSWR) {
|
|
50
|
+
if (isSWR) return `get${capitalize(routeName(method, pathStr, paths))}Key`;
|
|
51
|
+
return `get${capitalize(routeName(queryNameMethod(method), pathStr, paths))}QueryKey`;
|
|
52
52
|
}
|
|
53
|
-
function makeMutationKeyGetterName(method, pathStr, isSWR) {
|
|
54
|
-
if (isSWR) return `get${capitalize(
|
|
55
|
-
return `get${capitalize(
|
|
53
|
+
function makeMutationKeyGetterName(method, pathStr, paths, isSWR) {
|
|
54
|
+
if (isSWR) return `get${capitalize(routeName(method, pathStr, paths))}Key`;
|
|
55
|
+
return `get${capitalize(routeName(method, pathStr, paths))}MutationKey`;
|
|
56
56
|
}
|
|
57
57
|
function makeMutationKeyGetterCode(keyGetterName, method, honoPath) {
|
|
58
58
|
return `export function ${keyGetterName}(){return['${honoPath.replace(/^\//u, "").split("/")[0]}','${honoPath}','${method.toUpperCase()}']as const}`;
|
|
59
59
|
}
|
|
60
|
-
function makeInfiniteQueryKeyGetterName(method, pathStr, isSWR) {
|
|
61
|
-
if (isSWR) return `get${capitalize(
|
|
62
|
-
return `get${capitalize(
|
|
60
|
+
function makeInfiniteQueryKeyGetterName(method, pathStr, paths, isSWR) {
|
|
61
|
+
if (isSWR) return `get${capitalize(routeName(method, pathStr, paths))}InfiniteKey`;
|
|
62
|
+
return `get${capitalize(routeName(queryNameMethod(method), pathStr, paths))}InfiniteQueryKey`;
|
|
63
63
|
}
|
|
64
64
|
function makeVueReactiveKey(keyCall) {
|
|
65
65
|
return `computed(()=>${keyCall})`;
|
|
@@ -382,16 +382,16 @@ function makeMutationHookCode(hookName, optionsGetterName, hasArgs, argsType, re
|
|
|
382
382
|
if (config.useThunk) return `export function ${hookName}${tErrorGeneric}(options?:()=>${optionsType}${tail.sig}){return ${config.mutationFn}(()=>{const{mutation,options:clientOptions}=options?.()??{};const mutationDefaults=${factoryCall};return{...mutation,...mutationDefaults,mutationKey:mutation?.mutationKey??mutationDefaults.mutationKey}}${tail.arg})}`;
|
|
383
383
|
return `export function ${hookName}${tErrorGeneric}(options?:${optionsType}${tail.sig}){const{mutation:mutationOptions,options:clientOptions}=options??{};const mutationDefaults=${factoryCall};return ${config.mutationFn}({...mutationOptions,...mutationDefaults,mutationKey:mutationOptions?.mutationKey??mutationDefaults.mutationKey}${tail.arg})}`;
|
|
384
384
|
}
|
|
385
|
-
function makeHookCode(pathStr, method, item, deps, config, clientName, hasBasePath = false) {
|
|
385
|
+
function makeHookCode(paths, pathStr, method, item, deps, config, clientName, hasBasePath = false) {
|
|
386
386
|
const op = item[method];
|
|
387
387
|
if (!isOperationLike(op)) return null;
|
|
388
|
-
const hookName = makeHookName(method, pathStr, config.hookPrefix);
|
|
388
|
+
const hookName = makeHookName(method, pathStr, config.hookPrefix, paths);
|
|
389
389
|
const hasArgs = operationHasArgs(item, op, deps);
|
|
390
390
|
const isQuery = method === "get" || method === "query";
|
|
391
391
|
const hasPagination = op["x-pagination"] === true;
|
|
392
392
|
const params = [...deps.toParameterLikes(item.parameters), ...deps.toParameterLikes(op.parameters)];
|
|
393
393
|
const excludedArgs = KEY_EXCLUDED_ARGS.filter((kind) => params.some((p) => p.in === kind));
|
|
394
|
-
const operationFileName =
|
|
394
|
+
const operationFileName = routeName(method, pathStr, paths);
|
|
395
395
|
const argsType = makeArgsType(clientName, method, pathStr, hasBasePath);
|
|
396
396
|
const runtimeAccess = makeRuntimeAccess(clientName, method, pathStr, hasBasePath);
|
|
397
397
|
const responseType = makeResponseTypeFromClient(clientName, method, pathStr, hasBasePath);
|
|
@@ -399,12 +399,12 @@ function makeHookCode(pathStr, method, item, deps, config, clientName, hasBasePa
|
|
|
399
399
|
const honoPath = pathStr.replaceAll(/\{([^}]+)\}/gu, ":$1");
|
|
400
400
|
if (config.isSWR) {
|
|
401
401
|
if (isQuery) {
|
|
402
|
-
const keyGetterName = makeQueryKeyGetterName(method, pathStr, true);
|
|
402
|
+
const keyGetterName = makeQueryKeyGetterName(method, pathStr, paths, true);
|
|
403
403
|
const keyGetterCode = makeQueryKeyGetterCode(keyGetterName, hasArgs, argsType, honoPath, config, excludedArgs, method);
|
|
404
404
|
const hookCode = makeSWRQueryHookCode(hookName, keyGetterName, hasArgs, argsType, runtimeAccess, responseType, config.queryFn, config.errorType);
|
|
405
405
|
const immutableHookName = `${config.hookPrefix}Immutable${capitalize(operationFileName)}`;
|
|
406
406
|
const immutableHookCode = config.immutableQueryFn ? makeSWRQueryHookCode(immutableHookName, keyGetterName, hasArgs, argsType, runtimeAccess, responseType, config.immutableQueryFn, config.errorType) : null;
|
|
407
|
-
const infiniteKeyGetterName = makeInfiniteQueryKeyGetterName(method, pathStr, true);
|
|
407
|
+
const infiniteKeyGetterName = makeInfiniteQueryKeyGetterName(method, pathStr, paths, true);
|
|
408
408
|
const infiniteKeyGetterCode = hasPagination ? makeInfiniteQueryKeyGetterCode(infiniteKeyGetterName, hasArgs, argsType, honoPath, config, excludedArgs, method) : null;
|
|
409
409
|
const infiniteHookName = `${config.hookPrefix}Infinite${capitalize(operationFileName)}`;
|
|
410
410
|
return {
|
|
@@ -421,7 +421,7 @@ function makeHookCode(pathStr, method, item, deps, config, clientName, hasBasePa
|
|
|
421
421
|
operationFileName
|
|
422
422
|
};
|
|
423
423
|
}
|
|
424
|
-
const mutationKeyGetterName = makeMutationKeyGetterName(method, pathStr, true);
|
|
424
|
+
const mutationKeyGetterName = makeMutationKeyGetterName(method, pathStr, paths, true);
|
|
425
425
|
return {
|
|
426
426
|
code: `${makeMutationKeyGetterCode(mutationKeyGetterName, method, honoPath)}\n\n${makeSWRMutationHookCode(hookName, `${mutationKeyGetterName}()`, hasArgs, argsType, responseType, runtimeAccess, hasNoContent, config.errorType)}`,
|
|
427
427
|
isQuery: false,
|
|
@@ -431,14 +431,14 @@ function makeHookCode(pathStr, method, item, deps, config, clientName, hasBasePa
|
|
|
431
431
|
};
|
|
432
432
|
}
|
|
433
433
|
if (isQuery) {
|
|
434
|
-
const queryHookName = makeHookName(queryNameMethod(method), pathStr, config.hookPrefix);
|
|
435
|
-
const pathFuncName =
|
|
436
|
-
const keyGetterName = makeQueryKeyGetterName(method, pathStr);
|
|
434
|
+
const queryHookName = makeHookName(queryNameMethod(method), pathStr, config.hookPrefix, paths);
|
|
435
|
+
const pathFuncName = routeName(queryNameMethod(method), pathStr, paths);
|
|
436
|
+
const keyGetterName = makeQueryKeyGetterName(method, pathStr, paths);
|
|
437
437
|
const optionsGetterName = `get${capitalize(pathFuncName)}QueryOptions`;
|
|
438
438
|
const keyGetterCode = makeQueryKeyGetterCode(keyGetterName, hasArgs, argsType, honoPath, config, excludedArgs, method);
|
|
439
439
|
const optionsGetterCode = makeQueryOptionsGetterCode(optionsGetterName, keyGetterName, hasArgs, argsType, runtimeAccess, responseType, config);
|
|
440
440
|
const hookCode = makeQueryHookCode(queryHookName, keyGetterName, optionsGetterName, runtimeAccess, hasArgs, argsType, responseType, config);
|
|
441
|
-
const infiniteKeyGetterName = makeInfiniteQueryKeyGetterName(method, pathStr);
|
|
441
|
+
const infiniteKeyGetterName = makeInfiniteQueryKeyGetterName(method, pathStr, paths);
|
|
442
442
|
const infiniteOptionsGetterName = `get${capitalize(pathFuncName)}InfiniteQueryOptions`;
|
|
443
443
|
const { infiniteQueryFn, useInfiniteQueryOptionsType } = config;
|
|
444
444
|
const hasInfinite = !!(infiniteQueryFn && useInfiniteQueryOptionsType) && hasPagination;
|
|
@@ -497,8 +497,8 @@ function makeHookCode(pathStr, method, item, deps, config, clientName, hasBasePa
|
|
|
497
497
|
operationFileName
|
|
498
498
|
};
|
|
499
499
|
}
|
|
500
|
-
const optionsGetterName = `get${capitalize(
|
|
501
|
-
const mutationKeyGetterName = makeMutationKeyGetterName(method, pathStr);
|
|
500
|
+
const optionsGetterName = `get${capitalize(routeName(method, pathStr, paths))}MutationOptions`;
|
|
501
|
+
const mutationKeyGetterName = makeMutationKeyGetterName(method, pathStr, paths);
|
|
502
502
|
return {
|
|
503
503
|
code: `${makeMutationKeyGetterCode(mutationKeyGetterName, method, honoPath)}\n\n${makeMutationOptionsGetterCode(optionsGetterName, mutationKeyGetterName, hasArgs, argsType, runtimeAccess, responseType, hasNoContent, config)}\n\n${makeMutationHookCode(hookName, optionsGetterName, hasArgs, argsType, responseType, config, hasNoContent)}`,
|
|
504
504
|
isQuery: false,
|
|
@@ -513,9 +513,9 @@ function makeHookCodes(paths, deps, config, clientOf, hasBasePath = false) {
|
|
|
513
513
|
return HTTP_METHODS.map((method) => {
|
|
514
514
|
const operation = pathItem[method];
|
|
515
515
|
const client = clientOf(p, isOperationLike(operation) ? operationTags(operation) : void 0);
|
|
516
|
-
const result = makeHookCode(p, method, pathItem, deps, config, client, hasBasePath);
|
|
516
|
+
const result = makeHookCode(paths, p, method, pathItem, deps, config, client, hasBasePath);
|
|
517
517
|
return result ? {
|
|
518
|
-
hookName: makeHookName(method, p, config.hookPrefix),
|
|
518
|
+
hookName: makeHookName(method, p, config.hookPrefix, paths),
|
|
519
519
|
client,
|
|
520
520
|
code: result.code,
|
|
521
521
|
isQuery: result.isQuery,
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { Effect, FileSystem, Schema } from "effect";
|
|
2
2
|
import { FormatConfig } from "oxfmt";
|
|
3
3
|
//#region src/constants/index.d.ts
|
|
4
|
+
/** The extensions of an input document: OpenAPI as YAML (`.yaml` or `.yml`) or JSON, or a TypeSpec entry. */
|
|
5
|
+
declare const INPUT_EXTENSIONS: readonly ['.yaml', '.yml', '.json', '.tsp'];
|
|
6
|
+
/**
|
|
7
|
+
* An input document: a path by its extension, or an `http(s)` URL whatever its path (a
|
|
8
|
+
* document served without an extension is OpenAPI by content).
|
|
9
|
+
*/
|
|
10
|
+
type InputPath = `${string}${(typeof INPUT_EXTENSIONS)[number]}` | `http://${string}` | `https://${string}`;
|
|
4
11
|
/** The query libraries the hooks are generated for, each a config key of its own. */
|
|
5
12
|
declare const HOOK_LIBRARIES: readonly ['swr', 'tanstack-query', 'preact-query', 'solid-query', 'vue-query', 'svelte-query', 'angular-query'];
|
|
6
13
|
//#endregion
|
|
7
14
|
//#region src/config/index.d.ts
|
|
8
15
|
declare const ConfigSchema: Schema.decodeTo<Schema.toType<Schema.Struct<{
|
|
9
|
-
readonly input: Schema.declare
|
|
16
|
+
readonly input: Schema.declare<InputPath, InputPath>;
|
|
10
17
|
readonly output: Schema.optionalKey<Schema.declare<`${string}.ts`, `${string}.ts`>>;
|
|
11
18
|
readonly basePath: Schema.withDecodingDefault<Schema.String, never>;
|
|
12
19
|
readonly readonly: Schema.optionalKey<Schema.Boolean>;
|
|
@@ -220,7 +227,7 @@ declare const ConfigSchema: Schema.decodeTo<Schema.toType<Schema.Struct<{
|
|
|
220
227
|
readonly baseUrl: Schema.optionalKey<Schema.String>;
|
|
221
228
|
}>]>>;
|
|
222
229
|
}>>, Schema.Struct<{
|
|
223
|
-
readonly input: Schema.declare
|
|
230
|
+
readonly input: Schema.declare<InputPath, InputPath>;
|
|
224
231
|
readonly output: Schema.optionalKey<Schema.declare<`${string}.ts`, `${string}.ts`>>;
|
|
225
232
|
readonly basePath: Schema.withDecodingDefault<Schema.String, never>;
|
|
226
233
|
readonly readonly: Schema.optionalKey<Schema.Boolean>;
|
|
@@ -441,7 +448,7 @@ declare const ConfigError_base: Schema.Class<ConfigError, Schema.TaggedStruct<"C
|
|
|
441
448
|
}>, import("effect/Cause").YieldableError>;
|
|
442
449
|
declare class ConfigError extends ConfigError_base {}
|
|
443
450
|
declare function parseConfig(config: unknown): Effect.Effect<{
|
|
444
|
-
readonly input:
|
|
451
|
+
readonly input: InputPath;
|
|
445
452
|
readonly output?: `${string}.ts`;
|
|
446
453
|
readonly basePath: string;
|
|
447
454
|
readonly readonly?: boolean;
|
|
@@ -656,7 +663,7 @@ declare function parseConfig(config: unknown): Effect.Effect<{
|
|
|
656
663
|
};
|
|
657
664
|
}, ConfigError, never>;
|
|
658
665
|
declare function readConfig(configPath?: string, reload?: boolean): Effect.Effect<{
|
|
659
|
-
readonly input:
|
|
666
|
+
readonly input: InputPath;
|
|
660
667
|
readonly output?: `${string}.ts`;
|
|
661
668
|
readonly basePath: string;
|
|
662
669
|
readonly readonly?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as parseConfig, i as defineConfig, n as ConfigError, o as readConfig, r as ConfigInput, t as Config } from "./index-
|
|
1
|
+
import { a as parseConfig, i as defineConfig, n as ConfigError, o as readConfig, r as ConfigInput, t as Config } from "./index-BNrSddFB.js";
|
|
2
2
|
export { Config, ConfigError, ConfigInput, defineConfig, parseConfig, readConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as isInputPath, l as IDENTIFIER_PATTERN, n as COMPONENT_NAMES, s as HOOK_LIBRARIES } from "./constants-hwmOoQfI.js";
|
|
2
2
|
import { Effect, FileSystem, Schema, SchemaIssue, SchemaTransformation } from "effect";
|
|
3
3
|
import { posix, resolve } from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
//#region src/config/index.ts
|
|
6
6
|
const ConfigSchema = Schema.Struct({
|
|
7
|
-
input: Schema.declare(
|
|
7
|
+
input: Schema.declare(isInputPath, { message: "must be .yaml | .yml | .json | .tsp, or an http(s) URL" }).annotate({
|
|
8
8
|
title: "Input document",
|
|
9
|
-
description: "OpenAPI or TypeSpec entry document that every generator reads.",
|
|
9
|
+
description: "OpenAPI or TypeSpec entry document that every generator reads: a file by its extension, or an http(s) URL.",
|
|
10
10
|
examples: [
|
|
11
11
|
"openapi.yaml",
|
|
12
12
|
"./spec/openapi.json",
|
|
13
|
-
"./spec/main.tsp"
|
|
13
|
+
"./spec/main.tsp",
|
|
14
|
+
"https://example.com/openapi"
|
|
14
15
|
]
|
|
15
16
|
}),
|
|
16
17
|
output: Schema.optionalKey(Schema.declare(Schema.is(Schema.TemplateLiteral([Schema.String, ".ts"])), { message: "must be .ts file" }).annotate({
|