hono-takibi 0.31.0 → 0.32.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 +8 -8
- package/dist/core/docs/index.d.ts +1 -1
- package/dist/core/docs/index.js +1 -1
- package/dist/core/hooks/index.d.ts +2 -2
- package/dist/core/hooks/index.js +1 -1
- package/dist/core/rpc/index.d.ts +2 -2
- package/dist/core/rpc/index.js +4 -4
- package/dist/core/type/index.d.ts +1 -1
- package/dist/core/type/index.js +11 -12
- package/dist/{core-Dr2bFSj6.js → core-BErYCEq-.js} +51 -57
- package/dist/{docs-B35NJDqJ.js → docs-DC7Q_-PY.js} +25 -23
- package/dist/{emit-uG6QWP1c.js → emit-8SmO5pHF.js} +1 -1
- package/dist/{file-Bip_L0oR.js → file-hO_bjDys.js} +3 -3
- package/dist/generate/index.js +3 -7
- package/dist/generator/mock/index.d.ts +1 -1
- package/dist/generator/mock/index.js +1 -1
- 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/{guard-BNQ9WfOm.js → guard-Rvg4ztIZ.js} +13 -4
- package/dist/{hooks-Bjzy2N8f.js → hooks-B2Fcpr_z.js} +4 -4
- package/dist/{index-nkUsldwj.d.ts → index-3KCqBGY8.d.ts} +1 -1
- package/dist/{index-DN54hj9W.d.ts → index-BKV6o2oF.d.ts} +1 -1
- package/dist/index.js +2 -2
- package/dist/{mock-BKLmjjh-.js → mock-D2cCG7D7.js} +34 -33
- package/dist/{openapi-OPxB_-2_.js → openapi-B8oA5BKZ.js} +12 -8
- package/dist/openapi-BxSVfs_l.js +34 -0
- package/dist/{routes-De93FgAf.js → routes-BaXZEgTP.js} +111 -86
- package/dist/{rpc-B7PiQ1sR.js → rpc-yhnsv_ji.js} +3 -3
- package/dist/{shared-Dj8C8Wcq.js → shared-BohdqQVB.js} +8 -8
- package/dist/{utils-BhQ-YVD3.js → utils-yHmzthJJ.js} +23 -30
- package/dist/vite-plugin/index.js +4 -4
- package/package.json +1 -1
- package/dist/openapi-DCo11_TE.js +0 -96
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { _ as isInputPath,
|
|
2
|
+
import { _ as isInputPath, tt as INPUT_EXTENSIONS } from "./guard-Rvg4ztIZ.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
|
// package.json
|
|
8
|
-
var version = "0.
|
|
8
|
+
var version = "0.32.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";
|
|
@@ -39,9 +39,9 @@ function loadConfig(configPath, reload) {
|
|
|
39
39
|
function runJobs(config) {
|
|
40
40
|
return Effect.gen(function* () {
|
|
41
41
|
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob, openAPI3, packageRoots }] = yield* Effect.promise(() => Promise.all([
|
|
42
|
-
import("./openapi-
|
|
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-BohdqQVB.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-BohdqQVB.js").then((n) => n.o));
|
|
83
83
|
const inputDirectory = path.dirname(path.resolve(config.input));
|
|
84
84
|
return {
|
|
85
85
|
inputDirectory,
|
|
@@ -207,9 +207,9 @@ function generate(args) {
|
|
|
207
207
|
});
|
|
208
208
|
if (input !== void 0 && output !== void 0) {
|
|
209
209
|
const [{ parseOpenAPI }, { takibi }, { openAPI3 }] = yield* Effect.promise(() => Promise.all([
|
|
210
|
-
import("./openapi-
|
|
211
|
-
import("./core-
|
|
212
|
-
import("./shared-
|
|
210
|
+
import("./openapi-BxSVfs_l.js").then((n) => n.t),
|
|
211
|
+
import("./core-BErYCEq-.js").then((n) => n.t),
|
|
212
|
+
import("./shared-BohdqQVB.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));
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as OpenAPI } from "../../index-
|
|
1
|
+
import { t as OpenAPI } from "../../index-BKV6o2oF.js";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
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-DC7Q_-PY.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as GenerateError, t as FormatError } from "../../index-sZ1C8djg.js";
|
|
2
|
-
import { t as Grouping } from "../../index-
|
|
3
|
-
import { t as OpenAPI } from "../../index-
|
|
2
|
+
import { t as Grouping } from "../../index-3KCqBGY8.js";
|
|
3
|
+
import { t as OpenAPI } from "../../index-BKV6o2oF.js";
|
|
4
4
|
declare const HOOK_CONFIGS: {
|
|
5
5
|
readonly swr: {
|
|
6
6
|
readonly packageName: 'swr';
|
package/dist/core/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as hooks } from "../../hooks-
|
|
1
|
+
export { t as hooks } from "../../hooks-B2Fcpr_z.js";
|
package/dist/core/rpc/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as GenerateError, t as FormatError } from "../../index-sZ1C8djg.js";
|
|
2
|
-
import { t as Grouping } from "../../index-
|
|
3
|
-
import { t as OpenAPI } from "../../index-
|
|
2
|
+
import { t as Grouping } from "../../index-3KCqBGY8.js";
|
|
3
|
+
import { t as OpenAPI } from "../../index-BKV6o2oF.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
/**
|
|
6
6
|
* Generates RPC client wrapper functions from OpenAPI specification.
|
package/dist/core/rpc/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as emit } from "../../emit-
|
|
1
|
+
import { $ as HTTP_METHODS, C as isOperationLike, M as isRecord, x as isOpenAPIPaths } from "../../guard-Rvg4ztIZ.js";
|
|
2
|
+
import { t as emit } from "../../emit-8SmO5pHF.js";
|
|
3
3
|
import { i as GenerateError } from "../../format-BF7SbaMP.js";
|
|
4
|
-
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-
|
|
5
|
-
import { _ as routeName, u as makeInferRequestType } from "../../utils-
|
|
4
|
+
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-yhnsv_ji.js";
|
|
5
|
+
import { _ as routeName, u as makeInferRequestType } from "../../utils-yHmzthJJ.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import { dirname } from "node:path";
|
|
8
8
|
// src/core/rpc/index.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as FormatError } from "../../index-sZ1C8djg.js";
|
|
2
|
-
import { t as OpenAPI } from "../../index-
|
|
2
|
+
import { t as OpenAPI } from "../../index-BKV6o2oF.js";
|
|
3
3
|
import { Effect } from "effect";
|
|
4
4
|
/**
|
|
5
5
|
* Generates TypeScript type declarations from OpenAPI specification.
|
package/dist/core/type/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as emit } from "../../emit-
|
|
3
|
-
import { d as makeSafeKey, v as statusCodeToNumber, y as toIdentifierPascalCase } from "../../utils-
|
|
1
|
+
import { F as isRequestBody, L as isSchemaArray, S as isOperation, T as isParameterArray, U as isStringRef, j as isPresent, l as isBinaryFile, m as isHttpMethod, w as isParameter, x as isOpenAPIPaths, y as isMediaWithSchema } from "../../guard-Rvg4ztIZ.js";
|
|
2
|
+
import { t as emit } from "../../emit-8SmO5pHF.js";
|
|
3
|
+
import { d as makeSafeKey, v as statusCodeToNumber, y as toIdentifierPascalCase } from "../../utils-yHmzthJJ.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
// src/core/type/index.ts
|
|
@@ -94,7 +94,7 @@ function makeInputType(operation, openApiPath, aliases, pathLevelParams) {
|
|
|
94
94
|
return parts.length === 0 ? "{}" : parts.join("&");
|
|
95
95
|
}
|
|
96
96
|
function makePathParams(openApiPath) {
|
|
97
|
-
return [...openApiPath.matchAll(/\{([^}]+)\}/gu)].
|
|
97
|
+
return [...openApiPath.matchAll(/\{([^}]+)\}/gu)].flatMap((m) => m[1] ?? []);
|
|
98
98
|
}
|
|
99
99
|
function makeParamPart(params, aliases) {
|
|
100
100
|
const props = params.map((p) => {
|
|
@@ -137,7 +137,7 @@ function makeBodyParts(requestBody, aliases) {
|
|
|
137
137
|
return [classified.jsonTypes.length > 0 ? `{json:${classified.jsonTypes.length === 1 ? classified.jsonTypes[0] : `(${classified.jsonTypes.join("|")})`}}` : void 0, classified.formTypes.length > 0 ? `{form:${classified.formTypes.length === 1 ? classified.formTypes[0] : `(${classified.formTypes.join("|")})`}}` : void 0].filter((p) => p !== void 0);
|
|
138
138
|
}
|
|
139
139
|
function makeOutputTypes(responses, aliases, inputType) {
|
|
140
|
-
return Object.entries(responses).flatMap(([statusCode, response]) => {
|
|
140
|
+
return Object.entries(responses ?? {}).flatMap(([statusCode, response]) => {
|
|
141
141
|
const resolvedResponse = makeResolvedResponse(response, aliases.components);
|
|
142
142
|
const status = statusCodeToNumber(statusCode);
|
|
143
143
|
if (!resolvedResponse.content) return [`{input:${inputType};output:{};outputFormat:string;status:${status}}`];
|
|
@@ -158,7 +158,7 @@ function makeResolvedParameter(parameter, components) {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
function makeResolvedRequestBody(requestBody, components) {
|
|
161
|
-
if (
|
|
161
|
+
if (typeof requestBody !== "object" || requestBody === null) return void 0;
|
|
162
162
|
if (isRequestBody(requestBody) && !isStringRef(requestBody)) return requestBody;
|
|
163
163
|
if (isStringRef(requestBody) && components?.requestBodies) {
|
|
164
164
|
const refName = requestBody.$ref.split("/").at(-1);
|
|
@@ -188,7 +188,7 @@ function makeParameterSchema(parameter) {
|
|
|
188
188
|
return parameter.schema ?? {};
|
|
189
189
|
}
|
|
190
190
|
function makeSchemaTypeString(schema, aliases, visited) {
|
|
191
|
-
if (!schema) return "unknown";
|
|
191
|
+
if (!isPresent(schema)) return "unknown";
|
|
192
192
|
if (schema.$ref) return makeRefTypeString(schema.$ref, aliases);
|
|
193
193
|
if (schema.oneOf && schema.oneOf.length > 0) return schema.oneOf.map((s) => makeSchemaTypeString(s, aliases, visited)).join("|");
|
|
194
194
|
if (schema.anyOf && schema.anyOf.length > 0) return schema.anyOf.map((s) => makeSchemaTypeString(s, aliases, visited)).join("|");
|
|
@@ -203,14 +203,14 @@ function makeSchemaTypeString(schema, aliases, visited) {
|
|
|
203
203
|
}
|
|
204
204
|
const types = makeNormalizedTypes(schema);
|
|
205
205
|
const isNullable = schema.nullable === true || types.includes("null");
|
|
206
|
-
const baseType = makeBaseTypeString(schema, types.filter((
|
|
206
|
+
const baseType = makeBaseTypeString(schema, types.filter((typeName) => typeName !== "null"), aliases, visited);
|
|
207
207
|
return isNullable ? `(${baseType}|null)` : baseType;
|
|
208
208
|
}
|
|
209
209
|
function makeNormalizedTypes(schema) {
|
|
210
|
-
return schema.type ? Array.isArray(schema.type) ? schema.type : [schema.type]
|
|
210
|
+
return schema.type === void 0 ? ["object"] : Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
211
211
|
}
|
|
212
212
|
function makeBaseTypeString(schema, types, aliases, visited) {
|
|
213
|
-
return types.length > 1 ? types.map((
|
|
213
|
+
return types.length > 1 ? types.map((typeName) => makeSingleTypeString(schema, typeName, aliases, visited)).join("|") : makeSingleTypeString(schema, types[0] ?? "object", aliases, visited);
|
|
214
214
|
}
|
|
215
215
|
const PRIMITIVE_TYPE_MAP = {
|
|
216
216
|
boolean: "boolean",
|
|
@@ -278,9 +278,8 @@ function makePropertyMap(schema, aliases, visited) {
|
|
|
278
278
|
return new Map([...fromAllOf, ...currentProps]);
|
|
279
279
|
}
|
|
280
280
|
function makeArrayTypeString(schema, aliases, visited) {
|
|
281
|
-
if (!schema.items) return "unknown[]";
|
|
281
|
+
if (!isPresent(schema.items) || schema.items === true) return "unknown[]";
|
|
282
282
|
const items = schema.items;
|
|
283
|
-
if (typeof items === "boolean") return items ? "unknown[]" : "[]";
|
|
284
283
|
if (isSchemaArray(items)) return items.length > 1 ? `[${items.map((item) => makeSchemaTypeString(item, aliases, visited)).join(",")}]` : items[0] ? makeWrappedArrayType(makeSchemaTypeString(items[0], aliases, visited)) : "unknown[]";
|
|
285
284
|
return makeWrappedArrayType(makeSchemaTypeString(items, aliases, visited));
|
|
286
285
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
|
-
import {
|
|
2
|
+
import { $ as HTTP_METHODS, G as isValidIdent, M as isRecord, O as isPathItem, S as isOperation, k as isPathItemEntry, m as isHttpMethod, q as COMPONENT_NAMES, u as isCallbacks, x as isOpenAPIPaths } from "./guard-Rvg4ztIZ.js";
|
|
3
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, h as renderNamedImport, l as makeBarrel, x as uncapitalizeWord, y as toIdentifierPascalCase } from "./utils-
|
|
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-
|
|
6
|
-
import { t as zodOpenAPIHono } from "./openapi-
|
|
7
|
-
import { t as makeMock } from "./mock-
|
|
8
|
-
import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-
|
|
9
|
-
import { i as readdir, n as mkdir, o as writeFile, r as readFile } from "./file-
|
|
10
|
-
import { t as emit } from "./emit-
|
|
11
|
-
import { t as hooks } from "./hooks-
|
|
12
|
-
import { t as docs } from "./docs-
|
|
4
|
+
import { S as zodToOpenAPISchema, _ as routeName, a as ensureSuffix, b as uncapitalize, c as escapeRegexLiteral, h as renderNamedImport, l as makeBarrel, x as uncapitalizeWord, y as toIdentifierPascalCase } from "./utils-yHmzthJJ.js";
|
|
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-BaXZEgTP.js";
|
|
6
|
+
import { t as zodOpenAPIHono } from "./openapi-B8oA5BKZ.js";
|
|
7
|
+
import { t as makeMock } from "./mock-D2cCG7D7.js";
|
|
8
|
+
import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-yhnsv_ji.js";
|
|
9
|
+
import { i as readdir, n as mkdir, o as writeFile, r as readFile } from "./file-hO_bjDys.js";
|
|
10
|
+
import { t as emit } from "./emit-8SmO5pHF.js";
|
|
11
|
+
import { t as hooks } from "./hooks-B2Fcpr_z.js";
|
|
12
|
+
import { t as docs } from "./docs-DC7Q_-PY.js";
|
|
13
13
|
import { rpc } from "./core/rpc/index.js";
|
|
14
14
|
import { type } from "./core/type/index.js";
|
|
15
15
|
import { Effect } from "effect";
|
|
@@ -438,10 +438,10 @@ function mergeImports(existingFile, generatedFile, dropStaleAutoNames = true) {
|
|
|
438
438
|
return [...mergeImportEntries([...filterExistingImports(existingImports, makeGeneratedImportIndex(generatedImports), dropStaleAutoNames), ...generatedImports]).entries()].flatMap(([spec, info]) => formatImportLine(spec, info));
|
|
439
439
|
}
|
|
440
440
|
function parseImportDeclarations(source) {
|
|
441
|
-
return source.program.body.filter((statement) => statement.type === "ImportDeclaration").map((
|
|
442
|
-
const defaultImport =
|
|
443
|
-
const namespaceImport =
|
|
444
|
-
const namedImports =
|
|
441
|
+
return source.program.body.filter((statement) => statement.type === "ImportDeclaration").map((declaration) => {
|
|
442
|
+
const defaultImport = declaration.specifiers.find((specifier) => specifier.type === "ImportDefaultSpecifier");
|
|
443
|
+
const namespaceImport = declaration.specifiers.find((specifier) => specifier.type === "ImportNamespaceSpecifier");
|
|
444
|
+
const namedImports = declaration.specifiers.flatMap((specifier) => {
|
|
445
445
|
if (specifier.type !== "ImportSpecifier") return [];
|
|
446
446
|
return [{
|
|
447
447
|
name: textOf(source.code, specifier.imported),
|
|
@@ -450,12 +450,12 @@ function parseImportDeclarations(source) {
|
|
|
450
450
|
}];
|
|
451
451
|
});
|
|
452
452
|
return {
|
|
453
|
-
moduleSpecifier:
|
|
454
|
-
isTypeOnlyImport:
|
|
453
|
+
moduleSpecifier: declaration.source.value,
|
|
454
|
+
isTypeOnlyImport: declaration.importKind === "type",
|
|
455
455
|
defaultImport: defaultImport?.local.name,
|
|
456
456
|
namespaceImport: namespaceImport?.local.name,
|
|
457
457
|
namedImports,
|
|
458
|
-
isSideEffectOnly:
|
|
458
|
+
isSideEffectOnly: declaration.specifiers.length === 0
|
|
459
459
|
};
|
|
460
460
|
});
|
|
461
461
|
}
|
|
@@ -557,11 +557,11 @@ function formatImportLine(moduleSpecifier, info) {
|
|
|
557
557
|
* Returns empty string if there is no prefix chain.
|
|
558
558
|
*/
|
|
559
559
|
function extractChainPrefix(apiStmtText, app) {
|
|
560
|
-
const initMatch =
|
|
560
|
+
const initMatch = new RegExp(String.raw`[=]\s*${escapeRegexLiteral(app)}\b`, "u").exec(apiStmtText);
|
|
561
561
|
if (initMatch?.index === void 0) return "";
|
|
562
562
|
const afterApp = apiStmtText.slice(initMatch.index + initMatch[0].length);
|
|
563
|
-
const routeMatch =
|
|
564
|
-
if (!routeMatch || routeMatch.index ===
|
|
563
|
+
const routeMatch = /\.(?:openapiRoutes|openapi|route)\s*\(/u.exec(afterApp);
|
|
564
|
+
if (!routeMatch || routeMatch.index === 0) return "";
|
|
565
565
|
const candidate = afterApp.slice(0, routeMatch.index).trim();
|
|
566
566
|
return candidate.startsWith(".") ? candidate : "";
|
|
567
567
|
}
|
|
@@ -601,9 +601,9 @@ function mergeInlineHandler(existingText, generatedText) {
|
|
|
601
601
|
const generatedCalls = extractOpenApiCalls(generatedText);
|
|
602
602
|
if (generatedCalls.size === 0) return generatedText;
|
|
603
603
|
const existingCalls = extractOpenApiCalls(existingText);
|
|
604
|
-
const firstCallMatch =
|
|
604
|
+
const firstCallMatch = /\.openapi\s*\(/u.exec(generatedText);
|
|
605
605
|
if (firstCallMatch?.index === void 0) return generatedText;
|
|
606
|
-
const existingFirstCall =
|
|
606
|
+
const existingFirstCall = /\.openapi\s*\(/u.exec(existingText);
|
|
607
607
|
return `${existingCalls.size > 0 && existingFirstCall?.index !== void 0 ? existingText.slice(0, existingFirstCall.index).trimEnd() : generatedText.slice(0, firstCallMatch.index).trimEnd()}\n${[...generatedCalls.entries()].map(([routeName, genCall]) => existingCalls.get(routeName) ?? genCall).join("\n")}`;
|
|
608
608
|
}
|
|
609
609
|
/**
|
|
@@ -640,11 +640,11 @@ function exportDeclarations(source) {
|
|
|
640
640
|
function mergeBarrelFile(existingCode, generatedCode) {
|
|
641
641
|
const { existingFile, generatedFile } = makeSourcePair(existingCode, generatedCode);
|
|
642
642
|
if (existingFile.errors.length > 0) return existingCode;
|
|
643
|
-
const existingModules = new Set(exportDeclarations(existingFile).map((
|
|
644
|
-
const missingExports = exportDeclarations(generatedFile).filter((
|
|
645
|
-
const spec =
|
|
643
|
+
const existingModules = new Set(exportDeclarations(existingFile).map((declaration) => declaration.specifier).filter((spec) => spec !== void 0).map((spec) => spec.replace(/\.(?:js|ts)$/u, "")));
|
|
644
|
+
const missingExports = exportDeclarations(generatedFile).filter((declaration) => {
|
|
645
|
+
const spec = declaration.specifier;
|
|
646
646
|
return spec !== void 0 && !existingModules.has(spec.replace(/\.(?:js|ts)$/u, ""));
|
|
647
|
-
}).map((
|
|
647
|
+
}).map((declaration) => declaration.text);
|
|
648
648
|
if (missingExports.length === 0) return existingCode;
|
|
649
649
|
const base = existingCode.trimEnd();
|
|
650
650
|
return `${base ? `${base}\n` : ""}${missingExports.join("\n")}\n`;
|
|
@@ -716,7 +716,7 @@ function appEntryOutput(config) {
|
|
|
716
716
|
}
|
|
717
717
|
// src/helper/handler.ts
|
|
718
718
|
function sanitizeHandlerSegment(segment) {
|
|
719
|
-
return segment.replaceAll(/\{([^}]+)\}/gu, "$1").replaceAll(/[^0-9A-Za-z._-]/gu, "_").replaceAll(/^[._-]+|[._-]+$/gu, "").replaceAll(/__+/gu, "_").replaceAll(/[-._](\w)/gu, (_,
|
|
719
|
+
return segment.replaceAll(/\{([^}]+)\}/gu, "$1").replaceAll(/[^0-9A-Za-z._-]/gu, "_").replaceAll(/^[._-]+|[._-]+$/gu, "").replaceAll(/__+/gu, "_").replaceAll(/[-._](\w)/gu, (_, char) => char.toUpperCase());
|
|
720
720
|
}
|
|
721
721
|
/**
|
|
722
722
|
* Derives the handler file name for an operation: the first tag (lower camel case) when
|
|
@@ -835,7 +835,7 @@ function makeStubFileContent(handler, importFrom) {
|
|
|
835
835
|
return `${`import type { RouteHandler } from '@hono/zod-openapi'\n${routeTypes ? `import type { ${routeTypes} } from '${importFrom}';` : ""}`}\n\n${handler.contents.join("\n\n")}`;
|
|
836
836
|
}
|
|
837
837
|
function makeBarrelContent(fileNames) {
|
|
838
|
-
return fileNames.map((
|
|
838
|
+
return fileNames.map((fileName) => `export * from './${basename(fileName, ".ts")}'`).join("\n");
|
|
839
839
|
}
|
|
840
840
|
/** oxfmt, keeping the source as-is when it will not parse what we just built. */
|
|
841
841
|
function fmtOrKeep(source) {
|
|
@@ -880,14 +880,14 @@ function zodOpenAPIHonoHandler(openapi, output, pathAlias, routeImport, routeHan
|
|
|
880
880
|
const { handlerPath, importFrom } = makePaths(output, pathAlias, routeImport);
|
|
881
881
|
const existing = yield* scanExistingHandlerFiles(handlerPath, routeHandler ? (code) => collectExportedNames(code, "RouteHandler") : collectInlineRouteNames);
|
|
882
882
|
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))));
|
|
883
|
-
const handlers = [...specHandlers, ...makeOrphanHandlers(existing, specHandlers.map((
|
|
883
|
+
const handlers = [...specHandlers, ...makeOrphanHandlers(existing, specHandlers.map((handler) => handler.fileName))];
|
|
884
884
|
yield* mkdir(handlerPath);
|
|
885
885
|
yield* Effect.all([...handlers.map((handler) => writeHandler({
|
|
886
886
|
handlerPath,
|
|
887
887
|
handler,
|
|
888
888
|
fileContent: routeHandler ? makeStubFileContent(handler, importFrom) : makeInlineStubFileContent(handler, importFrom),
|
|
889
889
|
merge: mergeHandlerFile
|
|
890
|
-
})), writeBarrel(handlerPath, handlers.map((
|
|
890
|
+
})), writeBarrel(handlerPath, handlers.map((handler) => handler.fileName))], { concurrency: "unbounded" });
|
|
891
891
|
});
|
|
892
892
|
}
|
|
893
893
|
/**
|
|
@@ -938,7 +938,7 @@ function defineOpenAPIRouteHandler(openapi, output, componentsOutput, pathAlias,
|
|
|
938
938
|
handler,
|
|
939
939
|
fileContent: makeImports(handler.contents.join("\n\n"), `${handlerPath}/${handler.fileName}`, componentsMap, false, ["defineOpenAPIRoute"]),
|
|
940
940
|
merge: mergeDefineFile
|
|
941
|
-
})), writeBarrel(handlerPath, handlerList.map((
|
|
941
|
+
})), writeBarrel(handlerPath, handlerList.map((handler) => handler.fileName))], { concurrency: "unbounded" });
|
|
942
942
|
});
|
|
943
943
|
}
|
|
944
944
|
// src/core/client/index.ts
|
|
@@ -1074,7 +1074,7 @@ function examples(examples, output, split, readonly) {
|
|
|
1074
1074
|
const v = examples[k];
|
|
1075
1075
|
const name = toIdentifierPascalCase(ensureSuffix(k, "Example"));
|
|
1076
1076
|
const filePath = path.join(outDir, `${uncapitalize(k)}.ts`);
|
|
1077
|
-
if (
|
|
1077
|
+
if (isRecord(v) && "$ref" in v && typeof v.$ref === "string") {
|
|
1078
1078
|
const refName = makeRef(v.$ref);
|
|
1079
1079
|
const refKey = v.$ref.split("/").at(-1) ?? "";
|
|
1080
1080
|
const body = `import { ${refName} } from '${`./${uncapitalize(refKey)}`}'\n\nexport const ${name} = ${refName}\n`;
|
|
@@ -1094,13 +1094,11 @@ function examples(examples, output, split, readonly) {
|
|
|
1094
1094
|
function headers(headers, output, split, exportType, components, readonly) {
|
|
1095
1095
|
return Effect.gen(function* () {
|
|
1096
1096
|
if (!headers) return yield* new GenerateError({ message: "No headers found" });
|
|
1097
|
-
|
|
1098
|
-
if (headerNames.length === 0) return "No headers found";
|
|
1097
|
+
if (Object.keys(headers).length === 0) return "No headers found";
|
|
1099
1098
|
if (split) {
|
|
1100
1099
|
const outDir = path.join(path.dirname(output), path.basename(output, ".ts"));
|
|
1101
|
-
yield* Effect.all([...
|
|
1102
|
-
const
|
|
1103
|
-
const code = headersCode(singleComponent, true, exportType, readonly);
|
|
1100
|
+
yield* Effect.all([...Object.entries(headers).map(([headerName, header]) => {
|
|
1101
|
+
const code = headersCode({ headers: { [headerName]: header } }, true, exportType, readonly);
|
|
1104
1102
|
const filePath = path.join(outDir, `${uncapitalize(headerName)}.ts`);
|
|
1105
1103
|
return emit(makeImports(code, filePath, components, split), path.dirname(filePath), filePath);
|
|
1106
1104
|
}), emit(makeBarrel(headers), outDir, path.join(outDir, "index.ts"))], { concurrency: "unbounded" });
|
|
@@ -1147,12 +1145,12 @@ function mediaTypes(mediaTypes, output, split, readonly, components) {
|
|
|
1147
1145
|
const v = mediaTypes[k];
|
|
1148
1146
|
const name = toIdentifierPascalCase(ensureSuffix(k, "MediaTypeSchema"));
|
|
1149
1147
|
const filePath = path.join(outDir, `${uncapitalize(k)}.ts`);
|
|
1150
|
-
if (
|
|
1148
|
+
if (isRecord(v) && "$ref" in v && v.$ref) {
|
|
1151
1149
|
const refKey = v.$ref.split("/").at(-1) ?? "";
|
|
1152
1150
|
const body = `export const ${name} = ${toIdentifierPascalCase(ensureSuffix(refKey, "MediaTypeSchema"))}\n`;
|
|
1153
1151
|
return emit(makeImports(body, filePath, components, split), path.dirname(filePath), filePath);
|
|
1154
1152
|
}
|
|
1155
|
-
if (
|
|
1153
|
+
if (isRecord(v) && "schema" in v) {
|
|
1156
1154
|
const zodCode = zodToOpenAPI(v.schema, void 0, options);
|
|
1157
1155
|
const schemaCode = zodToOpenAPISchema(name, zodCode, true, false, true);
|
|
1158
1156
|
return emit(makeImports(schemaCode, filePath, components, split), path.dirname(filePath), filePath);
|
|
@@ -1165,11 +1163,11 @@ function mediaTypes(mediaTypes, output, split, readonly, components) {
|
|
|
1165
1163
|
const code = `${importCode}\n\n${keys.map((k) => {
|
|
1166
1164
|
const v = mediaTypes[k];
|
|
1167
1165
|
const name = toIdentifierPascalCase(ensureSuffix(k, "MediaTypeSchema"));
|
|
1168
|
-
if (
|
|
1166
|
+
if (isRecord(v) && "$ref" in v && v.$ref) {
|
|
1169
1167
|
const refKey = v.$ref.split("/").at(-1) ?? "";
|
|
1170
1168
|
return `export const ${name} = ${toIdentifierPascalCase(ensureSuffix(refKey, "MediaTypeSchema"))}`;
|
|
1171
1169
|
}
|
|
1172
|
-
if (
|
|
1170
|
+
if (isRecord(v) && "schema" in v) {
|
|
1173
1171
|
const zodCode = zodToOpenAPI(v.schema, void 0, options);
|
|
1174
1172
|
return zodToOpenAPISchema(name, zodCode, true, false, true);
|
|
1175
1173
|
}
|
|
@@ -1211,13 +1209,12 @@ function components(openAPI, output, readonly) {
|
|
|
1211
1209
|
function parameters(parameters, output, split, exportType, components, readonly, schemas) {
|
|
1212
1210
|
return Effect.gen(function* () {
|
|
1213
1211
|
if (!parameters) return yield* new GenerateError({ message: "No parameters found" });
|
|
1214
|
-
|
|
1215
|
-
if (parameterNames.length === 0) return "No parameters found";
|
|
1212
|
+
if (Object.keys(parameters).length === 0) return "No parameters found";
|
|
1216
1213
|
if (split) {
|
|
1217
1214
|
const outDir = path.join(path.dirname(output), path.basename(output, ".ts"));
|
|
1218
|
-
yield* Effect.all([...
|
|
1215
|
+
yield* Effect.all([...Object.entries(parameters).map(([parameterName, parameter]) => {
|
|
1219
1216
|
const singleComponent = {
|
|
1220
|
-
parameters: { [parameterName]:
|
|
1217
|
+
parameters: { [parameterName]: parameter },
|
|
1221
1218
|
...schemas === void 0 ? {} : { schemas }
|
|
1222
1219
|
};
|
|
1223
1220
|
const code = parametersCode(singleComponent, true, exportType, readonly);
|
|
@@ -1269,13 +1266,12 @@ function pathItems(components, pathItemsConfig, componentsConfig, readonly) {
|
|
|
1269
1266
|
function requestBodies(requestBodies, output, split, components, readonly, schemas) {
|
|
1270
1267
|
return Effect.gen(function* () {
|
|
1271
1268
|
if (!requestBodies) return yield* new GenerateError({ message: "No requestBodies found" });
|
|
1272
|
-
|
|
1273
|
-
if (bodyNames.length === 0) return "No requestBodies found";
|
|
1269
|
+
if (Object.keys(requestBodies).length === 0) return "No requestBodies found";
|
|
1274
1270
|
if (split) {
|
|
1275
1271
|
const outDir = path.join(path.dirname(output), path.basename(output, ".ts"));
|
|
1276
|
-
yield* Effect.all([...
|
|
1272
|
+
yield* Effect.all([...Object.entries(requestBodies).map(([bodyName, requestBody]) => {
|
|
1277
1273
|
const singleComponent = {
|
|
1278
|
-
requestBodies: { [bodyName]:
|
|
1274
|
+
requestBodies: { [bodyName]: requestBody },
|
|
1279
1275
|
...schemas === void 0 ? {} : { schemas }
|
|
1280
1276
|
};
|
|
1281
1277
|
const code = requestBodiesCode(singleComponent, true, readonly);
|
|
@@ -1296,13 +1292,11 @@ function requestBodies(requestBodies, output, split, components, readonly, schem
|
|
|
1296
1292
|
function responses(responses, output, split, components, readonly) {
|
|
1297
1293
|
return Effect.gen(function* () {
|
|
1298
1294
|
if (!responses) return yield* new GenerateError({ message: "No responses found" });
|
|
1299
|
-
|
|
1300
|
-
if (responseNames.length === 0) return "No responses found";
|
|
1295
|
+
if (Object.keys(responses).length === 0) return "No responses found";
|
|
1301
1296
|
if (split) {
|
|
1302
1297
|
const outDir = path.join(path.dirname(output), path.basename(output, ".ts"));
|
|
1303
|
-
yield* Effect.all([...
|
|
1304
|
-
const
|
|
1305
|
-
const code = responsesCode(singleComponent, true, readonly);
|
|
1298
|
+
yield* Effect.all([...Object.entries(responses).map(([responseName, response]) => {
|
|
1299
|
+
const code = responsesCode({ responses: { [responseName]: response } }, true, readonly);
|
|
1306
1300
|
const filePath = path.join(outDir, `${uncapitalize(responseName)}.ts`);
|
|
1307
1301
|
return emit(makeImports(code, filePath, components, split), path.dirname(filePath), filePath);
|
|
1308
1302
|
}), emit(makeBarrel(responses), outDir, path.join(outDir, "index.ts"))], { concurrency: "unbounded" });
|
|
@@ -1322,8 +1316,8 @@ function schemas(schemas, output, split, exportType, readonly) {
|
|
|
1322
1316
|
if (split) {
|
|
1323
1317
|
const outDir = path.join(path.dirname(output), path.basename(output, ".ts"));
|
|
1324
1318
|
const analysis = analyzeCircularSchemas(schemas, schemaNames, readonly);
|
|
1325
|
-
yield* Effect.all([...
|
|
1326
|
-
const fileCode = makeSplitSchemaFile(schemaName,
|
|
1319
|
+
yield* Effect.all([...Object.entries(schemas).map(([schemaName, schema]) => {
|
|
1320
|
+
const fileCode = makeSplitSchemaFile(schemaName, schema, schemas, analysis, exportType, readonly);
|
|
1327
1321
|
const filePath = `${outDir}/${uncapitalize(schemaName)}.ts`;
|
|
1328
1322
|
return emit(fileCode, path.dirname(filePath), filePath);
|
|
1329
1323
|
}), emit(makeBarrel(schemas), path.dirname(`${outDir}/index.ts`), `${outDir}/index.ts`)], { concurrency: "unbounded" });
|
|
@@ -1463,7 +1457,7 @@ function app(openapi, output, basePath, pathAlias, routeImport, routeHandler = f
|
|
|
1463
1457
|
}
|
|
1464
1458
|
if (!routeHandler) {
|
|
1465
1459
|
const handlerFileNames = inlineHandlerFileNames ?? handlerFilesOf(openapi);
|
|
1466
|
-
const handlerExportNames = handlerFileNames.map((
|
|
1460
|
+
const handlerExportNames = handlerFileNames.map((fileName) => `${basename(fileName, ".ts")}Handler`);
|
|
1467
1461
|
const handlerModule = handlerModuleOverride ?? (aliasPrefix ? `${aliasPrefix}/handlers` : "./handlers");
|
|
1468
1462
|
const importSection = [honoImport, handlerExportNames.length > 0 ? `import{${handlerExportNames.join(",")}}from'${handlerModule}'` : ""].filter(Boolean).join("\n");
|
|
1469
1463
|
if (split) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as mkdir, o as writeFile } from "./file-
|
|
2
|
-
import {
|
|
3
|
-
import { i as decodePercent, s as escapeHtml } from "./utils-
|
|
1
|
+
import { n as mkdir, o as writeFile } from "./file-hO_bjDys.js";
|
|
2
|
+
import { $ as HTTP_METHODS, L as isSchemaArray, M as isRecord, N as isRefObject, rt as MULTIPART_MEDIA_TYPE } from "./guard-Rvg4ztIZ.js";
|
|
3
|
+
import { i as decodePercent, s as escapeHtml } from "./utils-yHmzthJJ.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { STATUS_CODES } from "node:http";
|
|
@@ -23,7 +23,7 @@ const SHELL_VARIABLE_PATTERN = /\$\{[A-Z_]+\}/u;
|
|
|
23
23
|
const MULTIPART_BOUNDARY = "boundary";
|
|
24
24
|
const SLUG_STRIP = /[^\p{L}\p{N}\p{M} -鿿- -]/gu;
|
|
25
25
|
function toSlug(text) {
|
|
26
|
-
return (typeof text === "string" ? text : String(text
|
|
26
|
+
return (typeof text === "string" ? text : typeof text === "number" || typeof text === "boolean" ? String(text) : "").toLowerCase().replaceAll(SLUG_STRIP, "").replaceAll(/\s+/gu, "-");
|
|
27
27
|
}
|
|
28
28
|
function findFreeId(used, base, n = 0) {
|
|
29
29
|
const id = n === 0 ? base : `${base}-${n}`;
|
|
@@ -266,7 +266,7 @@ function expandSchema(schema, doc, inside) {
|
|
|
266
266
|
};
|
|
267
267
|
}
|
|
268
268
|
function primaryType(schema) {
|
|
269
|
-
return Array.isArray(schema.type) ? schema.type.find((
|
|
269
|
+
return Array.isArray(schema.type) ? schema.type.find((typeName) => typeName !== "null") : schema.type;
|
|
270
270
|
}
|
|
271
271
|
function isObjectSchema(schema) {
|
|
272
272
|
if (!isRecord(schema.properties)) return false;
|
|
@@ -300,9 +300,10 @@ function inferType(value) {
|
|
|
300
300
|
return "object";
|
|
301
301
|
}
|
|
302
302
|
function baseTypeOf(schema, doc, visited) {
|
|
303
|
-
|
|
304
|
-
if (
|
|
305
|
-
if (
|
|
303
|
+
const type = schema.type;
|
|
304
|
+
if (Array.isArray(type)) return type.map(String).join(" | ");
|
|
305
|
+
if (typeof type === "string") return type;
|
|
306
|
+
if (type !== void 0) return "any";
|
|
306
307
|
if (isRecord(schema.properties)) return "object";
|
|
307
308
|
const variants = variantsOf(schema);
|
|
308
309
|
if (variants.length > 0) return [...new Set(variants.map((variant) => formatSchemaType(variant.schema, doc, visited)))].join(" | ");
|
|
@@ -560,13 +561,13 @@ function makeAuthenticationSection(doc) {
|
|
|
560
561
|
}
|
|
561
562
|
function makeAsideAuth(operation, doc) {
|
|
562
563
|
const reqs = securityRequirements(operation, doc);
|
|
563
|
-
const named = reqs.filter((
|
|
564
|
+
const named = reqs.filter((requirement) => Object.keys(requirement).length > 0);
|
|
564
565
|
if (named.length === 0) return [
|
|
565
566
|
"<aside class=\"success\">",
|
|
566
567
|
"This operation does not require authentication",
|
|
567
568
|
"</aside>"
|
|
568
569
|
];
|
|
569
|
-
const methods = named.map((
|
|
570
|
+
const methods = named.map((requirement) => Object.entries(requirement).map(([name, scopes]) => {
|
|
570
571
|
const scheme = securitySchemeOf(name, doc);
|
|
571
572
|
const scopeArr = Array.isArray(scopes) ? scopes : [];
|
|
572
573
|
return scheme?.type === "oauth2" && scopeArr.length > 0 ? `${name} ( Scopes: ${scopeArr.join(" ")} )` : name;
|
|
@@ -586,7 +587,7 @@ function makeShellQuote(value) {
|
|
|
586
587
|
* expand, escaping everything else the shell would interpret.
|
|
587
588
|
*/
|
|
588
589
|
function makeShellQuoteWithVars(value) {
|
|
589
|
-
return `"${value.replaceAll(/[\\"`]/gu, (
|
|
590
|
+
return `"${value.replaceAll(/[\\"`]/gu, (char) => `\\${char}`).replaceAll(/\$(?!\{[A-Z_]+\})/gu, "\\$")}"`;
|
|
590
591
|
}
|
|
591
592
|
/**
|
|
592
593
|
* ANSI-C quoting (`$'...'`), the one shell string that can carry the CRLF a
|
|
@@ -752,7 +753,7 @@ function getBodyMedia(operation, doc) {
|
|
|
752
753
|
function indentJsonBody(body) {
|
|
753
754
|
const lines = body.split("\n");
|
|
754
755
|
if (lines.length <= 1) return body;
|
|
755
|
-
return [lines[0], ...lines.slice(1).map((
|
|
756
|
+
return [lines[0], ...lines.slice(1).map((line) => ` ${line}`)].join("\n");
|
|
756
757
|
}
|
|
757
758
|
function isBinarySchema(schema, doc) {
|
|
758
759
|
if (!isSchemaLike(schema)) return false;
|
|
@@ -797,7 +798,7 @@ function acceptedMediaType(operation, doc) {
|
|
|
797
798
|
return mediaTypes.find((mediaType) => baseMediaType(mediaType) === "application/json") ?? mediaTypes.find((mediaType) => isJsonMediaType(mediaType));
|
|
798
799
|
}
|
|
799
800
|
function makeFullPath(basePath, pathStr) {
|
|
800
|
-
return `${
|
|
801
|
+
return `${basePath.replace(/\/+$/u, "")}${pathStr}`;
|
|
801
802
|
}
|
|
802
803
|
function makeCodeSample(endpoint, doc, options) {
|
|
803
804
|
const { operation } = endpoint;
|
|
@@ -829,7 +830,7 @@ function makeCodeSample(endpoint, doc, options) {
|
|
|
829
830
|
const fullPath = makeFullPath(options.basePath, samplePath);
|
|
830
831
|
const target = query.length > 0 ? `${fullPath}?${query.join("&")}` : fullPath;
|
|
831
832
|
if (curl) {
|
|
832
|
-
const baseUrl =
|
|
833
|
+
const baseUrl = options.baseUrl.replace(/\/+$/u, "");
|
|
833
834
|
const args = [
|
|
834
835
|
...method === "GET" ? [] : [`-X ${method}`],
|
|
835
836
|
...headers,
|
|
@@ -859,7 +860,8 @@ function makeCodeSample(endpoint, doc, options) {
|
|
|
859
860
|
];
|
|
860
861
|
}
|
|
861
862
|
function toYamlScalar(item) {
|
|
862
|
-
if (
|
|
863
|
+
if (item === void 0) return "null";
|
|
864
|
+
if (typeof item !== "string") return JSON.stringify(item);
|
|
863
865
|
return /^[A-Za-z_/][\w ./@-]*$/u.test(item) && !/^(?:true|false|null|yes|no)$/iu.test(item) && item.trim() === item ? item : JSON.stringify(item);
|
|
864
866
|
}
|
|
865
867
|
/**
|
|
@@ -906,7 +908,7 @@ function enumValuesOf(schema, doc, visited = /* @__PURE__ */ new Set()) {
|
|
|
906
908
|
}
|
|
907
909
|
function formatEnumValue(value) {
|
|
908
910
|
if (typeof value === "string") return value === "" ? "\"\"" : value;
|
|
909
|
-
return JSON.stringify(value)
|
|
911
|
+
return value === void 0 ? "undefined" : JSON.stringify(value);
|
|
910
912
|
}
|
|
911
913
|
function restrictionsOf(schema) {
|
|
912
914
|
if (schema.readOnly === true) return "read-only";
|
|
@@ -993,7 +995,7 @@ function makeFieldTable(fields) {
|
|
|
993
995
|
return [
|
|
994
996
|
"|Name|Type|Required|Restrictions|Description|",
|
|
995
997
|
"|---|---|---|---|---|",
|
|
996
|
-
...fields.map((
|
|
998
|
+
...fields.map((field) => `|${escapeCell(field.name)}|${escapeCell(field.type)}|${field.required}|${field.restrictions}|${escapeCell(field.description)}|`),
|
|
997
999
|
""
|
|
998
1000
|
];
|
|
999
1001
|
}
|
|
@@ -1033,12 +1035,12 @@ function makeParametersTable(operation, slugBase, params, doc) {
|
|
|
1033
1035
|
type: formatSchemaType(bodySchema, doc),
|
|
1034
1036
|
required: body?.required === true,
|
|
1035
1037
|
description: describe(body?.description, false)
|
|
1036
|
-
}, ...makeBodyFields(operation, doc).map((
|
|
1037
|
-
name:
|
|
1038
|
+
}, ...makeBodyFields(operation, doc).map((field) => ({
|
|
1039
|
+
name: field.name,
|
|
1038
1040
|
location: "body",
|
|
1039
|
-
type:
|
|
1040
|
-
required:
|
|
1041
|
-
description:
|
|
1041
|
+
type: field.type,
|
|
1042
|
+
required: field.required,
|
|
1043
|
+
description: field.description
|
|
1042
1044
|
}))] : []];
|
|
1043
1045
|
if (rows.length === 0) return [];
|
|
1044
1046
|
return [
|
|
@@ -1046,7 +1048,7 @@ function makeParametersTable(operation, slugBase, params, doc) {
|
|
|
1046
1048
|
"",
|
|
1047
1049
|
"|Name|In|Type|Required|Description|",
|
|
1048
1050
|
"|---|---|---|---|---|",
|
|
1049
|
-
...rows.map((
|
|
1051
|
+
...rows.map((row) => `|${escapeCell(row.name)}|${escapeCell(row.location)}|${escapeCell(row.type)}|${row.required}|${escapeCell(row.description)}|`),
|
|
1050
1052
|
""
|
|
1051
1053
|
];
|
|
1052
1054
|
}
|
|
@@ -25,11 +25,11 @@ function readFile(path) {
|
|
|
25
25
|
return yield* (yield* FileSystem.FileSystem).readFileString(path).pipe(Effect.catchIf((error) => error.reason._tag === "NotFound", () => Effect.succeed(null)));
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
function writeFile(path,
|
|
28
|
+
function writeFile(path, content) {
|
|
29
29
|
return Effect.gen(function* () {
|
|
30
30
|
const fs = yield* FileSystem.FileSystem;
|
|
31
|
-
if ((yield* fs.readFileString(path).pipe(Effect.orElseSucceed(() => null))) ===
|
|
32
|
-
yield* fs.writeFileString(path,
|
|
31
|
+
if ((yield* fs.readFileString(path).pipe(Effect.orElseSucceed(() => null))) === content) return;
|
|
32
|
+
yield* fs.writeFileString(path, content);
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
export { unlink as a, readdir as i, mkdir as n, writeFile as o, readFile as r, exists as t };
|