/
ResourceSchema.js
168 lines (165 loc) · 4.6 KB
/
ResourceSchema.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
'use strict';
const makeSchema = require('../utils/makeSchema');
const ResourceMethodGetSchema = require('./ResourceMethodGetSchema');
const ResourceMethodHookSchema = require('./ResourceMethodHookSchema');
const ResourceMethodListSchema = require('./ResourceMethodListSchema');
const ResourceMethodSearchSchema = require('./ResourceMethodSearchSchema');
const ResourceMethodCreateSchema = require('./ResourceMethodCreateSchema');
const DynamicFieldsSchema = require('./DynamicFieldsSchema');
const KeySchema = require('./KeySchema');
module.exports = makeSchema(
{
id: '/ResourceSchema',
description:
'Represents a resource, which will in turn power triggers, searches, or creates.',
type: 'object',
required: ['key', 'noun'],
properties: {
key: {
description: 'A key to uniquely identify this resource.',
$ref: KeySchema.id,
},
noun: {
description:
'A noun for this resource that completes the sentence "create a new XXX".',
type: 'string',
minLength: 2,
maxLength: 255,
},
// TODO: do we need to break these all apart too? :-/
get: {
description: ResourceMethodGetSchema.schema.description,
$ref: ResourceMethodGetSchema.id,
},
hook: {
description: ResourceMethodHookSchema.schema.description,
$ref: ResourceMethodHookSchema.id,
},
list: {
description: ResourceMethodListSchema.schema.description,
$ref: ResourceMethodListSchema.id,
},
search: {
description: ResourceMethodSearchSchema.schema.description,
$ref: ResourceMethodSearchSchema.id,
},
create: {
description: ResourceMethodCreateSchema.schema.description,
$ref: ResourceMethodCreateSchema.id,
},
outputFields: {
description: 'What fields of data will this return?',
$ref: DynamicFieldsSchema.id,
},
sample: {
description: 'What does a sample of data look like?',
type: 'object',
// TODO: require id, ID, Id property?
minProperties: 1,
},
},
additionalProperties: false,
examples: [
{
key: 'tag',
noun: 'Tag',
get: {
display: {
label: 'Get Tag by ID',
description: 'Grab a specific Tag by ID.',
},
operation: {
perform: {
url: 'https://fake-crm.getsandbox.com/tags/{{inputData.id}}',
},
sample: {
id: 385,
name: 'proactive enable ROI',
},
},
},
},
{
key: 'tag',
noun: 'Tag',
sample: {
id: 385,
name: 'proactive enable ROI',
},
get: {
display: {
label: 'Get Tag by ID',
description: 'Grab a specific Tag by ID.',
},
operation: {
perform: {
url: 'https://fake-crm.getsandbox.com/tags/{{inputData.id}}',
},
// resource sample is used
},
},
},
{
key: 'tag',
noun: 'Tag',
get: {
display: {
label: 'Get Tag by ID',
description: 'Grab a specific Tag by ID.',
hidden: true,
},
operation: {
perform: {
url: 'https://fake-crm.getsandbox.com/tags/{{inputData.id}}',
},
},
},
list: {
display: {
label: 'New Tag',
description: 'Trigger when a new Tag is created in your account.',
},
operation: {
perform: {
url: 'https://fake-crm.getsandbox.com/tags',
},
sample: {
id: 385,
name: 'proactive enable ROI',
},
},
},
},
],
antiExamples: [
{
example: {
key: 'tag',
noun: 'Tag',
get: {
display: {
label: 'Get Tag by ID',
description: 'Grab a specific Tag by ID.',
},
operation: {
perform: {
url: 'https://fake-crm.getsandbox.com/tags/{{inputData.id}}',
},
},
},
},
reason:
'Missing key from operation: sample. Note – this is valid if the resource has defined a sample.',
},
],
},
[
ResourceMethodGetSchema,
ResourceMethodHookSchema,
ResourceMethodListSchema,
ResourceMethodSearchSchema,
ResourceMethodCreateSchema,
DynamicFieldsSchema,
KeySchema,
]
);