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}}');
|
const {{classname}} = require('../{{apiPackage}}/{{classname}}');
|
||||||
{{/apis}}
|
{{/apis}}
|
||||||
{{/apiInfo}}
|
{{/apiInfo}}
|
||||||
const { triggerMiddleware, isTrigger, searchMiddleware, hasSearchRequisites, isSearchAction } = require('../utils/utils');
|
const { triggerMiddleware, isTrigger, searchMiddleware, hasSearchRequisites, isSearchAction, isCreateAction } = require('../utils/utils');
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
{{#apiInfo}}
|
{{#apiInfo}}
|
||||||
@ -19,6 +19,6 @@ const actions = {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
searchActions: () => Object.entries(actions).reduce((actions, [key, value]) => isSearchAction(key) && hasSearchRequisites(value) ? {...actions, [key]: searchMiddleware(value)} : actions, {}),
|
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, {}),
|
triggers: () => Object.entries(actions).reduce((actions, [key, value]) => isTrigger(key) ? {...actions, [key]: triggerMiddleware(value)} : actions, {}),
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,6 @@ module.exports = {
|
|||||||
method: '{{httpMethod}}',
|
method: '{{httpMethod}}',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{=<% %>=}}{{bundle.authData.access_token}}<%={{ }}=%>',
|
|
||||||
{{^isMultipart}}'Content-Type': '{{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}',{{/isMultipart}}
|
{{^isMultipart}}'Content-Type': '{{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}',{{/isMultipart}}
|
||||||
'Accept': '{{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}',
|
'Accept': '{{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}',
|
||||||
},
|
},
|
||||||
|
@ -23,6 +23,11 @@ const searchMiddleware = (action) => {
|
|||||||
return 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) => {
|
const requestOptionsMiddleware = (z, bundle, requestOptions) => {
|
||||||
// TODO: modify the request options for all outgoing request to your api
|
// TODO: modify the request options for all outgoing request to your api
|
||||||
// if you are using session authentication without a Bearer token.
|
// if you are using session authentication without a Bearer token.
|
||||||
@ -50,4 +55,5 @@ module.exports = {
|
|||||||
requestOptionsMiddleware: requestOptionsMiddleware,
|
requestOptionsMiddleware: requestOptionsMiddleware,
|
||||||
isTrigger: isTrigger,
|
isTrigger: isTrigger,
|
||||||
triggerMiddleware: triggerMiddleware,
|
triggerMiddleware: triggerMiddleware,
|
||||||
|
isCreateAction: isCreateAction,
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ module.exports = {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': 'application/json, application/xml',
|
'Content-Type': 'application/json, application/xml',
|
||||||
'Accept': 'application/xml, application/json',
|
'Accept': 'application/xml, application/json',
|
||||||
},
|
},
|
||||||
@ -75,7 +74,6 @@ module.exports = {
|
|||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': '',
|
'Content-Type': '',
|
||||||
'Accept': '',
|
'Accept': '',
|
||||||
},
|
},
|
||||||
@ -117,7 +115,6 @@ module.exports = {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': '',
|
'Content-Type': '',
|
||||||
'Accept': 'application/xml, application/json',
|
'Accept': 'application/xml, application/json',
|
||||||
},
|
},
|
||||||
@ -160,7 +157,6 @@ module.exports = {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': '',
|
'Content-Type': '',
|
||||||
'Accept': 'application/xml, application/json',
|
'Accept': 'application/xml, application/json',
|
||||||
},
|
},
|
||||||
@ -205,7 +201,6 @@ module.exports = {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': '',
|
'Content-Type': '',
|
||||||
'Accept': 'application/xml, application/json',
|
'Accept': 'application/xml, application/json',
|
||||||
},
|
},
|
||||||
@ -244,7 +239,6 @@ module.exports = {
|
|||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': 'application/json, application/xml',
|
'Content-Type': 'application/json, application/xml',
|
||||||
'Accept': 'application/xml, application/json',
|
'Accept': 'application/xml, application/json',
|
||||||
},
|
},
|
||||||
@ -298,7 +292,6 @@ module.exports = {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
'Accept': '',
|
'Accept': '',
|
||||||
},
|
},
|
||||||
@ -356,7 +349,6 @@ module.exports = {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
|
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
},
|
},
|
||||||
|
@ -28,7 +28,6 @@ module.exports = {
|
|||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': '',
|
'Content-Type': '',
|
||||||
'Accept': '',
|
'Accept': '',
|
||||||
},
|
},
|
||||||
@ -65,7 +64,6 @@ module.exports = {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': '',
|
'Content-Type': '',
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
},
|
},
|
||||||
@ -109,7 +107,6 @@ module.exports = {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': '',
|
'Content-Type': '',
|
||||||
'Accept': 'application/xml, application/json',
|
'Accept': 'application/xml, application/json',
|
||||||
},
|
},
|
||||||
@ -148,7 +145,6 @@ module.exports = {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/xml, application/json',
|
'Accept': 'application/xml, application/json',
|
||||||
},
|
},
|
||||||
|
@ -23,7 +23,6 @@ module.exports = {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': '',
|
'Accept': '',
|
||||||
},
|
},
|
||||||
@ -66,7 +65,6 @@ module.exports = {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': '',
|
'Accept': '',
|
||||||
},
|
},
|
||||||
@ -109,7 +107,6 @@ module.exports = {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': '',
|
'Accept': '',
|
||||||
},
|
},
|
||||||
@ -153,7 +150,6 @@ module.exports = {
|
|||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': '',
|
'Content-Type': '',
|
||||||
'Accept': '',
|
'Accept': '',
|
||||||
},
|
},
|
||||||
@ -197,7 +193,6 @@ module.exports = {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': '',
|
'Content-Type': '',
|
||||||
'Accept': 'application/xml, application/json',
|
'Accept': 'application/xml, application/json',
|
||||||
},
|
},
|
||||||
@ -246,7 +241,6 @@ module.exports = {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': '',
|
'Content-Type': '',
|
||||||
'Accept': 'application/xml, application/json',
|
'Accept': 'application/xml, application/json',
|
||||||
},
|
},
|
||||||
@ -285,7 +279,6 @@ module.exports = {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': '',
|
'Content-Type': '',
|
||||||
'Accept': '',
|
'Accept': '',
|
||||||
},
|
},
|
||||||
@ -329,7 +322,6 @@ module.exports = {
|
|||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
removeMissingValuesFrom: { params: true, body: true },
|
removeMissingValuesFrom: { params: true, body: true },
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer {{bundle.authData.access_token}}',
|
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': '',
|
'Accept': '',
|
||||||
},
|
},
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
const PetApi = require('../apis/PetApi');
|
const PetApi = require('../apis/PetApi');
|
||||||
const StoreApi = require('../apis/StoreApi');
|
const StoreApi = require('../apis/StoreApi');
|
||||||
const UserApi = require('../apis/UserApi');
|
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 = {
|
const actions = {
|
||||||
[PetApi.addPet.key]: PetApi.addPet,
|
[PetApi.addPet.key]: PetApi.addPet,
|
||||||
@ -28,6 +28,6 @@ const actions = {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
searchActions: () => Object.entries(actions).reduce((actions, [key, value]) => isSearchAction(key) && hasSearchRequisites(value) ? {...actions, [key]: searchMiddleware(value)} : actions, {}),
|
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, {}),
|
triggers: () => Object.entries(actions).reduce((actions, [key, value]) => isTrigger(key) ? {...actions, [key]: triggerMiddleware(value)} : actions, {}),
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,11 @@ const searchMiddleware = (action) => {
|
|||||||
return 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) => {
|
const requestOptionsMiddleware = (z, bundle, requestOptions) => {
|
||||||
// TODO: modify the request options for all outgoing request to your api
|
// TODO: modify the request options for all outgoing request to your api
|
||||||
// if you are using session authentication without a Bearer token.
|
// if you are using session authentication without a Bearer token.
|
||||||
@ -50,4 +55,5 @@ module.exports = {
|
|||||||
requestOptionsMiddleware: requestOptionsMiddleware,
|
requestOptionsMiddleware: requestOptionsMiddleware,
|
||||||
isTrigger: isTrigger,
|
isTrigger: isTrigger,
|
||||||
triggerMiddleware: triggerMiddleware,
|
triggerMiddleware: triggerMiddleware,
|
||||||
|
isCreateAction: isCreateAction,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user