ArkType `toJsonSchema` returning not open-api compatible schema.

Hi, I am trying to get my arktype schemas working with fastify (was previously using zod but editor performance was tragic) so I started with setting OpenAPI.

Zod tools use https://www.npmjs.com/package/zod-to-json-schema for this but since ArkType has a method built in I decided to use it the output however is different and zod's one actually uses enums/unions in a way that openapi can handle.

import { type } from "arktype";
import { z } from "zod";
import { zodToJsonSchema } from "zod-to-json-schema";

const mySchemaZod = z
  .object({
    myString: z.string().min(5),
    myUnion: z.union([z.number(), z.boolean()]),
  })
  .describe("My neat object schema");

const jsonSchemaZod = zodToJsonSchema(mySchemaZod, "mySchema");

console.log("ZOD ", jsonSchemaZod);

const mySchemaArk = type({
  myString: "string >= 5",
  myUnion: "number | boolean"
})

const jsonSchemaArk = mySchemaArk.toJsonSchema();

console.log("ARKTYPE ", jsonSchemaArk);
Was this page helpful?