question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

angular_devkit schematics must be boolean input validation error

See original GitHub issue

๐Ÿž Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

i dont know

Description

I am trying to use the schematics cli to generate templates, since the templates are not for angular projects they are for broader use cases.

I am running into an issue when trying to use boolean values in the schematics cli. Whenever I try to pass a value for a boolean property it seems to interpret it as a string instead. โ€œx-promptโ€ seems to handle it however I was wondering if there is a solution or work around that does not involve using any prompts.

A clear and concise description of the problem...

Here is an example cli command that is failing for me. schematics .:test-generate-file --name foo --transform=true

Error: Error: Schematic input does not validate against the Schema: {โ€œtransformโ€:โ€œtrueโ€,โ€œnameโ€:โ€œfooโ€} Errors:

Data path โ€œ/transformโ€ must be boolean. at MapSubscriber.project (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/@angular-devkit/schematics/tools/schema-option-transform.js:30:27) at MapSubscriber._next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/operators/map.js:49:35) at MapSubscriber.Subscriber.next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/Subscriber.js:66:18) at ThrowIfEmptySubscriber._next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/operators/throwIfEmpty.js:44:26) at ThrowIfEmptySubscriber.Subscriber.next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/Subscriber.js:66:18) at TakeSubscriber._next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/operators/take.js:54:30) at TakeSubscriber.Subscriber.next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/Subscriber.js:66:18) at MergeMapSubscriber.notifyNext (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/operators/mergeMap.js:93:26) at SimpleInnerSubscriber._next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/innerSubscribe.js:27:21) at SimpleInnerSubscriber.Subscriber.next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/Subscriber.js:66:18)

๐Ÿ”ฌ Minimal Reproduction

  1. Create a schematic schematics blank --name foo

  2. Inside src/foo create a schema.json something like this: { โ€œ$schemaโ€: โ€œhttp://json-schema.org/schemaโ€, โ€œ$idโ€: โ€œfooโ€, โ€œtitleโ€: โ€œschemaโ€, โ€œtypeโ€: โ€œobjectโ€, โ€œpropertiesโ€: { โ€œnameโ€: { โ€œdescriptionโ€: โ€œuniversal nameโ€, โ€œtypeโ€: โ€œstringโ€, โ€œ$defaultโ€: { โ€œ$sourceโ€: โ€œargvโ€, โ€œindexโ€: 0 }, }, โ€œtransformโ€: { โ€œtypeโ€: โ€œbooleanโ€, โ€œdefaultโ€: false } }, โ€œrequiredโ€: [ โ€œnameโ€ ], โ€œadditionalPropertiesโ€: false }

  3. Then in the collection.json set a schema property inside foo { โ€œ$schemaโ€: โ€œโ€ฆ/node_modules/@angular-devkit/schematics/collection-schema.jsonโ€, โ€œschematicsโ€: { โ€œfooโ€: { โ€œdescriptionโ€: โ€œA blank schematic.โ€, โ€œfactoryโ€: โ€œ./foo/index#fooโ€, โ€œschemaโ€: โ€œfoo/schema.jsonโ€ } } }

  4. After that npm run build

  5. Then finally run the schematic command to try to run it schematics .:foo --name foo --transform=true

๐Ÿ”ฅ Exception or Error


Error: Schematic input does not validate against the Schema: {"transform":"true","name":"foo"}
Errors:

  Data path "/transform" must be boolean.
    at MapSubscriber.project (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/@angular-devkit/schematics/tools/schema-option-transform.js:30:27)
    at MapSubscriber._next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/operators/map.js:49:35)
    at MapSubscriber.Subscriber.next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/Subscriber.js:66:18)
    at ThrowIfEmptySubscriber._next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/operators/throwIfEmpty.js:44:26)
    at ThrowIfEmptySubscriber.Subscriber.next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/Subscriber.js:66:18)
    at TakeSubscriber._next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/operators/take.js:54:30)
    at TakeSubscriber.Subscriber.next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/Subscriber.js:66:18)
    at MergeMapSubscriber.notifyNext (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/operators/mergeMap.js:93:26)
    at SimpleInnerSubscriber._next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/innerSubscribe.js:27:21)
    at SimpleInnerSubscriber.Subscriber.next (/home/tokuj/.nvm/versions/node/v14.15.5/lib/node_modules/@angular-devkit/schematics-cli/node_modules/rxjs/internal/Subscriber.js:66:18)


๐ŸŒ Your Environment





Anything else relevant?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
jaredtfornidacommented, Dec 14, 2021

Can you try

schematics .:foo --name foo --transform

Hi, your solution seems to work only when the default value is false. If instead, the default value was true, that would not work. Am I wrong?

You are correct. Yesterday I found that if you want to set false flag you can do this: --no-transform

1reaction
jaredtfornidacommented, Nov 19, 2021

oh wow that worked thank you for the fast response

Read more comments on GitHub >

github_iconTop Results From Across the Web

Schema validation failed with error optimization.styles should ...
Okay, based on this answer @angular-devkit/build-angular 0.1100.7 is outdated. Updating it manually fixed the issue.
Read more >
Authoring schematics - Angular
The $schema property specifies the schema that the CLI uses for validation. ยท The schematics property lists named schematics that belong to this...
Read more >
angular-devkit/schematics - npm
Schematics provides some JSON Schema formats for validation that tooling should add. These validate paths, html selectors and app names. Pleaseย ...
Read more >
Angular Schematics from 0 to publishing your own library (III)
When you generate a blank schematic, options are declared as type any . That's because the generator has no idea what will be...
Read more >
Total Guide To Custom Angular Schematics | by Tomas Trajan
Before we start, we have to install @angular-devkit/schematics-cli package ... we would encounter following Error: Schematic input does not validate against ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found