Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON schemas for extracts export validation function #1075

Merged
merged 3 commits into from
Sep 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1026,14 +1026,31 @@ function getInterfaceTreeInfo(iface, interfaces) {
* if the requested schema does not exist.
*/
function getSchemaValidationFunction(schemaName) {
// Helper function that selects the right schema file from the given
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may question-mark as much as you want, it actually does improve readability :)

// schema name.
function getSchemaFileFromSchemaName(name) {
switch (name) {
case 'index.json':
return path.join('files', name);
case 'idlnamesparsed':
return path.join('postprocessing', 'idlnames-parsed.json');
case 'idlparsed':
return path.join('postprocessing', 'idlparsed.json');
default:
if (name.startsWith('extract-')) {
return path.join('browserlib', `${name}.json`);
}
else if (name.endsWith('.json')) {
return path.join('postprocessing', name);
}
else {
return path.join('files', 'extracts', `${name}.json`)
}
}
}

const schemasFolder = path.join(__dirname, '..', '..', 'schemas');
const schemaFile =
(schemaName === 'index.json') ? path.join('files', schemaName) :
(schemaName === 'idlnamesparsed') ? path.join('postprocessing', 'idlnames-parsed.json') :
(schemaName === 'idlparsed') ? path.join('postprocessing', 'idlparsed.json') :
schemaName.startsWith('extract-') ? path.join('browserlib', `${schemaName}.json`) :
schemaName.endsWith('.json') ? path.join('postprocessing', schemaName) :
path.join('files', 'extracts', `${schemaName}.json`);
const schemaFile = getSchemaFileFromSchemaName(schemaName);
let schema;
try {
schema = require(path.join(schemasFolder, schemaFile));
Expand Down