Skip to content

Commit 5aa872b

Browse files
authored
Adds additional anyOf example for objects. (#236)
1 parent f8975d5 commit 5aa872b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,35 @@ const stringify = fastJson({
301301
})
302302
```
303303

304+
When specifying object JSON schemas for *anyOf*, add *required* validation keyword to match only the objects with the properties you want.
305+
306+
Example:
307+
```javascript
308+
const stringify = fastJson({
309+
title: 'Example Schema',
310+
type: 'array',
311+
items: {
312+
anyOf: [
313+
{
314+
type: 'object',
315+
properties: {
316+
savedId: { type: 'string' }
317+
},
318+
// without "required" validation any object will match
319+
required: ['saveId']
320+
},
321+
{
322+
type: 'object',
323+
properties: {
324+
error: { type: 'string' }
325+
},
326+
required: ['error']
327+
}
328+
]
329+
}
330+
})
331+
```
332+
304333
<a name="if-then-else"></a>
305334
#### If/then/else
306335
`fast-json-stringify` supports `if/then/else` jsonschema feature. See [ajv documentation](https://ajv.js.org/keywords.html#ifthenelse).

0 commit comments

Comments
 (0)