diff --git a/examples/schemas/join.schema.json b/examples/schemas/join.schema.json index 51f1ea23..855b017e 100644 --- a/examples/schemas/join.schema.json +++ b/examples/schemas/join.schema.json @@ -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" + } + } + } + ] } ] } \ No newline at end of file diff --git a/lib/markdownBuilder.js b/lib/markdownBuilder.js index 372f0ec6..4e380a08 100644 --- a/lib/markdownBuilder.js +++ b/lib/markdownBuilder.js @@ -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) ] }