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

Nx does not respect types defined in schema.json #1952

Closed
ZachJW34 opened this issue Oct 16, 2019 · 2 comments · Fixed by #1973
Closed

Nx does not respect types defined in schema.json #1952

ZachJW34 opened this issue Oct 16, 2019 · 2 comments · Fixed by #1973
Assignees

Comments

@ZachJW34
Copy link
Contributor

ZachJW34 commented Oct 16, 2019

Expected Behavior

Running a custom schematic using npm run workspace-schematic -- custom-schematic --routing false with a schema.json of

{
  "$schema": "http://json-schema.org/schema",
  "id": "custom-schematic",
  "type": "object",
  "properties": {
    "routing": {
      "type": "boolean",
      "description": "Add routing",
      "default": true
    }
  },
  "required": ["routing"]
}

should run without error.

Current Behavior

The schematic fails with error:

Error: Schematic input does not validate against the Schema: {blah-blah}
Errors:

  Data path ".routing" should be boolean.

Steps to Reproduce

Create a custom schematic that has a boolean property that defaults to true and overwrite the property to false on the command line.

Context

The AngularCLI implements its own parser for command line inputs. Nx uses yargs and the handoff the the parsed yargs args to the AngularCLI for running schematics does not mesh well. The reason the schematic fails is the routing boolean is parsed as 'false', a string rather than a boolean.

This can be remedied by always having boolean properties default to false in the schema.json and passing just the flag i.e. npm run workspace-schematic -- custom-schematic --routing, but this is limiting. This problem compounds if schematic schemas are more complex. For example, it is not possible to pass an array without comma delimiting it and splitting the string.

The boolean problem can be fixed by reading the schema.json associated with the schematic being run and adding the properties with type === boolean to the yargs-parser config seen here. This isn't a perfect solution, but building an equivalency between nx and the angular cli is a bit involved.

Let me know what you think. I can submit a PR fixing the boolean problem.

@jaysoo
Copy link
Member

jaysoo commented Oct 17, 2019

@ZachJW34 That sounds like a good idea. We should add an e2e test to cover this (e2e/command-line.test.ts). Let us know if you need any help. :)

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants