Skip to content

Commit d03daeb

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 d03daeb

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ describe('parseJsonSchemaToOptions', () => {
116116
],
117117
},
118118
},
119+
'oneOfAtRoot': {
120+
'oneOf': [
121+
{'type': 'array', 'items': {'type': 'string'}},
122+
{'type': 'boolean'},
123+
]
124+
}
119125
},
120126
};
121127
const registry = new schema.CoreSchemaRegistry();
@@ -199,6 +205,21 @@ describe('parseJsonSchemaToOptions', () => {
199205
});
200206
});
201207

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

0 commit comments

Comments
 (0)