hono-takibi 0.26.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +12 -15
- package/dist/core/docs/index.d.ts +2 -4
- package/dist/core/docs/index.js +1 -1
- package/dist/core/hooks/index.d.ts +3 -5
- package/dist/core/hooks/index.js +1 -1
- package/dist/core/rpc/index.d.ts +4 -6
- package/dist/core/rpc/index.js +6 -7
- package/dist/core/type/index.d.ts +3 -5
- package/dist/core/type/index.js +4 -5
- package/dist/{core-FnayWJZV.js → core-D141ZWzp.js} +61 -77
- package/dist/{docs-D8ivFJrR.js → docs-CDFG1tXT.js} +20 -16
- package/dist/{emit-uwlZZeRM.js → emit-CqkT9T4Q.js} +3 -4
- package/dist/{file-K6j5IJXi.js → file-Bip_L0oR.js} +1 -2
- package/dist/{format-CuHABcKC.js → format-BF7SbaMP.js} +3 -5
- package/dist/generator/zod-openapi-hono/openapi/index.d.ts +2 -4
- package/dist/generator/zod-openapi-hono/openapi/index.js +1 -1
- package/dist/guard-BH6yBr0M.js +332 -0
- package/dist/{hooks-DJHtFXnM.js → hooks-CKIK30qr.js} +9 -10
- package/dist/{index-D3apEdjU.d.ts → index-8HyUtaew.d.ts} +2 -4
- package/dist/{index-BNrSddFB.d.ts → index-DqcEtGVl.d.ts} +4 -15
- package/dist/{index-B3ze4n_I.d.ts → index-DvZscmYm.d.ts} +0 -2
- package/dist/{index-D_gf3Xzx.d.ts → index-sZ1C8djg.d.ts} +0 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -5
- package/dist/{openapi-CU23GKuM.js → openapi-imhqgahL.js} +132 -88
- package/dist/{openapi-t_u-tF52.js → openapi-tYYvoKiU.js} +2 -3
- package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
- package/dist/{rpc-CSZ3hBkn.js → rpc-GDi7a_Ep.js} +3 -6
- package/dist/{shared-BvbKZMJK.js → shared-CyBkG8gM.js} +12 -10
- package/dist/{utils-Bw0Q2Ozg.js → utils-CDLiYepO.js} +50 -254
- package/dist/vite-plugin/index.d.ts +1 -3
- package/dist/vite-plugin/index.js +6 -8
- package/package.json +5 -5
- package/dist/constants-hwmOoQfI.js +0 -103
package/dist/cli.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { Z as INPUT_EXTENSIONS, m as isInputPath } from "./guard-BH6yBr0M.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
|
-
|
|
8
|
-
var version = "0.
|
|
7
|
+
// package.json
|
|
8
|
+
var version = "0.28.0";
|
|
9
9
|
var description = "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi";
|
|
10
|
-
|
|
11
|
-
//#region src/cli/index.ts
|
|
10
|
+
// src/cli/index.ts
|
|
12
11
|
const COMMAND_NAME = "hono-takibi";
|
|
13
12
|
const DEFAULT_CONFIG_FILE = "hono-takibi.config.ts";
|
|
14
13
|
const DocumentPathSchema = Schema.String.pipe(Schema.refine(isInputPath, { message: "an OpenAPI (.yaml, .yml, .json) or TypeSpec (.tsp) document" })).annotate({
|
|
@@ -40,9 +39,9 @@ function loadConfig(configPath, reload) {
|
|
|
40
39
|
function runJobs(config) {
|
|
41
40
|
return Effect.gen(function* () {
|
|
42
41
|
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob, openAPI3, packageRoots }] = yield* Effect.promise(() => Promise.all([
|
|
43
|
-
import("./openapi-
|
|
44
|
-
import("./format-
|
|
45
|
-
import("./shared-
|
|
42
|
+
import("./openapi-tYYvoKiU.js").then((n) => n.t),
|
|
43
|
+
import("./format-BF7SbaMP.js").then((n) => n.r),
|
|
44
|
+
import("./shared-CyBkG8gM.js").then((n) => n.o)
|
|
46
45
|
]));
|
|
47
46
|
const openAPI = yield* openAPI3(yield* parseOpenAPI(config.input), config.input);
|
|
48
47
|
const jobs = makeJob(openAPI, config, yield* packageRoots(openAPI, config));
|
|
@@ -80,7 +79,7 @@ function reportJobs(config, previous) {
|
|
|
80
79
|
onFailure: (error) => Console.error(`❌ ${error.message}`),
|
|
81
80
|
onSuccess: (report) => Console.log(report)
|
|
82
81
|
}));
|
|
83
|
-
const { outsideSources } = yield* Effect.promise(() => import("./shared-
|
|
82
|
+
const { outsideSources } = yield* Effect.promise(() => import("./shared-CyBkG8gM.js").then((n) => n.o));
|
|
84
83
|
const inputDirectory = path.dirname(path.resolve(config.input));
|
|
85
84
|
return {
|
|
86
85
|
inputDirectory,
|
|
@@ -208,9 +207,9 @@ function generate(args) {
|
|
|
208
207
|
});
|
|
209
208
|
if (input !== void 0 && output !== void 0) {
|
|
210
209
|
const [{ parseOpenAPI }, { takibi }, { openAPI3 }] = yield* Effect.promise(() => Promise.all([
|
|
211
|
-
import("./openapi-
|
|
212
|
-
import("./core-
|
|
213
|
-
import("./shared-
|
|
210
|
+
import("./openapi-tYYvoKiU.js").then((n) => n.t),
|
|
211
|
+
import("./core-D141ZWzp.js").then((n) => n.t),
|
|
212
|
+
import("./shared-CyBkG8gM.js").then((n) => n.o)
|
|
214
213
|
]));
|
|
215
214
|
const document = yield* openAPI3(yield* parseOpenAPI(input), input);
|
|
216
215
|
return yield* Console.log(yield* takibi(document, output));
|
|
@@ -253,8 +252,6 @@ function makeCli() {
|
|
|
253
252
|
function honoTakibi() {
|
|
254
253
|
return Command.run(makeCli(), { version });
|
|
255
254
|
}
|
|
256
|
-
|
|
257
|
-
//#region src/index.ts
|
|
255
|
+
// src/index.ts
|
|
258
256
|
NodeRuntime.runMain(honoTakibi().pipe(Effect.provide(NodeServices.layer)));
|
|
259
|
-
//#endregion
|
|
260
257
|
export {};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../index-
|
|
1
|
+
import { t as OpenAPI } from "../../index-DvZscmYm.js";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
|
-
|
|
4
|
-
export declare function docs(openAPI: OpenAPI, output: string, entry?: string, basePath?: string, curl?: boolean, baseUrl?: string): Effect.Effect<string, import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
|
5
|
-
//#endregion
|
|
3
|
+
export declare function docs(openAPI: OpenAPI, output: string, entry?: string, basePath?: string, curl?: boolean, baseUrl?: string): Effect.Effect<string, import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
package/dist/core/docs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as docs } from "../../docs-
|
|
1
|
+
export { t as docs } from "../../docs-CDFG1tXT.js";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../index-
|
|
2
|
-
import { n as GenerateError, t as FormatError } from "../../index-
|
|
3
|
-
import { t as Grouping } from "../../index-
|
|
4
|
-
//#region src/core/hooks/index.d.ts
|
|
1
|
+
import { t as OpenAPI } from "../../index-DvZscmYm.js";
|
|
2
|
+
import { n as GenerateError, t as FormatError } from "../../index-sZ1C8djg.js";
|
|
3
|
+
import { t as Grouping } from "../../index-8HyUtaew.js";
|
|
5
4
|
declare const HOOK_CONFIGS: {
|
|
6
5
|
readonly swr: {
|
|
7
6
|
readonly packageName: 'swr';
|
|
@@ -167,5 +166,4 @@ export declare function hooks(openAPI: OpenAPI, output: string, importPath: stri
|
|
|
167
166
|
readonly grouping?: Grouping;
|
|
168
167
|
readonly basePath?: string;
|
|
169
168
|
}): import("effect/Effect").Effect<`Generated ${string} hooks written to ${string}`, FormatError | GenerateError | import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
|
170
|
-
//#endregion
|
|
171
169
|
export {};
|
package/dist/core/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as hooks } from "../../hooks-
|
|
1
|
+
export { t as hooks } from "../../hooks-CKIK30qr.js";
|
package/dist/core/rpc/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../index-
|
|
2
|
-
import { n as GenerateError, t as FormatError } from "../../index-
|
|
3
|
-
import { t as Grouping } from "../../index-
|
|
1
|
+
import { t as OpenAPI } from "../../index-DvZscmYm.js";
|
|
2
|
+
import { n as GenerateError, t as FormatError } from "../../index-sZ1C8djg.js";
|
|
3
|
+
import { t as Grouping } from "../../index-8HyUtaew.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
|
-
//#region src/core/rpc/index.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Generates RPC client wrapper functions from OpenAPI specification.
|
|
8
7
|
*/
|
|
9
|
-
export declare function rpc(openAPI: OpenAPI, output: string, importPath: string, clientName?: string, useParseResponse?: boolean, basePath?: string, docs?: boolean, grouping?: Grouping): Effect.Effect<string, FormatError | GenerateError | import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
|
10
|
-
//#endregion
|
|
8
|
+
export declare function rpc(openAPI: OpenAPI, output: string, importPath: string, clientName?: string, useParseResponse?: boolean, basePath?: string, docs?: boolean, grouping?: Grouping): Effect.Effect<string, FormatError | GenerateError | import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
package/dist/core/rpc/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as GenerateError } from "../../format-
|
|
3
|
-
import {
|
|
4
|
-
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-
|
|
5
|
-
import { t as emit } from "../../emit-
|
|
1
|
+
import { O as isRecord, Y as HTTP_METHODS, b as isOperationLike, v as isOpenAPIPaths } from "../../guard-BH6yBr0M.js";
|
|
2
|
+
import { i as GenerateError } from "../../format-BF7SbaMP.js";
|
|
3
|
+
import { _ as routeName, u as makeInferRequestType } from "../../utils-CDLiYepO.js";
|
|
4
|
+
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-GDi7a_Ep.js";
|
|
5
|
+
import { t as emit } from "../../emit-CqkT9T4Q.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import { dirname } from "node:path";
|
|
8
|
-
|
|
8
|
+
// src/core/rpc/index.ts
|
|
9
9
|
/**
|
|
10
10
|
* Builds a JSDoc block from operation `summary` / `description` plus the HTTP route line.
|
|
11
11
|
* Returns an empty string when neither summary nor description is present (the route line
|
|
@@ -70,5 +70,4 @@ function rpc(openAPI, output, importPath, clientName = "client", useParseRespons
|
|
|
70
70
|
return `Generated rpc code written to ${output}`;
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
//#endregion
|
|
74
73
|
export { rpc };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../index-
|
|
2
|
-
import { t as FormatError } from "../../index-
|
|
1
|
+
import { t as OpenAPI } from "../../index-DvZscmYm.js";
|
|
2
|
+
import { t as FormatError } from "../../index-sZ1C8djg.js";
|
|
3
3
|
import { Effect } from "effect";
|
|
4
|
-
//#region src/core/type/index.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Generates TypeScript type declarations from OpenAPI specification.
|
|
7
6
|
*/
|
|
8
|
-
export declare function type(openAPI: OpenAPI, output: `${string}.ts`, readonly?: boolean): Effect.Effect<string, FormatError | import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
|
9
|
-
//#endregion
|
|
7
|
+
export declare function type(openAPI: OpenAPI, output: `${string}.ts`, readonly?: boolean): Effect.Effect<string, FormatError | import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
package/dist/core/type/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "../../
|
|
2
|
-
import {
|
|
3
|
-
import { t as emit } from "../../emit-
|
|
1
|
+
import { N as isSchemaArray, S as isParameterArray, d as isHttpMethod, g as isMediaWithSchema, j as isRequestBody, v as isOpenAPIPaths, x as isParameter, y as isOperation, z as isStringRef } from "../../guard-BH6yBr0M.js";
|
|
2
|
+
import { d as makeSafeKey, v as statusCodeToNumber, y as toIdentifierPascalCase } from "../../utils-CDLiYepO.js";
|
|
3
|
+
import { t as emit } from "../../emit-CqkT9T4Q.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
|
|
6
|
+
// src/core/type/index.ts
|
|
7
7
|
/**
|
|
8
8
|
* DeepReadonly utility type that recursively makes all properties readonly.
|
|
9
9
|
*/
|
|
@@ -300,5 +300,4 @@ function makeObjectTypeString(schema, aliases, visited) {
|
|
|
300
300
|
return requiredSet.has(key) ? `${safeKey}:${propType}` : `${safeKey}?:${propType}|undefined`;
|
|
301
301
|
}).join(";")}}`;
|
|
302
302
|
}
|
|
303
|
-
//#endregion
|
|
304
303
|
export { type };
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-
|
|
2
|
-
import {
|
|
3
|
-
import { i as GenerateError, n as fmt } from "./format-
|
|
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-
|
|
7
|
-
import { i as readdir, n as mkdir, o as writeFile, r as readFile } from "./file-
|
|
8
|
-
import { t as emit } from "./emit-
|
|
9
|
-
import { t as hooks } from "./hooks-
|
|
10
|
-
import { t as docs } from "./docs-
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
|
+
import { D as isPathItemRef, E as isPathItemEntry, I as isSecurityArray, L as isSecurityScheme, N as isSchemaArray, P as isSchemaObject, Q as JSON_MEDIA_TYPE, T as isPathItem, U as COMPONENT_NAMES, V as isValidIdent, W as COMPONENT_REF_PREFIX, Y as HTTP_METHODS, a as hasRequestBodyContent, d as isHttpMethod, g as isMediaWithSchema, i as hasNumericConstraint, k as isRefObject, p as isInlineMedia, s as isCallbacks, tt as TEXT_MEDIA_TYPE, v as isOpenAPIPaths, x as isParameter, y as isOperation } from "./guard-BH6yBr0M.js";
|
|
3
|
+
import { i as GenerateError, n as fmt } from "./format-BF7SbaMP.js";
|
|
4
|
+
import { S as zodToOpenAPISchema, _ as routeName, a as ensureSuffix, b as uncapitalize, c as escapeRegexLiteral, d as makeSafeKey, f as makeStringLiteral, h as renderNamedImport, l as makeBarrel, p as normalizeTypes, r as cyclicNodes, v as statusCodeToNumber, x as uncapitalizeWord, y as toIdentifierPascalCase } from "./utils-CDLiYepO.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-imhqgahL.js";
|
|
6
|
+
import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-GDi7a_Ep.js";
|
|
7
|
+
import { i as readdir, n as mkdir, o as writeFile, r as readFile } from "./file-Bip_L0oR.js";
|
|
8
|
+
import { t as emit } from "./emit-CqkT9T4Q.js";
|
|
9
|
+
import { t as hooks } from "./hooks-CKIK30qr.js";
|
|
10
|
+
import { t as docs } from "./docs-CDFG1tXT.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";
|
|
14
14
|
import path, { basename, dirname, join, relative } from "node:path";
|
|
15
|
-
|
|
15
|
+
// src/helper/faker.ts
|
|
16
16
|
const FORMAT_TO_FAKER = {
|
|
17
17
|
date: "faker.date.past().toISOString().slice(0, 10)",
|
|
18
18
|
"date-time": "faker.date.past().toISOString()",
|
|
@@ -365,8 +365,15 @@ function recursiveCall(schema, recursive) {
|
|
|
365
365
|
const refName = schema.$ref.split("/").at(-1);
|
|
366
366
|
return refName !== void 0 && recursive.has(refName) ? `${mockFunctionName(refName)}(depth + 1)` : void 0;
|
|
367
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* The head of the function that mocks a component schema. It answers the type the schema
|
|
370
|
+
* infers, so that a value that does not fit is reported there, once, and the handlers that
|
|
371
|
+
* answer with it type-check against the route (a nested object that takes any key, read
|
|
372
|
+
* through Hono's own mapping of the response, would otherwise not). A recursive schema's
|
|
373
|
+
* function answers `any`: its depth guard answers `undefined` where the schema does not.
|
|
374
|
+
*/
|
|
368
375
|
function mockFunctionSignature(refName, isRecursive) {
|
|
369
|
-
return isRecursive ? `function ${mockFunctionName(refName)}(depth = 0): any` : `function ${mockFunctionName(refName)}()
|
|
376
|
+
return isRecursive ? `function ${mockFunctionName(refName)}(depth = 0): any` : `function ${mockFunctionName(refName)}(): z.infer<typeof ${toIdentifierPascalCase(ensureSuffix(refName, "Schema"))}>`;
|
|
370
377
|
}
|
|
371
378
|
function resolveRef(schema, schemas) {
|
|
372
379
|
if (!schema.$ref) return schema;
|
|
@@ -507,20 +514,22 @@ function schemaValue(schema, propertyName, options = {}) {
|
|
|
507
514
|
const key = makeSafeKey(k);
|
|
508
515
|
const value = schemaToFaker(v, k, options);
|
|
509
516
|
const isNullable = v.nullable === true || normalizeTypes(v.type).includes("null");
|
|
510
|
-
if (value === "undefined") return requiredSet.has(k) ? `${key}: null` :
|
|
517
|
+
if (value === "undefined") return requiredSet.has(k) ? `${key}: null` : void 0;
|
|
511
518
|
if (!(requiredSet.has(k) || isNullable)) {
|
|
512
|
-
|
|
513
|
-
|
|
519
|
+
if (!containsRecursion(value)) return `...(faker.datatype.boolean() ? { ${key}: ${value} } : {})`;
|
|
520
|
+
const drawn = value.match(/^depth < \d+ \? ([\s\S]*) : undefined$/u)?.[1] ?? value;
|
|
521
|
+
return `...(depth < ${MAX_RECURSION_DEPTH} && faker.datatype.boolean() ? { ${key}: ${drawn} } : {})`;
|
|
514
522
|
}
|
|
515
523
|
if (v.nullable) return `${key}: faker.helpers.arrayElement([${value}, null])`;
|
|
516
524
|
return `${key}: ${value}`;
|
|
517
|
-
}).join(", ");
|
|
525
|
+
}).filter((entry) => entry !== void 0).join(", ");
|
|
518
526
|
};
|
|
519
527
|
if (schema.type === "object" && schema.properties) {
|
|
520
528
|
const required = [...schema.required ?? [], ...conditionalRequired(schema)];
|
|
521
529
|
const optional = Object.keys(schema.properties).filter((k) => !required.includes(k));
|
|
522
530
|
const missing = Math.max(0, (schema.minProperties ?? 0) - required.length);
|
|
523
|
-
|
|
531
|
+
const props = renderProps(schema.properties, [...required, ...optional.slice(0, missing)]);
|
|
532
|
+
return props === "" ? "{}" : `{ ${props} }`;
|
|
524
533
|
}
|
|
525
534
|
if (schema.type === "object" && !schema.properties && schema.additionalProperties) {
|
|
526
535
|
if (typeof schema.additionalProperties === "boolean" || schema.propertyNames !== void 0 || schema.patternProperties !== void 0) return "{}";
|
|
@@ -542,11 +551,12 @@ function schemaValue(schema, propertyName, options = {}) {
|
|
|
542
551
|
const required = [...schema.required ?? [], ...resolvedMembers.flatMap((member) => member.required ?? [])];
|
|
543
552
|
const promoted = resolvedMembers.flatMap((member) => Object.entries(member.properties ?? {}).filter(([k]) => required.includes(k) && !(member.required ?? []).includes(k)).map(([k, v]) => renderProps({ [k]: v }, [k])));
|
|
544
553
|
const own = schema.properties ? [renderProps(schema.properties, required)] : [];
|
|
545
|
-
|
|
554
|
+
const entries = [
|
|
546
555
|
...spreads,
|
|
547
556
|
...promoted,
|
|
548
557
|
...own
|
|
549
|
-
].
|
|
558
|
+
].filter((entry) => entry !== "");
|
|
559
|
+
return entries.length === 0 ? "{}" : `{ ${entries.join(", ")} }`;
|
|
550
560
|
}
|
|
551
561
|
const union = schema.oneOf && schema.oneOf.length > 0 ? schema.discriminator ? schema.oneOf : exclusiveVariants(schema.oneOf, options.schemas) : schema.anyOf && schema.anyOf.length > 0 ? schema.anyOf : void 0;
|
|
552
562
|
if (union) {
|
|
@@ -598,8 +608,7 @@ function getNonExistentValue(schema, schemas) {
|
|
|
598
608
|
if (resolved.format === "uuid") return "00000000-0000-0000-0000-000000000000";
|
|
599
609
|
return "__non_existent__";
|
|
600
610
|
}
|
|
601
|
-
|
|
602
|
-
//#region src/generator/zod-openapi-hono/openapi/define/index.ts
|
|
611
|
+
// src/generator/zod-openapi-hono/openapi/define/index.ts
|
|
603
612
|
/**
|
|
604
613
|
* Builds `defineOpenAPIRoute({ route: createRoute({...}), handler })` entries.
|
|
605
614
|
*
|
|
@@ -639,8 +648,7 @@ function defineEntries(openapi, readonly) {
|
|
|
639
648
|
});
|
|
640
649
|
});
|
|
641
650
|
}
|
|
642
|
-
|
|
643
|
-
//#region src/merge/index.ts
|
|
651
|
+
// src/merge/index.ts
|
|
644
652
|
function isInlineHandlerName(name) {
|
|
645
653
|
return name.endsWith("Handler") && !name.endsWith("RouteHandler");
|
|
646
654
|
}
|
|
@@ -1235,8 +1243,7 @@ function mergeBarrelFile(existingCode, generatedCode) {
|
|
|
1235
1243
|
const base = existingCode.trimEnd();
|
|
1236
1244
|
return `${base ? `${base}\n` : ""}${missingExports.join("\n")}\n`;
|
|
1237
1245
|
}
|
|
1238
|
-
|
|
1239
|
-
//#region src/helper/path.ts
|
|
1246
|
+
// src/helper/path.ts
|
|
1240
1247
|
/**
|
|
1241
1248
|
* Whether `filePath` sits under `directory`, at any depth.
|
|
1242
1249
|
*
|
|
@@ -1301,8 +1308,7 @@ function appEntryOutput(config) {
|
|
|
1301
1308
|
const anchor = container.includes("/") ? container.slice(0, container.lastIndexOf("/")) : "";
|
|
1302
1309
|
return anchor === "" || anchor === "." ? "index.ts" : `${anchor}/index.ts`;
|
|
1303
1310
|
}
|
|
1304
|
-
|
|
1305
|
-
//#region src/helper/handler.ts
|
|
1311
|
+
// src/helper/handler.ts
|
|
1306
1312
|
function sanitizeHandlerSegment(segment) {
|
|
1307
1313
|
return segment.replaceAll(/\{([^}]+)\}/gu, "$1").replaceAll(/[^0-9A-Za-z._-]/gu, "_").replaceAll(/^[._-]+|[._-]+$/gu, "").replaceAll(/__+/gu, "_").replaceAll(/[-._](\w)/gu, (_, c) => c.toUpperCase());
|
|
1308
1314
|
}
|
|
@@ -1529,8 +1535,7 @@ function defineOpenAPIRouteHandler(openapi, output, componentsOutput, pathAlias,
|
|
|
1529
1535
|
})), writeBarrel(handlerPath, handlerList.map((h) => h.fileName))], { concurrency: "unbounded" });
|
|
1530
1536
|
});
|
|
1531
1537
|
}
|
|
1532
|
-
|
|
1533
|
-
//#region src/core/client/index.ts
|
|
1538
|
+
// src/core/client/index.ts
|
|
1534
1539
|
function capitalizeFirst(name) {
|
|
1535
1540
|
return name.replace(/^([_$]*)(.)/u, (_, lead, first) => `${lead}${first.toUpperCase()}`);
|
|
1536
1541
|
}
|
|
@@ -1621,8 +1626,7 @@ function client(openAPI, output, importPath, baseUrl, basePath, grouping, barrel
|
|
|
1621
1626
|
return `Generated client code written to ${output}`;
|
|
1622
1627
|
});
|
|
1623
1628
|
}
|
|
1624
|
-
|
|
1625
|
-
//#region src/core/components/callbacks.ts
|
|
1629
|
+
// src/core/components/callbacks.ts
|
|
1626
1630
|
function callbacks(callbacks, output, split, components, readonly) {
|
|
1627
1631
|
return Effect.gen(function* () {
|
|
1628
1632
|
if (!callbacks) return yield* new GenerateError({ message: "No callbacks found" });
|
|
@@ -1651,8 +1655,7 @@ function callbacks(callbacks, output, split, components, readonly) {
|
|
|
1651
1655
|
return `Generated callbacks code written to ${output}`;
|
|
1652
1656
|
});
|
|
1653
1657
|
}
|
|
1654
|
-
|
|
1655
|
-
//#region src/core/components/examples.ts
|
|
1658
|
+
// src/core/components/examples.ts
|
|
1656
1659
|
function examples(examples, output, split, readonly) {
|
|
1657
1660
|
return Effect.gen(function* () {
|
|
1658
1661
|
if (!examples) return yield* new GenerateError({ message: "No examples found" });
|
|
@@ -1681,8 +1684,7 @@ function examples(examples, output, split, readonly) {
|
|
|
1681
1684
|
return `Generated examples code written to ${output}`;
|
|
1682
1685
|
});
|
|
1683
1686
|
}
|
|
1684
|
-
|
|
1685
|
-
//#region src/core/components/headers.ts
|
|
1687
|
+
// src/core/components/headers.ts
|
|
1686
1688
|
function headers(headers, output, split, exportType, components, readonly) {
|
|
1687
1689
|
return Effect.gen(function* () {
|
|
1688
1690
|
if (!headers) return yield* new GenerateError({ message: "No headers found" });
|
|
@@ -1703,8 +1705,7 @@ function headers(headers, output, split, exportType, components, readonly) {
|
|
|
1703
1705
|
return `Generated headers code written to ${output}`;
|
|
1704
1706
|
});
|
|
1705
1707
|
}
|
|
1706
|
-
|
|
1707
|
-
//#region src/core/components/links.ts
|
|
1708
|
+
// src/core/components/links.ts
|
|
1708
1709
|
function links(links, output, split, readonly) {
|
|
1709
1710
|
return Effect.gen(function* () {
|
|
1710
1711
|
if (!links) return yield* new GenerateError({ message: "No links found" });
|
|
@@ -1726,8 +1727,7 @@ function links(links, output, split, readonly) {
|
|
|
1726
1727
|
return `Generated links code written to ${output}`;
|
|
1727
1728
|
});
|
|
1728
1729
|
}
|
|
1729
|
-
|
|
1730
|
-
//#region src/core/components/mediaTypes.ts
|
|
1730
|
+
// src/core/components/mediaTypes.ts
|
|
1731
1731
|
function mediaTypes(mediaTypes, output, split, readonly, components) {
|
|
1732
1732
|
return Effect.gen(function* () {
|
|
1733
1733
|
if (!mediaTypes) return yield* new GenerateError({ message: "No mediaTypes found" });
|
|
@@ -1773,8 +1773,7 @@ function mediaTypes(mediaTypes, output, split, readonly, components) {
|
|
|
1773
1773
|
return `Generated mediaTypes code written to ${output}`;
|
|
1774
1774
|
});
|
|
1775
1775
|
}
|
|
1776
|
-
|
|
1777
|
-
//#region src/core/components/output.ts
|
|
1776
|
+
// src/core/components/output.ts
|
|
1778
1777
|
function components(openAPI, output, readonly) {
|
|
1779
1778
|
return Effect.gen(function* () {
|
|
1780
1779
|
if (!openAPI.components) return "No components found";
|
|
@@ -1802,8 +1801,7 @@ function components(openAPI, output, readonly) {
|
|
|
1802
1801
|
return `Generated components code written to ${output}`;
|
|
1803
1802
|
});
|
|
1804
1803
|
}
|
|
1805
|
-
|
|
1806
|
-
//#region src/core/components/parameters.ts
|
|
1804
|
+
// src/core/components/parameters.ts
|
|
1807
1805
|
function parameters(parameters, output, split, exportType, components, readonly, schemas) {
|
|
1808
1806
|
return Effect.gen(function* () {
|
|
1809
1807
|
if (!parameters) return yield* new GenerateError({ message: "No parameters found" });
|
|
@@ -1830,8 +1828,7 @@ function parameters(parameters, output, split, exportType, components, readonly,
|
|
|
1830
1828
|
return `Generated parameters code written to ${output}`;
|
|
1831
1829
|
});
|
|
1832
1830
|
}
|
|
1833
|
-
|
|
1834
|
-
//#region src/core/components/pathItems.ts
|
|
1831
|
+
// src/core/components/pathItems.ts
|
|
1835
1832
|
function pathItems(components, pathItemsConfig, componentsConfig, readonly) {
|
|
1836
1833
|
return Effect.gen(function* () {
|
|
1837
1834
|
if (!pathItemsConfig?.output) return yield* new GenerateError({ message: "pathItems.output is required" });
|
|
@@ -1862,8 +1859,7 @@ function pathItems(components, pathItemsConfig, componentsConfig, readonly) {
|
|
|
1862
1859
|
return `Generated PathItem code written to ${outDir}/*.ts (index.ts included)`;
|
|
1863
1860
|
});
|
|
1864
1861
|
}
|
|
1865
|
-
|
|
1866
|
-
//#region src/core/components/requestBodies.ts
|
|
1862
|
+
// src/core/components/requestBodies.ts
|
|
1867
1863
|
function requestBodies(requestBodies, output, split, components, readonly, schemas) {
|
|
1868
1864
|
return Effect.gen(function* () {
|
|
1869
1865
|
if (!requestBodies) return yield* new GenerateError({ message: "No requestBodies found" });
|
|
@@ -1890,8 +1886,7 @@ function requestBodies(requestBodies, output, split, components, readonly, schem
|
|
|
1890
1886
|
return `Generated requestBodies code written to ${output}`;
|
|
1891
1887
|
});
|
|
1892
1888
|
}
|
|
1893
|
-
|
|
1894
|
-
//#region src/core/components/responses.ts
|
|
1889
|
+
// src/core/components/responses.ts
|
|
1895
1890
|
function responses(responses, output, split, components, readonly) {
|
|
1896
1891
|
return Effect.gen(function* () {
|
|
1897
1892
|
if (!responses) return yield* new GenerateError({ message: "No responses found" });
|
|
@@ -1912,8 +1907,7 @@ function responses(responses, output, split, components, readonly) {
|
|
|
1912
1907
|
return `Generated responses code written to ${output}`;
|
|
1913
1908
|
});
|
|
1914
1909
|
}
|
|
1915
|
-
|
|
1916
|
-
//#region src/core/components/schemas.ts
|
|
1910
|
+
// src/core/components/schemas.ts
|
|
1917
1911
|
function schemas(schemas, output, split, exportType, readonly) {
|
|
1918
1912
|
return Effect.gen(function* () {
|
|
1919
1913
|
if (!schemas) return yield* new GenerateError({ message: "No schemas found" });
|
|
@@ -1936,8 +1930,7 @@ function schemas(schemas, output, split, exportType, readonly) {
|
|
|
1936
1930
|
return `Generated schema code written to ${output}`;
|
|
1937
1931
|
});
|
|
1938
1932
|
}
|
|
1939
|
-
|
|
1940
|
-
//#region src/core/components/securitySchemes.ts
|
|
1933
|
+
// src/core/components/securitySchemes.ts
|
|
1941
1934
|
function securitySchemes(securitySchemes, output, split, readonly) {
|
|
1942
1935
|
return Effect.gen(function* () {
|
|
1943
1936
|
if (!securitySchemes) return yield* new GenerateError({ message: "No securitySchemes found" });
|
|
@@ -1959,8 +1952,7 @@ function securitySchemes(securitySchemes, output, split, readonly) {
|
|
|
1959
1952
|
return `Generated securitySchemes code written to ${output}`;
|
|
1960
1953
|
});
|
|
1961
1954
|
}
|
|
1962
|
-
|
|
1963
|
-
//#region src/generator/mock/index.ts
|
|
1955
|
+
// src/generator/mock/index.ts
|
|
1964
1956
|
function collectRefs(schema, refs = /* @__PURE__ */ new Set()) {
|
|
1965
1957
|
if (schema.$ref) {
|
|
1966
1958
|
const refName = schema.$ref.split("/").at(-1);
|
|
@@ -2123,7 +2115,7 @@ function resolveSuccessResponse(responses, componentResponses) {
|
|
|
2123
2115
|
"default"
|
|
2124
2116
|
].filter((key) => keys.includes(key));
|
|
2125
2117
|
const others = keys.filter((key) => !priority.includes(key) && statusCodeToNumber(key) >= 200 && statusCodeToNumber(key) < 300).toSorted((a, b) => statusCodeToNumber(a) - statusCodeToNumber(b));
|
|
2126
|
-
const key = [...priority, ...others][0];
|
|
2118
|
+
const key = [...priority, ...others][0] ?? keys.find((candidate) => /^\d{3}$/u.test(candidate) && resolveResponse(responses[candidate], componentResponses)?.content !== void 0);
|
|
2127
2119
|
if (!key) return void 0;
|
|
2128
2120
|
return {
|
|
2129
2121
|
key,
|
|
@@ -2205,11 +2197,12 @@ function resolveMedia(media, components, seen = /* @__PURE__ */ new Set()) {
|
|
|
2205
2197
|
if (name === void 0 || seen.has(name)) return void 0;
|
|
2206
2198
|
return resolveMedia(components?.mediaTypes?.[name], components, seen.add(name));
|
|
2207
2199
|
}
|
|
2208
|
-
function describeResponse(key, response, components, useExamples) {
|
|
2200
|
+
function describeResponse(key, response, components, useExamples, routeId) {
|
|
2209
2201
|
const jsonType = jsonMediaType(response.content);
|
|
2210
2202
|
const jsonMedia = resolveMedia(jsonType ? response.content?.[jsonType] : void 0, components);
|
|
2211
2203
|
const textMedia = resolveMedia(response.content?.[TEXT_MEDIA_TYPE], components);
|
|
2212
2204
|
const jsonSchema = jsonMedia && isMediaWithSchema(jsonMedia) ? jsonMedia.schema : void 0;
|
|
2205
|
+
const inlineCast = jsonSchema !== void 0 && jsonType !== void 0 ? `z.infer<(typeof ${routeId}Route)['responses'][${/^\d+$/u.test(key) ? key : JSON.stringify(key)}]['content'][${JSON.stringify(jsonType)}]['schema']>` : void 0;
|
|
2213
2206
|
return {
|
|
2214
2207
|
key: /^[1-5]xx$/iu.test(key) ? key.toUpperCase() : key,
|
|
2215
2208
|
jsonType,
|
|
@@ -2220,12 +2213,12 @@ function describeResponse(key, response, components, useExamples) {
|
|
|
2220
2213
|
const value = exampleEntryValue(entry, components);
|
|
2221
2214
|
return value === void 0 ? [] : [[name, value]];
|
|
2222
2215
|
}),
|
|
2223
|
-
exampleCast: jsonSchema?.$ref ? toIdentifierPascalCase(ensureSuffix(jsonSchema.$ref.split("/").at(-1) ?? "", "Schema")) :
|
|
2216
|
+
exampleCast: jsonSchema?.$ref ? `z.infer<typeof ${toIdentifierPascalCase(ensureSuffix(jsonSchema.$ref.split("/").at(-1) ?? "", "Schema"))}>` : inlineCast
|
|
2224
2217
|
};
|
|
2225
2218
|
}
|
|
2226
2219
|
function responsePayload(response, example, schemas, fakerOptions, allRefs) {
|
|
2227
2220
|
if (example !== void 0) {
|
|
2228
|
-
const cast = response.exampleCast ? ` as
|
|
2221
|
+
const cast = response.exampleCast ? ` as unknown as ${response.exampleCast}` : "";
|
|
2229
2222
|
return {
|
|
2230
2223
|
kind: "json",
|
|
2231
2224
|
data: `${exampleCode(example, response.jsonSchema, schemas)}${cast}`
|
|
@@ -2364,7 +2357,7 @@ function makeMock(openapi, basePath, options = {}) {
|
|
|
2364
2357
|
const successKey = success?.key ?? "200";
|
|
2365
2358
|
const responses = Object.entries(operation.responses ?? {}).flatMap(([key, raw]) => {
|
|
2366
2359
|
const response = resolveResponse(raw, componentResponses);
|
|
2367
|
-
return response ? [describeResponse(key, response, openapi.components, useExamples !== false)] : [];
|
|
2360
|
+
return response ? [describeResponse(key, response, openapi.components, useExamples !== false, routeId)] : [];
|
|
2368
2361
|
});
|
|
2369
2362
|
const successResponse = responses.find((r) => r.key === successKey);
|
|
2370
2363
|
const handlerBody = makeHandlerBody(statusCode, successResponse, successResponse ? responsePayload(successResponse, successResponse.example, schemas, fakerOptions, allRefs) : { kind: "none" });
|
|
@@ -2474,8 +2467,7 @@ export default app`;
|
|
|
2474
2467
|
appCode
|
|
2475
2468
|
].filter((s) => s.length > 0).join("\n\n");
|
|
2476
2469
|
}
|
|
2477
|
-
|
|
2478
|
-
//#region src/core/mock/index.ts
|
|
2470
|
+
// src/core/mock/index.ts
|
|
2479
2471
|
function mock(openAPI, output, basePath, options = {}) {
|
|
2480
2472
|
return Effect.gen(function* () {
|
|
2481
2473
|
const mockCode = makeMock(openAPI, basePath, options);
|
|
@@ -2483,8 +2475,7 @@ function mock(openAPI, output, basePath, options = {}) {
|
|
|
2483
2475
|
return `Generated mock server written to ${output}`;
|
|
2484
2476
|
});
|
|
2485
2477
|
}
|
|
2486
|
-
|
|
2487
|
-
//#region src/core/route/index.ts
|
|
2478
|
+
// src/core/route/index.ts
|
|
2488
2479
|
function route(openAPI, routes, components, readonly) {
|
|
2489
2480
|
return Effect.gen(function* () {
|
|
2490
2481
|
if (!routes?.output) return yield* new GenerateError({ message: "routes.output is required" });
|
|
@@ -2503,16 +2494,14 @@ function route(openAPI, routes, components, readonly) {
|
|
|
2503
2494
|
return `Generated route code written to ${outDir}/*.ts (index.ts included)`;
|
|
2504
2495
|
});
|
|
2505
2496
|
}
|
|
2506
|
-
|
|
2507
|
-
//#region src/core/takibi/index.ts
|
|
2497
|
+
// src/core/takibi/index.ts
|
|
2508
2498
|
function takibi(openAPI, output, componentsOptions = {}) {
|
|
2509
2499
|
return Effect.gen(function* () {
|
|
2510
2500
|
yield* emit(zodOpenAPIHono(openAPI, componentsOptions), path.dirname(output), output);
|
|
2511
2501
|
return `🔥 Generated code written to ${output}`;
|
|
2512
2502
|
});
|
|
2513
2503
|
}
|
|
2514
|
-
|
|
2515
|
-
//#region src/generator/zod-openapi-hono/app/index.ts
|
|
2504
|
+
// src/generator/zod-openapi-hono/app/index.ts
|
|
2516
2505
|
/** The handler files the operations of a document are written to, in document order. */
|
|
2517
2506
|
function handlerFilesOf(openapi) {
|
|
2518
2507
|
return [...new Set(Object.entries(openapi.paths).flatMap(([path, pathItem]) => Object.entries(pathItem).flatMap(([method, operation]) => isHttpMethod(method) && isOperation(operation) ? [makeHandlerFileName(path, operation.tags)] : [])))];
|
|
@@ -2625,8 +2614,7 @@ function app(openapi, output, basePath, pathAlias, routeImport, routeHandler = f
|
|
|
2625
2614
|
appExport
|
|
2626
2615
|
].join("\n\n");
|
|
2627
2616
|
}
|
|
2628
|
-
|
|
2629
|
-
//#region src/core/template/define.ts
|
|
2617
|
+
// src/core/template/define.ts
|
|
2630
2618
|
function defineTemplate(openAPI, output, componentsOutput, basePath, pathAlias, routeImport, readonly, split = false, componentsPackage) {
|
|
2631
2619
|
const target = output.endsWith(".ts") ? output : path.join(output, "index.ts");
|
|
2632
2620
|
const baseDir = path.dirname(target);
|
|
@@ -2642,8 +2630,7 @@ function defineTemplate(openAPI, output, componentsOutput, basePath, pathAlias,
|
|
|
2642
2630
|
return "🔥 Generated code and template files written";
|
|
2643
2631
|
});
|
|
2644
2632
|
}
|
|
2645
|
-
|
|
2646
|
-
//#region src/core/template/index.ts
|
|
2633
|
+
// src/core/template/index.ts
|
|
2647
2634
|
function template(openAPI, output, basePath, pathAlias, routeImport, routeHandler, split = false) {
|
|
2648
2635
|
return Effect.gen(function* () {
|
|
2649
2636
|
const target = makeAppEntryFile(output, false);
|
|
@@ -2657,8 +2644,7 @@ function template(openAPI, output, basePath, pathAlias, routeImport, routeHandle
|
|
|
2657
2644
|
return "🔥 Generated code and template files written";
|
|
2658
2645
|
});
|
|
2659
2646
|
}
|
|
2660
|
-
|
|
2661
|
-
//#region src/core/webhooks/index.ts
|
|
2647
|
+
// src/core/webhooks/index.ts
|
|
2662
2648
|
function webhooks(openAPI, webhooks, components, readonly) {
|
|
2663
2649
|
return Effect.gen(function* () {
|
|
2664
2650
|
if (!webhooks?.output) return yield* new GenerateError({ message: "webhooks.output is required" });
|
|
@@ -2679,8 +2665,7 @@ function webhooks(openAPI, webhooks, components, readonly) {
|
|
|
2679
2665
|
return `Generated webhooks code written to ${outDir}/*.ts (index.ts included)`;
|
|
2680
2666
|
});
|
|
2681
2667
|
}
|
|
2682
|
-
|
|
2683
|
-
//#region src/core/index.ts
|
|
2668
|
+
// src/core/index.ts
|
|
2684
2669
|
var core_exports = /* @__PURE__ */ __exportAll({
|
|
2685
2670
|
callbacks: () => callbacks,
|
|
2686
2671
|
client: () => client,
|
|
@@ -2706,5 +2691,4 @@ var core_exports = /* @__PURE__ */ __exportAll({
|
|
|
2706
2691
|
type: () => type,
|
|
2707
2692
|
webhooks: () => webhooks
|
|
2708
2693
|
});
|
|
2709
|
-
//#endregion
|
|
2710
2694
|
export { isInsideDirectory as C, makeGeneratedImport as E, appEntryOutput as S, makeAppEntryImport as T, headers as _, takibi as a, client as b, securitySchemes as c, requestBodies as d, pathItems as f, links as g, mediaTypes as h, defineTemplate as i, schemas as l, components as m, webhooks as n, route as o, parameters as p, template as r, mock as s, core_exports as t, responses as u, examples as v, makeAppEntryFile as w, handlerGroupOf as x, callbacks as y };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { n as mkdir, o as writeFile } from "./file-
|
|
1
|
+
import { $ as MULTIPART_MEDIA_TYPE, N as isSchemaArray, O as isRecord, Y as HTTP_METHODS, k as isRefObject } from "./guard-BH6yBr0M.js";
|
|
2
|
+
import { i as decodePercent, s as escapeHtml } from "./utils-CDLiYepO.js";
|
|
3
|
+
import { n as mkdir, o as writeFile } from "./file-Bip_L0oR.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { STATUS_CODES } from "node:http";
|
|
7
|
-
|
|
7
|
+
// src/generator/docs/index.ts
|
|
8
8
|
const documentCaches = /* @__PURE__ */ new WeakMap();
|
|
9
9
|
function cacheOf(doc) {
|
|
10
10
|
const found = documentCaches.get(doc);
|
|
@@ -101,18 +101,24 @@ function componentSchemaName(ref) {
|
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* Lower-cased anchor suffix of a schema. Names that differ only in case would
|
|
104
|
-
* share it, so every one after the first gets a numeric suffix.
|
|
104
|
+
* share it, so every one after the first gets a numeric suffix. The anchors of every
|
|
105
|
+
* schema are given in one pass over the names, the first time one is asked for: asked
|
|
106
|
+
* one at a time, each would read every name again, which on a document of thousands of
|
|
107
|
+
* schemas took longer than the rest of the docs.
|
|
105
108
|
*/
|
|
106
109
|
function schemaAnchor(name, doc) {
|
|
107
110
|
const { anchors } = cacheOf(doc);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
if (anchors.size === 0) {
|
|
112
|
+
const schemas = doc.components?.schemas;
|
|
113
|
+
const seen = /* @__PURE__ */ new Map();
|
|
114
|
+
for (const key of isRecord(schemas) ? Object.keys(schemas) : []) {
|
|
115
|
+
const lower = key.toLowerCase();
|
|
116
|
+
const index = seen.get(lower) ?? 0;
|
|
117
|
+
seen.set(lower, index + 1);
|
|
118
|
+
anchors.set(key, index > 0 ? `${lower}-${index}` : lower);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return anchors.get(name) ?? name.toLowerCase();
|
|
116
122
|
}
|
|
117
123
|
/** A `$ref` to a schema under `components.schemas`: linked in a table, listed under Schemas. */
|
|
118
124
|
function isComponentRef(schema) {
|
|
@@ -1409,8 +1415,7 @@ function makeDocs(openAPI, entry = "src/index.ts", basePath = "/", curl = false,
|
|
|
1409
1415
|
...makeSchemasSection(openAPI)
|
|
1410
1416
|
].join("\n");
|
|
1411
1417
|
}
|
|
1412
|
-
|
|
1413
|
-
//#region src/core/docs/index.ts
|
|
1418
|
+
// src/core/docs/index.ts
|
|
1414
1419
|
function docs(openAPI, output, entry = "src/index.ts", basePath = "/", curl = false, baseUrl) {
|
|
1415
1420
|
return Effect.gen(function* () {
|
|
1416
1421
|
const markdown = makeDocs(openAPI, entry, basePath, curl, baseUrl);
|
|
@@ -1419,5 +1424,4 @@ function docs(openAPI, output, entry = "src/index.ts", basePath = "/", curl = fa
|
|
|
1419
1424
|
return `Generated docs written to ${output}`;
|
|
1420
1425
|
});
|
|
1421
1426
|
}
|
|
1422
|
-
//#endregion
|
|
1423
1427
|
export { docs as t };
|