From e5b425267e18c355d0d3c946fbb2896353ecf923 Mon Sep 17 00:00:00 2001 From: "Stephen (Alex) Wallen" Date: Tue, 24 Sep 2024 17:36:27 -0700 Subject: [PATCH 1/2] feat: implement createAction predicate rather than negating isSearchAction predicate --- .../src/main/resources/zapier/actions.mustache | 4 ++-- .../src/main/resources/zapier/api.mustache | 1 - .../src/main/resources/zapier/utils.mustache | 6 ++++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/zapier/actions.mustache b/modules/openapi-generator/src/main/resources/zapier/actions.mustache index 4d596866ac95..294493c12427 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 1c512e665c98..7b49251f5609 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 07c4915aaae3..7690a1cda1ea 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, } From f7cc3c8c73b63dd8434c8309692278e58feea76f Mon Sep 17 00:00:00 2001 From: "Stephen (Alex) Wallen" Date: Wed, 25 Sep 2024 19:46:03 -0700 Subject: [PATCH 2/2] chore: update samples --- 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 ++++++ 5 files changed, 8 insertions(+), 22 deletions(-) diff --git a/samples/client/petstore/zapier/apis/PetApi.js b/samples/client/petstore/zapier/apis/PetApi.js index 98b42df84caa..88c4c34898a3 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 ead3f914108c..bb5d80be83bf 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 ed64420abf37..8138b724a504 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 6e9b6d9478e7..c0bac3a264ed 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 07c4915aaae3..7690a1cda1ea 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, }