-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Deeply merge configuration schema defaults (#124)
- Loading branch information
1 parent
3a8b108
commit 1583ff0
Showing
10 changed files
with
212 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
test/input/config-cli/deep-defaults/glossarify-md.conf.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "../../../../conf.schema.json", | ||
"baseUrl": "file://localhost", | ||
"baseDir": ".", | ||
"outDir": "../../../output-actual/config-cli/deep-defaults", | ||
"includeFiles": ["."], | ||
"indexing": {}, | ||
"glossaries": [], | ||
"linking": "relative", | ||
"dev": { | ||
"effectiveConfFile": "./glossarify-md-effective.conf.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Glossary | ||
|
||
## Test Case | ||
|
||
- GIVEN a configuration schema WITH a complex option `glossaries` WITH a complex `default` value | ||
|
||
*./node_modules/glossarify-md/conf.schema.json*: | ||
~~~json | ||
{ | ||
"$id": "...", | ||
"properties": { | ||
"glossaries": { | ||
"default": [ | ||
{ "file": "./glossary.md", "termHint": ""} | ||
], | ||
"...": "...", | ||
}, | ||
"...": "..." | ||
} | ||
} | ||
~~~ | ||
- AND a configuration file with an incomplete *partial* definition of the complex object `glossaries` | ||
|
||
*Some partial user configuration* | ||
~~~json | ||
{ | ||
"$schema": "./node_modules/glossarify-md/conf.schema.json", | ||
"glossaries": [], | ||
"...": "..." | ||
} | ||
~~~ | ||
|
||
- THEN the default values MUST be *deep-merged* into the configuration file such that the actual configuration applied is identical to a configuration file | ||
|
||
*Expected config to apply* | ||
~~~json | ||
{ | ||
"$schema": "./node_modules/glossarify-md/conf.schema.json", | ||
"glossaries": [ | ||
{ "file": "./glossary.md", "termHint": ""} | ||
], | ||
"...": "..." | ||
} | ||
~~~ |
39 changes: 39 additions & 0 deletions
39
test/output-expected/config-cli/deep-defaults/glossarify-md-effective.conf.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"baseDir": "{CWD}/output-actual/config-cli/deep-defaults", | ||
"baseUrl": "file://localhost", | ||
"excludeFiles": [ | ||
"node_modules", | ||
".git" | ||
], | ||
"force": false, | ||
"generateFiles": { | ||
"listOf": [] | ||
}, | ||
"glossaries": [ | ||
{ | ||
"file": "./glossary.md", | ||
"termHint": "", | ||
"basePath": "/{CWD}/output-actual/config-cli/deep-defaults/glossary.md", | ||
"outPath": "/{CWD}/output-actual/config-cli/deep-defaults/glossary.md" | ||
} | ||
], | ||
"ignoreCase": false, | ||
"includeFiles": [ | ||
"." | ||
], | ||
"indexing": { | ||
"groupByHeadingDepth": 6 | ||
}, | ||
"i18n": { | ||
"locale": "en" | ||
}, | ||
"keepRawFiles": [], | ||
"linking": "relative", | ||
"outDir": "{CWD}/output-actual/config-cli/deep-defaults", | ||
"outDirDropOld": true, | ||
"reportNotMentioned": false, | ||
"dev": { | ||
"effectiveConfFile": "./glossarify-md-effective.conf.json" | ||
}, | ||
"$schema": "../../../../conf.schema.json" | ||
} |
13 changes: 13 additions & 0 deletions
13
test/output-expected/config-cli/deep-defaults/glossarify-md.conf.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "../../../../conf.schema.json", | ||
"baseUrl": "file://localhost", | ||
"baseDir": ".", | ||
"outDir": "../../../output-actual/config-cli/deep-defaults", | ||
"includeFiles": ["."], | ||
"indexing": {}, | ||
"glossaries": [], | ||
"linking": "relative", | ||
"dev": { | ||
"effectiveConfFile": "./glossarify-md-effective.conf.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# [Glossary](#glossary) | ||
|
||
## [Test Case](#test-case) | ||
|
||
- GIVEN a configuration schema WITH a complex option `glossaries` WITH a complex `default` value | ||
|
||
_./node_modules/glossarify-md/conf.schema.json_: | ||
|
||
```json | ||
{ | ||
"$id": "...", | ||
"properties": { | ||
"glossaries": { | ||
"default": [ | ||
{ "file": "./glossary.md", "termHint": ""} | ||
], | ||
"...": "...", | ||
}, | ||
"...": "..." | ||
} | ||
} | ||
``` | ||
|
||
- AND a configuration file with an incomplete _partial_ definition of the complex object `glossaries` | ||
|
||
_Some partial user configuration_ | ||
|
||
```json | ||
{ | ||
"$schema": "./node_modules/glossarify-md/conf.schema.json", | ||
"glossaries": [], | ||
"...": "..." | ||
} | ||
``` | ||
|
||
- THEN the default values MUST be _deep-merged_ into the configuration file such that the actual configuration applied is identical to a configuration file | ||
|
||
_Expected config to apply_ | ||
|
||
```json | ||
{ | ||
"$schema": "./node_modules/glossarify-md/conf.schema.json", | ||
"glossaries": [ | ||
{ "file": "./glossary.md", "termHint": ""} | ||
], | ||
"...": "..." | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters