Skip to content

Schematics schema should take custom validation functions #12705

Description

@natsid

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, 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.

Activity

  1. added this to the Backlog milestone on Oct 23, 2018
  2. FriOne commented on Jun 18, 2019

    @FriOne

    As I understand schematics uses inquirer inside. We could use validation property with reference to a file and a function. And call it after json schema validation pass.

    "x-prompt": {
        "message": "Insert a name",
        "validate": "./validation#checkNameUniqness"
    },
    

    Function should accept options that was inserted by user before.

  3. angular-robot commented on Feb 1, 2022

    @angular-robot
    Contributor

    Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

    Find more details about Angular's feature request process in our documentation.

  4. modified the milestones: Backlog, needsTriage on Feb 1, 2022
  5. angular-robot commented on Feb 21, 2022

    @angular-robot
    Contributor

    Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

    We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

    You can find more details about the feature request process in our documentation.

  6. added
    feature: insufficient votesLabel to add when the not a sufficient number of votes or comments from unique authors
    and removed
    feature: votes requiredFeature request which is currently still in the voting phase
    on Feb 21, 2022
  7. alan-agius4 commented on Sep 24, 2026

    @alan-agius4
    Collaborator

    Thank you for taking the time to submit this feature request.

    At this time, we are not planning to implement this feature, as it did not gather sufficient community interest and we want to be mindful of expanding the CLI configuration surface area when existing workarounds are available.

    We will be closing this issue as not planned for now, though we are happy to reconsider it in the future if community interest changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: @angular-devkit/schematicsfeatureLabel used to distinguish feature request from other issuesfeature: insufficient votesLabel to add when the not a sufficient number of votes or comments from unique authors

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions