Skip to content

Commit

Permalink
Add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
fhennig committed Dec 11, 2024
1 parent 8aa879f commit 03f4267
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion website/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,33 @@ function getConfigDir(): string {
return configDir;
}

function validateWebsiteConfig(config: WebsiteConfig): Error[] {
const errors: Error[] = [];
Array.from(Object.entries(config.organisms).values()).forEach(([organism, schema]) => {
if (schema.schema.metadataTemplate !== undefined) {
schema.schema.metadataTemplate.forEach((fieldName) => {
if (schema.schema.inputFields.find((inputField) => inputField.name === fieldName) === undefined) {
errors.push(
Error(
`Error in ${organism}.schema.metadataTemplate: ` +
`${fieldName} is not defined in the inputFields.`,
),
);
}
});
}
});
return errors;
}

export function getWebsiteConfig(): WebsiteConfig {
if (_config === null) {
_config = readTypedConfigFile('website_config.json', websiteConfig);
const config = readTypedConfigFile('website_config.json', websiteConfig);
const validationErrors = validateWebsiteConfig(config);
if (validationErrors.length > 0) {
throw new AggregateError(validationErrors, 'There were validation errors in the website_config.json');
}
_config = config;
}
return _config;
}
Expand Down

0 comments on commit 03f4267

Please sign in to comment.