Skip to content

Commit 57a8100

Browse files
committed
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.
1 parent 9850ebc commit 57a8100

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/angular/cli/src/command-builder/utilities/json-schema.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ function isSupportedArrayItemSchema(schema: json.JsonObject): boolean {
156156
return true;
157157
}
158158

159+
if (isJsonObject(schema.items)) {
160+
return isSupportedArrayItemSchema(schema.items);
161+
}
162+
159163
if (json.isJsonArray(schema.items)) {
160164
return schema.items.some((item) => isJsonObject(item) && isSupportedArrayItemSchema(item));
161165
}
@@ -198,7 +202,7 @@ function getSupportedTypes(
198202
case 'string':
199203
return true;
200204
case 'array':
201-
return isJsonObject(current.items) && isSupportedArrayItemSchema(current.items);
205+
return isSupportedArrayItemSchema(current);
202206
case 'object':
203207
return isStringMap(current);
204208
default:

packages/angular/cli/src/command-builder/utilities/json-schema_spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ describe('parseJsonSchemaToOptions', () => {
116116
],
117117
},
118118
},
119+
'oneOfAtRoot': {
120+
'oneOf': [{ 'type': 'array', 'items': { 'type': 'string' } }, { 'type': 'boolean' }],
121+
},
119122
},
120123
};
121124
const registry = new schema.CoreSchemaRegistry();
@@ -199,6 +202,21 @@ describe('parseJsonSchemaToOptions', () => {
199202
});
200203
});
201204

205+
describe('type=array, oneOf at root', () => {
206+
it('parses valid option value', async () => {
207+
expect(
208+
await parse([
209+
'--oneOfAtRoot',
210+
'first',
211+
'--oneOfAtRoot',
212+
'second',
213+
'--oneOfAtRoot',
214+
'third',
215+
]),
216+
).toEqual(jasmine.objectContaining({ 'oneOfAtRoot': ['first', 'second', 'third'] }));
217+
});
218+
});
219+
202220
describe('type=string, enum', () => {
203221
it('parses valid option value', async () => {
204222
expect(await parse(['--ssr', 'never'])).toEqual(

0 commit comments

Comments
 (0)