feat: json field schemas (#5898)
This commit is contained in:
@@ -18,6 +18,21 @@ const JSON: CollectionConfig = {
|
||||
{
|
||||
name: 'json',
|
||||
type: 'json',
|
||||
jsonSchema: {
|
||||
fileMatch: ['a://b/foo.json'],
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: {
|
||||
enum: ['bar', 'foobar'],
|
||||
},
|
||||
number: {
|
||||
enum: [10, 5],
|
||||
},
|
||||
},
|
||||
},
|
||||
uri: 'a://b/foo.json',
|
||||
},
|
||||
},
|
||||
],
|
||||
versions: {
|
||||
|
||||
@@ -1247,6 +1247,17 @@ describe('Fields', () => {
|
||||
).rejects.toThrow('The following field is invalid: json')
|
||||
})
|
||||
|
||||
it('should validate json schema', async () => {
|
||||
await expect(async () =>
|
||||
payload.create({
|
||||
collection: 'json-fields',
|
||||
data: {
|
||||
json: { foo: 'bad' },
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow('The following field is invalid: json')
|
||||
})
|
||||
|
||||
it('should save empty json objects', async () => {
|
||||
const jsonFieldsDoc = await payload.create({
|
||||
collection: 'json-fields',
|
||||
|
||||
Reference in New Issue
Block a user