Emanuele Saccomandi 9baf4988f3
Zapier generator (#15997)
* First version of Zapier Generator

* fixed zapier codegen

* added zapier templates

* added zapier sample

* added zapier doc

* added zapier generator form data management

* added samples generation

* updated docs

* fixed zapier api template

* fixed zapier samples export

* added zapier readme template

* fixed zapier readme template

* added petstore readme

* cleaned zapier generator

* updated samples

* fixed zapier enum label

* cleaned code

* updated samples

* improved zapier search actions

* updated samples

---------

Co-authored-by: Mauro Valota <maurovalota@fattureincloud.it>
Co-authored-by: William Cheng <wing328hk@gmail.com>
2023-07-09 21:52:04 +08:00

55 lines
1.9 KiB
JavaScript

const utils = require('../utils/utils');
const Category = require('../models/Category');
const Tag = require('../models/Tag');
module.exports = {
fields: (prefix = '', isInput = true, isArrayChild = false) => {
const {keyPrefix, labelPrefix} = utils.buildKeyAndLabel(prefix, isInput, isArrayChild)
return [
{
key: `${keyPrefix}id`,
label: `[${labelPrefix}id]`,
type: 'number',
},
...Category.fields(`${keyPrefix}category`, isInput),
{
key: `${keyPrefix}name`,
label: `[${labelPrefix}name]`,
type: 'string',
},
{
key: `${keyPrefix}photoUrls`,
label: `[${labelPrefix}photoUrls]`,
list: true,
type: 'string',
},
{
key: `${keyPrefix}tags`,
label: `[${labelPrefix}tags]`,
children: Tag.fields(`${keyPrefix}tags${!isInput ? '[]' : ''}`, isInput, true),
},
{
key: `${keyPrefix}status`,
label: `pet status in the store - [${labelPrefix}status]`,
type: 'string',
choices: [
'available',
'pending',
'sold',
],
},
]
},
mapping: (bundle, prefix = '') => {
const {keyPrefix} = utils.buildKeyAndLabel(prefix)
return {
'id': bundle.inputData?.[`${keyPrefix}id`],
'category': utils.removeIfEmpty(Category.mapping(bundle, `${keyPrefix}category`)),
'name': bundle.inputData?.[`${keyPrefix}name`],
'photoUrls': bundle.inputData?.[`${keyPrefix}photoUrls`],
'tags': utils.removeKeyPrefixes(bundle.inputData?.[`${keyPrefix}tags`]),
'status': bundle.inputData?.[`${keyPrefix}status`],
}
},
}