Skip to content

Commit

Permalink
feat(markdown): show join types
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Dec 10, 2019
1 parent 515969c commit 12af018
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 24 deletions.
90 changes: 67 additions & 23 deletions examples/schemas/join.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,78 @@
"description": "This is an example of a JSON schema with only a join type key. Here a 'oneOf'.",
"oneOf": [
{
"type": "object",
"description": "A simple string.",
"properties": {
"foo": {
"type": "string",
"description": "A simple string.",
"examples": [
"hello"
],
"version": "1.0.0",
"testProperty": "test"
}
"not": {
"oneOf": [
{
"type": "object",
"description": "A simple string.",
"properties": {
"foo": {
"type": "string",
"description": "A simple string.",
"examples": [
"hello"
],
"version": "1.0.0",
"testProperty": "test"
}
}
},
{
"type": "object",
"description": "Another simple string.",
"properties": {
"bar": {
"type": "string",
"description": "A simple string.",
"examples": [
"world"
],
"version": "1.0.0",
"testProperty": "test"
}
}
}
]
}
},
{
"type": "object",
"description": "Another simple string.",
"properties": {
"bar": {
"type": "string",
"allOf": [
{
"type": "object",
"description": "A simple string.",
"examples": [
"world"
],
"version": "1.0.0",
"testProperty": "test"
"properties": {
"foo": {
"type": "string",
"description": "A simple string.",
"examples": [
"hello"
],
"version": "1.0.0",
"testProperty": "test"
}
}
}
}
]
},
{
"anyOf": [
{
"type": "object",
"description": "Another simple string.",
"properties": {
"bar": {
"type": "string",
"description": "A simple string.",
"examples": [
"world"
],
"version": "1.0.0",
"testProperty": "test"
}
}
}
]
}
]
}
42 changes: 41 additions & 1 deletion lib/markdownBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,52 @@ function build({ header, links = {}, includeproperties = [] } = {}) {
return [];
}

function makejointypelist(schema, depth = 0, maxdepth = 3) {
if (schema.oneOf && depth <= maxdepth) {
return [
paragraph(text(i18n`one (and only one) of`)),
list('unordered', [
...schema.oneOf.map(subschema => listItem(makejointypelist(subschema, depth + 1)))
]),
]
} else if (schema.anyOf && depth <= maxdepth) {
return [
paragraph(text(i18n`any of`)),
list('unordered', [
...schema.anyOf.map(subschema => listItem(makejointypelist(subschema, depth + 1)))
]),
]
} else if (schema.allOf && depth <= maxdepth) {
return [
paragraph(text(i18n`all of`)),
list('unordered', [
...schema.allOf.map(subschema => listItem(makejointypelist(subschema, depth + 1)))
]),
]
} else if (schema.not && depth <= maxdepth) {
const subschema = schema.not;
return [
paragraph(text(i18n`not`)),
list('unordered', [
listItem(makejointypelist(subschema, depth + 1))
]),
]
} else if (depth > 0) {
return [
link(`${schema[s.slug].md}`, i18n`check type definition`, text(gentitle(schema[s.titles], schema.type)))
];
} else {
return [];
}
}

function maketypesection(schema, level = 1) {
const { children } = maketypefact(schema);
children[0].children.shift();
return [
heading(level + 1, text(i18n`${simpletitle(schema)} Type`)),
...children
...children,
...makejointypelist(schema)
]
}

Expand Down

0 comments on commit 12af018

Please sign in to comment.