Skip to content

Commit

Permalink
feat(markdown): add support for default keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Dec 16, 2019
1 parent 96ca3a6 commit 72a0fde
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
15 changes: 15 additions & 0 deletions lib/markdownBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,17 @@ function build({
return [];
}

function makedefault(schema, level = 1) {
if (schema[keyword`default`]) {
return [
heading(level + 1, text(i18n`${simpletitle(schema)} Default Value`)),
paragraph(text(i18n`The default value is:`)),
paragraph(code('json', JSON.stringify(schema[keyword`default`], undefined, 2))),
];
}
return [];
}

function makeproplist(properties = {},
patternProperties = {},
additionalProperties,
Expand All @@ -658,6 +669,7 @@ function build({
makefactlist(name, definition, required),
...maketypesection(definition, level + 1),
...makeconstraintssection(definition, level + 1),
...makedefault(definition, level + 1),
...makeexamples(definition, level + 1),
];
}))),
Expand All @@ -671,6 +683,7 @@ function build({
makefactlist(name, definition, required),
...maketypesection(definition, level + 1),
...makeconstraintssection(definition, level + 1),
...makedefault(definition, level + 1),
...makeexamples(definition, level + 1),
];
}))),
Expand All @@ -684,6 +697,7 @@ function build({
makefactlist(i18n`Additional properties`, definition, required),
...maketypesection(definition, level + 1),
...makeconstraintssection(definition, level + 1),
...makedefault(definition, level + 1),
...makeexamples(definition, level + 1),
];
} else if (additionalProperties === true) {
Expand Down Expand Up @@ -771,6 +785,7 @@ function build({
...makeheader(schema),
...maketypesection(schema, 1),
...makeconstraintssection(schema, 1),
...makedefault(schema, 1),
...makeexamples(schema, 1),
...makedefinitions(schema, slugger),
...makeproperties(schema, slugger),
Expand Down
6 changes: 3 additions & 3 deletions schemasupport.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# JSON Schema Spec Coverage Report

This report lists the keywords of the JSON Schema spec that are covered in the tests. The overall coverage is 73%
This report lists the keywords of the JSON Schema spec that are covered in the tests. The overall coverage is 74%

## The JSON Schema Core Vocabulary

Expand Down Expand Up @@ -135,11 +135,11 @@ Coverage for [A Vocabulary for the Contents of String-Encoded Data](https://json

## A Vocabulary for Basic Meta-Data Annotations

Coverage for [A Vocabulary for Basic Meta-Data Annotations](https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.9) is 42%.
Coverage for [A Vocabulary for Basic Meta-Data Annotations](https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.9) is 57%.

| Keyword | Supported |
| :------------ | --------- |
| `default` | No |
| `default` | Yes |
| `deprecated` | No |
| `description` | Yes |
| `examples` | Yes |
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/readme-1/simple.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"description": "A unique identifier given to every addressable thing.",
"version": "1.0.0",
"testProperty": "test"
},
"name": {
"type": "string",
"default": "Simply Untitled"
}
}
}
1 change: 1 addition & 0 deletions test/markdownBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ Reference this group by using

it('Simple Schema looks OK', () => {
assertMarkdown(results.simple)
.contains('"Simply Untitled"')
.contains('# Simple Schema');
});
});
1 change: 1 addition & 0 deletions test/zSchemaCoverage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const expected = [
'relative-json-pointer',
'regex',
'uri-template',
'default',
];

const allkeywords = {
Expand Down

0 comments on commit 72a0fde

Please sign in to comment.