Skip to content

Commit b22c90f

Browse files
authored
727 fix conditions in allOf accidentally merged for parents with allOf (#728)
* fix if multiple conditions are in child property allOf, they get accidentally merged by mergeAllOfs of parent if parent also has allOfs * show allOfs in schema diagram by default * show required but otherwise not defined schema properties in the schema diagram view * apply formatting changes --------- Co-authored-by: Logende <[email protected]>
1 parent 4765aa4 commit b22c90f

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

meta_configurator/src/schema/mergeAllOfs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import type {JsonSchemaType} from '@/schema/jsonSchemaType';
22
// @ts-ignore
33
import mergeAllOf from 'json-schema-merge-allof';
44

5-
export function mergeAllOfs(schema: JsonSchemaType): JsonSchemaType {
5+
export function mergeAllOfs(schema: JsonSchemaType, deep: boolean = true): JsonSchemaType {
66
if (typeof schema !== 'object') {
77
return schema;
88
}
99

1010
return mergeAllOf(schema, {
11-
deep: true,
11+
deep: deep,
1212
resolvers: {
1313
defaultResolver: mergeAllOf.options.resolvers.title,
1414
// add additional resolvers here, most of the keywords are NOT supported by default

meta_configurator/src/schema/oneTimeSchemaPreprocessor.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ function preprocessOneTimeRecursive(schema: JsonSchemaType | undefined, schemaPa
7373
preprocessOneTimeRecursive(schema.unevaluatedItems, `${schemaPath}/unevaluatedItems`);
7474
preprocessOneTimeRecursive(schema.unevaluatedProperties, `${schemaPath}/unevaluatedProperties`);
7575
preprocessOneTimeRecursive(schema.contentSchema, `${schemaPath}/contentSchema`);
76+
77+
// this is useful for the schema diagram, because then it can render required properties even if there is no further definition
78+
createEmptyPropertiesIfRequiredButMissing(schema);
7679
}
7780

7881
function preprocessSchemaArray(
@@ -152,3 +155,23 @@ function injectTypesOfEnum(schema: JsonSchemaObjectType): void {
152155
schema.type = [...foundTypes];
153156
}
154157
}
158+
159+
function createEmptyPropertiesIfRequiredButMissing(schema: JsonSchemaObjectType): void {
160+
if (schema.required) {
161+
for (const propertyName of schema.required) {
162+
createEmptyPropertyIfRequiredButMissing(schema, propertyName);
163+
}
164+
}
165+
}
166+
167+
function createEmptyPropertyIfRequiredButMissing(
168+
schema: JsonSchemaObjectType,
169+
propertyName: string
170+
): void {
171+
if (schema.properties === undefined) {
172+
schema.properties = {};
173+
}
174+
if (schema.properties[propertyName] === undefined) {
175+
schema.properties[propertyName] = {};
176+
}
177+
}

meta_configurator/src/schema/schemaLazyResolver.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ function handleAllOfs(schema: JsonSchemaType, mode: SessionMode) {
6666
schema.allOf = schema.allOf!.map(subSchema => resolveAndTransform(subSchema, mode));
6767

6868
schema = extractIfsOfAllOfs(schema, mode);
69-
schema = mergeAllOfs(schema);
69+
// do not merge deeply, as this could merge and mess up conditions of children properties
70+
schema = mergeAllOfs(schema, false);
7071
}
7172
return schema;
7273
}

meta_configurator/src/settings/defaultSettingsData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const SETTINGS_DATA_DEFAULT = {
3030
moveViewToSelectedElement: false,
3131
automaticZoomMaxValue: 1,
3232
automaticZoomMinValue: 0.5,
33-
mergeAllOfs: true,
33+
mergeAllOfs: false,
3434
},
3535
metaSchema: {
3636
allowBooleanSchema: false,

0 commit comments

Comments
 (0)