feat: json field schemas (#5898)

This commit is contained in:
Kendell Joseph
2024-04-19 13:35:59 -04:00
committed by GitHub
parent 23c5b71f95
commit 3af3a91c87
10 changed files with 177 additions and 4 deletions

View File

@@ -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: {

View File

@@ -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',