Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error if required schematic properties without defaults are not provided #12167

Closed
alexeagle opened this issue Sep 5, 2018 · 4 comments
Closed
Labels
freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix

Comments

@alexeagle
Copy link
Contributor

From @dansanderson on June 14, 2017 18:15

Currently if a schematic property is in schema.json's "required" list, nothing different happens if the option is not provided on the command line and doesn't have a "default". It should report a user error in this case.

Copied from original issue: angular/devkit#6

@alexeagle alexeagle added comp: angular-devkit/schematics freq1: low Only reported by a handful of users who observe it rarely severity3: broken labels Sep 5, 2018
@alexeagle
Copy link
Contributor Author

From @ssilvert on January 10, 2018 15:45

I was just about to report this. It works fine for me if the schematic is run with the "schematics" tool. However, if the schematic is run from "ng" it ignores required properties.

schematics @Mystuff:myschematic <-- throws error if required prop not specified

ng g myschematic --collection @Mystuff <-- ignores required props

IMO, this is a BUG and not a feature request.

@dgp1130
Copy link
Collaborator

dgp1130 commented May 26, 2020

This still appears to reproduce on the latest version.

Initialized a new schematic with:

$ schematics blank --name test-schematic

Then added src/test-schematic/schema.json with:

{
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1
    }
  },
  "required": [ "name" ]
}

This requires a single name argument without a default value. Used this in the schematic:

import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';

export function testSchematic(_options: any): Rule {
  return (tree: Tree, _context: SchematicContext) => {
    _context.logger.info('The name is', _options.name);
    return tree;
  };
}

And ran with:

$ npm run build && schematics test-schematic:test-schematic
The name is

Definitely should throw an error in such a case.

douglasparker@basilisk (~/Source/fixit-test)
[20-05-26 15:31:02]$ (cd test-schematic/ && ng version)                                               

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 9.1.7
Node: 12.16.1
OS: linux x64

Angular: 9.1.9
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.7
@angular-devkit/build-angular     0.901.7
@angular-devkit/build-optimizer   0.901.7
@angular-devkit/build-webpack     0.901.7
@angular-devkit/core              9.1.7
@angular-devkit/schematics        9.1.7
@angular/cli                      9.1.7
@ngtools/webpack                  9.1.7
@schematics/angular               9.1.7
@schematics/update                0.901.7
rxjs                              6.5.5
typescript                        3.8.3
webpack                           4.42.0

@ngbot ngbot bot removed this from the Backlog milestone Jan 6, 2021
@alan-agius4
Copy link
Collaborator

Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version.

If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 6, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Projects
None yet
Development

No branches or pull requests

5 participants