Skip to content

Commit

Permalink
fix(validation): support customDatasources.description strings (#28448)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
rarkins and viceice committed Apr 18, 2024
1 parent b357e4d commit a9e0c64
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
11 changes: 8 additions & 3 deletions lib/config/validation.spec.ts
Expand Up @@ -237,6 +237,7 @@ describe('config/validation', () => {
const config = {
customDatasources: {
foo: {
description: 3,
randomKey: '',
defaultRegistryUrlTemplate: [],
transformTemplates: [{}],
Expand All @@ -247,15 +248,19 @@ describe('config/validation', () => {
expect(errors).toMatchObject([
{
message:
'Invalid `customDatasources.customDatasources.defaultRegistryUrlTemplate` configuration: is a string',
'Invalid `customDatasources.defaultRegistryUrlTemplate` configuration: is a string',
},
{
message:
'Invalid `customDatasources.customDatasources.randomKey` configuration: key is not allowed',
'Invalid `customDatasources.description` configuration: is not an array of strings',
},
{
message:
'Invalid `customDatasources.customDatasources.transformTemplates` configuration: is not an array of string',
'Invalid `customDatasources.randomKey` configuration: key is not allowed',
},
{
message:
'Invalid `customDatasources.transformTemplates` configuration: is not an array of string',
},
]);
});
Expand Down
15 changes: 12 additions & 3 deletions lib/config/validation.ts
Expand Up @@ -712,19 +712,28 @@ export async function validateConfig(
if (!allowedKeys.includes(subKey)) {
errors.push({
topic: 'Configuration Error',
message: `Invalid \`${currentPath}.${key}.${subKey}\` configuration: key is not allowed`,
message: `Invalid \`${currentPath}.${subKey}\` configuration: key is not allowed`,
});
} else if (subKey === 'transformTemplates') {
if (!is.array(subValue, is.string)) {
errors.push({
topic: 'Configuration Error',
message: `Invalid \`${currentPath}.${key}.${subKey}\` configuration: is not an array of string`,
message: `Invalid \`${currentPath}.${subKey}\` configuration: is not an array of string`,
});
}
} else if (subKey === 'description') {
if (
!(is.string(subValue) || is.array(subValue, is.string))
) {
errors.push({
topic: 'Configuration Error',
message: `Invalid \`${currentPath}.${subKey}\` configuration: is not an array of strings`,
});
}
} else if (!is.string(subValue)) {
errors.push({
topic: 'Configuration Error',
message: `Invalid \`${currentPath}.${key}.${subKey}\` configuration: is a string`,
message: `Invalid \`${currentPath}.${subKey}\` configuration: is a string`,
});
}
}
Expand Down

0 comments on commit a9e0c64

Please sign in to comment.