fix(@angular/cli): handle oneOf when converting schema to yargs options#32554
fix(@angular/cli): handle oneOf when converting schema to yargs options#32554terencehonles wants to merge 1 commit intoangular:mainfrom
oneOf when converting schema to yargs options#32554Conversation
d03daeb to
57a8100
Compare
|
This is a breaking change |
|
I forgot I looked into how yargs does its parsing and it almost works (it doesn't actually are about the option definition). Using |
57a8100 to
2f9690d
Compare
…ions This change fixes JSONSchemas where `oneOf` is placed at the root of the schema rather than in an array's `items`. This allows an array to be passed via the command-line, but additional types to be represented via configuration.
2f9690d to
b9b858a
Compare
|
The change I pushed should handle |
|
|
||
| const SUPPORTED_PRIMITIVE_TYPES = new Set(['boolean', 'number', 'string']); | ||
| const SUPPORTED_PRIMITIVE_TYPES = new Set(['boolean', 'number', 'string'] as const); | ||
| type SupportedPrimitiveType = Parameters<typeof SUPPORTED_PRIMITIVE_TYPES.add>[0]; |
There was a problem hiding this comment.
Consider the below, which IMO it's slightly easier to read.
| type SupportedPrimitiveType = Parameters<typeof SUPPORTED_PRIMITIVE_TYPES.add>[0]; | |
| const types = ['boolean', 'number', 'string'] as const; | |
| const SUPPORTED_PRIMITIVE_TYPES: ReadonlySet<string> = new Set(types); | |
| type SupportedPrimitiveType = (typeof types)[number]; |
| function isSupportedPrimitiveType(value: string): boolean { | ||
| return SUPPORTED_PRIMITIVE_TYPES.has(value); | ||
| function isSupportedPrimitiveType(value: string): value is SupportedPrimitiveType { | ||
| return SUPPORTED_PRIMITIVE_TYPES.has(value as any); |
There was a problem hiding this comment.
Remove the casting, this is not needed if you change the set type.
| return SUPPORTED_PRIMITIVE_TYPES.has(value as any); | |
| return SUPPORTED_PRIMITIVE_TYPES.has(value); |
| : { | ||
| type, | ||
| }), | ||
| : type === 'array' |
There was a problem hiding this comment.
This isn't right as it cause the array type to be replaced by a primitive and forces yargs to parse it as a non array. Example --flag foo bar will now become invalid.
PR Checklist
Please check to confirm your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Options such as
--allowed-hostsare defined asoneOf([array<string>, boolean])but the array option is not chosen, even though it is first, because the JSONSchema conversion only supports an array at the root of the option schema.Issue Number: N/A
What is the new behavior?
This change fixes JSONSchemas where
oneOfis placed at the root of the option schema rather than in an array'sitems. This allows an array to be passed via the command-line, but additional types to be represented via configuration.Does this PR introduce a breaking change?
This will affect any commands for each of the options that use
oneOfat the root of their schemas. This change does not change the precedence of schema definition, so if there are any changes and they are not wanted then it is just uncovering a bug where the preferred type should have been ordered first.Other information