Skip to content

Commit 22760af

Browse files
committed
resolve schema like 'items': true
1 parent 532fa9f commit 22760af

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

packages/core/src/mappers/renderer.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export const doCreateDefaultValue = (
186186
rootSchema: JsonSchema
187187
) => {
188188
const resolvedSchema =
189-
typeof schema.$ref === 'string'
189+
typeof schema?.$ref === 'string'
190190
? Resolve.schema(rootSchema, schema.$ref, rootSchema)
191191
: schema;
192192
if (resolvedSchema.default !== undefined) {
@@ -872,7 +872,21 @@ export const mapStateToArrayControlProps = (
872872
const { path, schema, uischema, label, ...props } =
873873
mapStateToControlWithDetailProps(state, ownProps);
874874

875-
const resolvedSchema = Resolve.schema(schema, 'items', props.rootSchema);
875+
let resolvedSchema = Resolve.schema(schema, 'items', props.rootSchema);
876+
if ((resolvedSchema as any) === true) {
877+
// help the testers to determine the mixed control
878+
resolvedSchema = {
879+
type: [
880+
'array',
881+
'boolean',
882+
'integer',
883+
'null',
884+
'number',
885+
'object',
886+
'string',
887+
],
888+
};
889+
}
876890
const childErrors = getSubErrorsAt(path, resolvedSchema)(state);
877891

878892
return {

packages/core/src/util/resolvers.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,20 @@ const resolveSchemaWithSegments = (
123123
pathSegments: string[],
124124
rootSchema: JsonSchema
125125
): JsonSchema => {
126+
if (
127+
typeof schema === 'boolean' &&
128+
(!pathSegments || pathSegments.length === 0)
129+
) {
130+
// add the case where the schema can be true value for example: items: true or additionalProperties: false
131+
return schema;
132+
}
133+
126134
if (isEmpty(schema)) {
127135
return undefined;
128136
}
129137

130138
// use typeof because schema can by of any type - check singleSegmentResolveSchema below
131-
if (typeof schema.$ref === 'string') {
139+
if (typeof schema?.$ref === 'string') {
132140
schema = resolveSchema(rootSchema, schema.$ref, rootSchema);
133141
}
134142

0 commit comments

Comments
 (0)