From 80bc43b571b2ac39a01b43da365fa86c3f026ffd Mon Sep 17 00:00:00 2001 From: Gregoire Krahenbuhl Date: Fri, 25 Mar 2022 16:53:33 +0100 Subject: [PATCH] add option to generate summary only --- bin/wetzel.js | 6 ++++-- lib/generateMarkdown.js | 27 +++++++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/bin/wetzel.js b/bin/wetzel.js index 9662813..1867ada 100755 --- a/bin/wetzel.js +++ b/bin/wetzel.js @@ -27,7 +27,8 @@ if (!defined(argv._[0]) || defined(argv.h) || defined(argv.help)) { ' artifacts useful in debugging wetzel.\n' + ' -w, --suppressWarnings Will not print out WETZEL_WARNING strings indicating identified\n' + ' conversion problems. Default: false\n' + - ' -z, --detailedSummary Adds more details in the summary table. Default: false\n' + ' --detailedSummary Adds more details in the summary table. Default: false\n' + + ' --summary Only write the summary and skip the detailed section, useful for a more concise documentation. Default: false\n' process.stdout.write(help); return; } @@ -82,7 +83,8 @@ var options = { suppressWarnings: defaultValue(defaultValue(argv.w, argv.suppressWarnings), false), autoLink: autoLink, ignorableTypes: ignorableTypes, - detailedSummary: defaultValue(defaultValue(argv.z, argv.detailedSummary), false), + detailedSummary: defaultValue(argv.detailedSummary, false), + summaryOnly: defaultValue(argv.summary, false) }; if (defined(embedOutput)) { diff --git a/lib/generateMarkdown.js b/lib/generateMarkdown.js index 7d4bdc9..feb69da 100644 --- a/lib/generateMarkdown.js +++ b/lib/generateMarkdown.js @@ -76,6 +76,7 @@ function generateMarkdown(options) { orderedTypesDescending, options.autoLink, options.embedMode, + options.summaryOnly, options.detailedSummary); } @@ -155,7 +156,7 @@ function getRecursiveTOC(orderedTypes, parentTitle, depth) { * @param {string} embedMode Emum value indicating if we are embedding JSON schema include directives. * @return {string} The markdown for the schema. */ -function getSchemaMarkdown(schema, fileName, headerLevel, suppressWarnings, schemaRelativeBasePath, knownTypes, autoLink, embedMode, detailedSummary) { +function getSchemaMarkdown(schema, fileName, headerLevel, suppressWarnings, schemaRelativeBasePath, knownTypes, autoLink, embedMode, summaryOnly, detailedSummary) { var md = ''; if (schema === undefined) { @@ -200,12 +201,15 @@ function getSchemaMarkdown(schema, fileName, headerLevel, suppressWarnings, sche // Render table with summary of each property md += createPropertiesSummary(schema, knownTypes, autoLink, detailedSummary); - value = schema.additionalProperties; - if (defined(value) && !value) { - md += 'Additional properties are not allowed.\n\n'; - } else { - md += 'Additional properties are allowed.\n\n'; - // TODO: display their schema + if (!summaryOnly) + { + value = schema.additionalProperties; + if (defined(value) && !value) { + md += 'Additional properties are not allowed.\n\n'; + } else { + md += 'Additional properties are allowed.\n\n'; + // TODO: display their schema + } } // Schema reference @@ -219,9 +223,12 @@ function getSchemaMarkdown(schema, fileName, headerLevel, suppressWarnings, sche } // Render section for each property - var title = defaultValue(schema.title, suppressWarnings ? '' : 'WETZEL_WARNING: title not defined'); - md += createPropertiesDetails(schema, title, headerLevel + 1, knownTypes, autoLink); - md += createExamples(schema, headerLevel); + if (!summaryOnly) + { + var title = defaultValue(schema.title, suppressWarnings ? '' : 'WETZEL_WARNING: title not defined'); + md += createPropertiesDetails(schema, title, headerLevel + 1, knownTypes, autoLink); + md += createExamples(schema, headerLevel); + } } return md;