Skip to content

Commit

Permalink
Merge d17b970 into 09bea1d
Browse files Browse the repository at this point in the history
  • Loading branch information
mokkabonna committed Feb 22, 2021
2 parents 09bea1d + d17b970 commit 34d65fb
Show file tree
Hide file tree
Showing 14 changed files with 3,464 additions and 2,860 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
language: node_js
after_success: npm run coverage
node_js:
- 10
- 12
- 14
- node
- lts/*
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ When multiple conflicting **not** values are found, we also use the approach tha

Allows you to combine schema properties even though some schemas have `additionalProperties: false` This is the most common issue people face when trying to expand schemas using allOf and a limitation of the json schema spec. Be aware though that the schema produced will allow more than the original schema. But this is useful if just want to combine schemas using allOf as if additionalProperties wasn't false during the merge process. The resulting schema will still get additionalProperties set to false.

**deep** boolean, default *true*
If false, resolves only the top-level `allOf` keyword in the schema.

If true, resolves all `allOf` keywords in the schema.


**resolvers** Object
Override any default resolver like this:

Expand All @@ -92,11 +98,6 @@ mergeAllOf(schema, {
})
```

**deep** boolean, default *true*
If false, resolves only the top-level `allOf` keyword in the schema.

If true, resolves all `allOf` keywords in the schema.

The function is passed:

- **values** an array of the conflicting values that need to be resolved
Expand All @@ -106,9 +107,22 @@ The function is passed:


### Combined resolvers
No separate resolver is called for patternProperties and additionalProperties, only the properties resolver is called. Same for additionalItems, only items resolver is called. This is because those keywords need to be resolved together as they affect each other.
Some keyword are dependant on other keywords, like properties, patternProperties, additionalProperties. To create a resolver for these the resolver requires this structure:

```js
mergeAllOf(schema, {
resolvers: {
properties:
keywords: ['properties', 'patternProperties', 'additionalProperties'],
resolver(values, parents, mergers, options) {

}
}
}
})
```

Those two resolvers are expected to return an object containing the resolved values of all the associated keywords. The keys must be the name of the keywords. So the properties resolver need to return an object like this containing the resolved values for each keyword:
This type of resolvers are expected to return an object containing the resolved values of all the associated keywords. The keys must be the name of the keywords. So the properties resolver need to return an object like this containing the resolved values for each keyword:

```js
{
Expand All @@ -121,7 +135,7 @@ Those two resolvers are expected to return an object containing the resolved val
Also the resolve function is not passed **mergeSchemas**, but an object **mergers** that contains mergers for each of the related keywords. So properties get passed an object like this:

```js
var mergers = {
const mergers = {
properties: function mergeSchemas(schemas, childSchemaName){...},
patternProperties: function mergeSchemas(schemas, childSchemaName){...},
additionalProperties: function mergeSchemas(schemas){...},
Expand Down

0 comments on commit 34d65fb

Please sign in to comment.