Skip to content

Commit 22482f5

Browse files
committed
feat: add index operator for templating arrays
1 parent 841fbec commit 22482f5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/utils/Utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ function replaceTag(match: string, mediaTypeModel: MediaTypeModel): string {
6464
return '{{ INVALID TEMPLATE TAG - operator ENUM is only applicable on an array }}';
6565
}
6666
return obj.join(', ');
67+
} else if (operator === 'FIRST') {
68+
if (!Array.isArray(obj)) {
69+
return '{{ INVALID TEMPLATE TAG - operator FIRST is only applicable on an array }}';
70+
}
71+
return obj[0];
72+
} else if (operator === 'LAST') {
73+
if (!Array.isArray(obj)) {
74+
return '{{ INVALID TEMPLATE TAG - operator LAST is only applicable on an array }}';
75+
}
76+
return obj[obj.length - 1];
6777
}
6878

6979
return `{{ INVALID TEMPLATE TAG - unknown operator ${operator} }}`;

0 commit comments

Comments
 (0)