Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e41c15d
preserve the form data so when we update the additionalErrors the dat…
kchobantonov Aug 12, 2025
a6a21e3
Merge branch 'master' into preserve-edit-data
kchobantonov Aug 15, 2025
d5218b1
also update the schema and uischema when they depend on the data and …
kchobantonov Aug 23, 2025
0b979c0
properly generate schema in case when the data is not an object but s…
kchobantonov Aug 23, 2025
ebe262b
always return valid UISchemaElement, in case of empty schema this was…
kchobantonov Aug 24, 2025
51aa0bc
revert back the ability to return null from the generate but default …
kchobantonov Aug 24, 2025
b27ce7f
only for undefined use emtpy data for others the core can handle those
kchobantonov Sep 5, 2025
87bfaa6
Merge branch 'master' into preserve-edit-data
kchobantonov Sep 27, 2025
e413248
Merge branch 'master' into preserve-edit-data
kchobantonov Nov 7, 2025
7bde214
Merge branch 'master' into preserve-edit-data
kchobantonov Nov 10, 2025
6f736d2
Merge branch 'master' into preserve-edit-data
kchobantonov Nov 10, 2025
4803dec
Merge branch 'master' into preserve-edit-data
kchobantonov Dec 2, 2025
22b4016
Merge branch 'master' into preserve-edit-data
kchobantonov Dec 16, 2025
fd04fe0
Merge branch 'master' into preserve-edit-data
kchobantonov Jan 23, 2026
d9de6ab
Merge branch 'master' into preserve-edit-data
kchobantonov Feb 15, 2026
63f16bf
Merge branch 'master' into preserve-edit-data
kchobantonov Mar 1, 2026
972c194
Merge branch 'master' into preserve-edit-data
kchobantonov Mar 27, 2026
8353196
Merge branch 'master' into preserve-edit-data
kchobantonov Apr 19, 2026
aa5b3c4
add test case for schema generation for primitive types
kchobantonov Apr 19, 2026
4af7884
preserve undefined Vue form data and type primitive schema generation
kchobantonov Apr 19, 2026
66e5c00
avoid regenerating Vue schemas when parent echoes unchanged form shape
kchobantonov Apr 19, 2026
7194ebf
Merge branch 'master' into preserve-edit-data
kchobantonov May 6, 2026
75a7203
organize imports and code format
kchobantonov May 6, 2026
1299f70
Merge branch 'master' into preserve-edit-data
kchobantonov Jun 6, 2026
82e985c
Merge branch 'master' into preserve-edit-data
kchobantonov Jun 14, 2026
c925284
Merge branch 'master' into preserve-edit-data
kchobantonov Jun 25, 2026
f02d205
Merge branch 'master' into preserve-edit-data
kchobantonov Jul 17, 2026
c1a54b7
Merge branch 'master' into preserve-edit-data
kchobantonov Jul 30, 2026
18d6212
add fixes based on the code review
kchobantonov Jul 30, 2026
ade1fa2
Merge branch 'master' into preserve-edit-data
kchobantonov Aug 3, 2026
ff46e0f
Merge branch 'master' into preserve-edit-data
kchobantonov Aug 12, 2026
99e448e
address EclipseSourceAI comments
kchobantonov Aug 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

## Migration to JSON Forms 3.9

### JSON Schema generation supports non-object root values

`generateJsonSchema` now generates a schema matching the root value's actual type. In particular, arrays produce an array schema with an `items` schema, primitives produce their corresponding primitive schema, and `undefined` produces an empty schema.

Previously all root values were handled as objects. For example, `generateJsonSchema([1, 2])` produced an object schema with properties named `"0"` and `"1"`; it now produces an array schema with an integer `items` schema. If you depend on the previous object-shaped output, adapt the generated schema before consuming it.

### Default UI schema generation always returns a layout

`generateDefaultUISchema` previously returned `null` when no UI schema elements could be generated. It now returns an empty layout of the requested type instead.

If you call `generateDefaultUISchema` directly, remove any `null` handling and check the returned layout's `elements` when you need to know whether controls were generated.

### Data update paths treat all segments literally

Data updates (e.g. dispatched `update` actions) previously wrote to the form data via lodash's `set`/`unset`, which interpret bracket notation and array indices in paths.
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/generators/Generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ import { generateJsonSchema } from './schema';
import { createControlElement, generateDefaultUISchema } from './uischema';

