Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add ability to switch to expression when editing an "OpenObjectField" (object with additionalProperties) & only show OpenObjectField when additionalProperties is an object #4600

Merged
merged 7 commits into from
Nov 2, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ export function getOptions(
const expression = (resolvedOneOf as JSONSchema7[]).find(({ $role }) => $role === 'expression');
const merged = merge({}, omit(schema, 'oneOf'), expression);

if (expression && (resolvedOneOf as JSONSchema7[]).some(({ properties, items }) => properties || items)) {
isNested =
isNested ||
!!(expression && (resolvedOneOf as JSONSchema7[]).some(({ properties, items }) => properties || items));

if (expression && isNested) {
options.push({
key: 'expression',
text: formatMessage('Write an expression'),
Expand All @@ -76,7 +80,6 @@ export function getOptions(
schema: merged,
},
});
isNested = true;
}

return { options, isNested };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ describe('resolveFieldWidget', () => {
it('returns OpenObjectField when additional properties are allowed', () => {
const schema = {
type: 'object' as const,
additionalProperties: true,
additionalProperties: {
type: 'string',
title: '',
description: '',
},
};

const { field: ReturnedField } = resolveFieldWidget({ schema });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export function resolveFieldWidget(params: {
return { field: DefaultFields.ArrayField };
}
case 'object':
if (schema.additionalProperties) {
if (typeof schema.additionalProperties === 'object') {
return { field: DefaultFields.OpenObjectField };
} else if (!schema.properties) {
if (showIntellisense && isOneOf) {
Expand Down