From 565af33e24fc7bb38f1a28bdcb9d861658f5e6c5 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 23 Sep 2024 12:03:44 +0800 Subject: [PATCH] Make it easier to specify triggers for Zapier (#19645) * chore: add triggers * update samples --------- Co-authored-by: Stephen (Alex) Wallen --- .../src/main/resources/zapier/actions.mustache | 5 +++-- .../src/main/resources/zapier/index.mustache | 3 ++- .../src/main/resources/zapier/utils.mustache | 11 +++++++++++ samples/client/petstore/zapier/index.js | 3 ++- samples/client/petstore/zapier/operations/actions.js | 5 +++-- samples/client/petstore/zapier/utils/utils.js | 11 +++++++++++ 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/zapier/actions.mustache b/modules/openapi-generator/src/main/resources/zapier/actions.mustache index d398927b6d82..4d596866ac95 100644 --- a/modules/openapi-generator/src/main/resources/zapier/actions.mustache +++ b/modules/openapi-generator/src/main/resources/zapier/actions.mustache @@ -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}} @@ -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, {}), -} \ No newline at end of file + triggers: () => Object.entries(actions).reduce((actions, [key, value]) => isTrigger(key) ? {...actions, [key]: triggerMiddleware(value)} : actions, {}), +} diff --git a/modules/openapi-generator/src/main/resources/zapier/index.mustache b/modules/openapi-generator/src/main/resources/zapier/index.mustache index 8f60b0c7b1e6..2e98dba0e32c 100644 --- a/modules/openapi-generator/src/main/resources/zapier/index.mustache +++ b/modules/openapi-generator/src/main/resources/zapier/index.mustache @@ -1,5 +1,5 @@ const authentication = require('./authentication'); -const { searchActions, createActions } = require('./operations/actions'); +const { searchActions, createActions, triggers } = require('./operations/actions'); module.exports = { version: require('./package.json').version, @@ -7,4 +7,5 @@ module.exports = { authentication: authentication, searches: searchActions(), creates: createActions(), + triggers: triggers(), }; diff --git a/modules/openapi-generator/src/main/resources/zapier/utils.mustache b/modules/openapi-generator/src/main/resources/zapier/utils.mustache index b00174f3f7b0..07c4915aaae3 100644 --- a/modules/openapi-generator/src/main/resources/zapier/utils.mustache +++ b/modules/openapi-generator/src/main/resources/zapier/utils.mustache @@ -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, @@ -39,4 +48,6 @@ module.exports = { isSearchAction: isSearchAction, searchMiddleware: searchMiddleware, requestOptionsMiddleware: requestOptionsMiddleware, + isTrigger: isTrigger, + triggerMiddleware: triggerMiddleware, } diff --git a/samples/client/petstore/zapier/index.js b/samples/client/petstore/zapier/index.js index 8f60b0c7b1e6..2e98dba0e32c 100644 --- a/samples/client/petstore/zapier/index.js +++ b/samples/client/petstore/zapier/index.js @@ -1,5 +1,5 @@ const authentication = require('./authentication'); -const { searchActions, createActions } = require('./operations/actions'); +const { searchActions, createActions, triggers } = require('./operations/actions'); module.exports = { version: require('./package.json').version, @@ -7,4 +7,5 @@ module.exports = { authentication: authentication, searches: searchActions(), creates: createActions(), + triggers: triggers(), }; diff --git a/samples/client/petstore/zapier/operations/actions.js b/samples/client/petstore/zapier/operations/actions.js index d9a6a9afbbab..6e9b6d9478e7 100644 --- a/samples/client/petstore/zapier/operations/actions.js +++ b/samples/client/petstore/zapier/operations/actions.js @@ -1,7 +1,7 @@ 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 = { [PetApi.addPet.key]: PetApi.addPet, @@ -29,4 +29,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, {}), -} \ No newline at end of file + triggers: () => Object.entries(actions).reduce((actions, [key, value]) => isTrigger(key) ? {...actions, [key]: triggerMiddleware(value)} : actions, {}), +} diff --git a/samples/client/petstore/zapier/utils/utils.js b/samples/client/petstore/zapier/utils/utils.js index b00174f3f7b0..07c4915aaae3 100644 --- a/samples/client/petstore/zapier/utils/utils.js +++ b/samples/client/petstore/zapier/utils/utils.js @@ -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, @@ -39,4 +48,6 @@ module.exports = { isSearchAction: isSearchAction, searchMiddleware: searchMiddleware, requestOptionsMiddleware: requestOptionsMiddleware, + isTrigger: isTrigger, + triggerMiddleware: triggerMiddleware, }