export const Generate: {
// TODO fix @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/ban-types
jsonSchema(instance: Object, options?: any): JsonSchema;
jsonSchema(instance: unknown, options?: any): JsonSchema;
uiSchema(
jsonSchema: JsonSchema,
layoutType?: string,
Expand Down
12 changes: 4 additions & 8 deletions packages/core/src/generators/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ class Gen {
private findOption: (props: Properties) => (optionName: string) => any
) {}

// TODO fix @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/ban-types
schemaObject = (data: Object): JsonSchema4 => {
schemaObject = (data: Record<string, any>): JsonSchema4 => {
const props: Properties = this.properties(data);
const schema: JsonSchema4 = {
type: 'object',
Expand Down Expand Up @@ -140,14 +138,12 @@ class Gen {

/**
* Generate a JSON schema based on the given data and any additional options.
* @param {Object} instance the data to create a JSON schema for
* @param {unknown} instance the data to create a JSON schema for
* @param {any} options any additional options that may alter the generated JSON schema
* @returns {JsonSchema} the generated schema
*/
export const generateJsonSchema = (
// TODO fix @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/ban-types
instance: Object,
instance: unknown,
options: any = {}
): JsonSchema4 => {
const findOption =
Expand Down Expand Up @@ -177,5 +173,5 @@ export const generateJsonSchema = (

const gen = new Gen(findOption);

return gen.schemaObject(instance);
return gen.property(instance);
Comment thread
kchobantonov marked this conversation as resolved.
Comment thread
kchobantonov marked this conversation as resolved.
};
2 changes: 1 addition & 1 deletion packages/core/src/generators/uischema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,4 @@ export const generateDefaultUISchema = (
wrapInLayoutIfNecessary(
generateUISchema(jsonSchema, [], prefix, '', layoutType, rootSchema),
layoutType
);
) ?? createLayout(layoutType);
Comment thread
kchobantonov marked this conversation as resolved.
32 changes: 32 additions & 0 deletions packages/core/test/generators/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@ import test from 'ava';

import { generateJsonSchema } from '../../src/generators/schema';

test('default schema generation root primitive types', (t) => {
t.deepEqual(generateJsonSchema(undefined), {});
t.deepEqual(generateJsonSchema('hello'), {
type: 'string',
});
t.deepEqual(generateJsonSchema(42), {
type: 'integer',
});
t.deepEqual(generateJsonSchema(3.14), {
type: 'number',
});
t.deepEqual(generateJsonSchema(true), {
type: 'boolean',
});
t.deepEqual(generateJsonSchema(null), {
type: 'null',
});
Comment thread
kchobantonov marked this conversation as resolved.
});

test('default schema generation root array types', (t) => {
t.deepEqual(generateJsonSchema([]), {
type: 'array',
items: {},
});
t.deepEqual(generateJsonSchema([1, 2]), {
type: 'array',
items: {
type: 'integer',
},
});
});

test('default schema generation basic types', (t) => {
const instance: any = {
boolean: false,
Expand Down
15 changes: 12 additions & 3 deletions packages/core/test/generators/uischema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,19 +496,28 @@ test('generate unnamed array control w/o type', (t) => {

test('generate for empty schema', (t) => {
const schema: JsonSchema = {};
const uischema: Layout = null;
const uischema: Layout = {
type: 'VerticalLayout',
elements: [],
};
t.deepEqual(generateDefaultUISchema(schema), uischema);
});

test('generate for null schema', (t) => {
const schema: JsonSchema = null;
const uischema: Layout = null;
const uischema: Layout = {
type: 'VerticalLayout',
elements: [],
};
t.deepEqual(generateDefaultUISchema(schema), uischema);
});

test('generate for undefined schema', (t) => {
const schema: JsonSchema = undefined;
const uischema: Layout = null;
const uischema: Layout = {
type: 'VerticalLayout',
elements: [],
};
t.deepEqual(generateDefaultUISchema(schema), uischema);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ export class CombinatorProperties extends React.Component<
undefined,
rootSchema
);
let isLayoutWithElements = false;
if (foundUISchema !== null && isLayout(foundUISchema)) {
isLayoutWithElements = foundUISchema.elements.length > 0;
}
const isLayoutWithElements =
isLayout(foundUISchema) && foundUISchema.elements.length > 0;

if (isLayoutWithElements) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ export default defineComponent({
const isLayout = (uischema: UISchemaElement): uischema is Layout =>
Object.prototype.hasOwnProperty.call(uischema, 'elements');

let isLayoutWithElements = false;
if (foundUISchema !== null && isLayout(foundUISchema)) {
isLayoutWithElements = foundUISchema.elements.length > 0;
}
const isLayoutWithElements =
isLayout(foundUISchema) && foundUISchema.elements.length > 0;

return {
otherProps,
Expand Down
7 changes: 6 additions & 1 deletion packages/vue-vuetify/dev/components/ExampleForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ const resolvedSchema = shallowReactive<ResolvedSchema>({
error: undefined,
});

const emits = defineEmits(['jsfchange']);
const emits = defineEmits(['jsfchange', 'update:data']);

const onChange = (event: JsonFormsChangeEvent): void => {
emits('jsfchange', event);
};

const onUpdateData = (data: any): void => {
emits('update:data', data);
};

watch(
() => props.state.schema,
(schema) => {
Expand Down Expand Up @@ -101,6 +105,7 @@ const properties = computed<JsonFormsProps>(() => ({
v-if="resolvedSchema.resolved && resolvedSchema.error === undefined"
v-bind="properties"
@change="onChange"
@update:data="onUpdateData"
></json-forms>
<v-container v-else>
<v-row
Expand Down
24 changes: 20 additions & 4 deletions packages/vue-vuetify/dev/views/ExampleView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,14 @@ const onChange = (event: JsonFormsChangeEvent): void => {
monaco.Uri.parse(toDataUri(props.example.name)),
event.data !== undefined ? JSON.stringify(event.data, null, 2) : '',
);
state.data = event.data;
Comment thread
kchobantonov marked this conversation as resolved.
}
errors.value = event.errors;
};

const onDataChange = (data: any): void => {
state.data = data;
};

const reloadMonacoSchema = () => {
const example = find(
examples,
Expand Down Expand Up @@ -346,7 +349,11 @@ const handleAction = (action: Action) => {
</v-toolbar>
</v-card-title>
<v-divider class="mx-4"></v-divider>
<example-form :state="state" @jsfchange="onChange" />
<example-form
:state="state"
@update:data="onDataChange"
@jsfchange="onChange"
/>
</v-card>
</pane>
<pane>
Expand Down Expand Up @@ -392,7 +399,12 @@ const handleAction = (action: Action) => {
</pane>
</splitpanes>

<example-form :state="state" @jsfchange="onChange" v-else />
<example-form
:state="state"
@update:data="onDataChange"
@jsfchange="onChange"
v-else
/>
</div>
</v-card>
</v-window-item>
Expand Down Expand Up @@ -505,7 +517,11 @@ const handleAction = (action: Action) => {
</v-snackbar>
</v-container>
<div class="json-forms" v-else>
<example-form :state="state" @jsfchange="onChange" />
<example-form
:state="state"
@update:data="onDataChange"
@jsfchange="onChange"
/>
</div>
</div>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ export default defineComponent({
const isLayout = (uischema: UISchemaElement): uischema is Layout =>
Object.prototype.hasOwnProperty.call(uischema, 'elements');

let isLayoutWithElements = false;
if (foundUISchema !== null && isLayout(foundUISchema)) {
isLayoutWithElements = foundUISchema.elements.length > 0;
}
const isLayoutWithElements =
isLayout(foundUISchema) && foundUISchema.elements.length > 0;

return {
otherProps,
Expand Down
8 changes: 5 additions & 3 deletions packages/vue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Use the `json-forms` component for each form you want to render.

Mandatory props:

- `data: any` - the data to show
- `data: any` - the controlled data to show. Use `v-model:data` to keep the parent state synchronized with form edits. When binding with `:data` instead, update the bound value from `update:data` or `change`; otherwise later prop updates can restore stale data.
- `renderers: JsonFormsRendererRegistryEntry[]` - the Vue renderer set to use

Optional props:
Expand All @@ -37,12 +37,13 @@ Optional props:
Events:

- `change: {data: any; errors: AJVError[]}` - Whenever data and/or errors change this event is emitted.
- `update:data: any` - Emits the current data alongside `change`, enabling `v-model:data`.

Example:

```html
<json-forms
:data="data"
v-model:data="data"
:renderers="renderers"
:schema="schema"
:uischema="uischema"
Expand All @@ -62,6 +63,7 @@ export default defineComponent({
data: {
number: 5,
},
validationErrors: [] as JsonFormsChangeEvent['errors'],
schema: {
properties: {
number: {
Expand All @@ -82,7 +84,7 @@ export default defineComponent({
},
methods: {
onChange(event: JsonFormsChangeEvent) {
this.data = event.data;
this.validationErrors = event.errors;
},
},
});
Expand Down
Loading