Skip to content

Commit ca4bdca

Browse files
alan-agius4dgp1130
authored andcommitted
fix(@angular-devkit/core): retain order of types set in allOf, anyOf and oneOf when parsing schema
With this change we retain the order of types are declared in the schema. Ex: ```json "oneOf": [ { "type": "boolean" }, { "type": "string", "description": "The name of the migration to run." } ] ``` Currently this will result in: ```js { type: "string", types: ["string", "boolean"] } ``` This is because we use the order of types from the `allTypes` contant variable.https://github.com/angular/angular-cli/blob/a3a657f7e7c20eafd49dfe80ab8fad5a973be9b7/packages/angular_devkit/core/src/json/schema/utility.ts#L12 Now this will result in: ```js { type: "boolean", types: ["boolean", "string"] }; ``` The CLI parser will iterate over each type and will set a value of true if `--migrate-only` option is provided. Related test in the CLL parser https://github.com/angular/angular-cli/blob/1d105eb5691e7a0cf08383f56334ed2dfced3ad3/packages/angular/cli/models/parser_spec.ts#L34 https://github.com/angular/angular-cli/blob/1d105eb5691e7a0cf08383f56334ed2dfced3ad3/packages/angular/cli/models/parser_spec.ts#L132-L138
1 parent 0ee5f2f commit ca4bdca

File tree

1 file changed

+3
-3
lines changed
  • packages/angular_devkit/core/src/json/schema

1 file changed

+3
-3
lines changed

packages/angular_devkit/core/src/json/schema/utility.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function getTypesOfSchema(schema: JsonSchema): Set<string> {
5959
if (Array.isArray(schema.allOf)) {
6060
for (const sub of schema.allOf) {
6161
const types = getTypesOfSchema(sub as JsonObject);
62-
potentials = new Set([...potentials].filter(p => types.has(p)));
62+
potentials = new Set([...types].filter(t => potentials.has(t)));
6363
}
6464
}
6565

@@ -69,7 +69,7 @@ export function getTypesOfSchema(schema: JsonSchema): Set<string> {
6969
const types = getTypesOfSchema(sub as JsonObject);
7070
options = new Set([...options, ...types]);
7171
}
72-
potentials = new Set([...potentials].filter(p => options.has(p)));
72+
potentials = new Set([...options].filter(o => potentials.has(o)));
7373
}
7474

7575
if (Array.isArray(schema.anyOf)) {
@@ -78,7 +78,7 @@ export function getTypesOfSchema(schema: JsonSchema): Set<string> {
7878
const types = getTypesOfSchema(sub as JsonObject);
7979
options = new Set([...options, ...types]);
8080
}
81-
potentials = new Set([...potentials].filter(p => options.has(p)));
81+
potentials = new Set([...options].filter(o => potentials.has(o)));
8282
}
8383

8484
if (schema.properties) {

0 commit comments

Comments
 (0)