Skip to content

Commit

Permalink
fix: Resolve references for generated UI schemas
Browse files Browse the repository at this point in the history
Previously, UI schemas generated by JsonForms were incomplete in many instances
because not all references were resolved. This commit addresses the issue by
providing the root schema to all usages of the Generate.uischema function,
ensuring the resolution of all references.

Closes #2187
  • Loading branch information
LukasBoll committed Nov 6, 2023
1 parent f905c82 commit 0f1fc78
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 13 deletions.
7 changes: 6 additions & 1 deletion packages/angular-material/src/other/object.renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ export class ObjectControlRenderer extends JsonFormsControlWithDetail {
delete newSchema.oneOf;
delete newSchema.anyOf;
delete newSchema.allOf;
return Generate.uiSchema(newSchema, 'Group');
return Generate.uiSchema(
newSchema,
'Group',
undefined,
this.rootSchema
);
},
props.uischema,
props.rootSchema
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/reducers/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const findUISchema = (
return fallback();
}
// force generation of uischema
return Generate.uiSchema(schema, fallback);
return Generate.uiSchema(schema, fallback, undefined, rootSchema);
}
} else if (typeof control.options.detail === 'object') {
// check if detail is a valid uischema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface CombinatorPropertiesProps {
schema: JsonSchema;
combinatorKeyword: 'oneOf' | 'anyOf';
path: string;
rootSchema: JsonSchema;
}

export class CombinatorProperties extends React.Component<
Expand All @@ -45,15 +46,17 @@ export class CombinatorProperties extends React.Component<
{}
> {
render() {
const { schema, combinatorKeyword, path } = this.props;
const { schema, combinatorKeyword, path, rootSchema } = this.props;

const otherProps: JsonSchema = omit(
schema,
combinatorKeyword
) as JsonSchema;
const foundUISchema: UISchemaElement = Generate.uiSchema(
otherProps,
'VerticalLayout'
'VerticalLayout',
undefined,
rootSchema
);
let isLayoutWithElements = false;
if (foundUISchema !== null && isLayout(foundUISchema)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const MaterialAnyOfRenderer = ({
schema={schema}
combinatorKeyword={anyOf}
path={path}
rootSchema={rootSchema}
/>
<Tabs value={selectedAnyOf} onChange={handleTabChange}>
{anyOfRenderInfos.map((anyOfRenderInfo) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ export const MaterialObjectRenderer = ({
path,
() =>
isEmpty(path)
? Generate.uiSchema(schema, 'VerticalLayout')
: { ...Generate.uiSchema(schema, 'Group'), label },
? Generate.uiSchema(schema, 'VerticalLayout', undefined, rootSchema)
: {
...Generate.uiSchema(schema, 'Group', undefined, rootSchema),
label,
},
uischema,
rootSchema
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const MaterialOneOfRenderer = ({
schema={schema}
combinatorKeyword={'oneOf'}
path={path}
rootSchema={rootSchema}
/>
<Tabs value={selectedIndex} onChange={handleTabChange}>
{oneOfRenderInfos.map((oneOfRenderInfo) => (
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/JsonForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ export const JsonForms = (
);
const uischemaToUse = useMemo(
() =>
typeof uischema === 'object' ? uischema : Generate.uiSchema(schemaToUse),
typeof uischema === 'object'
? uischema
: Generate.uiSchema(schemaToUse, undefined, undefined, schemaToUse),
[uischema, schemaToUse]
);

Expand Down
7 changes: 6 additions & 1 deletion packages/vue-vanilla/src/complex/ObjectRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ const controlRenderer = defineComponent({
computed: {
detailUiSchema(): UISchemaElement {
const uiSchemaGenerator = () => {
const uiSchema = Generate.uiSchema(this.control.schema, 'Group');
const uiSchema = Generate.uiSchema(
this.control.schema,
'Group',
undefined,
this.control.rootSchema
);
if (isEmpty(this.control.path)) {
uiSchema.type = 'VerticalLayout';
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface CombinatorProps {
schema: JsonSchema;
combinatorKeyword: 'oneOf' | 'anyOf' | 'allOf';
path: string;
rootSchema: JsonSchema;
}
export default defineComponent({
Expand All @@ -38,6 +39,10 @@ export default defineComponent({
type: String,
required: true,
},
rootSchema: {
type: Object as PropType<JsonSchema>,
required: true,
},
},
setup(props: CombinatorProps) {
const otherProps: JsonSchema = omit(
Expand All @@ -46,7 +51,9 @@ export default defineComponent({
) as JsonSchema;
const foundUISchema: UISchemaElement = Generate.uiSchema(
otherProps,
'VerticalLayout'
'VerticalLayout',
undefined,
props.rootSchema
);
const isLayout = (uischema: UISchemaElement): uischema is Layout =>
Expand Down
23 changes: 19 additions & 4 deletions packages/vue/src/components/JsonForms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ export default defineComponent({
data() {
const dataToUse = this.data;
const generatorData = isObject(dataToUse) ? dataToUse : {};
const schemaToUse = this.schema ?? Generate.jsonSchema(generatorData);
const uischemaToUse = this.uischema ?? Generate.uiSchema(schemaToUse);
const schemaToUse: JsonSchema =
this.schema ?? Generate.jsonSchema(generatorData);
const uischemaToUse =
this.uischema ??
Generate.uiSchema(schemaToUse, undefined, undefined, schemaToUse);
const initCore = (): JsonFormsCore => {
const initialCore = {
data: dataToUse,
Expand Down Expand Up @@ -177,11 +180,23 @@ export default defineComponent({
const generatorData = isObject(this.data) ? this.data : {};
this.schemaToUse = newSchema ?? Generate.jsonSchema(generatorData);
if (!this.uischema) {
this.uischemaToUse = Generate.uiSchema(this.schemaToUse);
this.uischemaToUse = Generate.uiSchema(
this.schemaToUse,
undefined,
undefined,
this.schemaToUse
);
}
},
uischema(newUischema) {
this.uischemaToUse = newUischema ?? Generate.uiSchema(this.schemaToUse);
this.uischemaToUse =
newUischema ??
Generate.uiSchema(
this.schemaToUse,
undefined,
undefined,
this.schemaToUse
);
},
data(newData) {
this.dataToUse = newData;
Expand Down

0 comments on commit 0f1fc78

Please sign in to comment.