forked from loafle/openapi-generator-original
zapier: create a search action predicate (#19670)
* feat: implement createAction predicate rather than negating isSearchAction predicate * chore: update samples
This commit is contained in:
parent
849b3e8e17
commit
241f51c56b
@ -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, {}),
|
||||
}
|
||||
|
@ -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}}',
|
||||
},
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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',
|
||||
},
|
||||
|
@ -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',
|
||||
},
|
||||
|
@ -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': '',
|
||||
},
|
||||
|
@ -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, {}),
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user