Skip to content

Commit

Permalink
Merge branch 'zapier_triggers' of https://github.com/MarketplaceSoftw…
Browse files Browse the repository at this point in the history
…are/openapi-generator into MarketplaceSoftware-zapier_triggers234
  • Loading branch information
wing328 committed Sep 23, 2024
2 parents b42027d + 435c73d commit ccf28e3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const {{classname}} = require('../{{apiPackage}}/{{classname}}');
{{/apis}}
{{/apiInfo}}
const { searchMiddleware, hasSearchRequisites, isSearchAction } = require('../utils/utils');
const { triggerMiddleware, isTrigger, searchMiddleware, hasSearchRequisites, isSearchAction } = require('../utils/utils');

const actions = {
{{#apiInfo}}
Expand All @@ -20,4 +20,5 @@ const actions = {
module.exports = {
searchActions: () => Object.entries(actions).reduce((actions, [key, value]) => isSearchAction(key) && hasSearchRequisites(value) ? {...actions, [key]: searchMiddleware(value)} : actions, {}),
createActions: () => Object.entries(actions).reduce((actions, [key, value]) => !isSearchAction(key) ? {...actions, [key]: value} : actions, {}),
}
triggers: () => Object.entries(actions).reduce((actions, [key, value]) => isTrigger(key) ? {...actions, [key]: triggerMiddleware(value)} : actions, {}),
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const authentication = require('./authentication');
const { searchActions, createActions } = require('./operations/actions');
const { searchActions, createActions, triggers } = require('./operations/actions');

module.exports = {
version: require('./package.json').version,
platformVersion: require('zapier-platform-core').version,
authentication: authentication,
searches: searchActions(),
creates: createActions(),
triggers: triggers(),
};
11 changes: 11 additions & 0 deletions modules/openapi-generator/src/main/resources/zapier/utils.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ const requestOptionsMiddleware = (z, bundle, requestOptions) => {
return requestOptions
}

const isTrigger = (key) => {
// TODO: custom logic
return false
}

const triggerMiddleware = (action) => {
return action
}

module.exports = {
replacePathParameters: replacePathParameters,
childMapping: childMapping,
Expand All @@ -39,4 +48,6 @@ module.exports = {
isSearchAction: isSearchAction,
searchMiddleware: searchMiddleware,
requestOptionsMiddleware: requestOptionsMiddleware,
isTrigger: isTrigger,
triggerMiddleware: triggerMiddleware,
}
30 changes: 27 additions & 3 deletions samples/client/petstore/zapier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ This generator generates a partial implementation of a zapier integration from a

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.

Here there are all the parts you need to complete by yourself:
Here there are all the parts you need to complete by yourself:

### 1) **utils/utils.js** isSearchAction method

This method has to return either true or false if a method is a [zapier search action](https://platform.zapier.com/docs/search-create).

```
const isSearchAction = (key) => {
// TODO: custom logic
Expand All @@ -18,6 +20,7 @@ const isSearchAction = (key) => {
```

### 2) **utils/utils.js** searchMiddleware method

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.

```
Expand All @@ -27,13 +30,34 @@ const searchMiddleware = (action) => {
}
```

### 3) **utils/utils.js** isTrigger method

This method has to return either true or false if a method is a [zapier search action](https://platform.zapier.com/docs/search-create).

```
const isTrigger = (key) => {
// TODO: custom logic
return false
}
```

### 4) **utils/utils.js** searchMiddleware method

```
const triggerMiddleware = (action) => {
return action
}
```

### 3) **authentication.js**

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).

## Samples
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.

For example:
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.

For example:

```
CreateUserResponse:
Expand Down

0 comments on commit ccf28e3

Please sign in to comment.