From 57a81003b739986247c61ecc8a2cbc0b7c90468d Mon Sep 17 00:00:00 2001 From: "Terence D. Honles" Date: Tue, 24 Feb 2026 09:25:24 +0100 Subject: [PATCH] fix(@angular/cli): handle `oneOf` when converting schema to yargs options 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. --- .../command-builder/utilities/json-schema.ts | 6 +++++- .../utilities/json-schema_spec.ts | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/angular/cli/src/command-builder/utilities/json-schema.ts b/packages/angular/cli/src/command-builder/utilities/json-schema.ts index 0a4215be8eed..e398b34dbe07 100644 --- a/packages/angular/cli/src/command-builder/utilities/json-schema.ts +++ b/packages/angular/cli/src/command-builder/utilities/json-schema.ts @@ -156,6 +156,10 @@ function isSupportedArrayItemSchema(schema: json.JsonObject): boolean { return true; } + if (isJsonObject(schema.items)) { + return isSupportedArrayItemSchema(schema.items); + } + if (json.isJsonArray(schema.items)) { return schema.items.some((item) => isJsonObject(item) && isSupportedArrayItemSchema(item)); } @@ -198,7 +202,7 @@ function getSupportedTypes( case 'string': return true; case 'array': - return isJsonObject(current.items) && isSupportedArrayItemSchema(current.items); + return isSupportedArrayItemSchema(current); case 'object': return isStringMap(current); default: diff --git a/packages/angular/cli/src/command-builder/utilities/json-schema_spec.ts b/packages/angular/cli/src/command-builder/utilities/json-schema_spec.ts index d311373d69f0..86e8e8e6fc63 100644 --- a/packages/angular/cli/src/command-builder/utilities/json-schema_spec.ts +++ b/packages/angular/cli/src/command-builder/utilities/json-schema_spec.ts @@ -116,6 +116,9 @@ describe('parseJsonSchemaToOptions', () => { ], }, }, + 'oneOfAtRoot': { + 'oneOf': [{ 'type': 'array', 'items': { 'type': 'string' } }, { 'type': 'boolean' }], + }, }, }; const registry = new schema.CoreSchemaRegistry(); @@ -199,6 +202,21 @@ describe('parseJsonSchemaToOptions', () => { }); }); + describe('type=array, oneOf at root', () => { + it('parses valid option value', async () => { + expect( + await parse([ + '--oneOfAtRoot', + 'first', + '--oneOfAtRoot', + 'second', + '--oneOfAtRoot', + 'third', + ]), + ).toEqual(jasmine.objectContaining({ 'oneOfAtRoot': ['first', 'second', 'third'] })); + }); + }); + describe('type=string, enum', () => { it('parses valid option value', async () => { expect(await parse(['--ssr', 'never'])).toEqual(