Skip to content

Commit 52666fc

Browse files
author
Bradley Marques
authored
Support schema and meta keywords (#84)
* Adds support for $schema keyword * Support for meta keyword * Adds unit test
1 parent d31971b commit 52666fc

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

src/formBuilder/FormBuilder.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,55 @@ describe('FormBuilder', () => {
212212
expect(cardInputs.at(1).props().value).toEqual('Custom Title');
213213
expect(cardInputs.at(2).props().value).toEqual('Custom Description');
214214
});
215+
216+
it('supports the $schema keyword and there is no error', () => {
217+
const jsonSchema = {
218+
$schema: 'http://json-schema.org/draft-07/schema#',
219+
};
220+
221+
const props = {
222+
schema: JSON.stringify(jsonSchema),
223+
uiSchema: '{}',
224+
onChange: jest.fn(() => {}),
225+
mods: {},
226+
className: 'my-form-builder',
227+
};
228+
229+
const div = document.createElement('div');
230+
document.body.appendChild(div);
231+
const wrapper = mount(<FormBuilder {...props} />, { attachTo: div });
232+
const errors = wrapper
233+
.find('.alert-warning')
234+
.first()
235+
.find('li')
236+
.map((error) => error.text());
237+
expect(errors).toEqual([]);
238+
});
239+
240+
it('supports the meta keyword and there is no error', () => {
241+
const jsonSchema = {
242+
$schema: 'http://json-schema.org/draft-07/schema#',
243+
meta: {
244+
some: 'meta information',
245+
},
246+
};
247+
248+
const props = {
249+
schema: JSON.stringify(jsonSchema),
250+
uiSchema: '{}',
251+
onChange: jest.fn(() => {}),
252+
mods: {},
253+
className: 'my-form-builder',
254+
};
255+
256+
const div = document.createElement('div');
257+
document.body.appendChild(div);
258+
const wrapper = mount(<FormBuilder {...props} />, { attachTo: div });
259+
const errors = wrapper
260+
.find('.alert-warning')
261+
.first()
262+
.find('li')
263+
.map((error) => error.text());
264+
expect(errors).toEqual([]);
265+
});
215266
});

src/formBuilder/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ const supportedPropertyParameters = new Set([
130130
'enumNames',
131131
'dependencies',
132132
'$id',
133+
'$schema',
134+
'meta',
133135
]);
134136

135137
const supportedUiParameters = new Set([

src/formBuilder/utils.test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ describe('parse', () => {
7676
`
7777
{
7878
"key": {
79-
"array": ["item1", "item2"],
80-
"name": "obj1",
79+
"array": ["item1", "item2"],
80+
"name": "obj1",
8181
"num": 0
8282
}
8383
}`,
@@ -240,6 +240,24 @@ describe('checkForUnsupportedFeatures', () => {
240240
).toEqual([]);
241241
});
242242

243+
it('gives no warnings for the inclusion of $schema and meta keywords', () => {
244+
let testSchema = {
245+
type: 'object',
246+
$schema: 'http://json-schema.org/draft-07/schema#',
247+
meta: {
248+
some: 'meta information',
249+
},
250+
};
251+
let testUischema = {};
252+
expect(
253+
checkForUnsupportedFeatures(
254+
testSchema,
255+
testUischema,
256+
DEFAULT_FORM_INPUTS,
257+
),
258+
).toEqual([]);
259+
});
260+
243261
it('gives warnings for unknown features in schema', () => {
244262
let testSchema = {
245263
type: 'object',

0 commit comments

Comments
 (0)