Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 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
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
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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix, but it changes results for existing callers: generateJsonSchema([1, 2]) used to return an object schema with "0"/"1" properties and now returns {type: 'array', items: {type: 'integer'}}. Worth a MIGRATION.md entry alongside the uischema change.

};
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generateDefaultUISchema returning an empty layout instead of null is a public API behavior change and deserves a MIGRATION.md entry under the existing 3.9 section (master). It also makes the foundUISchema !== null branches unreachable in both CombinatorProperties implementations (react, vue), which could be cleaned up here.

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
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
5 changes: 3 additions & 2 deletions packages/vue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down Expand Up @@ -82,7 +83,7 @@ export default defineComponent({
},
methods: {
onChange(event: JsonFormsChangeEvent) {
this.data = event.data;
console.log(event);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log(event) doesn't show a reader anything. Either drop the handler from the sample or use it for something real (e.g. storing event.errors). The data prop docs above also still don't say it is controlled and must be kept in sync, which is what makes v-model:data the recommended binding.

},
},
});
Expand Down
79 changes: 39 additions & 40 deletions packages/vue/src/components/JsonForms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,39 @@
</template>

<script lang="ts">
import { PropType, reactive, defineComponent } from 'vue';
import {
coreReducer,
Actions,
Generate,
configReducer,
JsonSchema,
UISchemaElement,
ValidationMode,
JsonFormsCore,
JsonFormsUISchemaRegistryEntry,
JsonFormsRendererRegistryEntry,
JsonFormsCellRendererRegistryEntry,
CoreActions,
coreReducer,
defaultMiddleware,
Generate,
i18nReducer,
JsonFormsCellRendererRegistryEntry,
JsonFormsCore,
JsonFormsI18nState,
defaultMiddleware,
Middleware,
JsonFormsRendererRegistryEntry,
JsonFormsSubStates,
JsonFormsUISchemaRegistryEntry,
JsonSchema,
Middleware,
UISchemaElement,
ValidationMode,
} from '@jsonforms/core';
import isEqual from 'lodash/isEqual';
import { defineComponent, PropType, reactive } from 'vue';
import { JsonFormsChangeEvent, MaybeReadonly } from '../types';
import DispatchRenderer from './DispatchRenderer.vue';

import type Ajv from 'ajv';
import type { ErrorObject } from 'ajv';

// TODO fix @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/ban-types
const isObject = (elem: any): elem is Object => {
return elem && typeof elem === 'object';
};

const EMPTY: ErrorObject[] = reactive([]);

const getSchemaGeneratorInput = (data: any) => (data === undefined ? {} : data);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With generateJsonSchema(undefined) now returning {}, this local undefined -> {} mapping is dead weight and keeps Vue diverging from React, which passes data straight through (master). Same argument that moved the uischema fallback into the generator applies here: drop the helper and pass dataToUse.

const generateUISchema = (schema: JsonSchema) =>
Generate.uiSchema(schema, undefined, undefined, schema);

export default defineComponent({
name: 'JsonForms',
components: {
Expand Down Expand Up @@ -121,15 +120,12 @@ export default defineComponent({
default: defaultMiddleware,
},
},
emits: ['change'],
emits: ['change', 'update:data'],
data() {
const dataToUse = this.data;
const generatorData = isObject(dataToUse) ? dataToUse : {};
const schemaToUse: JsonSchema =
this.schema ?? Generate.jsonSchema(generatorData);
const uischemaToUse =
this.uischema ??
Generate.uiSchema(schemaToUse, undefined, undefined, schemaToUse);
this.schema ?? Generate.jsonSchema(getSchemaGeneratorInput(dataToUse));
const uischemaToUse = this.uischema ?? generateUISchema(schemaToUse);
const initCore = (): JsonFormsCore => {
const initialCore = {
data: dataToUse,
Expand Down Expand Up @@ -189,29 +185,31 @@ export default defineComponent({
},
watch: {
schema(newSchema) {
const generatorData = isObject(this.data) ? this.data : {};
this.schemaToUse = newSchema ?? Generate.jsonSchema(generatorData);
this.schemaToUse =
newSchema ??
Generate.jsonSchema(getSchemaGeneratorInput(this.dataToUse));
if (!this.uischema) {
this.uischemaToUse = Generate.uiSchema(
this.schemaToUse,
undefined,
undefined,
this.schemaToUse
);
this.uischemaToUse = generateUISchema(this.schemaToUse);
}
},
uischema(newUischema) {
this.uischemaToUse =
newUischema ??
Generate.uiSchema(
this.schemaToUse,
undefined,
undefined,
this.schemaToUse
);
this.uischemaToUse = newUischema ?? generateUISchema(this.schemaToUse);
},
data(newData) {
const isSameAsCurrentData = newData === this.jsonforms.core.data;
this.dataToUse = newData;

if (!this.schema && !isSameAsCurrentData) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!this.schema breaks schema: false, which is a legal JSON Schema and allowed by the prop type. Init uses ?? (master), so schemaToUse starts out as false and then gets silently replaced by a generated object schema on the first data prop change. Use this.schema === undefined to stay consistent.

const nextSchema = Generate.jsonSchema(
getSchemaGeneratorInput(this.dataToUse)
);
if (!isEqual(nextSchema, this.schemaToUse)) {
this.schemaToUse = nextSchema;
if (!this.uischema) {
this.uischemaToUse = generateUISchema(this.schemaToUse);
}
}
}
},
renderers(newRenderers) {
this.jsonforms.renderers = newRenderers;
Expand Down Expand Up @@ -251,6 +249,7 @@ export default defineComponent({
);
},
eventToEmit(newEvent) {
this.$emit('update:data', newEvent.data);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mounted() emits only change, so the initial core state never reaches a v-model:data parent. A middleware that transforms data inside Actions.init is then lost on the next unrelated prop change (additionalErrors hands dataToUse back into updateCore), which is the same bug class this PR fixes. Emit update:data in mounted() too.

this.$emit('change', newEvent);
},
i18n: {
Expand Down
Loading
Loading