Skip to content

Commit 7ddeb71

Browse files
LukasBollsdirix
authored andcommitted
fix: Resolve references for generated UI schemas
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
1 parent ddabac6 commit 7ddeb71

File tree

10 files changed

+55
-13
lines changed

10 files changed

+55
-13
lines changed

packages/angular-material/src/other/object.renderer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ export class ObjectControlRenderer extends JsonFormsControlWithDetail {
7373
delete newSchema.oneOf;
7474
delete newSchema.anyOf;
7575
delete newSchema.allOf;
76-
return Generate.uiSchema(newSchema, 'Group');
76+
return Generate.uiSchema(
77+
newSchema,
78+
'Group',
79+
undefined,
80+
this.rootSchema
81+
);
7782
},
7883
props.uischema,
7984
props.rootSchema

packages/core/src/reducers/reducers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const findUISchema = (
7777
return fallback();
7878
}
7979
// force generation of uischema
80-
return Generate.uiSchema(schema, fallback);
80+
return Generate.uiSchema(schema, fallback, undefined, rootSchema);
8181
}
8282
} else if (typeof control.options.detail === 'object') {
8383
// check if detail is a valid uischema

packages/material-renderers/src/complex/CombinatorProperties.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface CombinatorPropertiesProps {
3636
schema: JsonSchema;
3737
combinatorKeyword: 'oneOf' | 'anyOf';
3838
path: string;
39+
rootSchema: JsonSchema;
3940
}
4041

4142
export class CombinatorProperties extends React.Component<
@@ -45,15 +46,17 @@ export class CombinatorProperties extends React.Component<
4546
{}
4647
> {
4748
render() {
48-
const { schema, combinatorKeyword, path } = this.props;
49+
const { schema, combinatorKeyword, path, rootSchema } = this.props;
4950

5051
const otherProps: JsonSchema = omit(
5152
schema,
5253
combinatorKeyword
5354
) as JsonSchema;
5455
const foundUISchema: UISchemaElement = Generate.uiSchema(
5556
otherProps,
56-
'VerticalLayout'
57+
'VerticalLayout',
58+
undefined,
59+
rootSchema
5760
);
5861
let isLayoutWithElements = false;
5962
if (foundUISchema !== null && isLayout(foundUISchema)) {

packages/material-renderers/src/complex/MaterialAnyOfRenderer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export const MaterialAnyOfRenderer = ({
110110
schema={schema}
111111
combinatorKeyword={anyOf}
112112
path={path}
113+
rootSchema={rootSchema}
113114
/>
114115
<Tabs value={selectedAnyOf} onChange={handleTabChange}>
115116
{anyOfRenderInfos.map((anyOfRenderInfo) => (

packages/material-renderers/src/complex/MaterialObjectRenderer.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ export const MaterialObjectRenderer = ({
5656
path,
5757
() =>
5858
isEmpty(path)
59-
? Generate.uiSchema(schema, 'VerticalLayout')
60-
: { ...Generate.uiSchema(schema, 'Group'), label },
59+
? Generate.uiSchema(schema, 'VerticalLayout', undefined, rootSchema)
60+
: {
61+
...Generate.uiSchema(schema, 'Group', undefined, rootSchema),
62+
label,
63+
},
6164
uischema,
6265
rootSchema
6366
),

packages/material-renderers/src/complex/MaterialOneOfRenderer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export const MaterialOneOfRenderer = ({
109109
schema={schema}
110110
combinatorKeyword={'oneOf'}
111111
path={path}
112+
rootSchema={rootSchema}
112113
/>
113114
<Tabs value={selectedIndex} onChange={handleTabChange}>
114115
{oneOfRenderInfos.map((oneOfRenderInfo) => (

packages/react/src/JsonForms.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ export const JsonForms = (
210210
);
211211
const uischemaToUse = useMemo(
212212
() =>
213-
typeof uischema === 'object' ? uischema : Generate.uiSchema(schemaToUse),
213+
typeof uischema === 'object'
214+
? uischema
215+
: Generate.uiSchema(schemaToUse, undefined, undefined, schemaToUse),
214216
[uischema, schemaToUse]
215217
);
216218

packages/vue-vanilla/src/complex/ObjectRenderer.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ const controlRenderer = defineComponent({
5151
computed: {
5252
detailUiSchema(): UISchemaElement {
5353
const uiSchemaGenerator = () => {
54-
const uiSchema = Generate.uiSchema(this.control.schema, 'Group');
54+
const uiSchema = Generate.uiSchema(
55+
this.control.schema,
56+
'Group',
57+
undefined,
58+
this.control.rootSchema
59+
);
5560
if (isEmpty(this.control.path)) {
5661
uiSchema.type = 'VerticalLayout';
5762
} else {

packages/vue-vanilla/src/complex/components/CombinatorProperties.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface CombinatorProps {
1818
schema: JsonSchema;
1919
combinatorKeyword: 'oneOf' | 'anyOf' | 'allOf';
2020
path: string;
21+
rootSchema: JsonSchema;
2122
}
2223
2324
export default defineComponent({
@@ -38,6 +39,10 @@ export default defineComponent({
3839
type: String,
3940
required: true,
4041
},
42+
rootSchema: {
43+
type: Object as PropType<JsonSchema>,
44+
required: true,
45+
},
4146
},
4247
setup(props: CombinatorProps) {
4348
const otherProps: JsonSchema = omit(
@@ -46,7 +51,9 @@ export default defineComponent({
4651
) as JsonSchema;
4752
const foundUISchema: UISchemaElement = Generate.uiSchema(
4853
otherProps,
49-
'VerticalLayout'
54+
'VerticalLayout',
55+
undefined,
56+
props.rootSchema
5057
);
5158
5259
const isLayout = (uischema: UISchemaElement): uischema is Layout =>

packages/vue/src/components/JsonForms.vue

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ export default defineComponent({
114114
data() {
115115
const dataToUse = this.data;
116116
const generatorData = isObject(dataToUse) ? dataToUse : {};
117-
const schemaToUse = this.schema ?? Generate.jsonSchema(generatorData);
118-
const uischemaToUse = this.uischema ?? Generate.uiSchema(schemaToUse);
117+
const schemaToUse: JsonSchema =
118+
this.schema ?? Generate.jsonSchema(generatorData);
119+
const uischemaToUse =
120+
this.uischema ??
121+
Generate.uiSchema(schemaToUse, undefined, undefined, schemaToUse);
119122
const initCore = (): JsonFormsCore => {
120123
const initialCore = {
121124
data: dataToUse,
@@ -177,11 +180,23 @@ export default defineComponent({
177180
const generatorData = isObject(this.data) ? this.data : {};
178181
this.schemaToUse = newSchema ?? Generate.jsonSchema(generatorData);
179182
if (!this.uischema) {
180-
this.uischemaToUse = Generate.uiSchema(this.schemaToUse);
183+
this.uischemaToUse = Generate.uiSchema(
184+
this.schemaToUse,
185+
undefined,
186+
undefined,
187+
this.schemaToUse
188+
);
181189
}
182190
},
183191
uischema(newUischema) {
184-
this.uischemaToUse = newUischema ?? Generate.uiSchema(this.schemaToUse);
192+
this.uischemaToUse =
193+
newUischema ??
194+
Generate.uiSchema(
195+
this.schemaToUse,
196+
undefined,
197+
undefined,
198+
this.schemaToUse
199+
);
185200
},
186201
data(newData) {
187202
this.dataToUse = newData;

0 commit comments

Comments
 (0)