Repository navigation
fix(@angular/cli): support array options defined in oneOf schemas - #34607
Open
alan-agius4 wants to merge 1 commit into
Open
alan-agius4 wants to merge 1 commit into
alan-agius4 wants to merge 1 commit into
Conversation
Previously, `getSupportedTypes` in `json-schema.ts` only checked top-level `items` when determining if an `array` type in a JSON schema was supported on the CLI. Options like `allowedHosts` in `@angular/build:dev-server`, which define their `array` schema inside a `oneOf` alongside `boolean`, had their `array` type filtered out and were registered in Yargs as `boolean` only. Additionally, when an option supports both `array` (or `string`) and `boolean`, Yargs parses bare flags (e.g. `--allowed-hosts`) as `[]` and `--allowed-hosts=true` as `['true']`. This change checks `oneOf`/`anyOf` subschemas for supported array items and coerces empty or boolean-like values to booleans when `boolean` is also a supported type. Closes angular#33955
There was a problem hiding this comment.
Code Review
This pull request adds support for options that can be either an array or a boolean (such as allowedHosts in oneOf schemas) by introducing a coerceToBoolean helper and updating schema parsing. The review feedback points out an issue where default values (like an empty array []) are incorrectly coerced to true when generating help output. To resolve this, the reviewer suggests wrapping the coercion logic in a factory function createCoerceToBoolean(defaultValue) to bypass coercion for the default value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously,
getSupportedTypesinjson-schema.tsonly checked top-levelitemswhen determining if anarraytype in a JSON schema was supported on the CLI. Options likeallowedHostsin@angular/build:dev-server, which define theirarrayschema inside aoneOfalongsideboolean, had theirarraytype filtered out and were registered in Yargs asbooleanonly.Additionally, when an option supports both
array(orstring) andboolean, Yargs parses bare flags (e.g.--allowed-hosts) as[]and--allowed-hosts=trueas['true']. This change checksoneOf/anyOfsubschemas for supported array items and coerces empty or boolean-like values to booleans whenbooleanis also a supported type.Fixes #33955