-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathtemplate.schema.ts
More file actions
36 lines (34 loc) · 949 Bytes
/
template.schema.ts
File metadata and controls
36 lines (34 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
const properties = {};
propertyNames.forEach(
(property) =>
(properties[property] = {
minLength: 1,
description: `The "${property}" cannot be empty`,
}),
);
return {
if: {
propertyNames: {
enum: [...propertyNames],
},
},
then: { properties },
};
};
export const templateSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
name: { type: 'string' },
category: { type: 'string', enum: ['AUTHENTICATION', 'MARKETING', 'UTILITY'] },
allowCategoryChange: { type: 'boolean' },
language: { type: 'string' },
components: { type: 'array' },
webhookUrl: { type: 'string' },
},
required: ['name', 'category', 'language', 'components'],
...isNotEmpty('name', 'category', 'language', 'components'),
};