Skip to content

Commit

Permalink
Fix schema validation to allow for arrays of strings when indexing pr…
Browse files Browse the repository at this point in the history
…operties (#3043)
  • Loading branch information
alexd-codaio authored Aug 27, 2024
1 parent 0d6e153 commit a6a4653
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
8 changes: 6 additions & 2 deletions dist/testing/upload_validation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codahq/packs-sdk",
"version": "1.7.12",
"version": "1.7.12-prelease.1",
"license": "MIT",
"workspaces": [
"dev/eslint"
Expand Down
38 changes: 25 additions & 13 deletions test/upload_validation_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3153,9 +3153,10 @@ describe('Pack metadata Validation', async () => {
properties: {
name: {type: ValueType.String},
value: {type: ValueType.Number},
attachments: {type: ValueType.Array, items: {type: ValueType.String}},
},
index: {
properties: ['name'],
properties: ['name', 'attachments'],
contextProperties: ['value'],
},
});
Expand All @@ -3170,10 +3171,12 @@ describe('Pack metadata Validation', async () => {
value: {type: ValueType.Number},
},
index: {
properties: [{
property: 'name',
strategy: IndexingStrategy.Raw,
}],
properties: [
{
property: 'name',
strategy: IndexingStrategy.Raw,
},
],
},
});
await validateJson(metadata);
Expand All @@ -3184,18 +3187,25 @@ describe('Pack metadata Validation', async () => {
type: ValueType.Object,
properties: {
num: {type: ValueType.Number},
values: {type: ValueType.Array, items: {type: ValueType.Number}},
},
index: {
properties: ['num'],
properties: ['num', 'values'],
contextProperties: ['value'],
},
});
const err = await validateJsonAndAssertFails(metadata);
assert.deepEqual(err.validationErrors, [
{
message: 'The "properties" field name "Num" must refer to a "ValueType.String" property.',
message:
'The "properties" field name "Num" must refer to a "ValueType.String" property or a "ValueType.Array" array of "ValueType.String" properties.',
path: 'formulas[0].schema.index.properties[0]',
},
{
message:
'The "properties" field name "Values" must refer to a "ValueType.String" property or a "ValueType.Array" array of "ValueType.String" properties.',
path: 'formulas[0].schema.index.properties[1]',
},
{
message: 'The "contextProperties" path "Value" does not exist in the "properties" object.',
path: 'formulas[0].schema.index.contextProperties[0]',
Expand All @@ -3211,10 +3221,12 @@ describe('Pack metadata Validation', async () => {
value: {type: ValueType.Number},
},
index: {
properties: [{
property: 'blah',
strategy: IndexingStrategy.Raw,
}],
properties: [
{
property: 'blah',
strategy: IndexingStrategy.Raw,
},
],
},
});
const err = await validateJsonAndAssertFails(metadata);
Expand Down Expand Up @@ -4825,7 +4837,7 @@ describe('Pack metadata Validation', async () => {
assert.deepEqual(err.validationErrors, [
{
message: 'Array must contain at least 1 element(s)',
path: 'defaultAuthentication.scopes'
path: 'defaultAuthentication.scopes',
},
]);
});
Expand All @@ -4851,7 +4863,7 @@ describe('Pack metadata Validation', async () => {
assert.deepEqual(err.validationErrors, [
{
message: 'Array must contain at least 1 element(s)',
path: 'defaultAuthentication.scopes'
path: 'defaultAuthentication.scopes',
},
]);
});
Expand Down
14 changes: 10 additions & 4 deletions testing/upload_validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1579,16 +1579,22 @@ function buildMetadataSchema({sdkVersion}: BuildMetadataSchemaArgs): {
validatePropertyValue(
indexedProperty,
'properties',
indexedPropertySchema => indexedPropertySchema.type === ValueType.String,
`must refer to a "ValueType.String" property.`,
indexedPropertySchema =>
indexedPropertySchema.type === ValueType.String ||
(indexedPropertySchema.type === ValueType.Array &&
indexedPropertySchema.items.type === ValueType.String),
`must refer to a "ValueType.String" property or a "ValueType.Array" array of "ValueType.String" properties.`,
objectPath,
);
} else {
validatePropertyValue(
indexedProperty.property,
'properties',
indexedPropertySchema => indexedPropertySchema.type === ValueType.String,
`must refer to a "ValueType.String" property.`,
indexedPropertySchema =>
indexedPropertySchema.type === ValueType.String ||
(indexedPropertySchema.type === ValueType.Array &&
indexedPropertySchema.items.type === ValueType.String),
`must refer to a "ValueType.String" property or a "ValueType.Array" array of "ValueType.String" properties.`,
[...objectPath, 'property'],
);
}
Expand Down

0 comments on commit a6a4653

Please sign in to comment.