Skip to content
Merged
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
17 changes: 11 additions & 6 deletions lib/renderer-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,16 @@ Handlebars.registerHelper("refToLink", function (ref, label) {
return refToLink(ref, label);
});

const attributeRow = (name, property) => {
const attributeRow = (name, property, parentKey) => {
let href = "";
if (typeof parentKey === "string") {
href = parentKey.toLowerCase();
}
href += name.toLowerCase();
let html =
"<tr>" +
'<td colspan="2"><a href="#' +
name.toLowerCase() +
href +
'">' +
name +
"</a></td>" +
Expand Down Expand Up @@ -164,7 +169,7 @@ const oneOfArrayRow = (oneOf) => {
return html;
};

const attributesTable = (schema) => {
const attributesTable = (schema, parentKey) => {
let properties = schema.properties;
let html =
"<table>" +
Expand All @@ -176,7 +181,7 @@ const attributesTable = (schema) => {
if (property && property.oneOf != undefined) {
html += oneOfRow(key, property.oneOf);
} else {
html += attributeRow(key, property);
html += attributeRow(key, property, parentKey);
}
}

Expand All @@ -190,8 +195,8 @@ const attributesTable = (schema) => {
return html;
};

Handlebars.registerHelper("attributesTable", function (schema) {
return new Handlebars.SafeString(attributesTable(schema));
Handlebars.registerHelper("attributesTable", function (schema, parentKey) {
return new Handlebars.SafeString(attributesTable(schema, parentKey));
});

Handlebars.registerHelper("propertyTypeRow", function (property) {
Expand Down
11 changes: 9 additions & 2 deletions templates/schema.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{{#if schema.$id}}<p>{{ schema.$id }}</p>{{/if}}


## Attributes
## Properties

{{attributesTable schema }}

Expand Down Expand Up @@ -54,7 +54,14 @@

{{> propertyTable}}

{{#unless (isDefined this.$ref)}}
{{#unless (isDefined parentKey)}}
{{#if this.properties}}
### Properties
{{attributesTable this propertyKey }}
{{/if}}
{{/unless}}

{{#unless (isExternalRef this.$ref)}}
{{#if this.properties}}
{{#each this.properties}}
{{> property parentKey=../propertyKey propertyKey=@key }}
Expand Down
4 changes: 2 additions & 2 deletions tests/renderer-markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ test("renders attributes", async () => {
await rendererMarkdown.setup();
let result = rendererMarkdown.renderSchema(mergedSchema);

result = result.match(/## Attributes(.*\n)*/)[0];
result = result.match(/## Properties(.*\n)*/)[0];

let expectedText =
"## Attributes\n\n" +
"## Properties\n\n" +
'<table><thead><tr><th colspan="2">Name</th><th>Type</th></tr></thead>' +
'<tr><td colspan="2"><a href="#property1">property1</a></td><td>String</td></tr>' +
'<tr><td colspan="2"><a href="#property2">property2</a></td><td>[string, integer]</td></tr>' +
Expand Down