Skip to content

Commit bbf9ccd

Browse files
authored
fixed zapier objects array mapping (#16780)
1 parent f180aa0 commit bbf9ccd

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

modules/openapi-generator/src/main/resources/zapier/model.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module.exports = {
8383
const {keyPrefix} = utils.buildKeyAndLabel(prefix)
8484
return {
8585
{{#vars}}
86-
'{{baseName}}': {{#isPrimitiveType}}bundle.inputData?.[`${keyPrefix}{{baseName}}`]{{/isPrimitiveType}}{{^isPrimitiveType}}{{^allowableValues}}{{^isArray}}utils.removeIfEmpty({{complexType}}.mapping(bundle, `${keyPrefix}{{baseName}}`)){{/isArray}}{{#isArray}}utils.removeKeyPrefixes(bundle.inputData?.[`${keyPrefix}{{baseName}}`], `${keyPrefix}{{baseName}}`){{/isArray}}{{/allowableValues}}{{#allowableValues}}bundle.inputData?.[`${keyPrefix}{{baseName}}`]{{/allowableValues}}{{/isPrimitiveType}},
86+
'{{baseName}}': {{#isPrimitiveType}}bundle.inputData?.[`${keyPrefix}{{baseName}}`]{{/isPrimitiveType}}{{^isPrimitiveType}}{{^allowableValues}}{{^isArray}}utils.removeIfEmpty({{complexType}}.mapping(bundle, `${keyPrefix}{{baseName}}`)){{/isArray}}{{#isArray}}{{^isEnumRef}}utils.childMapping(bundle.inputData?.[`${keyPrefix}{{baseName}}`], `${keyPrefix}{{baseName}}`, {{complexType}}){{/isEnumRef}}{{#isEnumRef}}bundle.inputData?.[`${keyPrefix}{{baseName}}`]{{/isEnumRef}}{{/isArray}}{{/allowableValues}}{{#allowableValues}}bundle.inputData?.[`${keyPrefix}{{baseName}}`]{{/allowableValues}}{{/isPrimitiveType}},
8787
{{/vars}}
8888
}
8989
},

modules/openapi-generator/src/main/resources/zapier/utils.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const _ = require('lodash')
22

33
const replacePathParameters = (url) => url.replace(/{([^{}]+)}/g, (keyExpr, key) => `{{bundle.inputData.${key}}}`)
4-
const removeKeyPrefixes = (objectsArray, currentPath) => objectsArray == undefined || typeof objectsArray[0] != 'object' ? objectsArray : objectsArray.map((obj) => Object.keys(obj).reduce((res, key) =>_.set(res, key.replace(`${currentPath}.`, ''), obj[key]), {}))
4+
const childMapping = (objectsArray, prefix, model) => objectsArray.map(object => model.mapping({inputData: object}, prefix))
55
const removeIfEmpty = (obj) => _.isEmpty(JSON.parse(JSON.stringify(obj))) ? undefined : obj
66
const buildKeyAndLabel = (prefix, isInput = true, isArrayChild = false) => {
77
const keyPrefix = !_.isEmpty(prefix) && (!isArrayChild || isInput) ? `${prefix}${isInput ? '.' : '__'}` : prefix
@@ -25,7 +25,7 @@ const searchMiddleware = (action) => {
2525

2626
module.exports = {
2727
replacePathParameters: replacePathParameters,
28-
removeKeyPrefixes: removeKeyPrefixes,
28+
childMapping: childMapping,
2929
removeIfEmpty: removeIfEmpty,
3030
buildKeyAndLabel: buildKeyAndLabel,
3131
hasSearchRequisites: hasSearchRequisites,

samples/client/petstore/zapier/models/Pet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = {
4747
'category': utils.removeIfEmpty(Category.mapping(bundle, `${keyPrefix}category`)),
4848
'name': bundle.inputData?.[`${keyPrefix}name`],
4949
'photoUrls': bundle.inputData?.[`${keyPrefix}photoUrls`],
50-
'tags': utils.removeKeyPrefixes(bundle.inputData?.[`${keyPrefix}tags`], `${keyPrefix}tags`),
50+
'tags': utils.childMapping(bundle.inputData?.[`${keyPrefix}tags`], `${keyPrefix}tags`, Tag),
5151
'status': bundle.inputData?.[`${keyPrefix}status`],
5252
}
5353
},

samples/client/petstore/zapier/utils/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const _ = require('lodash')
22

33
const replacePathParameters = (url) => url.replace(/{([^{}]+)}/g, (keyExpr, key) => `{{bundle.inputData.${key}}}`)
4-
const removeKeyPrefixes = (objectsArray, currentPath) => objectsArray == undefined || typeof objectsArray[0] != 'object' ? objectsArray : objectsArray.map((obj) => Object.keys(obj).reduce((res, key) =>_.set(res, key.replace(`${currentPath}.`, ''), obj[key]), {}))
4+
const childMapping = (objectsArray, prefix, model) => objectsArray.map(object => model.mapping({inputData: object}, prefix))
55
const removeIfEmpty = (obj) => _.isEmpty(JSON.parse(JSON.stringify(obj))) ? undefined : obj
66
const buildKeyAndLabel = (prefix, isInput = true, isArrayChild = false) => {
77
const keyPrefix = !_.isEmpty(prefix) && (!isArrayChild || isInput) ? `${prefix}${isInput ? '.' : '__'}` : prefix
@@ -25,7 +25,7 @@ const searchMiddleware = (action) => {
2525

2626
module.exports = {
2727
replacePathParameters: replacePathParameters,
28-
removeKeyPrefixes: removeKeyPrefixes,
28+
childMapping: childMapping,
2929
removeIfEmpty: removeIfEmpty,
3030
buildKeyAndLabel: buildKeyAndLabel,
3131
hasSearchRequisites: hasSearchRequisites,

0 commit comments

Comments
 (0)