Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

options to add more details in summary table / skip generation of detailed information #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions bin/wetzel.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ if (!defined(argv._[0]) || defined(argv.h) || defined(argv.help)) {
' -d, --debug Provide a path, and this will save out intermediate processing\n' +
' artifacts useful in debugging wetzel.\n' +
' -w, --suppressWarnings Will not print out WETZEL_WARNING strings indicating identified\n' +
' conversion problems. Default: false\n';
' conversion problems. Default: false\n' +
' --describeEnums List enum values in the description column of 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;
}
Expand Down Expand Up @@ -80,7 +82,9 @@ var options = {
debug: defaultValue(defaultValue(argv.d, argv.debug), null),
suppressWarnings: defaultValue(defaultValue(argv.w, argv.suppressWarnings), false),
autoLink: autoLink,
ignorableTypes: ignorableTypes
ignorableTypes: ignorableTypes,
describeEnums: defaultValue(argv.describeEnums, false),
summaryOnly: defaultValue(argv.summary, false)
};

if (defined(embedOutput)) {
Expand Down
50 changes: 36 additions & 14 deletions lib/generateMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ function generateMarkdown(options) {
options.schemaRelativeBasePath,
orderedTypesDescending,
options.autoLink,
options.embedMode);
options.embedMode,
options.summaryOnly,
options.describeEnums);
}

return md;
Expand Down Expand Up @@ -154,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) {
function getSchemaMarkdown(schema, fileName, headerLevel, suppressWarnings, schemaRelativeBasePath, knownTypes, autoLink, embedMode, summaryOnly, describeEnums) {
var md = '';

if (schema === undefined) {
Expand Down Expand Up @@ -197,14 +199,17 @@ function getSchemaMarkdown(schema, fileName, headerLevel, suppressWarnings, sche
// Render each property if the type is object
if (schemaType === 'object') {
// Render table with summary of each property
md += createPropertiesSummary(schema, knownTypes, autoLink);
md += createPropertiesSummary(schema, knownTypes, autoLink, describeEnums);

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
Expand All @@ -218,17 +223,20 @@ 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;
}

////////////////////////////////////////////////////////////////////////////////

function createPropertiesSummary(schema, knownTypes, autoLink) {
function createPropertiesSummary(schema, knownTypes, autoLink, describeEnums) {
var md = '';

if (schema.properties !== undefined && Object.keys(schema.properties).length > 0) {
Expand All @@ -239,11 +247,25 @@ function createPropertiesSummary(schema, knownTypes, autoLink) {
if (properties.hasOwnProperty(name)) {
var property = properties[name];
var summary = getPropertySummary(property, knownTypes, autoLink);
var description = defaultValue(summary.description, '')

if (describeEnums) {
var enumString = getEnumString(property, summary.type, 1);
if (defined(enumString)) {
enumString = '**Allowed values** : ' + enumString.replace(/(?:\r\n|\r|\n|\*)/g, ' ');

if (description != ''){
description = description + "<br>"
}

description = description + enumString;
}
}

md += style.addTableRow([
style.propertyNameSummary(name),
summary.formattedType,
defaultValue(summary.description, ''),
description,
(summary.required === 'Yes' ? style.requiredIcon : '') + summary.required
]);
}
Expand Down