Embed json schema validator in binary #613
Draft
+954
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: this PR is part of a series broadly aimed at refactor config file to make it simpler to use, and drive towards a simpler testing experience.
This PR introduces a dependency on
json-schema-validatorand uses this to allow checking a config against the schema directly within c++. It avoids the need for a separate tracking of the schema by embedding it within the executable, to avoid the need for file reading. This adds ~30kB to the binary, but makes it effectively self describing. It effectively adds a set of redundant checks, given many of these constraints are checked during json reading, but this will enable a follow up PR that removes these checks whilst simplifyingconfigfile.hppandconfigfile.cpp.The validation can be done wholesale, where a top level json is provided, or using a keyword, to test only against a subset of the json. Additionally it was necessary to downgrade the schema version we are using, to match what the validator library was capable of, luckily the schema we have is actually already compliant with that version (with 1 tiny exception), so this required minimal changes other than the tag.
The error reporting from the schema follows the documentation
["Key1"]["Key2"]style of printing, and should also print all errors it finds in the config at once, rather than failing at the first it finds and then erroring out. So a user should get a more complete description of the fixes they need to make, without retrying so much.The check config github action will eventually become redundant and be removed, but for now I am leaving it in as a follow up PR hardens the schema to cover as much as possible.