diff --git a/examples/docs/arrays.schema.md b/examples/docs/arrays.schema.md index 86e4eb30df536b1f48a3b4e133b7660efaf19ee0..d63414f7c6e241da4fcf55ac0f2b8052805d0641 100644 --- a/examples/docs/arrays.schema.md +++ b/examples/docs/arrays.schema.md @@ -212,7 +212,49 @@ All items must be of the type: | `a`| string | **Required** | | `b`| integer | Optional | -full list. + + +#### a + +The a property + +`a` +* is **required** +* type: `string` +* defined in this schema + +##### a Type + + +`string` + + + + + + + + +#### b + +The b property + +`b` +* is optional +* type: `integer` +* defined in this schema + +##### b Type + + +`integer` + + + + + + + diff --git a/templates/md/nested-property.ejs b/templates/md/nested-property.ejs new file mode 100644 index 0000000000000000000000000000000000000000..bf7d1114b5f411f3cc032b1b9ea4f6d9c01d9f84 --- /dev/null +++ b/templates/md/nested-property.ejs @@ -0,0 +1,89 @@ +<% /** + * Copyright 2017 Adobe Systems Incorporated. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0 + */ %> + +#### <%=name %> +<% if (schema.title) { %>##### <%= schema.title %><% } %> + + +<%= (""+schema.description).replace(/\n/g, '\n\n') %> + + +`<%=name %>` +* is <% if (required) { %>**required**<% } else { %>optional<% } %> +* type: <%=schema.simpletype %><% if (schema.simpletype.match(/\[\]\[\]/)||schema.simpletype==="`array[]`") { %> (nested array)<% } %><% if (schema.type==='array') { %> +<% if (schema.maxItems!==undefined&&schema.minItems!==undefined) { %>* between `<%=schema.minItems %>` and `<%=schema.maxItems %>` items in the array<% } +else if (schema.maxItems!==undefined ) { %>* no more than `<%=schema.maxItems %>` items in the array<% } +else if (schema.minItems!==undefined ) { %>* at least `<%=schema.minItems %>` items in the array<% } %> +<% } %> +* defined in <% if (schema.$oSchema) { %>[<%= schema.$oSchema.$linkVal %>](<%= schema.$oSchema.$linkPath %>#<%= name %>)<% } else { %>this schema<% } %> + +<% if (schema.const!==undefined) { %> +The value of this property **must** be equal to: + + +```json +<%- JSON.stringify(schema.const, null, 2) %> +``` + +<% } else if (schema.enum!==undefined) { %> +The value of this property **must** be equal to one of the [known values below](#<%=name %>-known-values). +<% } else { %> + +##### <%=name %> Type + +<% if (schema.type==="string") { %> +<%- include("string-type",{schema:schema,_:_}) %> +<% } else if (schema.type==="number"||schema.type==="integer") { %> +<%- include("number-type",{schema:schema,_:_}) %> +<% } else if (schema.type==="boolean") { %> +<%- include("boolean-type",{schema:schema,_:_}) %> +<% } else if (schema.type==="array") { %> +<%- include("array-type",{schema:schema,_:_,nested:false,ejs:ejs}) %> +<% } else if (schema.$ref!==undefined) { %> +<%- include("referenced-type",{schema:schema,_:_}) %> +<% } else if (schema.anyOf!==undefined || schema.allOf!==undefined || schema.oneOf!==undefined) { %> +<%- include("join-type",{schema:schema,_:_,schemas:schema.anyOf || schema.allOf || schema.oneOf,ejs:ejs}) %> +<% } else { %> +Unknown type `<%= schema.type %>`. + + +```json +<%- JSON.stringify(schema, null, 2) %> +``` + +<% }} %> + +<% if (schema.enum!==undefined||schema["meta:enum"]!==undefined) { %> +##### <%=name %> Known Values + +| Value | Description | +|-------|-------------| +<% _.forIn(schema["meta:enum"], (value, key, object) => { %> +| `<%= key %>` | <%= value %> | +<% }); %> + +<% } %> + + +<% if (examples && examples.length == 1) { %> +##### <%=name %> Example + + +```json +<%- examples[0] %> +``` +<% } else if (examples && examples.length > 1) { %> +##### <%=name %> Examples +<% _.forEach(examples, example => { %> + +```json +<%- example %> +``` + +<% }); %> +<% } %> + diff --git a/templates/md/object-type.ejs b/templates/md/object-type.ejs index 4addd6aa852347a35f79fb901a9958c1f081247a..cc1902a15602aa54dd2397d757a8548ad5972bfe 100644 --- a/templates/md/object-type.ejs +++ b/templates/md/object-type.ejs @@ -9,4 +9,20 @@ <%- include("nested-properties",{outer:schema,props: schema.properties,_:_, nested:true}) %> -full list. \ No newline at end of file +<% _.keys(schema.properties).sort().forEach(property => { + const inner = schema.properties[property]; + inner.simpletype = "`" + inner.type + "`"; + const required = (schema.required&&schema.required.indexOf(property)>=0); %> + +<%- include("nested-property",{ + _:_, + nested:true, + name: property, + schema: inner, + required: required, + examples: inner.examples + }) %> + +<% +}); +%> \ No newline at end of file