Skip to content
Merged
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,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}}
Expand All @@ -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, {}),
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}}',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -50,4 +55,5 @@ module.exports = {
requestOptionsMiddleware: requestOptionsMiddleware,
isTrigger: isTrigger,
triggerMiddleware: triggerMiddleware,
isCreateAction: isCreateAction,
}
8 changes: 0 additions & 8 deletions samples/client/petstore/zapier/apis/PetApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down Expand Up @@ -75,7 +74,6 @@ module.exports = {
method: 'DELETE',
removeMissingValuesFrom: { params: true, body: true },
headers: {
'Authorization': 'Bearer {{bundle.authData.access_token}}',
'Content-Type': '',
'Accept': '',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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': '',
},
Expand Down Expand Up @@ -356,7 +349,6 @@ module.exports = {
method: 'POST',
removeMissingValuesFrom: { params: true, body: true },
headers: {
'Authorization': 'Bearer {{bundle.authData.access_token}}',

'Accept': 'application/json',
},
Expand Down
4 changes: 0 additions & 4 deletions samples/client/petstore/zapier/apis/StoreApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports = {
method: 'DELETE',
removeMissingValuesFrom: { params: true, body: true },
headers: {
'Authorization': 'Bearer {{bundle.authData.access_token}}',
'Content-Type': '',
'Accept': '',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
},
Expand Down
8 changes: 0 additions & 8 deletions samples/client/petstore/zapier/apis/UserApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': '',
},
Expand Down Expand Up @@ -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': '',
},
Expand Down Expand Up @@ -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': '',
},
Expand Down Expand Up @@ -153,7 +150,6 @@ module.exports = {
method: 'DELETE',
removeMissingValuesFrom: { params: true, body: true },
headers: {
'Authorization': 'Bearer {{bundle.authData.access_token}}',
'Content-Type': '',
'Accept': '',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -285,7 +279,6 @@ module.exports = {
method: 'GET',
removeMissingValuesFrom: { params: true, body: true },
headers: {
'Authorization': 'Bearer {{bundle.authData.access_token}}',
'Content-Type': '',
'Accept': '',
},
Expand Down Expand Up @@ -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': '',
},
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/zapier/operations/actions.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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, {}),
}
6 changes: 6 additions & 0 deletions samples/client/petstore/zapier/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -50,4 +55,5 @@ module.exports = {
requestOptionsMiddleware: requestOptionsMiddleware,
isTrigger: isTrigger,
triggerMiddleware: triggerMiddleware,
isCreateAction: isCreateAction,
}