Accessing the "final" schema and extracting it's rules
See original GitHub issueLet’s say I have the following schema (one of the examples in Yup’s documentation):
let schema = object({
isSpecial: boolean(),
isBig: boolean(),
count: number().when(['isBig', 'isSpecial'], {
is: true, // alternatively: (isBig, isSpecial) => isBig && isSpecial
then: yup.number().min(5),
otherwise: yup.number().min(0),
}),
});
const result = schema.validateSync({
isBig: true,
isSpecial: true,
count: 10,
});
The count
min value depends on the value of isBig
. That value is decided at runtime, when calling validate()
.
Is there a way I can somehow access the “final” schema and programatically check what Yup decided to enforce?
Something like:
const { result, finalSchema } = schema.validateSync({
isBig: true,
isSpecial: true,
count: 10,
});
console.log(finalSchema.count.min) // 5
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Extracting schemas from a rule application archive - IBM
Extracting schemas from a rule application archive. To access the schemas for an imported rule set, extract them from the decision service.
Read more >Creating and running an Extract rule - Pega
Create and open an Extract rule to run a manual BIX extraction process. To limit the properties included in your extract, ...
Read more >Finalizing the end schema JSON of your output file - Cloud - 8.0
About this task The last step of the wizard shows the end schema generated and allows you to customize the schema according to...
Read more >Create a Field Extraction Rule | Sumo Logic Docs
Extracted Fields (applicable to Ingest Time rules) shows the field names the rule will parse. Any fields that do not exist in the...
Read more >Learn the structure of an Access database - Microsoft Support
Tables to store your data. Queries to find and retrieve just the data that you want. Forms to view, add, and update data...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@alexandernst as mentioned above,
schema.resolve()
won’t resolve nested schemas. We must instead resolve the nested schema,count
in this case, viayup.reach()
.Now that we’re resolving at the nested schema, we’ll need to provide a
parent
object toschema.resolve()
in order for this nested schema to access the values of its siblings.Yes, that would be handy. Fortunately, Yup provides a good API for extending functionality like this.
For example, you can add a
resolveDeep
method to your schemas that traverses the schema and resolves each node in a similar manner to the workaround I posted above.