Skip to content

Commit

Permalink
feat(schema): add support for keyword $defs
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Dec 16, 2019
1 parent 0982f31 commit 70b63c8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
41 changes: 22 additions & 19 deletions lib/markdownBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,29 +765,32 @@ function build({
* @param {*} schema
*/
function makedefinitions(schema, slugger) {
if (schema.definitions) {
const defgroups = Object.entries(schema.definitions).map(([groupname, subschema]) => {
const grouptable = makeproptable(
subschema[keyword`properties`],
subschema[keyword`patternProperties`],
subschema[keyword`additionalProperties`],
subschema[keyword`required`],
slugger,
);
return [
heading(2, text(i18n`Definitions group ${groupname}`)),
paragraph(text(i18n`Reference this group by using`)),
code('json', JSON.stringify({ $ref: `${subschema[s.id]}#${subschema[s.pointer]}` })),
grouptable,
...makeproplist(
if (schema.definitions || schema[keyword`$defs`]) {
const defgroups = [
...Object.entries(schema[keyword`$defs`] || {}),
...Object.entries(schema.definitions || {})]
.map(([groupname, subschema]) => {
const grouptable = makeproptable(
subschema[keyword`properties`],
subschema[keyword`patternProperties`],
subschema[keyword`additionalProperties`],
subschema[keyword`required`],
2,
),
];
});
slugger,
);
return [
heading(2, text(i18n`Definitions group ${groupname}`)),
paragraph(text(i18n`Reference this group by using`)),
code('json', JSON.stringify({ $ref: `${subschema[s.id]}#${subschema[s.pointer]}` })),
grouptable,
...makeproplist(
subschema[keyword`properties`],
subschema[keyword`patternProperties`],
subschema[keyword`additionalProperties`],
subschema[keyword`required`],
2,
),
];
});

return [
heading(1, text(i18n`${gentitle(schema[s.titles], schema[keyword`type`])} Definitions`)),
Expand Down
6 changes: 3 additions & 3 deletions schemasupport.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# 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 81%
This report lists the keywords of the JSON Schema spec that are covered in the tests. The overall coverage is 82%

## The JSON Schema Core Vocabulary

Coverage for [The JSON Schema Core Vocabulary](https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.8.1) is 33%.
Coverage for [The JSON Schema Core Vocabulary](https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.8.1) is 44%.

| Keyword | Supported |
| :----------------- | --------- |
| `$anchor` | No |
| `$comment` | Yes |
| `$defs` | No |
| `$defs` | Yes |
| `$id` | Yes |
| `$recursiveAnchor` | No |
| `$recursiveRef` | No |
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/readme-1/abstract.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"writeOnly": true,
"description": "This is an abstract schema. It has `definitions`, but does not declare any properties",
"type": "object",
"definitions": {
"$defs": {
"first": {
"type": "object",
"properties": {
Expand Down
4 changes: 2 additions & 2 deletions test/markdownBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,15 @@ describe('Testing Markdown Builder: readme-1', () => {
Reference this group by using
\`\`\`json
{"$ref":"https://example.com/schemas/abstract#/definitions/second"}
{"$ref":"https://example.com/schemas/abstract#/$defs/second"}
\`\`\``
.fuzzy`
\`bar\`
- is optional
- Type: \`string\`
- cannot be null
- defined in: [Abstract](abstract-definitions-second-properties-bar.md "https://example.com/schemas/abstract#/definitions/second/properties/bar")
- defined in: [Abstract](abstract-defs-second-properties-bar.md "https://example.com/schemas/abstract#/$defs/second/properties/bar")
#### bar Type
Expand Down

0 comments on commit 70b63c8

Please sign in to comment.