hono-takibi 0.32.4 → 0.32.6

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 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.32.4";
8
+ var version = "0.32.6";
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-BDYWF9wQ.js").then((n) => n.o)
44
+ import("./shared-BmIHrl_h.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-BDYWF9wQ.js").then((n) => n.o));
82
+ const { outsideSources } = yield* Effect.promise(() => import("./shared-BmIHrl_h.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-DuBKXeEi.js").then((n) => n.t),
212
- import("./shared-BDYWF9wQ.js").then((n) => n.o)
211
+ import("./core-CT8AnDwr.js").then((n) => n.t),
212
+ import("./shared-BmIHrl_h.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));
@@ -2,9 +2,9 @@ import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
2
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
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-g-suwftT.js";
6
- import { t as zodOpenAPIHono } from "./openapi-Dy5PycHC.js";
7
- import { t as makeMock } from "./mock-m2jO1vos.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-936pvd-W.js";
6
+ import { t as zodOpenAPIHono } from "./openapi-DWSCULWR.js";
7
+ import { t as makeMock } from "./mock-Db6ltVgv.js";
8
8
  import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-yhnsv_ji.js";
9
9
  import { i as readdir, n as mkdir, o as writeFile, r as readFile } from "./file-hO_bjDys.js";
10
10
  import { t as emit } from "./emit-8SmO5pHF.js";
@@ -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-BDYWF9wQ.js";
4
+ import { a as packageRoots, n as makeJob, r as openAPI3, t as cleanSplitOutputs } from "../shared-BmIHrl_h.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 makeMock } from "../../mock-m2jO1vos.js";
1
+ export { t as makeMock } from "../../mock-Db6ltVgv.js";
@@ -1 +1 @@
1
- export { t as zodOpenAPIHono } from "../../../openapi-Dy5PycHC.js";
1
+ export { t as zodOpenAPIHono } from "../../../openapi-DWSCULWR.js";
@@ -1,6 +1,6 @@
1
1
  import { $ as HTTP_METHODS, A as isPathItemRef, B as isSecurityArray, J as COMPONENT_REF_PREFIX, L as isSchemaArray, N as isRefObject, R as isSchemaObject, S as isOperation, V as isSecurityScheme, a as hasNumericConstraint, at as TEXT_MEDIA_TYPE, g as isInlineMedia, j as isPresent, k as isPathItemEntry, m as isHttpMethod, nt as JSON_MEDIA_TYPE, o as hasRequestBodyContent, w as isParameter, y as isMediaWithSchema } from "./guard-Rvg4ztIZ.js";
2
2
  import { _ as routeName, a as ensureSuffix, d as makeSafeKey, f as makeStringLiteral, p as normalizeTypes, r as cyclicNodes, v as statusCodeToNumber, y as toIdentifierPascalCase } from "./utils-yHmzthJJ.js";
3
- import { n as componentsCode, t as routeCode } from "./routes-g-suwftT.js";
3
+ import { n as componentsCode, t as routeCode } from "./routes-936pvd-W.js";
4
4
  // src/helper/faker.ts
5
5
  const FORMAT_TO_FAKER = {
6
6
  date: "faker.date.past().toISOString().slice(0, 10)",
@@ -1,6 +1,6 @@
1
1
  import { $ as HTTP_METHODS, M as isRecord, Y as COMPONENT_SUFFIXES, q as COMPONENT_NAMES } from "./guard-Rvg4ztIZ.js";
2
2
  import { a as ensureSuffix, i as decodePercent, y as toIdentifierPascalCase } from "./utils-yHmzthJJ.js";
3
- import { D as makeWebhookEntries, n as componentsCode, t as routeCode } from "./routes-g-suwftT.js";
3
+ import { D as makeWebhookEntries, n as componentsCode, t as routeCode } from "./routes-936pvd-W.js";
4
4
  // src/helper/names.ts
5
5
  /**
6
6
  * Renames the components whose identifiers would collide, and every `$ref` to them.
@@ -1734,34 +1734,34 @@ function issueObj(messageExpr, pathExpr) {
1734
1734
  if (messageExpr !== void 0) parts.push(`message:${messageExpr}`);
1735
1735
  return `{${parts.join(",")}}`;
1736
1736
  }
1737
- function makeObjectChecks(schema, recurse) {
1737
+ function makeObjectChecks(schema, recurse, report = (issue) => `ctx.addIssue(${issue})`) {
1738
1738
  const ownKeys = Object.keys(schema.properties ?? {});
1739
1739
  const patterns = Object.keys(schema.patternProperties ?? {});
1740
1740
  const declared = [...ownKeys.length > 0 ? [`!${JSON.stringify(ownKeys)}.includes(k)`] : [], ...patterns.length > 0 ? [`!${JSON.stringify(patterns)}.some((p)=>new RegExp(p).test(k))`] : []];
1741
1741
  const forUndeclaredKeys = (body) => `for(const k of Object.keys(val)){${declared.length === 0 ? body : `if(${declared.join("&&")}){${body}}`}}`;
1742
1742
  const requiredMessage = messageFor(schema, "required");
1743
- const requiredChecks = Array.isArray(schema.required) ? schema.required.map((key) => `if(!Object.hasOwn(val,${JSON.stringify(key)})){ctx.addIssue(${issueObj(requiredMessage)})}`) : [];
1744
- const minPropertiesCheck = typeof schema.minProperties === "number" ? `if(Object.keys(val).length<${schema.minProperties}){ctx.addIssue(${issueObj(messageFor(schema, "minProperties"))})}` : void 0;
1745
- const maxPropertiesCheck = typeof schema.maxProperties === "number" ? `if(Object.keys(val).length>${schema.maxProperties}){ctx.addIssue(${issueObj(messageFor(schema, "maxProperties"))})}` : void 0;
1743
+ const requiredChecks = Array.isArray(schema.required) ? schema.required.map((key) => `if(!Object.hasOwn(val,${JSON.stringify(key)})){${report(issueObj(requiredMessage))}}`) : [];
1744
+ const minPropertiesCheck = typeof schema.minProperties === "number" ? `if(Object.keys(val).length<${schema.minProperties}){${report(issueObj(messageFor(schema, "minProperties")))}}` : void 0;
1745
+ const maxPropertiesCheck = typeof schema.maxProperties === "number" ? `if(Object.keys(val).length>${schema.maxProperties}){${report(issueObj(messageFor(schema, "maxProperties")))}}` : void 0;
1746
1746
  const propertiesMessage = messageFor(schema, "properties");
1747
- const propertyChecks = schema.properties ? Object.entries(schema.properties).map(([key, sub]) => `if(Object.hasOwn(val,${JSON.stringify(key)})){const Schema=${recurse(sub)};if(!Schema.safeParse(Reflect.get(val,${JSON.stringify(key)})).success){ctx.addIssue(${issueObj(propertiesMessage)})}}`) : [];
1747
+ const propertyChecks = schema.properties ? Object.entries(schema.properties).map(([key, sub]) => `if(Object.hasOwn(val,${JSON.stringify(key)})){const Schema=${recurse(sub)};if(!Schema.safeParse(Reflect.get(val,${JSON.stringify(key)})).success){${report(issueObj(propertiesMessage))}}}`) : [];
1748
1748
  const additionalPropertiesMessage = messageFor(schema, "additionalProperties");
1749
1749
  const additionalPropertiesCheck = (() => {
1750
- if (schema.additionalProperties === false) return forUndeclaredKeys(`ctx.addIssue(${issueObj(additionalPropertiesMessage)})`);
1751
- if (isSchemaObject(schema.additionalProperties)) return `{const Schema=${recurse(schema.additionalProperties)};${forUndeclaredKeys(`if(!Schema.safeParse(Reflect.get(val,k)).success){ctx.addIssue(${issueObj(additionalPropertiesMessage)})}`)}}`;
1750
+ if (schema.additionalProperties === false) return forUndeclaredKeys(report(issueObj(additionalPropertiesMessage)));
1751
+ if (isSchemaObject(schema.additionalProperties)) return `{const Schema=${recurse(schema.additionalProperties)};${forUndeclaredKeys(`if(!Schema.safeParse(Reflect.get(val,k)).success){${report(issueObj(additionalPropertiesMessage))}}`)}}`;
1752
1752
  })();
1753
1753
  const patternPropertiesMessage = messageFor(schema, "patternProperties");
1754
- const patternPropertiesChecks = schema.patternProperties ? Object.entries(schema.patternProperties).map(([pattern, sub]) => `{const Schema=${recurse(sub)};for(const k of Object.keys(val)){if(new RegExp(${JSON.stringify(pattern)}).test(k)){if(!Schema.safeParse(Reflect.get(val,k)).success){ctx.addIssue(${issueObj(patternPropertiesMessage)})}}}}`) : [];
1755
- const propertyNamesCheck = schema.propertyNames?.pattern ? `for(const k of Object.keys(val)){if(!new RegExp(${JSON.stringify(schema.propertyNames.pattern)}).test(k)){ctx.addIssue(${issueObj(messageFor(schema, "propertyNames"))})}}` : void 0;
1754
+ const patternPropertiesChecks = schema.patternProperties ? Object.entries(schema.patternProperties).map(([pattern, sub]) => `{const Schema=${recurse(sub)};for(const k of Object.keys(val)){if(new RegExp(${JSON.stringify(pattern)}).test(k)){if(!Schema.safeParse(Reflect.get(val,k)).success){${report(issueObj(patternPropertiesMessage))}}}}}`) : [];
1755
+ const propertyNamesCheck = schema.propertyNames?.pattern ? `for(const k of Object.keys(val)){if(!new RegExp(${JSON.stringify(schema.propertyNames.pattern)}).test(k)){${report(issueObj(messageFor(schema, "propertyNames")))}}}` : void 0;
1756
1756
  const dependentRequiredMessage = messageFor(schema, "dependentRequired");
1757
1757
  const dependentRequiredChecks = schema.dependentRequired ? Object.entries(schema.dependentRequired).map(([key, deps]) => {
1758
1758
  const depsCheck = deps.map((dependency) => `Object.hasOwn(val,${JSON.stringify(dependency)})`).join("&&");
1759
- return depsCheck ? `if(Object.hasOwn(val,${JSON.stringify(key)})){if(!(${depsCheck})){ctx.addIssue(${issueObj(dependentRequiredMessage)})}}` : void 0;
1759
+ return depsCheck ? `if(Object.hasOwn(val,${JSON.stringify(key)})){if(!(${depsCheck})){${report(issueObj(dependentRequiredMessage))}}}` : void 0;
1760
1760
  }).filter((s) => s !== void 0) : [];
1761
1761
  const dependentSchemasMessage = messageFor(schema, "dependentSchemas");
1762
1762
  const dependentSchemasMessageField = dependentSchemasMessage !== void 0 ? `,message:${JSON.stringify(dependentSchemasMessage)}` : "";
1763
- const dependentSchemasChecks = schema.dependentSchemas ? Object.entries(schema.dependentSchemas).map(([key, sub]) => `if(Object.hasOwn(val,${JSON.stringify(key)})){const Schema=${recurse(sub)};const result=Schema.safeParse(val);if(!result.success){for(const issue of result.error.issues){ctx.addIssue({...issue,path:issue.path${dependentSchemasMessageField}})}}}`) : [];
1764
- const unevaluatedPropertiesCheck = schema.unevaluatedProperties === false ? forUndeclaredKeys(`ctx.addIssue(${issueObj(messageFor(schema, "unevaluatedProperties"))})`) : void 0;
1763
+ const dependentSchemasChecks = schema.dependentSchemas ? Object.entries(schema.dependentSchemas).map(([key, sub]) => `if(Object.hasOwn(val,${JSON.stringify(key)})){const Schema=${recurse(sub)};const result=Schema.safeParse(val);if(!result.success){for(const issue of result.error.issues){${report(`{...issue,path:issue.path${dependentSchemasMessageField}}`)}}}}`) : [];
1764
+ const unevaluatedPropertiesCheck = schema.unevaluatedProperties === false && schema.additionalProperties !== true && !isSchemaObject(schema.additionalProperties) ? forUndeclaredKeys(report(issueObj(messageFor(schema, "unevaluatedProperties")))) : void 0;
1765
1765
  return [
1766
1766
  ...requiredChecks,
1767
1767
  minPropertiesCheck,
@@ -1882,6 +1882,82 @@ function emitTypelessRefine(schema, recurse) {
1882
1882
  if (blocks.length === 0) return "z.any()";
1883
1883
  return `z.unknown().superRefine((val,ctx)=>{${blocks.join(";")}})`;
1884
1884
  }
1885
+ function requiresObject(schema, schemas, seen = []) {
1886
+ if (typeof schema === "boolean") return !schema;
1887
+ if (schema.$ref !== void 0) {
1888
+ if (seen.includes(schema.$ref)) return false;
1889
+ const target = resolveSchemaRef(schema.$ref, schemas);
1890
+ return target === void 0 ? false : requiresObject(target, schemas, [...seen, schema.$ref]);
1891
+ }
1892
+ const types = normalizeTypes(schema.type);
1893
+ if (types.length > 0) return types.includes("object") && types.every((type) => type === "object" || type === "null");
1894
+ if (schema.allOf !== void 0) return schema.allOf.some((member) => requiresObject(member, schemas, seen));
1895
+ const union = schema.anyOf ?? schema.oneOf;
1896
+ if (union !== void 0) return union.length > 0 && union.every((branch) => requiresObject(branch, schemas, seen));
1897
+ return isUntypedObject(schema);
1898
+ }
1899
+ function canAcceptObject(schema, schemas, seen = []) {
1900
+ if (typeof schema === "boolean") return schema;
1901
+ if (schema.$ref !== void 0) {
1902
+ if (seen.includes(schema.$ref)) return true;
1903
+ const target = resolveSchemaRef(schema.$ref, schemas);
1904
+ return target === void 0 ? true : canAcceptObject(target, schemas, [...seen, schema.$ref]);
1905
+ }
1906
+ if (Array.isArray(schema.enum)) return schema.enum.some((member) => typeof member === "object" && member !== null && !Array.isArray(member));
1907
+ if (schema.const !== void 0) return typeof schema.const === "object" && schema.const !== null && !Array.isArray(schema.const);
1908
+ const types = normalizeTypes(schema.type);
1909
+ if (types.length > 0) return types.includes("object");
1910
+ if (schema.allOf !== void 0) return schema.allOf.length === 0 || schema.allOf.some((member) => canAcceptObject(member, schemas, seen));
1911
+ const union = schema.anyOf ?? schema.oneOf;
1912
+ if (union !== void 0) return union.some((branch) => canAcceptObject(branch, schemas, seen));
1913
+ return true;
1914
+ }
1915
+ function canAdmitNullOrUndefined(schema, schemas, seen = []) {
1916
+ if (typeof schema === "boolean") return schema;
1917
+ if (schema.$ref !== void 0) {
1918
+ if (seen.includes(schema.$ref)) return true;
1919
+ const target = resolveSchemaRef(schema.$ref, schemas);
1920
+ return target === void 0 ? true : canAdmitNullOrUndefined(target, schemas, [...seen, schema.$ref]);
1921
+ }
1922
+ if (schema.default !== void 0 || schema["x-prefault"] !== void 0 || schema["x-catch"] !== void 0 || schema["x-preprocess"] !== void 0 || schema["x-transform"] !== void 0 || schema["x-pipe"] !== void 0 || schema["x-codec"] !== void 0) return true;
1923
+ if (schema.nullable === true) return true;
1924
+ if (Array.isArray(schema.enum)) return schema.enum.some((member) => member === null);
1925
+ if (schema.const !== void 0) return schema.const === null;
1926
+ const types = normalizeTypes(schema.type);
1927
+ if (types.length > 0) return types.includes("null");
1928
+ if (schema.allOf !== void 0) return schema.allOf.every((member) => canAdmitNullOrUndefined(member, schemas, seen));
1929
+ const union = schema.anyOf ?? schema.oneOf;
1930
+ if (union !== void 0) return union.some((branch) => canAdmitNullOrUndefined(branch, schemas, seen));
1931
+ if (isUntypedObject(schema)) return false;
1932
+ return true;
1933
+ }
1934
+ function isStrippingObject(schema) {
1935
+ return Object.keys(schema.properties ?? {}).length > 0 && schema.additionalProperties === void 0 && schema.patternProperties === void 0 && schema.propertyNames === void 0 && schema.unevaluatedProperties === void 0;
1936
+ }
1937
+ function emitsStrippingObject(schema, schemas, seen = []) {
1938
+ if (typeof schema === "boolean") return false;
1939
+ if (schema.$ref !== void 0) {
1940
+ if (seen.includes(schema.$ref)) return true;
1941
+ const target = resolveSchemaRef(schema.$ref, schemas);
1942
+ return target === void 0 ? true : emitsStrippingObject(target, schemas, [...seen, schema.$ref]);
1943
+ }
1944
+ const types = normalizeTypes(schema.type);
1945
+ if (types.length > 0) return types.includes("object") && isStrippingObject(schema);
1946
+ if (schema.allOf !== void 0) return schema.allOf.length > 0 && schema.allOf.every((member) => emitsStrippingObject(member, schemas, seen));
1947
+ const union = schema.anyOf ?? schema.oneOf;
1948
+ if (union !== void 0) return union.some((branch) => emitsStrippingObject(branch, schemas, seen));
1949
+ return isUntypedObject(schema) && isStrippingObject(schema);
1950
+ }
1951
+ function emitObjectShapeCheck(schema, recurse) {
1952
+ const checks = makeObjectChecks(schema, recurse, (issue) => `ctx.issues.push({...${issue},input:val})`);
1953
+ if (checks.length === 0) return void 0;
1954
+ return `(ctx)=>{const val=ctx.value;if(typeof val==='object'&&val!==null&&!Array.isArray(val)){${checks.join(";")}}}`;
1955
+ }
1956
+ function emitObjectShapeRefine(schema, recurse) {
1957
+ const checks = makeObjectChecks(schema, recurse);
1958
+ if (checks.length === 0) return void 0;
1959
+ return `(val,ctx)=>{if(typeof val==='object'&&val!==null&&!Array.isArray(val)){${checks.join(";")}}}`;
1960
+ }
1885
1961
  function makeOwnPropsStmt(sub) {
1886
1962
  const keys = sub.properties ? Object.keys(sub.properties) : [];
1887
1963
  return keys.length > 0 ? `for(const k of ${JSON.stringify(keys)}){e.add(k)}` : void 0;
@@ -1891,6 +1967,13 @@ function makePatternPropsStmt(sub) {
1891
1967
  const patterns = Object.keys(sub.patternProperties);
1892
1968
  return `for(const k of Object.keys(o)){for(const p of ${JSON.stringify(patterns)}){if(new RegExp(p).test(k)){e.add(k)}}}`;
1893
1969
  }
1970
+ function makeAdditionalPropsStmt(sub) {
1971
+ if (sub.additionalProperties !== true && !isSchemaObject(sub.additionalProperties)) return;
1972
+ const ownKeys = sub.properties ? Object.keys(sub.properties) : [];
1973
+ const patterns = sub.patternProperties ? Object.keys(sub.patternProperties) : [];
1974
+ const guards = [...ownKeys.length > 0 ? [`!${JSON.stringify(ownKeys)}.includes(k)`] : [], ...patterns.length > 0 ? [`!${JSON.stringify(patterns)}.some((p)=>new RegExp(p).test(k))`] : []];
1975
+ return guards.length === 0 ? `for(const k of Object.keys(o)){e.add(k)}` : `for(const k of Object.keys(o)){if(${guards.join("&&")}){e.add(k)}}`;
1976
+ }
1894
1977
  function collectAllOfStmts(list, schemas, reading = /* @__PURE__ */ new Set()) {
1895
1978
  return list.flatMap((sub) => {
1896
1979
  if (sub.$ref !== void 0) {
@@ -1900,43 +1983,71 @@ function collectAllOfStmts(list, schemas, reading = /* @__PURE__ */ new Set()) {
1900
1983
  return [
1901
1984
  makeOwnPropsStmt(sub),
1902
1985
  makePatternPropsStmt(sub),
1986
+ makeAdditionalPropsStmt(sub),
1903
1987
  ...sub.allOf ? collectAllOfStmts(sub.allOf, schemas, reading) : []
1904
1988
  ].filter((s) => s !== void 0);
1905
1989
  });
1906
1990
  }
1907
- function conditionalBranchStmt(sub, recurse) {
1908
- if (!sub.properties && !sub.patternProperties) return;
1909
- const ifBody = [makeOwnPropsStmt(sub), makePatternPropsStmt(sub)].filter((s) => s !== void 0).join(";");
1910
- return ifBody ? `if(${recurse(sub)}.safeParse(o).success){${ifBody}}` : void 0;
1911
- }
1912
- function makeUnevaluatedEvaluationStmts(schema, recurse, schemas) {
1913
- const branchStmts = (branches) => branches ? branches.map((sub) => conditionalBranchStmt(sub, recurse)).filter((s) => s !== void 0) : [];
1991
+ function makeGatedStmts(sub, cond) {
1992
+ if (sub === void 0) return void 0;
1993
+ const body = [
1994
+ makeOwnPropsStmt(sub),
1995
+ makePatternPropsStmt(sub),
1996
+ makeAdditionalPropsStmt(sub)
1997
+ ].filter((s) => s !== void 0).join(";");
1998
+ if (!body) return void 0;
1999
+ return cond === void 0 ? body : `if(${cond}){${body}}`;
2000
+ }
2001
+ function makeIfStmts(schema, recurse) {
1914
2002
  const ifSchema = schema.if;
1915
- const ifStmts = ifSchema ? (() => {
1916
- const ifOkStmt = `const ifOk=${recurse(ifSchema)}.safeParse(o).success`;
1917
- const ifKeys = ifSchema.properties ? Object.keys(ifSchema.properties) : [];
1918
- const thenKeys = schema.then?.properties ? Object.keys(schema.then.properties) : [];
1919
- const elseKeys = schema.else?.properties ? Object.keys(schema.else.properties) : [];
1920
- return [
1921
- ifOkStmt,
1922
- ifKeys.length > 0 ? `if(ifOk){for(const k of ${JSON.stringify(ifKeys)}){e.add(k)}}` : void 0,
1923
- thenKeys.length > 0 ? `if(ifOk){for(const k of ${JSON.stringify(thenKeys)}){e.add(k)}}` : void 0,
1924
- elseKeys.length > 0 ? `if(!ifOk){for(const k of ${JSON.stringify(elseKeys)}){e.add(k)}}` : void 0
1925
- ].filter((s) => s !== void 0);
1926
- })() : [];
1927
- const depSchemaStmts = schema.dependentSchemas ? Object.entries(schema.dependentSchemas).map(([key, sub]) => {
1928
- const keys = sub.properties ? Object.keys(sub.properties) : [];
1929
- return keys.length > 0 ? `if(${JSON.stringify(key)} in o){for(const k of ${JSON.stringify(keys)}){e.add(k)}}` : void 0;
1930
- }).filter((s) => s !== void 0) : [];
2003
+ if (!ifSchema) return [];
2004
+ return [
2005
+ `const ifOk=${recurse(ifSchema)}.safeParse(o).success`,
2006
+ makeGatedStmts(ifSchema, "ifOk"),
2007
+ makeGatedStmts(schema.then, "ifOk"),
2008
+ makeGatedStmts(schema.else, "!ifOk")
2009
+ ].filter((s) => s !== void 0);
2010
+ }
2011
+ function makeDepSchemaStmts(schema) {
2012
+ if (!schema.dependentSchemas) return [];
2013
+ return Object.entries(schema.dependentSchemas).map(([key, sub]) => makeGatedStmts(sub, `${JSON.stringify(key)} in o`)).filter((s) => s !== void 0);
2014
+ }
2015
+ function collectBranchBody(sub, recurse, schemas, reading = /* @__PURE__ */ new Set()) {
2016
+ if (sub.$ref !== void 0) {
2017
+ const target = reading.has(sub.$ref) ? void 0 : resolveSchemaRef(sub.$ref, schemas);
2018
+ if (target === void 0) return void 0;
2019
+ return collectBranchBody(target, recurse, schemas, /* @__PURE__ */ new Set([...reading, sub.$ref]));
2020
+ }
2021
+ const branchStmts = (branches) => branches ? branches.map((branch) => conditionalBranchStmt(branch, recurse, schemas, reading)).filter((s) => s !== void 0) : [];
2022
+ return [
2023
+ makeOwnPropsStmt(sub),
2024
+ makePatternPropsStmt(sub),
2025
+ makeAdditionalPropsStmt(sub),
2026
+ ...sub.allOf ? collectAllOfStmts(sub.allOf, schemas, reading) : [],
2027
+ ...branchStmts(sub.anyOf),
2028
+ ...branchStmts(sub.oneOf),
2029
+ ...makeIfStmts(sub, recurse),
2030
+ ...makeDepSchemaStmts(sub)
2031
+ ].filter((s) => s !== void 0).join(";") || void 0;
2032
+ }
2033
+ function conditionalBranchStmt(sub, recurse, schemas, reading = /* @__PURE__ */ new Set(), countVar) {
2034
+ const body = collectBranchBody(sub, recurse, schemas, reading);
2035
+ if (body === void 0 && countVar === void 0) return void 0;
2036
+ const counted = countVar === void 0 ? "" : `${countVar}++;`;
2037
+ return `if(${recurse(sub)}.safeParse(o).success){${counted}${body ?? ""}}`;
2038
+ }
2039
+ function makeUnevaluatedEvaluationStmts(schema, recurse, schemas, track) {
2040
+ const branchStmts = (branches, countVar) => branches ? branches.map((sub) => conditionalBranchStmt(sub, recurse, schemas, void 0, countVar)).filter((s) => s !== void 0) : [];
1931
2041
  return [
1932
2042
  "const e=new Set()",
1933
2043
  makeOwnPropsStmt(schema),
1934
2044
  makePatternPropsStmt(schema),
2045
+ makeAdditionalPropsStmt(schema),
1935
2046
  ...schema.allOf ? collectAllOfStmts(schema.allOf, schemas) : [],
1936
- ...branchStmts(schema.anyOf),
1937
- ...branchStmts(schema.oneOf),
1938
- ...ifStmts,
1939
- ...depSchemaStmts
2047
+ ...branchStmts(schema.anyOf, track?.anyOf),
2048
+ ...branchStmts(schema.oneOf, track?.oneOf),
2049
+ ...makeIfStmts(schema, recurse),
2050
+ ...makeDepSchemaStmts(schema)
1940
2051
  ].filter((s) => s !== void 0);
1941
2052
  }
1942
2053
  function makeUnevaluatedMessageField(schema, messageOverride) {
@@ -1972,12 +2083,20 @@ const ISSUE_CODES = [
1972
2083
  function makeIssueForwarding(pushArg) {
1973
2084
  return ISSUE_CODES.map((code, i) => `${i === 0 ? "" : "else "}if(issue.code==='${code}'){ctx.issues.push(${pushArg})}`).join("");
1974
2085
  }
1975
- function makeUnevaluatedPropertiesCheck(schema, recurse, messageOverride, schemas) {
2086
+ function makeUnevaluatedPropertiesCheck(schema, recurse, messageOverride, schemas, guard) {
1976
2087
  const up = schema.unevaluatedProperties;
1977
2088
  if (up === void 0 || up === true) return "";
1978
2089
  const messageField = makeUnevaluatedMessageField(schema, messageOverride);
1979
2090
  const finalStmt = up === false ? `for(const k of Object.keys(o)){if(!e.has(k)){ctx.issues.push({code:"custom",path:[k],input:o${messageField}})}}` : `const Schema=${recurse(up)};for(const [k,val] of Object.entries(o)){if(e.has(k)){continue}const result=Schema.safeParse(val);if(!result.success){for(const issue of result.error.issues){${makeIssueForwarding("{...issue,path:[k,...issue.path],input:issue.input}")}}}}`;
1980
- return `(ctx)=>{const o=ctx.value;if(typeof o!=='object'||o===null||Array.isArray(o))return;${[...makeUnevaluatedEvaluationStmts(schema, recurse, schemas), finalStmt].join(";")}}`;
2091
+ const hasAnyOf = guard !== void 0 ? guard.anyOf === true : schema.anyOf !== void 0 && schema.anyOf.length > 0;
2092
+ const hasOneOf = guard !== void 0 ? guard.oneOf === true : schema.oneOf !== void 0 && schema.oneOf.length > 0;
2093
+ const counters = `${hasAnyOf ? "let mA=0;" : ""}${hasOneOf ? "let mO=0;" : ""}`;
2094
+ const evalStmts = makeUnevaluatedEvaluationStmts(schema, recurse, schemas, {
2095
+ ...hasAnyOf ? { anyOf: "mA" } : {},
2096
+ ...hasOneOf ? { oneOf: "mO" } : {}
2097
+ });
2098
+ const guardedFinal = !hasAnyOf && !hasOneOf ? finalStmt : `if(${[...hasAnyOf ? ["mA>0"] : [], ...hasOneOf ? ["mO===1"] : []].join("&&")}){${finalStmt}}`;
2099
+ return `(ctx)=>{const o=ctx.value;if(typeof o!=='object'||o===null||Array.isArray(o))return;${counters}${[...evalStmts, guardedFinal].join(";")}}`;
1981
2100
  }
1982
2101
  function makeBoundErrorArgs(schema, bound, errorMessage) {
1983
2102
  const message = schema[`x-${bound}-message`] ?? errorMessage;
@@ -2440,6 +2559,13 @@ function string(schema, options) {
2440
2559
  return `${makeValidationBase()}${postTrim}${postLower}${postUpper}${postNormalize}${refinements}`;
2441
2560
  }
2442
2561
  // src/generator/zod-to-openapi/index.ts
2562
+ function withUnevaluatedCheck(zod, unevalCheck) {
2563
+ if (unevalCheck === "") return zod;
2564
+ return `(()=>{const Schema=${zod};return z.preprocess((val: z.input<typeof Schema>,ctx)=>{(${unevalCheck})(ctx);return val},Schema)})()`;
2565
+ }
2566
+ function hasOwnWrapping(branch) {
2567
+ return branch.nullable === true || normalizeTypes(branch.type).includes("null") || branch.default !== void 0 || branch["x-prefault"] !== void 0 || branch["x-catch"] !== void 0;
2568
+ }
2443
2569
  function zodToOpenAPI(schema, meta, options) {
2444
2570
  if (schema === true) return wrap("z.any()", {}, meta, options);
2445
2571
  if (schema === false) return wrap("z.never()", {}, meta, options);
@@ -2484,6 +2610,74 @@ function zodToOpenAPI(schema, meta, options) {
2484
2610
  };
2485
2611
  const child = (s) => childOptions?.coerce !== true && isRefOnly(s) ? makeRef(s.$ref ?? "") : zodToOpenAPI(s, void 0, childOptions);
2486
2612
  const referenced = (s) => childOptions?.coerce !== true && s.$ref ? makeRef(s.$ref) : zodToOpenAPI(s, void 0, childOptions);
2613
+ const conformMerged = (coreSchema, shapeSchema, value) => {
2614
+ const core = conformDefault(coreSchema, value, childOptions?.schemas);
2615
+ const shape = conformDefault(shapeSchema, value, childOptions?.schemas);
2616
+ if (!core.ok || !shape.ok) return { ok: false };
2617
+ if (JSON.stringify(core.value) !== JSON.stringify(shape.value)) {
2618
+ if (isRecord(core.value) && isRecord(shape.value)) {
2619
+ for (const key of Object.keys(core.value)) if (Object.hasOwn(shape.value, key) && JSON.stringify(core.value[key]) !== JSON.stringify(shape.value[key])) return { ok: false };
2620
+ return {
2621
+ ok: true,
2622
+ value: {
2623
+ ...core.value,
2624
+ ...shape.value
2625
+ }
2626
+ };
2627
+ }
2628
+ return { ok: false };
2629
+ }
2630
+ return core;
2631
+ };
2632
+ const distributeAdmitting = (branch, shapeZ, shapeRefine, shapeHasProperties, shapeSchema) => {
2633
+ if (branch["x-preprocess"] !== void 0 || branch["x-transform"] !== void 0 || branch["x-pipe"] !== void 0 || branch["x-codec"] !== void 0 || branch["x-refine"] !== void 0 || branch["x-superRefine"] !== void 0 || branch["x-brand"] !== void 0 || branch["x-readonly"] === true || branch["x-catch"] !== void 0) return null;
2634
+ const { nullable: _nullable, default: _default, "x-prefault": _prefault, "x-catch": _catch, type: branchType, ...coreRest } = branch;
2635
+ const [first, ...rest] = normalizeTypes(branchType).filter((type) => type !== "null");
2636
+ const coreSchema = first === void 0 ? { ...coreRest } : {
2637
+ ...coreRest,
2638
+ type: rest.length === 0 ? first : [first, ...rest]
2639
+ };
2640
+ if (canAdmitNullOrUndefined(coreSchema, childOptions?.schemas)) return null;
2641
+ const andZ = `${child(coreSchema)}.and(${shapeZ})`;
2642
+ const distributed = shapeHasProperties ? andZ : `${andZ}.superRefine(${shapeRefine})`;
2643
+ const mergedDefault = branch.default === void 0 ? void 0 : conformMerged(coreSchema, shapeSchema, branch.default);
2644
+ const mergedPrefault = branch["x-prefault"] === void 0 ? void 0 : conformMerged(coreSchema, shapeSchema, branch["x-prefault"]);
2645
+ const defaultIsNull = mergedDefault !== void 0 && mergedDefault.ok && mergedDefault.value === null;
2646
+ const nullable = branch.nullable === true || normalizeTypes(branch.type).includes("null") || defaultIsNull;
2647
+ let out = distributed;
2648
+ if (nullable) out = `${out}.nullable()`;
2649
+ if (mergedDefault?.ok) out = `${out}.default(${JSON.stringify(mergedDefault.value)})`;
2650
+ if (mergedPrefault?.ok) out = `${out}.prefault(${JSON.stringify(mergedPrefault.value)})`;
2651
+ return out;
2652
+ };
2653
+ const distribute = (branch, shapeZ, shapeRefine, shapeHasProperties, shapeSchema) => {
2654
+ if (shapeRefine === void 0) return child(branch);
2655
+ if (requiresObject(branch, childOptions?.schemas)) {
2656
+ if (canAdmitNullOrUndefined(branch, childOptions?.schemas) || hasOwnWrapping(branch)) return distributeAdmitting(branch, shapeZ, shapeRefine, shapeHasProperties, shapeSchema);
2657
+ const andZ = `${child(branch)}.and(${shapeZ})`;
2658
+ return shapeHasProperties ? andZ : `${andZ}.superRefine(${shapeRefine})`;
2659
+ }
2660
+ if (!canAcceptObject(branch, childOptions?.schemas)) return child(branch);
2661
+ if (branch.allOf !== void 0) return emitsStrippingObject(branch, childOptions?.schemas) ? null : `${child(branch)}.superRefine(${shapeRefine})`;
2662
+ if (branch.anyOf !== void 0 && !(isBinaryFile(branch) && hasMimeAlternatives(branch))) {
2663
+ if (branch.anyOf.length === 0) return child(branch);
2664
+ const parts = branch.anyOf.map((b) => distribute(b, shapeZ, shapeRefine, shapeHasProperties, shapeSchema));
2665
+ if (parts.some((part) => part === null)) return null;
2666
+ const message = branch["x-implication-message"] ?? branch["x-anyOf-message"] ?? branch["x-error-message"];
2667
+ const branchUnevalCheck = makeUnevaluatedPropertiesCheck(branch, (s) => zodToOpenAPI(s, void 0, childOptions), branch["x-error-message"], childOptions?.schemas, { anyOf: true });
2668
+ return wrap(withUnevaluatedCheck(`z.union([${parts.join(",")}]${message ? `,${error(message)}` : ""})`, branchUnevalCheck), branch, void 0, childOptions?.schemas === void 0 ? {} : { schemas: childOptions.schemas });
2669
+ }
2670
+ if (branch.oneOf !== void 0) {
2671
+ if (branch.oneOf.length === 0) return child(branch);
2672
+ const parts = branch.oneOf.map((b) => distribute(b, shapeZ, shapeRefine, shapeHasProperties, shapeSchema));
2673
+ if (parts.some((part) => part === null)) return null;
2674
+ const message = branch["x-oneOf-message"] ?? branch["x-error-message"];
2675
+ const branchUnevalCheck = makeUnevaluatedPropertiesCheck(branch, (s) => zodToOpenAPI(s, void 0, childOptions), branch["x-error-message"], childOptions?.schemas, { oneOf: true });
2676
+ return wrap(withUnevaluatedCheck(`z.xor([${parts.join(",")}]${message ? `,${error(message)}` : ""})`, branchUnevalCheck), branch, void 0, childOptions?.schemas === void 0 ? {} : { schemas: childOptions.schemas });
2677
+ }
2678
+ if (normalizeTypes(branch.type).filter((type) => type !== "null").length > 1) return null;
2679
+ return emitsStrippingObject(branch, childOptions?.schemas) ? null : `${child(branch)}.superRefine(${shapeRefine})`;
2680
+ };
2487
2681
  if (schema.$ref !== void 0) {
2488
2682
  if (meta?.parameters !== void 0 && options?.coerce === true && isDecoratedRef(schema)) {
2489
2683
  const target = resolveSchemaRef(schema.$ref, options.schemas);
@@ -2510,37 +2704,64 @@ function zodToOpenAPI(schema, meta, options) {
2510
2704
  return done(makeRef(schema.$ref), schema, true);
2511
2705
  }
2512
2706
  if (schema.allOf !== void 0) {
2707
+ const hasShape = schema.properties !== void 0 && Object.keys(schema.properties).length > 0 || Array.isArray(schema.required) && schema.required.length > 0;
2708
+ const objectOnly = normalizeTypes(schema.type).includes("object") && normalizeTypes(schema.type).every((type) => type === "object" || type === "null");
2709
+ const membersRequireObject = schema.allOf.some((member) => requiresObject(member, childOptions?.schemas));
2710
+ const shapeSchema = hasShape ? {
2711
+ type: "object",
2712
+ ...schema.properties ? { properties: schema.properties } : {},
2713
+ ...schema.required ? { required: schema.required } : {}
2714
+ } : void 0;
2715
+ const intersectionAdmitsNullOrUndefined = (schema.type === void 0 || normalizeTypes(schema.type).includes("null")) && schema.allOf.length > 0 && schema.allOf.every((member) => canAdmitNullOrUndefined(member, childOptions?.schemas) || hasOwnWrapping(member));
2716
+ const parentReAdmitsNull = schema.nullable === true || normalizeTypes(schema.type).includes("null") || schema.allOf.some((s) => s.type === "null" || s.nullable === true && isAnnotationOnly(s));
2717
+ const shapeMember = (objectOnly || membersRequireObject) && schema.properties !== void 0 && !(intersectionAdmitsNullOrUndefined && !parentReAdmitsNull);
2718
+ const shapeRefine = shapeSchema === void 0 || shapeMember ? void 0 : emitObjectShapeRefine(shapeSchema, child);
2719
+ const shapeCheck = shapeSchema === void 0 || shapeMember ? void 0 : emitObjectShapeCheck(shapeSchema, child);
2513
2720
  const effectiveAllOf = schema.properties !== void 0 ? [...schema.allOf, {
2514
2721
  type: "object",
2515
2722
  properties: schema.properties,
2516
2723
  ...schema.required ? { required: schema.required } : {}
2517
2724
  }] : schema.allOf;
2518
- if (effectiveAllOf.length === 0) return done("z.any()", schema);
2519
- const nullable = schema.nullable === true || (Array.isArray(schema.type) ? schema.type.includes("null") : schema.type === "null") || effectiveAllOf.some((s) => s.type === "null" || s.nullable === true && isAnnotationOnly(s));
2520
- const nonNull = effectiveAllOf.filter((s) => !(s.type === "null" || s.nullable === true && Object.keys(s).length === 1)).map((s) => inheritedBase(s, childOptions?.schemas) ?? s);
2725
+ const memberAllOf = shapeMember ? effectiveAllOf : schema.allOf;
2726
+ if (memberAllOf.length === 0) return done(shapeRefine === void 0 ? "z.any()" : `z.any().superRefine(${shapeRefine})`, schema);
2727
+ const nullable = schema.nullable === true || (Array.isArray(schema.type) ? schema.type.includes("null") : schema.type === "null") || memberAllOf.some((s) => s.type === "null" || s.nullable === true && isAnnotationOnly(s));
2728
+ const nonNull = memberAllOf.filter((s) => !(s.type === "null" || s.nullable === true && Object.keys(s).length === 1)).map((s) => inheritedBase(s, childOptions?.schemas) ?? s);
2521
2729
  const members = nonNull.filter((s) => !isAnnotationOnly(s));
2522
2730
  const emitted = {
2523
2731
  ...nonNull.filter(isAnnotationOnly).reduce((acc, s) => Object.assign(acc, s), {}),
2524
2732
  ...schema,
2525
2733
  nullable
2526
2734
  };
2527
- if (members.length === 0) return done("z.any()", emitted);
2735
+ if (members.length === 0) return done(shapeRefine === void 0 ? "z.any()" : `z.any().superRefine(${shapeRefine})`, emitted);
2528
2736
  const schemas = members.map(child);
2529
2737
  const isBareRef = schemas.length === 1 && members.every(isRefOnly) && Object.keys(schema).every((k) => k === "allOf" || k === "nullable" || k === "type");
2530
2738
  const [only] = schemas;
2531
2739
  if (isBareRef && only !== void 0) return done(only, emitted, true);
2532
2740
  const z = schemas.reduce((acc, s, i) => i === 0 ? s : `${acc}.and(${s})`);
2741
+ const shaped = (() => {
2742
+ if (shapeSchema === void 0 || shapeMember) return z;
2743
+ if (members.some((member) => !canAcceptObject(member, childOptions?.schemas))) return z;
2744
+ const shapeZ = zodToOpenAPI(shapeSchema, void 0, childOptions);
2745
+ for (let index = 0; index < members.length; index += 1) {
2746
+ const member = members[index];
2747
+ if (member === void 0) continue;
2748
+ const distributed = distribute(member, shapeZ, shapeRefine, schema.properties !== void 0, shapeSchema);
2749
+ if (distributed === null || distributed === schemas[index]) continue;
2750
+ return schemas.map((s, position) => position === index ? distributed : s).reduce((acc, s, i) => i === 0 ? s : `${acc}.and(${s})`);
2751
+ }
2752
+ return shapeCheck === void 0 ? z : `z.unknown().check(${shapeCheck}).pipe(${z})`;
2753
+ })();
2533
2754
  const allOfMessage = schema["x-allOf-message"] ?? schema["x-error-message"];
2534
2755
  const unevalCheck = makeUnevaluatedPropertiesCheck({
2535
2756
  ...schema,
2536
2757
  allOf: effectiveAllOf
2537
- }, (s) => zodToOpenAPI(s, void 0, childOptions), schema["x-error-message"], childOptions?.schemas);
2538
- if (allOfMessage || unevalCheck) return done(`(()=>{const Schema=${z};return z.unknown().check((ctx)=>{${(() => {
2758
+ }, (s) => zodToOpenAPI(s, void 0, childOptions), schema["x-error-message"], childOptions?.schemas, {});
2759
+ if (allOfMessage || unevalCheck) return done(`(()=>{const Schema=${shaped};return z.unknown().check((ctx)=>{${(() => {
2539
2760
  const isArrow = allOfMessage ? ARROW_FUNCTION_PATTERN.test(allOfMessage) : false;
2540
2761
  const msgExpr = allOfMessage ? isArrow ? `(${allOfMessage})(issue)` : JSON.stringify(allOfMessage) : void 0;
2541
2762
  return `const result=Schema.safeParse(ctx.value);if(!result.success){for(const issue of result.error.issues){${makeIssueForwarding(msgExpr ? `{...issue,input:issue.input,message:${msgExpr}}` : "{...issue,input:issue.input}")}}}`;
2542
2763
  })()}${unevalCheck ? `;(${unevalCheck})(ctx)` : ""}}).pipe(Schema)})()`, emitted);
2543
- return done(z, emitted, schemas.length === 1 && members.every(isRefOnly));
2764
+ return done(shaped, emitted, schemas.length === 1 && members.every(isRefOnly));
2544
2765
  }
2545
2766
  if (schema.anyOf !== void 0 && !(isBinaryFile(schema) && hasMimeAlternatives(schema))) {
2546
2767
  if (schema.anyOf.length === 0) return done("z.any()", schema);
@@ -2548,12 +2769,32 @@ function zodToOpenAPI(schema, meta, options) {
2548
2769
  const anyOfMessage = schema["x-implication-message"] ?? schema["x-anyOf-message"] ?? schema["x-error-message"];
2549
2770
  const anyOfErrorArg = anyOfMessage ? `,${error(anyOfMessage)}` : "";
2550
2771
  const unionZ = `z.union([${anyOfSchemas.join(",")}]${anyOfErrorArg})`;
2551
- if (schema.properties !== void 0 && Object.keys(schema.properties).length > 0 || Array.isArray(schema.required) && schema.required.length > 0) return done(`${unionZ}.and(${zodToOpenAPI({
2552
- type: "object",
2553
- ...schema.properties ? { properties: schema.properties } : {},
2554
- ...schema.required ? { required: schema.required } : {}
2555
- }, void 0, childOptions)})`, schema);
2556
- return done(unionZ, schema);
2772
+ const unevalCheck = makeUnevaluatedPropertiesCheck(schema, (s) => zodToOpenAPI(s, void 0, childOptions), schema["x-error-message"], childOptions?.schemas, { anyOf: true });
2773
+ if (schema.properties !== void 0 && Object.keys(schema.properties).length > 0 || Array.isArray(schema.required) && schema.required.length > 0) {
2774
+ const shapeSchema = {
2775
+ type: "object",
2776
+ ...schema.properties ? { properties: schema.properties } : {},
2777
+ ...schema.required ? { required: schema.required } : {}
2778
+ };
2779
+ const objectOnly = normalizeTypes(schema.type).includes("object") && normalizeTypes(schema.type).every((type) => type === "object" || type === "null");
2780
+ const branchesRequireObject = schema.anyOf.every((branch) => requiresObject(branch, childOptions?.schemas));
2781
+ const branchesAdmitNullOrUndefined = (schema.type === void 0 || normalizeTypes(schema.type).includes("null")) && schema.anyOf.some((branch) => canAdmitNullOrUndefined(branch, childOptions?.schemas) || hasOwnWrapping(branch));
2782
+ if ((objectOnly || branchesRequireObject) && !branchesAdmitNullOrUndefined) {
2783
+ const andZ = `${unionZ}.and(${zodToOpenAPI(shapeSchema, void 0, childOptions)})`;
2784
+ if (schema.properties === void 0) {
2785
+ const shapeCheck = emitObjectShapeCheck(shapeSchema, child);
2786
+ return done(withUnevaluatedCheck(shapeCheck === void 0 ? andZ : `z.unknown().check(${shapeCheck}).pipe(${andZ})`, unevalCheck), schema);
2787
+ }
2788
+ return done(withUnevaluatedCheck(andZ, unevalCheck), schema);
2789
+ }
2790
+ const shapeZ = zodToOpenAPI(shapeSchema, void 0, childOptions);
2791
+ const shapeRefine = emitObjectShapeRefine(shapeSchema, child);
2792
+ const distributed = schema.anyOf.map((branch) => distribute(branch, shapeZ, shapeRefine, schema.properties !== void 0, shapeSchema));
2793
+ if (!distributed.some((part) => part === null)) return done(withUnevaluatedCheck(`z.union([${distributed.join(",")}]${anyOfErrorArg})`, unevalCheck), schema);
2794
+ const shapeCheck = emitObjectShapeCheck(shapeSchema, child);
2795
+ return done(withUnevaluatedCheck(shapeCheck === void 0 ? unionZ : `z.unknown().check(${shapeCheck}).pipe(${unionZ})`, unevalCheck), schema);
2796
+ }
2797
+ return done(withUnevaluatedCheck(unionZ, unevalCheck), schema);
2557
2798
  }
2558
2799
  if (schema.oneOf !== void 0) {
2559
2800
  if (schema.oneOf.length === 0) return done("z.any()", schema);
@@ -2561,7 +2802,33 @@ function zodToOpenAPI(schema, meta, options) {
2561
2802
  const discriminator = schema.discriminator?.propertyName;
2562
2803
  const oneOfMessage = schema["x-oneOf-message"] ?? schema["x-error-message"];
2563
2804
  const oneOfErrorArg = oneOfMessage ? `,${error(oneOfMessage)}` : "";
2564
- return done(discriminator !== void 0 && discriminatedBranches(schema, options?.schemas) !== void 0 ? `z.discriminatedUnion(${makeStringLiteral(discriminator)},[${oneOfSchemas.join(",")}]${oneOfErrorArg})` : `z.xor([${oneOfSchemas.join(",")}]${oneOfErrorArg})`, schema);
2805
+ const z = discriminator !== void 0 && discriminatedBranches(schema, options?.schemas) !== void 0 ? `z.discriminatedUnion(${makeStringLiteral(discriminator)},[${oneOfSchemas.join(",")}]${oneOfErrorArg})` : `z.xor([${oneOfSchemas.join(",")}]${oneOfErrorArg})`;
2806
+ const unevalCheck = makeUnevaluatedPropertiesCheck(schema, (s) => zodToOpenAPI(s, void 0, childOptions), schema["x-error-message"], childOptions?.schemas, { oneOf: true });
2807
+ if (schema.properties !== void 0 && Object.keys(schema.properties).length > 0 || Array.isArray(schema.required) && schema.required.length > 0) {
2808
+ const shapeSchema = {
2809
+ type: "object",
2810
+ ...schema.properties ? { properties: schema.properties } : {},
2811
+ ...schema.required ? { required: schema.required } : {}
2812
+ };
2813
+ const objectOnly = normalizeTypes(schema.type).includes("object") && normalizeTypes(schema.type).every((type) => type === "object" || type === "null");
2814
+ const branchesRequireObject = schema.oneOf.every((branch) => requiresObject(branch, childOptions?.schemas));
2815
+ const branchesAdmitNullOrUndefined = (schema.type === void 0 || normalizeTypes(schema.type).includes("null")) && schema.oneOf.some((branch) => canAdmitNullOrUndefined(branch, childOptions?.schemas) || hasOwnWrapping(branch));
2816
+ if ((objectOnly || branchesRequireObject) && !branchesAdmitNullOrUndefined) {
2817
+ const andZ = `${z}.and(${zodToOpenAPI(shapeSchema, void 0, childOptions)})`;
2818
+ if (schema.properties === void 0) {
2819
+ const shapeCheck = emitObjectShapeCheck(shapeSchema, child);
2820
+ return done(withUnevaluatedCheck(shapeCheck === void 0 ? andZ : `z.unknown().check(${shapeCheck}).pipe(${andZ})`, unevalCheck), schema);
2821
+ }
2822
+ return done(withUnevaluatedCheck(andZ, unevalCheck), schema);
2823
+ }
2824
+ const shapeZ = zodToOpenAPI(shapeSchema, void 0, childOptions);
2825
+ const shapeRefine = emitObjectShapeRefine(shapeSchema, child);
2826
+ const distributed = schema.oneOf.map((branch) => distribute(branch, shapeZ, shapeRefine, schema.properties !== void 0, shapeSchema));
2827
+ if (!distributed.some((part) => part === null)) return done(withUnevaluatedCheck(`z.xor([${distributed.join(",")}]${oneOfErrorArg})`, unevalCheck), schema);
2828
+ const shapeCheck = emitObjectShapeCheck(shapeSchema, child);
2829
+ return done(withUnevaluatedCheck(shapeCheck === void 0 ? z : `z.unknown().check(${shapeCheck}).pipe(${z})`, unevalCheck), schema);
2830
+ }
2831
+ return done(withUnevaluatedCheck(z, unevalCheck), schema);
2565
2832
  }
2566
2833
  if (schema.not !== void 0) {
2567
2834
  const notMessage = schema["x-not-message"] ?? schema["x-error-message"];
@@ -2629,22 +2896,23 @@ function zodToOpenAPI(schema, meta, options) {
2629
2896
  return done(isJson && isBigintFormat && schema.enum.some((member) => typeof member === "number") ? `z.preprocess(${JSON_BIGINT},${members})` : members, schema);
2630
2897
  }
2631
2898
  if (schema.properties !== void 0 && schema.type === void 0 && !isUntypedObject(schema)) return done(emitTypelessRefine(schema, (s) => zodToOpenAPI(s, void 0, childOptions)), schema);
2632
- if (schema.properties !== void 0 && normalizeTypes(schema.type).includes("object") || isUntypedObject(schema)) {
2633
- const needsDefaultRequired = schema.required === void 0 && Object.keys(schema.properties ?? {}).length > 0 && schema.anyOf === void 0;
2634
- return done(object(schema, childOptions), needsDefaultRequired ? {
2635
- ...schema,
2636
- required: []
2637
- } : schema);
2638
- }
2639
2899
  const types = normalizeTypes(schema.type);
2640
2900
  const alternatives = types.filter((type) => type !== "null");
2641
2901
  if (alternatives.length > 1) {
2642
2902
  const { type: _type, ...rest } = undecorated(schema);
2643
2903
  return done(`z.union([${alternatives.map((type) => zodToOpenAPI({
2644
2904
  ...rest,
2905
+ ...type === "object" && schema.required !== void 0 ? { required: schema.required } : {},
2645
2906
  type
2646
2907
  }, void 0, childOptions)).join(",")}])`, schema);
2647
2908
  }
2909
+ if (schema.properties !== void 0 && normalizeTypes(schema.type).includes("object") || isUntypedObject(schema)) {
2910
+ const needsDefaultRequired = schema.required === void 0 && Object.keys(schema.properties ?? {}).length > 0 && schema.anyOf === void 0;
2911
+ return done(object(schema, childOptions), needsDefaultRequired ? {
2912
+ ...schema,
2913
+ required: []
2914
+ } : schema);
2915
+ }
2648
2916
  if (types.includes("string")) return done(string(schema, childOptions), schema);
2649
2917
  if (types.includes("number")) return done(number(schema), schema);
2650
2918
  if (types.includes("integer")) return done(integer(schema, { json: isJson }), schema);
@@ -1,13 +1,13 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
2
2
  import { Q as HOOK_LIBRARIES, q as COMPONENT_NAMES } from "./guard-Rvg4ztIZ.js";
3
- import { C as isInsideDirectory, E as makeGeneratedImport, S as appEntryOutput, T as makeAppEntryImport, _ 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 makeAppEntryFile, x as handlerGroupOf, y as callbacks } from "./core-DuBKXeEi.js";
3
+ import { C as isInsideDirectory, E as makeGeneratedImport, S as appEntryOutput, T as makeAppEntryImport, _ 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 makeAppEntryFile, x as handlerGroupOf, y as callbacks } from "./core-CT8AnDwr.js";
4
4
  import { t as docs } from "./docs-DC7Q_-PY.js";
5
5
  import { t as hooks } from "./hooks-B2Fcpr_z.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-Dy5PycHC.js";
10
+ import { n as normalizeOpenAPI } from "./openapi-DWSCULWR.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 { M as isRecord, tt as INPUT_EXTENSIONS } from "../guard-Rvg4ztIZ.js";
3
3
  import { t as FormatOptions } from "../format-BF7SbaMP.js";
4
- import { C as isInsideDirectory, S as appEntryOutput } from "../core-DuBKXeEi.js";
4
+ import { C as isInsideDirectory, S as appEntryOutput } from "../core-CT8AnDwr.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-BDYWF9wQ.js";
6
+ import { a as packageRoots, i as outsideSources, n as makeJob, r as openAPI3, t as cleanSplitOutputs } from "../shared-BmIHrl_h.js";
7
7
  import { Effect, FileSystem, Option, Result } from "effect";
8
8
  import path from "node:path";
9
9
  import crypto from "node:crypto";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono-takibi",
3
- "version": "0.32.4",
3
+ "version": "0.32.6",
4
4
  "description": "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi",
5
5
  "keywords": [
6
6
  "hono",
@@ -64,19 +64,19 @@
64
64
  },
65
65
  "dependencies": {
66
66
  "@apidevtools/swagger-parser": "^13.1.0",
67
- "@effect/platform-node": "4.1.2",
67
+ "@effect/platform-node": "4.1.4",
68
68
  "@typespec/compiler": "^1.17.0",
69
69
  "@typespec/openapi3": "^1.17.0",
70
- "effect": "4.1.2",
71
- "oxc-parser": "^0.157.0",
72
- "oxfmt": "^0.77.0"
70
+ "effect": "4.1.4",
71
+ "oxc-parser": "^0.158.0",
72
+ "oxfmt": "^0.78.0"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@faker-js/faker": "^10.6.0",
76
76
  "@hono/zod-openapi": "^1.6.3",
77
77
  "@types/node": "^26.6.6",
78
78
  "@typespec/http": "^1.17.0",
79
- "@typespec/rest": "^0.87.0",
79
+ "@typespec/rest": "^0.88.0",
80
80
  "hono": "^4.13.17",
81
81
  "typescript": "^7.0.2",
82
82
  "zod": "^4.6.7"