|
1 | 1 | import { toJsonSchema } from "@valibot/to-json-schema";
|
2 | 2 | import type { Type as ArkTypeValidator } from "arktype";
|
3 |
| -import { mergeConfigs } from "tailwind-merge"; |
4 | 3 | import * as v from "valibot";
|
5 | 4 | import { zodToJsonSchema } from "zod-to-json-schema";
|
6 | 5 | import * as z3 from "zod/v3";
|
7 | 6 | import * as z4 from "zod/v4";
|
8 | 7 | import { detectValidatorType } from "./detectValidator";
|
9 | 8 | import type { ParsedTRPCRouter, Router } from "./types";
|
| 9 | +import type { JSONSchema7Object } from "json-schema"; |
10 | 10 |
|
11 | 11 | export function parseRootRouter(router: any): Router {
|
12 | 12 | return parseTRPCRouter(router, []) as unknown as Router;
|
@@ -101,13 +101,15 @@ export function parseTRPCRouter(
|
101 | 101 | }
|
102 | 102 | } else if (validatorType === "arktype") {
|
103 | 103 | console.log("arktype");
|
| 104 | + console.log(item._def.inputs); |
| 105 | + jsonSchema = arkToJson(item._def.inputs); |
104 | 106 | // const merged = item._def.inputs.reduce(
|
105 | 107 | // (merge: ArkTypeValidator, curr: ArkTypeValidator) => {
|
106 | 108 | // merge.and(curr);
|
107 | 109 | // },
|
108 | 110 | // );
|
109 | 111 | // jsonSchema = merged.toJsonSchema();
|
110 |
| - jsonSchema = item._def.inputs.toJSONSchema(); |
| 112 | + // jsonSchema = item._def.inputs.toJSONSchema(); |
111 | 113 | }
|
112 | 114 | }
|
113 | 115 |
|
@@ -147,3 +149,24 @@ export function parseTRPCRouter(
|
147 | 149 |
|
148 | 150 | return result;
|
149 | 151 | }
|
| 152 | + |
| 153 | +function arkToJson(inputs: ArkTypeValidator[]): JSONSchema7Object { |
| 154 | + if (inputs.length === 1) { |
| 155 | + return inputs[0]?.toJsonSchema(); |
| 156 | + } |
| 157 | + if (inputs.length > 1) { |
| 158 | + const [first, ...rest] = inputs; |
| 159 | + return arkRecursive(first, rest); |
| 160 | + } |
| 161 | + return {}; |
| 162 | +} |
| 163 | +function arkRecursive( |
| 164 | + base: ArkTypeValidator, |
| 165 | + rest: ArkTypeValidator[], |
| 166 | +): JSONSchema7Object { |
| 167 | + if (rest.length === 0) { |
| 168 | + return base.toJsonSchema(); |
| 169 | + } |
| 170 | + const [first, ...left] = rest; |
| 171 | + return arkRecursive(base.and(first), left); |
| 172 | +} |
0 commit comments