From 7f292892e841d599e167fae3936804bf0212df91 Mon Sep 17 00:00:00 2001 From: Colin Eberhardt Date: Wed, 4 Jan 2023 15:26:59 +0000 Subject: [PATCH] feat: minor jsdoc tweaks --- helpers/docComment.js | 5 +++++ partials/model.handlebars | 14 +++++++------- template/api.ts.handlebars | 30 ++++++++++++++++++------------ template/model.ts.handlebars | 2 ++ 4 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 helpers/docComment.js diff --git a/helpers/docComment.js b/helpers/docComment.js new file mode 100644 index 0000000..ffce6a6 --- /dev/null +++ b/helpers/docComment.js @@ -0,0 +1,5 @@ +const indent = (text) => + // add a star before each newline and the start of the string + text.replace(/^/gm, " * "); + +module.exports = indent; diff --git a/partials/model.handlebars b/partials/model.handlebars index e5ffe38..969ce6a 100644 --- a/partials/model.handlebars +++ b/partials/model.handlebars @@ -1,8 +1,11 @@ -{{#if description}} /** - * {{description}} + * {{@key}} + {{#if description}}* {{description}}{{/if~}} + * + {{#each properties}} + * @param { {{~typeConvert this~}} } {{#if _required}}{{@key}}{{else}}[{{@key}}]{{/if}} {{#if description}} - {{description}}{{/if}} + {{/each}} */ -{{/if}} export class {{@key}} { static propertyTypes: Array<{name: string, type: string}> = [ @@ -15,9 +18,6 @@ export class {{@key}} { ]; {{#each properties}} - {{#if description}} - // {{description}} - {{/if}} public {{@key}}{{#unless _required}}?{{/unless}}: {{typeConvert this}}; {{/each}} -} \ No newline at end of file +} diff --git a/template/api.ts.handlebars b/template/api.ts.handlebars index 744ee05..65dc4b4 100644 --- a/template/api.ts.handlebars +++ b/template/api.ts.handlebars @@ -5,14 +5,12 @@ import { request } from "./request"; import { Parameter, ParameterBuilder } from "./parameterBuilder"; import { deserialize, serialize } from "./serializer"; -/* -{{_info.title}} -{{info.description}} -Version: {{info.version}} -*/ - -{{#if _tag.description}}// {{_tag.description}}{{/if}} - +/** + * {{_info.title}} + * +{{#if info.description}}{{docComment info.description}}{{/if}} +{{#if info.version}} * @version {{info.version}}{{/if}} + */ export default class Api{{_tag.name}} { private config: Configuration; @@ -25,12 +23,20 @@ export default class Api{{_tag.name}} { {{#each this}} {{#ifEquals ../../_tag.name _tag.name}} - {{#if summary}}// {{summary}}{{/if}} - {{#if description}}// {{description}}{{/if}} - {{#if tags}}// tags: {{tags}}{{/if}} + /** + {{#if summary}} + * {{summary}} + * + {{/if}} + {{#if description}} + * {{description}} + * + {{/if}} + {{#if tags}} * @tags {{tags}}{{/if}} {{#each _sortedParameters}} - // @param {{name}} {{description}} + * @param { {{~typeConvert schema ../../../_options~}} } {{name}} {{description}} {{/each}} + */ async {{operationId}}( {{#each _sortedParameters}} {{name}}{{#if _optional}}?{{/if}}: diff --git a/template/model.ts.handlebars b/template/model.ts.handlebars index ede701f..53f9bd1 100644 --- a/template/model.ts.handlebars +++ b/template/model.ts.handlebars @@ -1,9 +1,11 @@ {{#each components.schemas}} {{> model}} + {{/each}} {{#each components.inlineObjects}} {{> model}} + {{/each}} export const models: string[] = [