hono-takibi 0.33.0 → 0.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +5 -5
- package/dist/{core-D9NtmI5f.js → core-CajXzO16.js} +1 -1
- package/dist/generate/index.js +1 -1
- package/dist/generator/zod-openapi-hono/openapi/index.js +1 -1
- package/dist/{openapi-CitBEjdx.js → openapi-BMJPrf4w.js} +111 -4
- package/dist/{shared-DJ1zD5Rg.js → shared-BrQVwt_b.js} +2 -2
- package/dist/vite-plugin/index.js +2 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
|
5
5
|
import { Console, Effect, FileSystem, Option, Path, Ref, Schema, Stream } from "effect";
|
|
6
6
|
import { Argument, CliError, Command, Flag } from "effect/cli";
|
|
7
7
|
// package.json
|
|
8
|
-
var version = "0.33.
|
|
8
|
+
var version = "0.33.1";
|
|
9
9
|
var description = "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi";
|
|
10
10
|
// src/cli/index.ts
|
|
11
11
|
const COMMAND_NAME = "hono-takibi";
|
|
@@ -41,7 +41,7 @@ function runJobs(config) {
|
|
|
41
41
|
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob, openAPI3, packageRoots }] = yield* Effect.promise(() => Promise.all([
|
|
42
42
|
import("./openapi-BxSVfs_l.js").then((n) => n.t),
|
|
43
43
|
import("./format-BF7SbaMP.js").then((n) => n.r),
|
|
44
|
-
import("./shared-
|
|
44
|
+
import("./shared-BrQVwt_b.js").then((n) => n.o)
|
|
45
45
|
]));
|
|
46
46
|
const openAPI = yield* openAPI3(yield* parseOpenAPI(config.input), config.input);
|
|
47
47
|
const jobs = makeJob(openAPI, config, yield* packageRoots(openAPI, config));
|
|
@@ -79,7 +79,7 @@ function reportJobs(config, previous) {
|
|
|
79
79
|
onFailure: (error) => Console.error(`❌ ${error.message}`),
|
|
80
80
|
onSuccess: (report) => Console.log(report)
|
|
81
81
|
}));
|
|
82
|
-
const { outsideSources } = yield* Effect.promise(() => import("./shared-
|
|
82
|
+
const { outsideSources } = yield* Effect.promise(() => import("./shared-BrQVwt_b.js").then((n) => n.o));
|
|
83
83
|
const inputDirectory = path.dirname(path.resolve(config.input));
|
|
84
84
|
return {
|
|
85
85
|
inputDirectory,
|
|
@@ -208,8 +208,8 @@ function generate(args) {
|
|
|
208
208
|
if (input !== void 0 && output !== void 0) {
|
|
209
209
|
const [{ parseOpenAPI }, { takibi }, { openAPI3 }] = yield* Effect.promise(() => Promise.all([
|
|
210
210
|
import("./openapi-BxSVfs_l.js").then((n) => n.t),
|
|
211
|
-
import("./core-
|
|
212
|
-
import("./shared-
|
|
211
|
+
import("./core-CajXzO16.js").then((n) => n.t),
|
|
212
|
+
import("./shared-BrQVwt_b.js").then((n) => n.o)
|
|
213
213
|
]));
|
|
214
214
|
const document = yield* openAPI3(yield* parseOpenAPI(input), input);
|
|
215
215
|
return yield* Console.log(yield* takibi(document, output));
|
|
@@ -3,7 +3,7 @@ import { A as isPathItemEntry, C as isOperation, J as COMPONENT_NAMES, K as isVa
|
|
|
3
3
|
import { i as GenerateError, n as fmt } from "./format-BF7SbaMP.js";
|
|
4
4
|
import { _ as routeName, a as ensureSuffix, b as uncapitalize, c as escapeRegexLiteral, h as renderNamedImport, l as makeBarrel, x as zodToOpenAPISchema, y as toIdentifierPascalCase } from "./utils-BeXPKXuG.js";
|
|
5
5
|
import { C as makePathItem, D as makeWebhookEntries, E as makeRouteProperties, O as resolveParameter, S as makeCallback, T as makeRouteEntries, _ as identifierNames, a as requestBodiesCode, b as textOf, c as makeSplitSchemaFile, d as makeImports, f as makeModuleSpec, g as descendantsWhere, h as declarationOf, i as responsesCode, k as resolvePathItem, l as makeConst, m as ast, n as componentsCode, o as parametersCode, p as analyzeCircularSchemas, r as schemasCode, s as headersCode, u as makeExportConst, v as parseModule, w as makeRef, x as zodToOpenAPI, y as parseSource } from "./routes-Cg-imktp.js";
|
|
6
|
-
import { t as zodOpenAPIHono } from "./openapi-
|
|
6
|
+
import { t as zodOpenAPIHono } from "./openapi-BMJPrf4w.js";
|
|
7
7
|
import { t as makeMock } from "./mock-CvrfyklR.js";
|
|
8
8
|
import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-DALShbf3.js";
|
|
9
9
|
import { i as readdir, n as mkdir, o as writeFile, r as readFile } from "./file-hO_bjDys.js";
|
package/dist/generate/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseConfig } from "../index.js";
|
|
2
2
|
import { t as FormatOptions } from "../format-BF7SbaMP.js";
|
|
3
3
|
import { n as parseOpenAPI } from "../openapi-BxSVfs_l.js";
|
|
4
|
-
import { a as packageRoots, n as makeJob, r as openAPI3, t as cleanSplitOutputs } from "../shared-
|
|
4
|
+
import { a as packageRoots, n as makeJob, r as openAPI3, t as cleanSplitOutputs } from "../shared-BrQVwt_b.js";
|
|
5
5
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
// src/generate/index.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as zodOpenAPIHono } from "../../../openapi-
|
|
1
|
+
export { t as zodOpenAPIHono } from "../../../openapi-BMJPrf4w.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { J as COMPONENT_NAMES, N as isRecord, X as COMPONENT_SUFFIXES, et as HTTP_METHODS } from "./guard-ngBos42D.js";
|
|
1
|
+
import { J as COMPONENT_NAMES, N as isRecord, X as COMPONENT_SUFFIXES, Y as COMPONENT_REF_PREFIX, et as HTTP_METHODS } from "./guard-ngBos42D.js";
|
|
2
2
|
import { a as ensureSuffix, i as decodePercent, y as toIdentifierPascalCase } from "./utils-BeXPKXuG.js";
|
|
3
3
|
import { D as makeWebhookEntries, n as componentsCode, t as routeCode } from "./routes-Cg-imktp.js";
|
|
4
4
|
// src/helper/names.ts
|
|
@@ -275,11 +275,118 @@ function resolveEmbeddedRefs(document) {
|
|
|
275
275
|
* The document as every generator reads it: the pointers of an embedded schema resource read
|
|
276
276
|
* against the resource, inline pointers written out where they stand, recursive ones declared
|
|
277
277
|
* as components, components whose names would make one identifier
|
|
278
|
-
* told apart,
|
|
279
|
-
* left out
|
|
278
|
+
* told apart, the Specification Extensions of the Paths, Responses and Callback Objects
|
|
279
|
+
* left out, and the parameters a path template names without declaring them declared. A
|
|
280
|
+
* document none of this touches comes back as it is.
|
|
280
281
|
*/
|
|
281
282
|
function normalizeOpenAPI(document) {
|
|
282
|
-
return withoutExtensions(uniqueComponentNames(inlinePointerRefs(hoistRecursivePointers(resolveEmbeddedRefs(document)))));
|
|
283
|
+
return withTemplateParameters(withoutExtensions(uniqueComponentNames(inlinePointerRefs(hoistRecursivePointers(resolveEmbeddedRefs(document))))));
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* The operations whose path template names a parameter that neither the operation nor its
|
|
287
|
+
* path item declares as `in: path`: `GET /users/{id}` with no `id` in `parameters` (#508).
|
|
288
|
+
* OpenAPI says every template expression MUST correspond to a path parameter, so such a
|
|
289
|
+
* document is invalid, but it is met (Knock).
|
|
290
|
+
*/
|
|
291
|
+
function undeclaredTemplateParameters(document) {
|
|
292
|
+
if (!isRecord(document.paths)) return [];
|
|
293
|
+
return Object.entries(document.paths).flatMap(([path, entry]) => {
|
|
294
|
+
const template = templateNames(path);
|
|
295
|
+
if (template.length === 0) return [];
|
|
296
|
+
const item = resolvedPathItem(entry, document);
|
|
297
|
+
if (item === void 0) return [];
|
|
298
|
+
const shared = declaredPathNames(item.parameters, document);
|
|
299
|
+
return HTTP_METHODS.flatMap((method) => {
|
|
300
|
+
const operation = item[method];
|
|
301
|
+
if (!isRecord(operation)) return [];
|
|
302
|
+
const declared = /* @__PURE__ */ new Set([...shared, ...declaredPathNames(operation.parameters, document)]);
|
|
303
|
+
const names = template.filter((name) => !declared.has(name));
|
|
304
|
+
return names.length === 0 ? [] : [{
|
|
305
|
+
path,
|
|
306
|
+
method,
|
|
307
|
+
names
|
|
308
|
+
}];
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* The document with every parameter a path template names declared (#508): one that neither
|
|
314
|
+
* the operation nor its path item declares is added to the operation as a required string
|
|
315
|
+
* `in: path` parameter, which is what the template says of it. Hono types `param` from the
|
|
316
|
+
* path only when a route declares none, so a route that left one out took `undefined` or
|
|
317
|
+
* could not be given the segment; with the names taken from the template, the route, the
|
|
318
|
+
* client type and the URL agree.
|
|
319
|
+
*
|
|
320
|
+
* A path item that is a `$ref` has its operations in the component, which other paths may
|
|
321
|
+
* share: the parameters are added beside the `$ref`, to the path item, where an operation
|
|
322
|
+
* that declares one of its own still overrides it.
|
|
323
|
+
*/
|
|
324
|
+
function withTemplateParameters(document) {
|
|
325
|
+
const undeclared = undeclaredTemplateParameters(document);
|
|
326
|
+
if (undeclared.length === 0 || !isRecord(document.paths)) return document;
|
|
327
|
+
const paths = Object.fromEntries(Object.entries(document.paths).map(([path, item]) => {
|
|
328
|
+
const found = undeclared.filter((operation) => operation.path === path);
|
|
329
|
+
if (found.length === 0 || !isRecord(item)) return [path, item];
|
|
330
|
+
if (typeof item.$ref === "string") {
|
|
331
|
+
const names = [...new Set(found.flatMap((operation) => operation.names))];
|
|
332
|
+
return [path, {
|
|
333
|
+
...item,
|
|
334
|
+
parameters: withAdded(resolvedPathItem(item, document)?.parameters, names)
|
|
335
|
+
}];
|
|
336
|
+
}
|
|
337
|
+
return [path, {
|
|
338
|
+
...item,
|
|
339
|
+
...Object.fromEntries(found.map(({ method, names }) => {
|
|
340
|
+
const operation = item[method];
|
|
341
|
+
return [method, isRecord(operation) ? {
|
|
342
|
+
...operation,
|
|
343
|
+
parameters: withAdded(operation.parameters, names)
|
|
344
|
+
} : operation];
|
|
345
|
+
}))
|
|
346
|
+
}];
|
|
347
|
+
}));
|
|
348
|
+
const result = {
|
|
349
|
+
...document,
|
|
350
|
+
paths
|
|
351
|
+
};
|
|
352
|
+
return isOpenAPI(result) ? result : document;
|
|
353
|
+
}
|
|
354
|
+
function withAdded(parameters, names) {
|
|
355
|
+
return [...Array.isArray(parameters) ? parameters : [], ...names.map((name) => ({
|
|
356
|
+
name,
|
|
357
|
+
in: "path",
|
|
358
|
+
required: true,
|
|
359
|
+
schema: { type: "string" }
|
|
360
|
+
}))];
|
|
361
|
+
}
|
|
362
|
+
/** The names in the template expressions of a path, `id` for `/users/{id}`, each once. */
|
|
363
|
+
function templateNames(path) {
|
|
364
|
+
return [...new Set([...path.matchAll(/\{([^}]+)\}/gu)].flatMap((match) => match[1] ?? []))];
|
|
365
|
+
}
|
|
366
|
+
/** The path item of a `paths` entry, a `$ref` into `components.pathItems` resolved as the routes resolve it. */
|
|
367
|
+
function resolvedPathItem(item, document) {
|
|
368
|
+
if (!isRecord(item)) return void 0;
|
|
369
|
+
const ref = item.$ref;
|
|
370
|
+
if (typeof ref !== "string" || !ref.startsWith(COMPONENT_REF_PREFIX.pathItems)) return item;
|
|
371
|
+
const pathItems = isRecord(document.components) ? document.components.pathItems : void 0;
|
|
372
|
+
const component = isRecord(pathItems) ? pathItems[ref.slice(ref.lastIndexOf("/") + 1)] : void 0;
|
|
373
|
+
if (!isRecord(component)) return item;
|
|
374
|
+
const { $ref: _, ...siblings } = item;
|
|
375
|
+
return {
|
|
376
|
+
...component,
|
|
377
|
+
...siblings
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
/** The names of the `in: path` parameters of a `parameters` list, `$ref`s into `components.parameters` resolved. */
|
|
381
|
+
function declaredPathNames(parameters, document) {
|
|
382
|
+
if (!Array.isArray(parameters)) return [];
|
|
383
|
+
const components = isRecord(document.components) ? document.components.parameters : void 0;
|
|
384
|
+
return parameters.flatMap((parameter) => {
|
|
385
|
+
if (!isRecord(parameter)) return [];
|
|
386
|
+
const ref = parameter.$ref;
|
|
387
|
+
const resolved = "name" in parameter && "in" in parameter ? parameter : typeof ref === "string" && ref.startsWith(COMPONENT_REF_PREFIX.parameters) && isRecord(components) ? components[ref.slice(ref.lastIndexOf("/") + 1)] : void 0;
|
|
388
|
+
return isRecord(resolved) && resolved.in === "path" && typeof resolved.name === "string" ? [resolved.name] : [];
|
|
389
|
+
});
|
|
283
390
|
}
|
|
284
391
|
/**
|
|
285
392
|
* The document without the Specification Extensions (`x-` keys) of the Paths Object, of the
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
2
|
import { $ as HOOK_LIBRARIES, J as COMPONENT_NAMES } from "./guard-ngBos42D.js";
|
|
3
|
-
import { C as appEntryOutput, D as makeGeneratedImport, E as makeAppEntryImport, S as pathGroupOf, T as makeAppEntryFile, _ as headers, a as takibi, b as client, c as securitySchemes, d as requestBodies, f as pathItems, g as links, h as mediaTypes, i as defineTemplate, l as schemas, m as components, n as webhooks, o as route, p as parameters, r as template, s as mock, u as responses, v as examples, w as isInsideDirectory, x as handlerGroupOf, y as callbacks } from "./core-
|
|
3
|
+
import { C as appEntryOutput, D as makeGeneratedImport, E as makeAppEntryImport, S as pathGroupOf, T as makeAppEntryFile, _ as headers, a as takibi, b as client, c as securitySchemes, d as requestBodies, f as pathItems, g as links, h as mediaTypes, i as defineTemplate, l as schemas, m as components, n as webhooks, o as route, p as parameters, r as template, s as mock, u as responses, v as examples, w as isInsideDirectory, x as handlerGroupOf, y as callbacks } from "./core-CajXzO16.js";
|
|
4
4
|
import { t as docs } from "./docs-hKJj12Gm.js";
|
|
5
5
|
import { t as hooks } from "./hooks-CSMf3pkH.js";
|
|
6
6
|
import { rpc } from "./core/rpc/index.js";
|
|
7
7
|
import { type } from "./core/type/index.js";
|
|
8
8
|
import { i as GenerateError } from "./format-BF7SbaMP.js";
|
|
9
9
|
import { a as unlink, i as readdir, t as exists } from "./file-hO_bjDys.js";
|
|
10
|
-
import { n as normalizeOpenAPI } from "./openapi-
|
|
10
|
+
import { n as normalizeOpenAPI } from "./openapi-BMJPrf4w.js";
|
|
11
11
|
import { Effect, FileSystem, Schema } from "effect";
|
|
12
12
|
import path from "node:path";
|
|
13
13
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { parseConfig } from "../index.js";
|
|
2
2
|
import { N as isRecord, nt as INPUT_EXTENSIONS } from "../guard-ngBos42D.js";
|
|
3
3
|
import { t as FormatOptions } from "../format-BF7SbaMP.js";
|
|
4
|
-
import { C as appEntryOutput, w as isInsideDirectory } from "../core-
|
|
4
|
+
import { C as appEntryOutput, w as isInsideDirectory } from "../core-CajXzO16.js";
|
|
5
5
|
import { n as parseOpenAPI } from "../openapi-BxSVfs_l.js";
|
|
6
|
-
import { a as packageRoots, i as outsideSources, n as makeJob, r as openAPI3, t as cleanSplitOutputs } from "../shared-
|
|
6
|
+
import { a as packageRoots, i as outsideSources, n as makeJob, r as openAPI3, t as cleanSplitOutputs } from "../shared-BrQVwt_b.js";
|
|
7
7
|
import { Effect, FileSystem, Option, Result } from "effect";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import crypto from "node:crypto";
|