Enable JSON schema validation for import#779
Conversation
Misspellings found, please review:
To accept these changes, run the following commands from this repository on this branch |
7e88d6e to
eed5fa4
Compare
| { | ||
| // TODO: Embed schema in binaries & validate file. This will return nullopt on failure. | ||
| // Validate the JSON against the schema. | ||
| Json::Value schemaJson = JsonSchema::LoadResourceAsSchemaDoc(MAKEINTRESOURCE(IDX_PACKAGES_SCHEMA_V1), MAKEINTRESOURCE(PACKAGESSCHEMA_RESOURCE_TYPE)); |
There was a problem hiding this comment.
LoadResourceAsSchemaDoc [](start = 49, length = 23)
How will we determine which schema to load in the future when there are more than one version? That can probably be a problem for future developer, but let's consider if we are just putting off the work or if we are making that work harder.
For instance, will a file with no "schema" json item validate as good? Do we want to support that and thus default to V1 schema if no value present? Or would we prefer to require the "schema" to be present and that it match the value that we expect, regardless of version.
There was a problem hiding this comment.
In the future we could load the schema depending on the $schema property, and have some fall back if it is missing or not recognized (e.g. use latest schema).
This does not validate that the file has a $schema property or that it has a specific value. We may be able to require it in the schema if we wanted to.
If we create newer versions this function will accept them as long as they are backwards compatible. All the nodes accept additional unrecognized properties to allow room for extending without causing validation failures.
There was a problem hiding this comment.
I think we should require the $schema property and that it contains the expected value, even if we don't actually use it to select the schema to use yet. This seems like something that should be done by the code rather than in the schema file itself.
Enabling validation of JSON files for import according to the schema.
Microsoft Reviewers: Open in CodeFlow