Skip to content

Add missing documentation for using schematics with array options #33851

Closed

Description

@d-koppenhagen

📚 Docs or angular.io bug report

Description

Hello! my recently opened issue angular/angular-cli#16104 has been closed (thanks for fixing it!) Unfortunatly I couldn't find any point for how to set multi select options via command line in the docs.
My expectation was to do it this way:

ng add packageName --param=foo,bar,baz

or something similar but I tried out a lot of ways without getting it working.
I expected to find it in the @next branch for angular.io -- maybe in the guards section (https://next.angular.io/cli/generate#guard-command : as --implements is using it) but it seems not to be documented there as well currently.

Playing a bit around, I found out that this seems to be the solution:

ng g g foo-bar --implements="CanActivate, CanLoad"

This should be documented better. However trying to implement this behaviour the same way failed for some reason.
When I configure my schematic this way:

{
  "$schema": "http://json-schema.org/schema",
  "id": "ngx-semantic-version",
  "title": "ngx-semantic-version Schema",
  "description": "configure commitlint, husky, commitizen and standard-version configuration",
  "type": "object",
  "properties": {
    "packages": {
      "type": "array",
      "description": "select the packages that should to be installed and configured",
      "uniqueItems": true,
      "items": {
        "type": "string"
      },
      "default": ["commitlint", "commitizen", "husky", "standard-version"],
      "x-prompt": {
        "message": "What packages do you want to be installed and configured?",
        "type": "list",
        "multiselect": true,
        "items": ["commitlint", "commitizen", "husky", "standard-version"]
      }
    },
  },
  "required": ["packages"]
}

and I run my schematic locally using schematics .:ng-add --debug=false --packages="commitlint, husky", I will receive the following output:

Error: Schematic input does not validate against the Schema: {"packages":"commitlint, husky"}
Errors:

  Data path ".packages" should be array.
    at MapSubscriber.registry.compile.pipe.operators_1.map.result [as project] (/usr/local/lib/node_modules/@angular-devkit/schematics-cli/node_modules/@angular-devkit/schematics/tools/schema-option-transform.js:31:27)
    at MapSubscriber._next (/usr/local/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/operators/map.js:49:35)
    at MapSubscriber.Subscriber.next (/usr/local/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/Subscriber.js:66:18)
    at ThrowIfEmptySubscriber._next (/usr/local/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/operators/throwIfEmpty.js:44:26)
    at ThrowIfEmptySubscriber.Subscriber.next (/usr/local/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/Subscriber.js:66:18)
    at TakeSubscriber._next (/usr/local/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/operators/take.js:54:30)
    at TakeSubscriber.Subscriber.next (/usr/local/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/Subscriber.js:66:18)
    at MergeMapSubscriber.notifyNext (/usr/local/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/operators/mergeMap.js:92:26)
    at InnerSubscriber._next (/usr/local/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/InnerSubscriber.js:28:21)
    at InnerSubscriber.Subscriber.next (/usr/local/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/Subscriber.js:66:18)

🔬 Minimal Reproduction

see above descriptions or https://github.com/d-koppenhagen/ngx-semantic-version/tree/ng9

What's the affected URL?**

https://next.angular.io

📷Screenshot

Screen Shot 2019-11-15 at 12 30 35

🔥 Exception or Error

see above image / pasted output.

🌍 Your Environment

Browser info

Anything else relevant?

Activity

  1. d-koppenhagen commented on Nov 15, 2019

    @d-koppenhagen
    ContributorAuthor

    I tried out some modifications but they lead to the same result:

    schema.d.ts:

    /**
     * ngx-semantic-version Schema
     * configure commitlint, husky, commitizen and standard-version configuration
     */
    export interface NgxSemanticVersion {
        /**
         * select the packages that should to be installed and configured
         */
        packages: ("commitlint" | "commitizen" | "husky" | "standard-version")[];
    }

    schema.json:

    {
      "$schema": "http://json-schema.org/schema",
      "id": "ngx-semantic-version",
      "title": "ngx-semantic-version Schema",
      "description": "configure commitlint, husky, commitizen and standard-version configuration",
      "type": "object",
      "properties": {
        "packages": {
          "type": "array",
          "description": "select the packages that should to be installed and configured",
          "uniqueItems": true,
          "minItems": 1,
          "items": {
            "enum": ["commitlint", "commitizen", "husky", "standard-version"],
            "type": "string"
          },
          "default": ["commitlint", "commitizen", "husky", "standard-version"],
          "x-prompt": "What packages do you want to be installed and configured?"
        },
      },
    }
  2. added this to the needsTriage milestone on Nov 16, 2019
  3. modified the milestones: needsTriage, Backlog on Nov 19, 2019
  4. d-koppenhagen commented on Nov 26, 2019

    @d-koppenhagen
    ContributorAuthor

    I wonder why it works for --implements within guard creation. Maybe the magic is hidden in the schema.d.ts which is unfortunately not checked in. But there are two things imported here: https://github.com/angular/angular-cli/blob/9.0.x/packages/schematics/angular/guard/index.ts#L25
    Would you mind to share the content of schema.d.ts?

  5. d-koppenhagen commented on Nov 26, 2019

    @d-koppenhagen
    ContributorAuthor

    Okay, I just forked the angular-cli project and built it locally. The schema produced for the guard seems to look basically like this:

    export interface Schema {
        ...
        implements?: Implement[];
       ...
    }
    
    export enum Implement {
        CanActivate = "CanActivate",
        CanActivateChild = "CanActivateChild",
        CanDeactivate = "CanDeactivate",
        CanLoad = "CanLoad",
    }

    I tried to copy the schema and implementation into a very simple example repo:
    https://github.com/d-koppenhagen/ngx-multi-select-schematic

    But the result will be the same as described in the original issue text. Probably it's a bug and not just a not documented feature?

  6. kapunahelewong commented on May 27, 2020

    @kapunahelewong
    Contributor

    Update: Docs team would like engineering input here on what exactly to document and/or fix in the current documentation. Thank you!

  7. added
    P4
    and removed on Oct 1, 2020
  8. added a commit that references this issue on Jun 27, 2022
    9c81746
  9. angular-automatic-lock-bot commented on Jul 28, 2022

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  10. locked and limited conversation to collaborators on Jul 28, 2022
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

    P4freq1: lowstate: needs eng inputtype: bug/fix

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions