import { parseDef as s } from "./parseDef.js";
import { getRefs as m } from "./Refs.js";
const g = (c, t) => {
  const e = m(t), r = typeof t == "object" && t.definitions ? Object.entries(t.definitions).reduce((o, [d, h]) => ({
    ...o,
    [d]: s(h._def, {
      ...e,
      currentPath: [...e.basePath, e.definitionPath, d]
    }, !0) ?? {}
  }), {}) : void 0, a = typeof t == "string" ? t : t?.nameStrategy === "title" ? void 0 : t?.name, i = s(c._def, a === void 0 ? e : {
    ...e,
    currentPath: [...e.basePath, e.definitionPath, a]
  }, !1) ?? {}, f = typeof t == "object" && t.name !== void 0 && t.nameStrategy === "title" ? t.name : void 0;
  f !== void 0 && (i.title = f);
  const n = a === void 0 ? r ? {
    ...i,
    [e.definitionPath]: r
  } : i : {
    $ref: [
      ...e.$refStrategy === "relative" ? [] : e.basePath,
      e.definitionPath,
      a
    ].join("/"),
    [e.definitionPath]: {
      ...r,
      [a]: i
    }
  };
  return e.target === "jsonSchema7" ? n.$schema = "http://json-schema.org/draft-07/schema#" : (e.target === "jsonSchema2019-09" || e.target === "openAi") && (n.$schema = "https://json-schema.org/draft/2019-09/schema#"), e.target === "openAi" && ("anyOf" in n || "oneOf" in n || "allOf" in n || "type" in n && Array.isArray(n.type)) && console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."), n;
};
export {
  g as zodToJsonSchema
};
//# sourceMappingURL=zodToJsonSchema.js.map
