diff --git a/gh-pages/_includes/examples-table.md b/gh-pages/_includes/examples-table.md
index 9e7f5d5..96a2591 100644
--- a/gh-pages/_includes/examples-table.md
+++ b/gh-pages/_includes/examples-table.md
@@ -5,6 +5,7 @@
| [Name](/json-schema-static-docs/examples/name.html) | [name.yml](/json-schema-static-docs/yml/name.yml) |
| [Enum Value Documentation](/json-schema-static-docs/examples/enums.html) | [enums.yml](/json-schema-static-docs/yml/enums.yml) |
| [One-of](/json-schema-static-docs/examples/oneof.html) | [oneof.yml](/json-schema-static-docs/yml/oneof.yml) |
+| [Root level property](/json-schema-static-docs/examples/root-level-property.html) | [root-level-property.yml](/json-schema-static-docs/yml/root-level-property.yml) |
| [Draft 2019-09 - Array](/json-schema-static-docs/examples/draft-2019-09/array.html) | [draft-2019-09/array.yml](/json-schema-static-docs/yml/draft-2019-09/array.yml) |
| [Draft 2019-09 - Deprecated](/json-schema-static-docs/examples/draft-2019-09/deprecated.html) | [draft-2019-09/deprecated.yml](/json-schema-static-docs/yml/draft-2019-09/deprecated.yml) |
| [Draft 07 - User](/json-schema-static-docs/examples/draft-07/user.html) | [draft-07/user.yml](/json-schema-static-docs/yml/draft-07/user.yml) |
diff --git a/gh-pages/examples/draft-06/animal.md b/gh-pages/examples/draft-06/animal.md
index 027d51a..53340fa 100644
--- a/gh-pages/examples/draft-06/animal.md
+++ b/gh-pages/examples/draft-06/animal.md
@@ -18,7 +18,7 @@ description: A schema demonstrating some draft 06 features
## Properties
-
+
## Example
@@ -39,11 +39,10 @@ description: A schema demonstrating some draft 06 features
-
## animalType
-
+
Title |
@@ -61,12 +60,10 @@ description: A schema demonstrating some draft 06 features
-
-
## canFly
-
+
Title |
@@ -89,7 +86,6 @@ description: A schema demonstrating some draft 06 features
-
## Schema
diff --git a/gh-pages/examples/draft-07/user.md b/gh-pages/examples/draft-07/user.md
index 937e7ee..ef28fa4 100644
--- a/gh-pages/examples/draft-07/user.md
+++ b/gh-pages/examples/draft-07/user.md
@@ -18,7 +18,7 @@ description: A schema demonstrating some draft 07 features
## Properties
-
+
## Example
@@ -32,11 +32,10 @@ description: A schema demonstrating some draft 07 features
-
## username
-
+
Title |
@@ -65,12 +64,10 @@ description: A schema demonstrating some draft 07 features
-
-
## password
-
+
Title |
@@ -101,7 +98,6 @@ description: A schema demonstrating some draft 07 features
-
## Schema
diff --git a/gh-pages/examples/draft-2019-09/array.md b/gh-pages/examples/draft-2019-09/array.md
index 502a194..35d63a3 100644
--- a/gh-pages/examples/draft-2019-09/array.md
+++ b/gh-pages/examples/draft-2019-09/array.md
@@ -18,7 +18,7 @@ description: A schema describing fruits and vegetables
## Properties
-
+
## Example
@@ -43,11 +43,10 @@ description: A schema describing fruits and vegetables
-
## fruits
-
+
Title |
@@ -72,12 +71,10 @@ description: A schema describing fruits and vegetables
-
-
## vegetables
-
+
Title |
@@ -101,7 +98,7 @@ description: A schema describing fruits and vegetables
### vegetables.name
-
+
Title |
@@ -122,7 +119,7 @@ description: A schema describing fruits and vegetables
### vegetables.hasARoundShape
-
+
Title |
@@ -146,7 +143,6 @@ description: A schema describing fruits and vegetables
-
## Schema
diff --git a/gh-pages/examples/draft-2019-09/deprecated.md b/gh-pages/examples/draft-2019-09/deprecated.md
index 54068ac..ae85731 100644
--- a/gh-pages/examples/draft-2019-09/deprecated.md
+++ b/gh-pages/examples/draft-2019-09/deprecated.md
@@ -18,7 +18,7 @@ description: A schema demonstrating use of deprecated
## Properties
-
+
## Example
@@ -32,11 +32,10 @@ description: A schema demonstrating use of deprecated
-
## firstName
-
+
Title |
@@ -58,12 +57,10 @@ description: A schema demonstrating use of deprecated
-
-
## lastName
-
+
Deprecated |
@@ -94,7 +91,6 @@ description: A schema demonstrating use of deprecated
-
## Schema
diff --git a/gh-pages/examples/enums.md b/gh-pages/examples/enums.md
index 7e7ae31..f245033 100644
--- a/gh-pages/examples/enums.md
+++ b/gh-pages/examples/enums.md
@@ -18,7 +18,7 @@ description: JSON schema example demonstrating documentation of enum values usin
## Properties
-
+
## Example
@@ -31,11 +31,10 @@ description: JSON schema example demonstrating documentation of enum values usin
-
## status
-
+
Title |
@@ -65,7 +64,6 @@ description: JSON schema example demonstrating documentation of enum values usin
-
## Schema
diff --git a/gh-pages/examples/examples-index.md b/gh-pages/examples/examples-index.md
index bad554f..ad0d848 100644
--- a/gh-pages/examples/examples-index.md
+++ b/gh-pages/examples/examples-index.md
@@ -4,13 +4,14 @@
- [oneof-and-anyof](oneof-and-anyof.md)
- [oneof](oneof.md)
- [person](person.md)
+- [root-level-property](root-level-property.md)
## Draft-06
- [draft-06/animal](draft-06/animal.md)
-## Draft-07
-- [draft-07/user](draft-07/user.md)
-
## Draft-2019-09
- [draft-2019-09/array](draft-2019-09/array.md)
- [draft-2019-09/deprecated](draft-2019-09/deprecated.md)
+
+## Draft-07
+- [draft-07/user](draft-07/user.md)
diff --git a/gh-pages/examples/name.md b/gh-pages/examples/name.md
index c39cab3..3646e6c 100644
--- a/gh-pages/examples/name.md
+++ b/gh-pages/examples/name.md
@@ -18,7 +18,7 @@ description: JSON schema example for a name entity
## Properties
-
+
## Example
@@ -33,11 +33,10 @@ description: JSON schema example for a name entity
-
## title
-
+
Title |
@@ -66,12 +65,10 @@ description: JSON schema example for a name entity
-
-
## firstName
-
+
Title |
@@ -102,12 +99,10 @@ description: JSON schema example for a name entity
-
-
## lastName
-
+
Title |
@@ -143,7 +138,6 @@ description: JSON schema example for a name entity
-
## Schema
diff --git a/gh-pages/examples/oneof.md b/gh-pages/examples/oneof.md
index 042e86a..614c41b 100644
--- a/gh-pages/examples/oneof.md
+++ b/gh-pages/examples/oneof.md
@@ -18,7 +18,7 @@ description: Example schema to demonstrate the use of the oneOf keyword
## Properties
-Name | Type |
---|
justOne | One of: | Object |
---|
Object |
+Name | Type |
---|
justOne | One of: | Object |
---|
Object |
## Example
@@ -42,11 +42,10 @@ description: Example schema to demonstrate the use of the oneOf keyword
-
## justOne
-
+
Title |
@@ -70,7 +69,7 @@ description: Example schema to demonstrate the use of the oneOf keyword
### justOne.0
-
+
Title |
@@ -86,7 +85,7 @@ description: Example schema to demonstrate the use of the oneOf keyword
### justOne.0.propertyA
-
+
Title |
@@ -104,7 +103,7 @@ description: Example schema to demonstrate the use of the oneOf keyword
### justOne.1
-
+
Title |
@@ -120,7 +119,7 @@ description: Example schema to demonstrate the use of the oneOf keyword
### justOne.1.propertyB
-
+
Title |
@@ -137,7 +136,7 @@ description: Example schema to demonstrate the use of the oneOf keyword
### justOne.1.propertyC
-
+
Title |
@@ -158,7 +157,6 @@ description: Example schema to demonstrate the use of the oneOf keyword
-
## Schema
diff --git a/gh-pages/examples/person.md b/gh-pages/examples/person.md
index 1463651..06aa832 100644
--- a/gh-pages/examples/person.md
+++ b/gh-pages/examples/person.md
@@ -18,7 +18,7 @@ description: JSON schema example for a person entity
## Properties
-
+
## Example
@@ -73,12 +73,11 @@ description: JSON schema example for a person entity
-
## name
Defined in ./name.html
-
+
$id |
@@ -102,16 +101,14 @@ description: JSON schema example for a person entity
### Properties
-
-
-
+
## dateOfBirth
-
+
Title |
@@ -139,12 +136,10 @@ description: JSON schema example for a person entity
-
-
## address
-
+
Title |
@@ -164,13 +159,13 @@ description: JSON schema example for a person entity
### Properties
-
+
### address.houseNumber
-
+
Title |
@@ -201,7 +196,7 @@ description: JSON schema example for a person entity
### address.street
-
+
Title |
@@ -232,7 +227,7 @@ description: JSON schema example for a person entity
### address.city
-
+
Title |
@@ -263,7 +258,7 @@ description: JSON schema example for a person entity
### address.timeAtAddress
-
+
Title |
@@ -287,7 +282,7 @@ description: JSON schema example for a person entity
### address.timeAtAddress.years
-
+
Title |
@@ -305,9 +300,6 @@ description: JSON schema example for a person entity
Minimum |
1 |
-
- Minimum |
- 1 |
Maximum |
100 |
@@ -321,7 +313,7 @@ description: JSON schema example for a person entity
### address.timeAtAddress.months
-
+
Title |
@@ -339,9 +331,6 @@ description: JSON schema example for a person entity
Minimum |
1 |
-
- Minimum |
- 1 |
Maximum |
12 |
@@ -354,13 +343,11 @@ description: JSON schema example for a person entity
-
-
## friends
Defined in ./name.html
-
+
Title |
@@ -387,7 +374,6 @@ description: JSON schema example for a person entity
-
## Schema
diff --git a/gh-pages/examples/root-level-property.md b/gh-pages/examples/root-level-property.md
new file mode 100644
index 0000000..5cb7b69
--- /dev/null
+++ b/gh-pages/examples/root-level-property.md
@@ -0,0 +1,90 @@
+---
+title: Root level property
+description: JSON schema example demonstrating a schema with a string property directly at the root level
+
+---
+
+
+# Root level property
+
+JSON schema example demonstrating a schema with a string property directly at the root level
+
+
+
+$id | root-level-property.yml |
+$schema | http://json-schema.org/draft-07/schema# |
+
+
+
+
+
+## Example
+```
+"Value one"
+```
+## Example
+```
+"Value two"
+```
+
+
+
+
+
+
+
+
+
+ $id |
+ root-level-property.yml |
+
+
+ Title |
+ Root level property |
+
+
+ Description |
+ JSON schema example demonstrating a schema with a string property directly at the root level |
+
+ Type | String |
+
+ Min Length |
+ 1 |
+
+ Max Length |
+ 100 |
+
+ Examples |
+ Value oneValue two |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+## Schema
+```
+{
+ "$id": "root-level-property.yml",
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "title": "Root level property",
+ "description": "JSON schema example demonstrating a schema with a string property directly at the root level",
+ "type": "string",
+ "examples": [
+ "Value one",
+ "Value two"
+ ],
+ "minLength": 1,
+ "maxLength": 100
+}
+```
+
+
diff --git a/gh-pages/yml/root-level-property.yml b/gh-pages/yml/root-level-property.yml
new file mode 100644
index 0000000..aaee65a
--- /dev/null
+++ b/gh-pages/yml/root-level-property.yml
@@ -0,0 +1,10 @@
+$id: root-level-property.yml
+$schema: http://json-schema.org/draft-07/schema#
+title: Root level property
+description: JSON schema example demonstrating a schema with a string property directly at the root level
+type: string
+examples:
+ - Value one
+ - Value two
+minLength: 1
+maxLength: 100
diff --git a/lib/renderer-markdown.js b/lib/renderer-markdown.js
index 16d7321..7b42a83 100644
--- a/lib/renderer-markdown.js
+++ b/lib/renderer-markdown.js
@@ -44,6 +44,10 @@ Handlebars.registerHelper("isDefined", function (value) {
return value !== undefined;
});
+Handlebars.registerHelper("isNotDefined", function (value) {
+ return value === undefined;
+});
+
Handlebars.registerHelper("isArrayOfStringLikeValues", function (value) {
return Array.isArray(value) && !value.find((v) => typeof v === "object");
});
@@ -118,7 +122,7 @@ const propertiesTable = (schema, parentKey) => {
let properties = schema.properties;
let html =
- "" +
+ '' +
'Name | Type |
' +
"";
diff --git a/package-lock.json b/package-lock.json
index 503f340..0854384 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "json-schema-static-docs",
- "version": "0.23.1",
+ "version": "0.24.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "json-schema-static-docs",
- "version": "0.23.1",
+ "version": "0.24.1",
"license": "GPL-3.0-only",
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^10.1.0",
diff --git a/templates/schema.hbs b/templates/schema.hbs
index 2599ea8..3aef63e 100644
--- a/templates/schema.hbs
+++ b/templates/schema.hbs
@@ -11,9 +11,11 @@
+{{#if schema.properties}}
## Properties
{{propertiesTable schema }}
+{{/if}}
{{#if example}}
## Example
@@ -33,22 +35,26 @@
+{{#if schema.properties}}
{{#each schema.properties}}
-
{{> property propertyKey=@key }}
-
{{/each}}
+{{else}}
+{{> property schema isRootLevelProperty=true }}
+{{/if}}
{{#*inline "property"}}
+{{#if (isNotDefined isRootLevelProperty)}}
{{#if (isDefined parentKey)}}
### {{ parentKey }}.{{ propertyKey }}
{{else}}
## {{ propertyKey }}
{{/if}}
+{{/if}}
{{#if (isExternalRef this.$ref)}}
Defined in {{{ getHtmlAnchorForRef this.$ref this.$ref }}}
@@ -109,7 +115,7 @@
{{#*inline "propertyTable"}}
-
+
{{!--
Attribute |
diff --git a/tests/renderer-markdown.test.js b/tests/renderer-markdown.test.js
index e45ad32..f0db3b1 100644
--- a/tests/renderer-markdown.test.js
+++ b/tests/renderer-markdown.test.js
@@ -71,6 +71,13 @@ const defaultMergedSchemaWithConst = {
},
},
};
+const mergedSchemaWithRootLevelString = {
+ schema: {
+ $id: "/property1",
+ title: "Property 1",
+ type: "string",
+ },
+};
let mergedSchema = {};
const removeFormatting = (value) => {
@@ -102,7 +109,7 @@ test("renders attributes", async () => {
let expectedText =
"## Properties" +
- 'Name | Type |
' +
+ 'Name | Type |
' +
'property1 | String |
' +
'property2 | [string, integer] |
' +
'property3 | Array [property3.html] |
' +
@@ -124,7 +131,7 @@ test("renders attributes with const", async () => {
let expectedText =
"## Properties" +
- 'Name | Type |
' +
+ '";
@@ -133,7 +140,7 @@ test("renders attributes with const", async () => {
// tests recursive rendering of nested properties
test("renders nested property title correctly", async () => {
- expect.assertions(1);
+ expect.assertions(3);
rendererMarkdown = new RendererMarkdown(defaultTemplatePath);
await rendererMarkdown.setup();
let result = rendererMarkdown.renderSchema(mergedSchema);
@@ -145,19 +152,24 @@ test("renders nested property title correctly", async () => {
'Title | Property 5 |
' +
'Type | Object |
' +
'Required | Yes |
' +
- "
" +
+ "
";
+ expect(result).toContain(expectedText);
+
+ let expectedText2 =
"### Properties" +
- '";
+ expect(result).toContain(expectedText2);
+
+ let expectedText3 =
"### property5.property5.1" +
- "" +
+ '' +
"### property5.property5.1.property5.1.1" +
- "" +
+ '';
-
- expect(result).toContain(expectedText);
+ expect(result).toContain(expectedText3);
});
test("renders string property enums", async () => {
@@ -231,3 +243,21 @@ test("renders array property types", async () => {
expect(result).toContain(expectedType);
});
+
+test("renders root level string property", async () => {
+ expect.assertions(2);
+ rendererMarkdown = new RendererMarkdown(defaultTemplatePath);
+ await rendererMarkdown.setup();
+ let result = rendererMarkdown.renderSchema(mergedSchemaWithRootLevelString);
+
+ console.log(result);
+
+ result = removeFormatting(result);
+
+ let expectedTitle = 'Title | Property 1 |
';
+ expect(result).toEqual(expect.stringContaining(expectedTitle));
+
+ let expectedType = 'Type | String |
';
+
+ expect(result).toContain(expectedType);
+});