WASD-Team / yup-ast

JSON AST schema generator for YUP
128 stars 16 forks source link

yup schema of an yup-ast definition itself #4

Open jakelowen opened 5 years ago

jakelowen commented 5 years ago

Amazing library. I've been playing with this concept for a while and your execution is very clean.

This may be very "meta" request, but do you have a ready example of a proper yup.schema of a yup-ast definition itself?

My use case: I'm attempting to validate an object of which a yup-ast definition is one aspect among others.

Example: see the "triggerConditions" line below.

let schema = yup.object().shape({
    name: yup.string(),
    id: yup.string(),
    notes: yup.string(),
    steps: yup
      .array()
      .of(
        yup.object().shape({
          name: yup.string().required(),
          topic: yup.string().required(),
          // triggerConditions is a yup-ast definition
          triggerConditions: yup.array().of(yup.array()),
          extractions: yup.array().of(
            yup.array().of(yup.string()).min(1)
          ).required(),
          required: yup.boolean().required(),
          maxAttempts: yup.number().min(1).positive().required()
        })
      )
      .required()

  });

Should I be more specific than yup.array().of(yup.array()) ?

avin-kavish commented 4 years ago

Sounds like you need to write a custom validator for yup, to validate the yup-ast format

tavurth commented 4 years ago

Unfortunately I can't make any changes due to https://github.com/WASD-Team/yup-ast/issues/10