UNPKG

sveltekit-superforms

Version:

Making SvelteKit forms a pleasure to use!

25 lines (24 loc) 687 B
function addMethod(yup, name) { yup.addMethod(yup.Schema, name, function (value) { const meta = this.describe().meta || {}; return this.meta({ ...meta, jsonSchema: { ...meta.jsonSchema, [name]: value } }); }); } export function extendSchema(yup) { addMethod(yup, 'example'); addMethod(yup, 'examples'); addMethod(yup, 'description'); yup.addMethod(yup.Schema, 'jsonSchema', function (callback) { const meta = this.describe().meta || {}; return this.meta({ ...meta, jsonSchema: callback(meta.jsonSchema || {}) }); }); }