Skip to content

Commit

Permalink
feat(markdown): show type, link, additional and custom properties in …
Browse files Browse the repository at this point in the history
…header
  • Loading branch information
trieloff committed Dec 5, 2019
1 parent b6fcf53 commit eff129a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
34 changes: 32 additions & 2 deletions lib/formatInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,45 @@ function formatInfo({ extension }) {
.length > 0;
}

function getdefined(schema) {
if (schema.rootpath) {
return {
text: path.basename(schema.rootpath) + "*",
link: schema.rootpath
}
}
if (schema.path) {
return {
text: path.basename(schema.path),
link: schema.path
}
}
return undefined;
}

function gettype(schema) {
if (typeof schema.type === 'string') {
return schema.type;
}
if (Array.isArray(schema.type)) {
return 'multiple';
}
if (isabstract(schema)) {
return gettype(schema.definitions);
}
return undefined;
}

function formatmeta(schema) {
return {
type: gettype(schema.schema),
abstract: isabstract(schema.schema),
extensible: isextensible(schema.schema),
status: schema.schema['meta:status'] || undefined,
identifiable: isidentifiable(schema.schema),
custom: iscustom(schema.schema),
additional: undefined,
definedin: undefined
additional: schema.schema.additionalProperties !== false,
definedin: getdefined(schema)
};
}

Expand Down
17 changes: 11 additions & 6 deletions lib/markdownBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const {

function build({ header, links = {} }) {
const headerprops = [
{
name: 'type',
title: 'Type',
objectlabel: 'Object',
arraylabel: 'Array',
},
{
name: 'abstract',
title: 'Abstract',
Expand Down Expand Up @@ -63,7 +69,7 @@ function build({ header, links = {} }) {
undefinedlabel: 'Unknown additional properties'
},
{
name: 'defined',
name: 'definedin',
title: 'Defined In',
undefinedlabel: 'Unknown definition'
},
Expand Down Expand Up @@ -94,12 +100,11 @@ function build({ header, links = {} }) {
map(headerprops,
(prop) => {
// this is a linked property

if (schema.meta &&
schema.meta[prop.name] &&
typeof schema.meta[prop.name] !== 'object' &&
typeof schema.meta[prop.name].link === 'string') {
return tableCell(link(schema.meta[prop.name].link, '', text(schema.meta[prop.name].text)));
typeof schema.meta[prop.name] === 'object' &&
schema.meta[prop.name].link &&
schema.meta[prop.name].text) {
return tableCell(link(schema.meta[prop.name].link, 'open original schema', [text(schema.meta[prop.name].text)]));
}
const value = schema.meta ? schema.meta[prop.name] : undefined;
return tableCell(text(prop[String(value) + 'label'] || 'Unknown'));
Expand Down
4 changes: 4 additions & 0 deletions lib/traverseSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const ignoreKeywords = [
*/
function traverse(node) {
const { schema, pointer = '', id } = node;
const rootpath = node.rootpath ? node.rootpath : node.path;
const items = pipe(
// turn the schema object into a sequence of key value pairs
iter(schema),
Expand All @@ -71,6 +72,7 @@ function traverse(node) {
pointer: `${pointer}/${key}/${index}`,
id,
root: schema,
rootpath,
// TODO add additional properties for tracking
})),
);
Expand All @@ -85,6 +87,7 @@ function traverse(node) {
pointer: `${pointer}/${key}/${subkey}`,
id,
root: schema,
rootpath,
// TODO add additional properties for tracking
})),
);
Expand All @@ -97,6 +100,7 @@ function traverse(node) {
pointer: `${pointer}/${key}`,
id,
root: schema,
rootpath,
// TODO add additional properties for tracking
}];
}
Expand Down

0 comments on commit eff129a

Please sign in to comment.