arktypea
arktype•6mo ago
noxy

Iterate over schema

Hello, I'm trying to create dynamic forms that would use ArkType to dynamically generate correct input type, but somehow I cannot find any good way to iterate over the schema. I've tried few things, and the only one that works is accessing schema.json.required which is not even part of TS type of JSON (it just exists at runtime). Is there any easier way?

Basically what I'm looking for is for a way to turn some schema
const schema = type({
  email: "string.email",
  name: "string",
  checkboxVal: "boolean",
  numVal: "number",
  color: type("string").configure({
    inputType: "color",
  }),
});

Into some representation that I can use to render components dynamically like
[
  {key: "email", value: "string.email"},
  {key: "name", value: "string"},
  {key: "checkboxVal", value: "boolean"},
  {key: "numVal", value: "number"},
  {key: "color", value: "string", meta: { inputType: "color" } },
]

Am I missing something? I've tried to look for solutions on the web, discord and LLMs but didn't find anything useful 😆
Was this page helpful?