Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier to specify triggers for Zapier #19638

Closed
wants to merge 7 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
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 = {
const operations = {
{{#apiInfo}}
{{#apis}}
{{#operations}}
Expand All @@ -18,6 +18,7 @@ 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, {}),
}
searchActions: () => Object.entries(operations).reduce((operations, [key, value]) => isSearchAction(key) && hasSearchRequisites(value) ? {...operations, [key]: searchMiddleware(value)} : operations, {}),
createActions: () => Object.entries(operations).reduce((operations, [key, value]) => !isSearchAction(key) ? {...operations, [key]: value} : operations, {}),
triggers: () => Object.entries(operations).reduce((operations, [key, value]) => isTrigger(key) ? {...operations, [key]: triggerMiddleware(value)} : operations, {}),
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ module.exports = {
inputFields: [
{{#allParams}}
{{#isPrimitiveType}}
{{#isHeaderParam}}
{{/isHeaderParam}}
{{^isHeaderParam}}
{
key: '{{baseName}}',
label: '{{description}}',
Expand All @@ -40,6 +43,7 @@ module.exports = {
],
{{/isEnum}}
},
{{/isHeaderParam}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isArray}}
Expand Down
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,
}
5 changes: 0 additions & 5 deletions samples/client/petstore/zapier/apis/PetApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ module.exports = {
type: 'number',
required: true,
},
{
key: 'api_key',
label: '',
type: 'string',
},
],
outputFields: [
],
Expand Down
3 changes: 2 additions & 1 deletion samples/client/petstore/zapier/index.js
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: 6 additions & 5 deletions samples/client/petstore/zapier/operations/actions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const PetApi = require('../apis/PetApi');
const StoreApi = require('../apis/StoreApi');
const UserApi = require('../apis/UserApi');
const { searchMiddleware, hasSearchRequisites, isSearchAction } = require('../utils/utils');
const { triggerMiddleware, isTrigger, searchMiddleware, hasSearchRequisites, isSearchAction } = require('../utils/utils');

const actions = {
const operations = {
Copy link
Member Author

Choose a reason for hiding this comment

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

@a-wallen is this a breaking change? shall we keep the const name as actions?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can keep the name. Also we need to drop the commit that says (EM Only)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

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

435c73d this might be the commit that you want to land on it's own. You could start from this PR #19643.

Sorry that I can't generate the samples on my computer. Git Bash generates the wrong path separator on Windows...

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like I was also able to update the samples properly by using the devcontainer in 86307de!

Copy link
Member Author

Choose a reason for hiding this comment

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

nice.

i merged via #19645

in which you're listed as co-author

thanks again for the PR

[PetApi.addPet.key]: PetApi.addPet,
[PetApi.deletePet.key]: PetApi.deletePet,
[PetApi.findPetsByStatus.key]: PetApi.findPetsByStatus,
Expand All @@ -27,6 +27,7 @@ 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, {}),
}
searchActions: () => Object.entries(operations).reduce((operations, [key, value]) => isSearchAction(key) && hasSearchRequisites(value) ? {...operations, [key]: searchMiddleware(value)} : operations, {}),
createActions: () => Object.entries(operations).reduce((operations, [key, value]) => !isSearchAction(key) ? {...operations, [key]: value} : operations, {}),
triggers: () => Object.entries(operations).reduce((operations, [key, value]) => isTrigger(key) ? {...operations, [key]: triggerMiddleware(value)} : operations, {}),
}
11 changes: 11 additions & 0 deletions samples/client/petstore/zapier/utils/utils.js
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,
}
Loading