schema-to-yup is a utility library for generating Yup validation schemas directly from declarative schema definitions such as JSON Schema or GraphQL type definitions. It helps automate the creation of validation logic, reducing boilerplate, especially in applications that consume or define data models externally. Currently at version 1.12.18, the package appears to be actively maintained, indicated by regular minor releases. A key differentiator is its configurability, allowing developers to customize error messages, enforce default `required` behavior, and integrate with existing schema ecosystems. While it supports common JSON Schema features, users should be aware that it does not automatically resolve `$ref` (JSON Pointers), requiring a pre-processing step with another library if `$ref`s are present in the input schema.
npm install schema-to-yupVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a JSON schema, configure custom error messages, build a Yup schema using `buildYup`, and then use the generated schema to validate data, showing both valid and invalid scenarios.
Use a JSON Schema dereferencing library like `json-schema-ref-parser` to preprocess your schema: `const dereferencedSchema = await refParser.dereference(originalSchema); const yupSchema = buildYup(dereferencedSchema, config);`
To change the default behavior for properties not explicitly marked `required`, configure the `mode` option: `const yupSchema = buildYup(jsonSchema, { mode: { notRequired: false } });` Setting `notRequired: false` will make properties required by default if not specified otherwise.No dependency data recorded yet.