Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions packages/input_schema/src/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@
"nullable": { "type": "boolean" },
"sectionCaption": { "type": "string" },
"sectionDescription": { "type": "string" },

"enum": {
"type": "array",
"items": { "type": "string" },
"minItems": 1,
"uniqueItems": true
},
"enumTitles": {
"type": "array",
"items": { "type": "string" }
"items": { "type": "string" },
"minItems": 1
}
},
"required": ["type", "title", "description", "enum"]
Expand Down
56 changes: 56 additions & 0 deletions test/input_schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ describe('input_schema.json', () => {
description: 'Some description ...',
editor: 'json',
},
myField2: {
title: 'Enum without titles',
type: 'string',
description: 'Some description ...',
editor: 'select',
enum: ['a', 'b', 'c'],
},
myField3: {
title: 'Enum with titles',
type: 'string',
description: 'Some description ...',
editor: 'select',
enum: ['a', 'b', 'c'],
enumTitles: ['A', 'B', 'C'],
},
},
};

Expand Down Expand Up @@ -208,6 +223,47 @@ describe('input_schema.json', () => {
);
});

it('should throw error on empty enum array', () => {
const schema = {
title: 'Test input schema',
type: 'object',
schemaVersion: 1,
properties: {
myField: {
title: 'Field title',
type: 'string',
description: 'Some description ...',
enum: [],
},
},
};

expect(() => validateInputSchema(validator, schema)).toThrow(
'Input schema is not valid (Field schema.properties.myField.enum.enum must NOT have fewer than 1 items)',
Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea why there is .enum.enum here, but AJV codebase is such a mess and I don't have the motivation to debug it deeper

);
});

it('should throw error on empty enumTitles array', () => {
const schema = {
title: 'Test input schema',
type: 'object',
schemaVersion: 1,
properties: {
myField: {
title: 'Field title',
type: 'string',
description: 'Some description ...',
enum: ['abcd'],
enumTitles: [],
},
},
};

expect(() => validateInputSchema(validator, schema)).toThrow(
'Input schema is not valid (Field schema.properties.myField.enum.enumTitles must NOT have fewer than 1 items)',
);
});

it('should throw error when required field is not defined', () => {
const schema = {
title: 'Test input schema',
Expand Down