From d9c549233ac9d5e1f82750fdaaf4e893c272752c Mon Sep 17 00:00:00 2001 From: Luka Dornhecker Date: Tue, 1 Jul 2025 16:02:03 +0200 Subject: [PATCH 1/3] chore(next): throw error when deprecated modifyConfig option is passed to createHeadlessForm --- next/src/form.ts | 12 ++++++++++++ next/test/form.test.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/next/src/form.ts b/next/src/form.ts index 671d7ce44..066e1b41c 100644 --- a/next/src/form.ts +++ b/next/src/form.ts @@ -242,10 +242,22 @@ function buildFields(params: { schema: JsfObjectSchema, originalSchema: JsfObjec return fields } +/** + * Ensures that no forbidden options are given + * @param options - The options to validate + * @throws An error if any forbidden options are found + */ +function validateOptions(options: CreateHeadlessFormOptions) { + if (Object.prototype.hasOwnProperty.call(options, 'modifyConfig')) { + throw new Error('modifyConfig has been removed from json-schema-form v1') + } +} + export function createHeadlessForm( schema: JsfObjectSchema, options: CreateHeadlessFormOptions = {}, ): FormResult { + validateOptions(options) const initialValues = options.initialValues || {} const strictInputType = options.strictInputType || false // Make a new version of the schema with all the computed attrs applied, as well as the final version of each property (taking into account conditional rules) diff --git a/next/test/form.test.ts b/next/test/form.test.ts index c21c49fe5..5b512040d 100644 --- a/next/test/form.test.ts +++ b/next/test/form.test.ts @@ -1,3 +1,4 @@ +import type { JsfObjectSchema } from '../src/types' import { describe, expect, it } from '@jest/globals' import { createHeadlessForm } from '../src' @@ -5,4 +6,35 @@ describe('createHeadlessForm', () => { it('should be a function', () => { expect(createHeadlessForm).toBeInstanceOf(Function) }) + + describe('options validation', () => { + const basicSchema: JsfObjectSchema = { + type: 'object', + properties: { + name: { type: 'string' }, + }, + } + + it('should throw error when modifyConfig option is provided', () => { + expect(() => { + createHeadlessForm(basicSchema, { modifyConfig: {} } as any) + }).toThrow('modifyConfig has been removed from json-schema-form v1') + }) + + it('should not throw error when modifyConfig option is not provided', () => { + expect(() => { + createHeadlessForm(basicSchema, {}) + }).not.toThrow() + }) + + it('should not throw error when other valid options are provided', () => { + expect(() => { + createHeadlessForm(basicSchema, { + initialValues: { name: 'test' }, + validationOptions: {}, + strictInputType: true, + }) + }).not.toThrow() + }) + }) }) From 3ab3c18e88dcd801c0bcd949621124f339b1d6c5 Mon Sep 17 00:00:00 2001 From: Luka Dornhecker Date: Tue, 1 Jul 2025 16:45:49 +0200 Subject: [PATCH 2/3] Update next/src/form.ts Co-authored-by: Capelo --- next/src/form.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/next/src/form.ts b/next/src/form.ts index 066e1b41c..fa88ec2d2 100644 --- a/next/src/form.ts +++ b/next/src/form.ts @@ -249,7 +249,7 @@ function buildFields(params: { schema: JsfObjectSchema, originalSchema: JsfObjec */ function validateOptions(options: CreateHeadlessFormOptions) { if (Object.prototype.hasOwnProperty.call(options, 'modifyConfig')) { - throw new Error('modifyConfig has been removed from json-schema-form v1') + throw new Error('`modifyConfig` is a deprecated option and it\'s not supported on json-schema-form v1') } } From 7a2ad055df98abd903203ed6ae752a1b1bce76b3 Mon Sep 17 00:00:00 2001 From: Luka Dornhecker Date: Tue, 1 Jul 2025 16:46:57 +0200 Subject: [PATCH 3/3] update test text --- next/test/form.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/next/test/form.test.ts b/next/test/form.test.ts index 5b512040d..e5e3e4b2f 100644 --- a/next/test/form.test.ts +++ b/next/test/form.test.ts @@ -18,7 +18,7 @@ describe('createHeadlessForm', () => { it('should throw error when modifyConfig option is provided', () => { expect(() => { createHeadlessForm(basicSchema, { modifyConfig: {} } as any) - }).toThrow('modifyConfig has been removed from json-schema-form v1') + }).toThrow('`modifyConfig` is a deprecated option and it\'s not supported on json-schema-form v1') }) it('should not throw error when modifyConfig option is not provided', () => {