Schematics schema should take custom validation functions
- Dominant language
- TypeScript
- Stars
- 27k
- Forks
- 11.8k
- Avg merge
- 14h 23m
- Merged PRs (30d)
- 162
Description
### Bug Report or Feature Request (mark with an `x`)
```
- [ ] bug report -> please search issues before submitting
- [x] feature request
```
### Desired functionality
I would like to be able to specify validation functions for options of a schematic in the schema. JSON Schema does have some [built-in validation](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6), but this doesn't cover everything.
Here are a couple of examples that are not covered by JSON Schema:
- An option for the name of a new directory or file that should not match the name of an existing directory or file
- An option whose validity is based on a previous option's value
A workaround is to perform this type of validation within the schematic function itself, however, this is not the best possible user experience when using the prompt system. As a user, I would expect my input to be validated as I enter it, then re-prompted for if necessary. With this workaround, a user would need to re-invoke the program from the beginning if their input is found invalid within the schematic function.
Contributor guide
Research direction
Start by tracing how schematic schemas are validated and how the prompt system handles option input; the issue names the schematic function as the current workaround. Done means schema-defined custom validation can cover cross-option and filesystem-based cases, validate input during prompting, and re-prompt when input is invalid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100