ProvenPin Install

AJV 8 JSON Schema validation with ajv-formats: working versions (tested 2026-10-15)

Compile JSON Schema drafts with AJV 8, enable email/uri/uuid formats via ajv-formats, and return field errors from validate.errors for API payloads.

passed2 passed · 0 failed2026-10-15 15:56 UTC
Status
passed
Last passed
2026-10-15 15:56 UTC
Tests
2 / 2
Language
TypeScript
Runtime
node v22.23.3
pinned versions4
ajv@8.20.0ajv-formats@3.0.1@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38764699834

The code

Exactly the files that passed. Your agent can pull them with get_recipe("ajv-formats-json-schema") (install), or see them on GitHub.

package.json
{
  "name": "ajv-formats-json-schema",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "ajv": "8.20.0",
    "ajv-formats": "3.0.1"
  },
  "devDependencies": {
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
src/validate.ts
import Ajv, { type ErrorObject } from "ajv";
import addFormats from "ajv-formats";

const ajv = new Ajv({ allErrors: true, removeAdditional: "all", coerceTypes: true });
addFormats(ajv);

export const userSchema = {
  type: "object",
  additionalProperties: false,
  required: ["email", "name"],
  properties: {
    email: { type: "string", format: "email" },
    name: { type: "string", minLength: 1, maxLength: 80 },
    age: { type: "integer", minimum: 13 },
    website: { type: "string", format: "uri" },
    id: { type: "string", format: "uuid" },
  },
} as const;

export const validateUser = ajv.compile(userSchema);

export function fieldErrors(errors: ErrorObject[] | null | undefined) {
  const out: Record<string, string[]> = {};
  for (const e of errors ?? []) {
    const key = (e.instancePath || "/").replace(/^\//, "") || e.params?.missingProperty || "_";
    (out[key] ??= []).push(e.message ?? e.keyword);
  }
  return out;
}
test/validate.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { fieldErrors, validateUser } from "../src/validate.ts";

test("accepts a valid payload and strips extras", () => {
  const data: Record<string, unknown> = {
    email: "[email protected]",
    name: "Ada",
    age: "30",
    admin: true,
    id: "123e4567-e89b-12d3-a456-426614174000",
  };
  assert.equal(validateUser(data), true);
  assert.equal(data.admin, undefined);
  assert.equal(data.age, 30);
});

test("rejects bad email and missing name", () => {
  assert.equal(validateUser({ email: "nope" }), false);
  const errs = fieldErrors(validateUser.errors);
  assert.ok(errs.email || errs._);
  assert.ok(Object.keys(errs).length >= 1);
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.