diff --git a/rollup.config.js b/rollup.config.js index d563874c3..955807bcf 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -37,6 +37,7 @@ const handlebarsPlugin = () => ({ escapeComment: true, escapeDescription: true, camelCase: true, + onceInList: true, }, }); return `export default ${templateSpec};`; diff --git a/src/templates/partials/parameters.hbs b/src/templates/partials/parameters.hbs index 57ab5a7d1..22877cfa7 100644 --- a/src/templates/partials/parameters.hbs +++ b/src/templates/partials/parameters.hbs @@ -2,21 +2,25 @@ {{#if @root.useOptions~}} { {{#each parameters}} -{{{name}}}{{#if default}} = {{{default}}}{{/if}}, + {{#onceInList ../parameters name}} + {{{name}}}{{#if default}} = {{{default}}}{{/if}}, + {{/onceInList}} {{/each}} }: { {{#each parameters}} -{{#ifdef description deprecated}} -/** -{{#if description}} - * {{{escapeComment description}}} -{{/if}} -{{#if deprecated}} - * @deprecated -{{/if}} - */ -{{/ifdef}} -{{{name}}}{{>isRequired}}: {{>type}}, + {{#onceInList ../parameters name}} + {{#ifdef description deprecated}} + /** + {{#if description}} + * {{{escapeComment description}}} + {{/if}} + {{#if deprecated}} + * @deprecated + {{/if}} + */ + {{/ifdef}} + {{{name}}}{{>isRequired}}: {{>type}}, + {{/onceInList}} {{/each}} } {{~else}} diff --git a/src/utils/registerHandlebarHelpers.ts b/src/utils/registerHandlebarHelpers.ts index 88f47c19b..e362161e8 100644 --- a/src/utils/registerHandlebarHelpers.ts +++ b/src/utils/registerHandlebarHelpers.ts @@ -4,6 +4,7 @@ import { EOL } from 'os'; import type { Enum } from '../client/interfaces/Enum'; import type { Model } from '../client/interfaces/Model'; +import { OperationParameter } from '../client/interfaces/OperationParameter'; import type { HttpClient } from '../HttpClient'; import { unique } from './unique'; @@ -104,4 +105,17 @@ export const registerHandlebarHelpers = (root: { Handlebars.registerHelper('camelCase', function (value: string): string { return camelCase(value); }); + + Handlebars.registerHelper( + 'onceInList', + function (this: any, list: OperationParameter[], name: string, options: Handlebars.HelperOptions): string { + const firstIndex = list.findIndex(param => param.name === name); + + if (firstIndex === options.data.index || !list.slice(firstIndex + 1).some(param => param.name === name)) { + return options.fn(this); + } else { + return options.inverse(this); + } + } + ); };