Search code examples
angularangular-schematics

Angular Schematics Prompt for array type


When setting up my schematics I see that I can prompt for any of the following types String | Boolean | Array | Number | Integer | Null | Object.

I am trying to set up a schematic that prompts the user to select a module from a list of available modules. So for example the user would see something like this:

What module are you adding this store to?
 > Foo
   Bar
   Baz

While there are a ton of examples of both the String and Boolean prompts nobody has provided an example that I've found for the Array prompts. For the life of me I can not figure out how to provide the options in the array to prompt the user to select from and this doesn't appear in their documentation at all.

{
  "$schema": "http://json-schema.org/schema",
  "id": "SchematicsIDXStoreGen",
  "title": "IDX Store Gen Schema",
  "type": "object",
  "properties": {
    "featureName": {
      "type": "string",
      "description": "The name of the store",
      "x-prompt": "What is the name of the store you'd like to create"
    },
    "module": {
      "type": "array",
      "description": "Select the appropriate module",
      "x-prompt": "What module are you adding this store to?" // I want to provide a list of available modules here.
    }
  },
  "required": ["featureName", "module"]
}

Solution

  • You can try the following method also you wanna check the option what ever suits you.

    "modules": {
          "type": "array",
          "description": "description",
          "uniqueItems": true,
          "items": {
            "type": "string"
          },
          "x-prompt": {
            "message": "Which module would you like to select?",
            "type": "list",
            "multiselect": true,
            "items": [
              "firstOption",
              "secondOption",
              "thirdOption"
            ]
          }
        }