From 03f42672d57929c60b66849cfcfc5633d4dfbea5 Mon Sep 17 00:00:00 2001 From: Felix Hennig Date: Wed, 11 Dec 2024 12:37:38 +0100 Subject: [PATCH] Add validation --- website/src/config.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/website/src/config.ts b/website/src/config.ts index 54df07cae0..4b971a3c54 100644 --- a/website/src/config.ts +++ b/website/src/config.ts @@ -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; }