npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@open-form-spec/plugin-yup

v0.2.0

Published

Yup schema generator plugin for Open Form Spec

Readme

@open-form-spec/plugin-yup

Generates type-preserving yup validation schemas from Open Form Spec files.

The generated code handles Layer 1 — field states (required / optional / forbidden), conditional logic (.when()), and enum constraints (.oneOf()). You only override fields where you need additional content validation.

Setup

// ofs.config.js
import { defineConfig } from "@open-form-spec/plugin";
import { yupGenerator } from "@open-form-spec/plugin-yup";

export default defineConfig({
  specs: "src/specs/**/*.ofs.yaml",
  openapi: { api: "src/openapi.yaml" },
  plugins: [
    yupGenerator({
      output: "src/generated/ofs",
      enumImport: "@/api/generated/backend/index.schemas",
    }),
  ],
});
npx ofs generate

What Gets Generated

For each spec section, the plugin generates a defaults object, a Fields type, and a schema function:

// registration.ofs.ts (auto-generated)
import { AccountType } from "@/api/generated/backend/index.schemas";

export const registrationDefaults = {
  email: yup.string(),
  accountType: yup.string().oneOf(Object.values(AccountType)),
  nickname: yup.string(),
};
export type RegistrationFields = typeof registrationDefaults;

export function registrationSchema<T extends Partial<RegistrationFields>>(overrides?: T) {
  const fields = { ...registrationDefaults, ...overrides };

  return yup.object().shape({
    email: fields.email.required(),
    accountType: fields.accountType.required(),
    nickname: fields.nickname.optional(),
  });
}

Types are fully preserved — RegistrationFields["accountType"] is StringSchema<"PERSONAL" | "BUSINESS" | ... | undefined>, not just StringSchema<string>.

Usage

Override only the fields where you need additional validation:

import { registrationSchema } from "./generated/ofs/registration.ofs";

const schema = registrationSchema({
  email: yup.string().email("Invalid email"),
  password: yup.string().min(8),
});

Fields you don't override keep their generated defaults — correct type, enum .oneOf(), format-specific factory. Layer 2 overrides should not call .required() or .optional() — Layer 1 handles that.

Plugin Options

| Option | Type | Description | |--------|------|-------------| | output | string | Output directory, relative to config root | | enumImport | string | Import path for enum types. Enables .oneOf(Object.values(EnumName)) generation | | types | Record<string, TypeOverride> | Custom schema factories per OpenAPI type or type:format |

Custom Type Factories

Override yup factories for specific OpenAPI types. Format-specific keys ("string:date") take priority over base type keys ("string"):

yupGenerator({
  output: "src/generated/ofs",
  enumImport: "@/api/generated/backend/index.schemas",
  types: {
    string: {
      factory: "string()",
      import: { name: "string", from: "@/utils/validation/types" },
    },
    "string:date": {
      factory: "dateString()",
      import: { name: "dateString", from: "@/utils/validation/date-string" },
    },
  },
})

See the full plugin documentation for react-hook-form integration, context passing, nested fields, and field state behavior details.