Skip to content

Commit 435c73d

Browse files
committed
chore: add triggers
1 parent eebecc8 commit 435c73d

4 files changed

Lines changed: 43 additions & 6 deletions

File tree

modules/openapi-generator/src/main/resources/zapier/actions.mustache

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const {{classname}} = require('../{{apiPackage}}/{{classname}}');
44
{{/apis}}
55
{{/apiInfo}}
6-
const { searchMiddleware, hasSearchRequisites, isSearchAction } = require('../utils/utils');
6+
const { triggerMiddleware, isTrigger, searchMiddleware, hasSearchRequisites, isSearchAction } = require('../utils/utils');
77

88
const actions = {
99
{{#apiInfo}}
@@ -20,4 +20,5 @@ const actions = {
2020
module.exports = {
2121
searchActions: () => Object.entries(actions).reduce((actions, [key, value]) => isSearchAction(key) && hasSearchRequisites(value) ? {...actions, [key]: searchMiddleware(value)} : actions, {}),
2222
createActions: () => Object.entries(actions).reduce((actions, [key, value]) => !isSearchAction(key) ? {...actions, [key]: value} : actions, {}),
23-
}
23+
triggers: () => Object.entries(actions).reduce((actions, [key, value]) => isTrigger(key) ? {...actions, [key]: triggerMiddleware(value)} : actions, {}),
24+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const authentication = require('./authentication');
2-
const { searchActions, createActions } = require('./operations/actions');
2+
const { searchActions, createActions, triggers } = require('./operations/actions');
33

44
module.exports = {
55
version: require('./package.json').version,
66
platformVersion: require('zapier-platform-core').version,
77
authentication: authentication,
88
searches: searchActions(),
99
creates: createActions(),
10+
triggers: triggers(),
1011
};

modules/openapi-generator/src/main/resources/zapier/utils.mustache

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ const requestOptionsMiddleware = (z, bundle, requestOptions) => {
3030
return requestOptions
3131
}
3232

33+
const isTrigger = (key) => {
34+
// TODO: custom logic
35+
return false
36+
}
37+
38+
const triggerMiddleware = (action) => {
39+
return action
40+
}
41+
3342
module.exports = {
3443
replacePathParameters: replacePathParameters,
3544
childMapping: childMapping,
@@ -39,4 +48,6 @@ module.exports = {
3948
isSearchAction: isSearchAction,
4049
searchMiddleware: searchMiddleware,
4150
requestOptionsMiddleware: requestOptionsMiddleware,
51+
isTrigger: isTrigger,
52+
triggerMiddleware: triggerMiddleware,
4253
}

samples/client/petstore/zapier/README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ This generator generates a partial implementation of a zapier integration from a
66

77
It's a partial integration because you have to put in some code for it to be 100% complete, code that depends only on how your api is structured.
88

9-
Here there are all the parts you need to complete by yourself:
9+
Here there are all the parts you need to complete by yourself:
1010

1111
### 1) **utils/utils.js** isSearchAction method
12+
1213
This method has to return either true or false if a method is a [zapier search action](https://platform.zapier.com/docs/search-create).
14+
1315
```
1416
const isSearchAction = (key) => {
1517
// TODO: custom logic
@@ -18,6 +20,7 @@ const isSearchAction = (key) => {
1820
```
1921

2022
### 2) **utils/utils.js** searchMiddleware method
23+
2124
This method has to return an array of resources (searches must return an array), if you have pagination or you api returns an array inside nested fields, here you have to extract the array.
2225

2326
```
@@ -27,13 +30,34 @@ const searchMiddleware = (action) => {
2730
}
2831
```
2932

33+
### 3) **utils/utils.js** isTrigger method
34+
35+
This method has to return either true or false if a method is a [zapier search action](https://platform.zapier.com/docs/search-create).
36+
37+
```
38+
const isTrigger = (key) => {
39+
// TODO: custom logic
40+
return false
41+
}
42+
```
43+
44+
### 4) **utils/utils.js** searchMiddleware method
45+
46+
```
47+
const triggerMiddleware = (action) => {
48+
return action
49+
}
50+
```
51+
3052
### 3) **authentication.js**
53+
3154
This file must be written completely according to your api authentication, you can get it generated automatically by creating the integration on the zapier website and filling the requested data, or you can build it yourself following [this guide](https://platform.zapier.com/cli_tutorials/getting-started#adding-authentication).
3255

3356
## Samples
34-
To get your app made public on zapier you must provide a sample (json example response) for each of your actions, these samples get automatically generated by this generator but you have to have actual response examples in you openapi file.
3557

36-
For example:
58+
To get your app made public on zapier you must provide a sample (json example response) for each of your actions, these samples get automatically generated by this generator but you have to have actual response examples in you openapi file.
59+
60+
For example:
3761

3862
```
3963
CreateUserResponse:

0 commit comments

Comments
 (0)