From 93a389cc16f98e5e7149c72c3788968159a74bfe Mon Sep 17 00:00:00 2001 From: anisite Date: Fri, 24 Mar 2023 15:04:09 -0400 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=F0=9F=90=9B=20correct=20handle=20ya?= =?UTF-8?q?ml=20example-format=20for=20default=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Render defaults as yaml when using --example-format yaml ✅ Closes: #246 --- lib/markdownBuilder.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/markdownBuilder.js b/lib/markdownBuilder.js index 33ae4492..a2fca279 100644 --- a/lib/markdownBuilder.js +++ b/lib/markdownBuilder.js @@ -705,7 +705,14 @@ export default function build({ } function makedefault(schema, level = 1) { - if (schema[keyword`default`]) { + if (schema[keyword`default`] && exampleFormat === 'yaml') { + return [ + heading(level + 1, text(i18n`${simpletitle(schema)} Default Value`)), + paragraph(text(i18n`The default value is:`)), + paragraph(code('yaml', yaml.dump(schema[keyword`default`], undefined, 2))), + ]; + } + if (schema[keyword`default`] && exampleFormat === 'json') { return [ heading(level + 1, text(i18n`${simpletitle(schema)} Default Value`)), paragraph(text(i18n`The default value is:`)), From 556e3107e8384d245214e407627f6f9fedb984f9 Mon Sep 17 00:00:00 2001 From: anisite Date: Fri, 24 Mar 2023 16:00:37 -0400 Subject: [PATCH 2/2] test(markdownbuilder.js/makedefault): add a test for new default yaml example-format --- test/fixtures/format/format.schema.json | 7 ++++++- test/markdownBuilder.test.js | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/test/fixtures/format/format.schema.json b/test/fixtures/format/format.schema.json index 941fc656..7887db99 100644 --- a/test/fixtures/format/format.schema.json +++ b/test/fixtures/format/format.schema.json @@ -21,5 +21,10 @@ "format": "Coolness", "value": "Maximum" } - ] + ], + "default": + { + "format": "Coolness", + "value": "Maximum" + } } \ No newline at end of file diff --git a/test/markdownBuilder.test.js b/test/markdownBuilder.test.js index 4fff2381..b6436ad5 100644 --- a/test/markdownBuilder.test.js +++ b/test/markdownBuilder.test.js @@ -167,6 +167,29 @@ value: Maximum }); }); +describe('Testing Markdown Builder: YAML default', () => { + let results; + + before(async () => { + const schemas = await traverseSchemas('format'); + const builder = build({ header: false, exampleFormat: 'yaml' }); + results = builder(schemas); + }); + + it('Format Schema has YAML default', () => { + assertMarkdown(results.format) + .fuzzy`## Properties Default Value + +The default value is: + +\`\`\`yaml +format: Coolness +value: Maximum + +\`\`\``; + }); +}); + describe('Testing Markdown Builder: enums', () => { let results;