runtypes-pretty-validation
v1.3.1
Published
convert runtypes schemas to jsonschema
Downloads
2
Maintainers
Readme
runtypes-pretty-validation
validate runtypes schemas against a value, and reflect back a pretty validation report, matching the schema. Prettyifies structural error messages arbitrarily deep.
import { validate } from "runtypes-pretty-validation";
const schema = rt.Record({ foo: rt.Literal("bar") });
validate(schema, null); // Expected object, got "null"
validate(schema, { bar: "bar" }); // { foo: 'Expected literal `bar`, but was `undefined`' }
validate(schema, { foo: "bar" }); // undefined, all valid
install
npm install runtypes-pretty-validation
options
Options may be specified. See ./index.ts for defaults.
validate(schema, value[, opts])
useFirstUnionSchemaOnFail: boolean
: if a validation fails all union members, report the schema validation errors from the first schema in the union.
examples
see test.ts for more.