Skip to content

Commit 78efb9b

Browse files
committed
add generating array example based on items
1 parent d9480be commit 78efb9b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

forward_engineering/helpers/typeHelper.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function getTypeProps(data, key, isParentActivated) {
3636
nullable: data.nullable,
3737
discriminator: data.discriminator,
3838
readOnly: data.readOnly,
39-
example: parseExample(data.sample),
39+
example: parseExample(data.sample) || getArrayItemsExample(items),
4040
xml: getXml(data.xml)
4141
};
4242
const arrayChoices = getChoices(data, key);
@@ -219,6 +219,22 @@ function addIfTrue(data, propertyName, value) {
219219
});
220220
}
221221

222+
function getArrayItemsExample(items) {
223+
const supportedDataTypes = ['object', 'string', 'number', 'integer', 'boolean'];
224+
if (Array.isArray(items) && items.length > 1) {
225+
const itemsExample = items.filter(item => item.isActivated !== false).reduce((acc, item) => {
226+
if (supportedDataTypes.includes(item.type) && item.sample) {
227+
const example = item.type === 'object' ? parseExample(item.sample) : item.sample;
228+
return acc.concat(example);
229+
}
230+
return acc;
231+
}, []);
232+
if (itemsExample.length > 1) {
233+
return itemsExample;
234+
}
235+
}
236+
}
237+
222238
module.exports = {
223239
getType,
224240
getRef,

0 commit comments

Comments
 (0)