From 241f51c56b8a51f53a82b28a961593a57d757091 Mon Sep 17 00:00:00 2001 From: Alex Wallen Date: Mon, 30 Sep 2024 20:34:09 -0700 Subject: [PATCH] zapier: create a search action predicate (#19670) * feat: implement createAction predicate rather than negating isSearchAction predicate * chore: update samples --- .../src/main/resources/zapier/actions.mustache | 4 ++-- .../src/main/resources/zapier/api.mustache | 1 - .../src/main/resources/zapier/utils.mustache | 6 ++++++ samples/client/petstore/zapier/apis/PetApi.js | 8 -------- samples/client/petstore/zapier/apis/StoreApi.js | 4 ---- samples/client/petstore/zapier/apis/UserApi.js | 8 -------- samples/client/petstore/zapier/operations/actions.js | 4 ++-- samples/client/petstore/zapier/utils/utils.js | 6 ++++++ 8 files changed, 16 insertions(+), 25 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/zapier/actions.mustache b/modules/openapi-generator/src/main/resources/zapier/actions.mustache index 4d596866ac9..294493c1242 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 { triggerMiddleware, isTrigger, searchMiddleware, hasSearchRequisites, isSearchAction } = require('../utils/utils'); +const { triggerMiddleware, isTrigger, searchMiddleware, hasSearchRequisites, isSearchAction, isCreateAction } = require('../utils/utils'); const actions = { {{#apiInfo}} @@ -19,6 +19,6 @@ 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, {}), + createActions: () => Object.entries(actions).reduce((actions, [key, value]) => isCreateAction(key) ? {...actions, [key]: value} : actions, {}), 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/api.mustache b/modules/openapi-generator/src/main/resources/zapier/api.mustache index 1c512e665c9..7b49251f560 100644 --- a/modules/openapi-generator/src/main/resources/zapier/api.mustache +++ b/modules/openapi-generator/src/main/resources/zapier/api.mustache @@ -84,7 +84,6 @@ module.exports = { method: '{{httpMethod}}', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{=<% %>=}}{{bundle.authData.access_token}}<%={{ }}=%>', {{^isMultipart}}'Content-Type': '{{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}',{{/isMultipart}} 'Accept': '{{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}', }, diff --git a/modules/openapi-generator/src/main/resources/zapier/utils.mustache b/modules/openapi-generator/src/main/resources/zapier/utils.mustache index 07c4915aaae..7690a1cda1e 100644 --- a/modules/openapi-generator/src/main/resources/zapier/utils.mustache +++ b/modules/openapi-generator/src/main/resources/zapier/utils.mustache @@ -23,6 +23,11 @@ const searchMiddleware = (action) => { return action } +const isCreateAction = (key) => { + // TODO: return true if the key is a "create" action for your API + return !isSearchAction(key); +} + const requestOptionsMiddleware = (z, bundle, requestOptions) => { // TODO: modify the request options for all outgoing request to your api // if you are using session authentication without a Bearer token. @@ -50,4 +55,5 @@ module.exports = { requestOptionsMiddleware: requestOptionsMiddleware, isTrigger: isTrigger, triggerMiddleware: triggerMiddleware, + isCreateAction: isCreateAction, } diff --git a/samples/client/petstore/zapier/apis/PetApi.js b/samples/client/petstore/zapier/apis/PetApi.js index 98b42df84ca..88c4c34898a 100644 --- a/samples/client/petstore/zapier/apis/PetApi.js +++ b/samples/client/petstore/zapier/apis/PetApi.js @@ -26,7 +26,6 @@ module.exports = { method: 'POST', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': 'application/json, application/xml', 'Accept': 'application/xml, application/json', }, @@ -75,7 +74,6 @@ module.exports = { method: 'DELETE', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': '', 'Accept': '', }, @@ -117,7 +115,6 @@ module.exports = { method: 'GET', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': '', 'Accept': 'application/xml, application/json', }, @@ -160,7 +157,6 @@ module.exports = { method: 'GET', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': '', 'Accept': 'application/xml, application/json', }, @@ -205,7 +201,6 @@ module.exports = { method: 'GET', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': '', 'Accept': 'application/xml, application/json', }, @@ -244,7 +239,6 @@ module.exports = { method: 'PUT', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': 'application/json, application/xml', 'Accept': 'application/xml, application/json', }, @@ -298,7 +292,6 @@ module.exports = { method: 'POST', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': 'application/x-www-form-urlencoded', 'Accept': '', }, @@ -356,7 +349,6 @@ module.exports = { method: 'POST', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Accept': 'application/json', }, diff --git a/samples/client/petstore/zapier/apis/StoreApi.js b/samples/client/petstore/zapier/apis/StoreApi.js index ead3f914108..bb5d80be83b 100644 --- a/samples/client/petstore/zapier/apis/StoreApi.js +++ b/samples/client/petstore/zapier/apis/StoreApi.js @@ -28,7 +28,6 @@ module.exports = { method: 'DELETE', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': '', 'Accept': '', }, @@ -65,7 +64,6 @@ module.exports = { method: 'GET', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': '', 'Accept': 'application/json', }, @@ -109,7 +107,6 @@ module.exports = { method: 'GET', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': '', 'Accept': 'application/xml, application/json', }, @@ -148,7 +145,6 @@ module.exports = { method: 'POST', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': 'application/json', 'Accept': 'application/xml, application/json', }, diff --git a/samples/client/petstore/zapier/apis/UserApi.js b/samples/client/petstore/zapier/apis/UserApi.js index ed64420abf3..8138b724a50 100644 --- a/samples/client/petstore/zapier/apis/UserApi.js +++ b/samples/client/petstore/zapier/apis/UserApi.js @@ -23,7 +23,6 @@ module.exports = { method: 'POST', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': 'application/json', 'Accept': '', }, @@ -66,7 +65,6 @@ module.exports = { method: 'POST', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': 'application/json', 'Accept': '', }, @@ -109,7 +107,6 @@ module.exports = { method: 'POST', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': 'application/json', 'Accept': '', }, @@ -153,7 +150,6 @@ module.exports = { method: 'DELETE', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': '', 'Accept': '', }, @@ -197,7 +193,6 @@ module.exports = { method: 'GET', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': '', 'Accept': 'application/xml, application/json', }, @@ -246,7 +241,6 @@ module.exports = { method: 'GET', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': '', 'Accept': 'application/xml, application/json', }, @@ -285,7 +279,6 @@ module.exports = { method: 'GET', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': '', 'Accept': '', }, @@ -329,7 +322,6 @@ module.exports = { method: 'PUT', removeMissingValuesFrom: { params: true, body: true }, headers: { - 'Authorization': 'Bearer {{bundle.authData.access_token}}', 'Content-Type': 'application/json', 'Accept': '', }, diff --git a/samples/client/petstore/zapier/operations/actions.js b/samples/client/petstore/zapier/operations/actions.js index 6e9b6d9478e..c0bac3a264e 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 { triggerMiddleware, isTrigger, searchMiddleware, hasSearchRequisites, isSearchAction } = require('../utils/utils'); +const { triggerMiddleware, isTrigger, searchMiddleware, hasSearchRequisites, isSearchAction, isCreateAction } = require('../utils/utils'); const actions = { [PetApi.addPet.key]: PetApi.addPet, @@ -28,6 +28,6 @@ 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, {}), + createActions: () => Object.entries(actions).reduce((actions, [key, value]) => isCreateAction(key) ? {...actions, [key]: value} : actions, {}), 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 07c4915aaae..7690a1cda1e 100644 --- a/samples/client/petstore/zapier/utils/utils.js +++ b/samples/client/petstore/zapier/utils/utils.js @@ -23,6 +23,11 @@ const searchMiddleware = (action) => { return action } +const isCreateAction = (key) => { + // TODO: return true if the key is a "create" action for your API + return !isSearchAction(key); +} + const requestOptionsMiddleware = (z, bundle, requestOptions) => { // TODO: modify the request options for all outgoing request to your api // if you are using session authentication without a Bearer token. @@ -50,4 +55,5 @@ module.exports = { requestOptionsMiddleware: requestOptionsMiddleware, isTrigger: isTrigger, triggerMiddleware: triggerMiddleware, + isCreateAction: isCreateAction, }