diff --git a/rollup.config.js b/rollup.config.js index 6333316d..60545d7c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -32,6 +32,7 @@ const handlebarsPlugin = () => ({ preventIndent: true, knownHelpersOnly: true, knownHelpers: { + escapeQuotes: true, equals: true, notEquals: true, containsSpaces: true, diff --git a/src/templates/partials/schemaComposition.hbs b/src/templates/partials/schemaComposition.hbs index 32c5a647..005ea046 100644 --- a/src/templates/partials/schemaComposition.hbs +++ b/src/templates/partials/schemaComposition.hbs @@ -1,5 +1,8 @@ { type: '{{export}}', +{{#if description}} + description: '{{{escapeQuotes description}}}', +{{/if}} contains: [{{#each properties}}{{>schema}}{{#unless @last}}, {{/unless}}{{/each}}], {{#if isReadOnly}} isReadOnly: {{{isReadOnly}}}, diff --git a/src/templates/partials/schemaGeneric.hbs b/src/templates/partials/schemaGeneric.hbs index 7b0d96c9..d41956a8 100644 --- a/src/templates/partials/schemaGeneric.hbs +++ b/src/templates/partials/schemaGeneric.hbs @@ -2,6 +2,9 @@ {{#if type}} type: '{{{base}}}', {{/if}} +{{#if description}} + description: '{{{escapeQuotes description}}}', +{{/if}} {{#if isReadOnly}} isReadOnly: {{{isReadOnly}}}, {{/if}} diff --git a/src/templates/partials/schemaInterface.hbs b/src/templates/partials/schemaInterface.hbs index 88460880..0488adae 100644 --- a/src/templates/partials/schemaInterface.hbs +++ b/src/templates/partials/schemaInterface.hbs @@ -1,4 +1,7 @@ { +{{#if description}} + description: '{{{escapeQuotes description}}}', +{{/if}} properties: { {{#if properties}} {{#each properties}} diff --git a/src/utils/registerHandlebarHelpers.ts b/src/utils/registerHandlebarHelpers.ts index a937d1cf..99c5dca2 100644 --- a/src/utils/registerHandlebarHelpers.ts +++ b/src/utils/registerHandlebarHelpers.ts @@ -10,6 +10,10 @@ export function registerHandlebarHelpers(root: { useOptions: boolean; useUnionTypes: boolean; }): void { + Handlebars.registerHelper('escapeQuotes', function (value: string): string { + return value.replace(/(['"])/g, '\\$1'); + }); + Handlebars.registerHelper( 'equals', function (this: any, a: string, b: string, options: Handlebars.HelperOptions): string {