Codify
Plugin Development

Schema validation

Validate user configurations with JSON Schema or Zod

Schema Validation

Use JSON Schema or Zod for validation:

JSON Schema

// my-resource-schema.json
{
  "type": "object",
  "properties": {
    "version": { "type": "string" },
    "path": { "type": "string" }
  },
  "required": ["version"]
}

// my-resource.ts
import Schema from './my-resource-schema.json';

interface MyConfig extends StringIndexedObject {
  version: string;
  path?: string;
}

getSettings() {
  return { schema: Schema };
}

Zod (Preferred)

Zod provides type safety with a single source of truth:

import { z } from 'zod';

const schema = z.object({
  version: z.string(),
  path: z.string().optional(),
});

type MyConfig = z.infer<typeof schema>;

getSettings() {
  return { schema };
}

On this page