diff --git a/lib/formatInfo.js b/lib/formatInfo.js index 9e05d315..a9488a57 100644 --- a/lib/formatInfo.js +++ b/lib/formatInfo.js @@ -17,6 +17,7 @@ const parse = require('remark-parse'); const stringify = require('mdast-util-to-string'); const { formatname } = require('./formatname'); const s = require('./symbols'); +const { keyword } = require('./keywords'); function isabstract(schema) { @@ -25,14 +26,14 @@ function isabstract(schema) { } function isextensible(schema) { - return schema.definitions !== undefined || schema['meta:extensible'] === true; + return schema.definitions !== undefined || schema[keyword`meta:extensible`] === true; } function isidentifiable(schema) { if (!schema.properties) { return 'undefined'; } - if (schema.properties['@id'] && schema.properties['@id'].type === 'string' && schema.properties['@id'].format === 'uri') { + if (schema.properties[keyword`@id`] && schema.properties[keyword`@id`].type === 'string' && schema.properties[keyword`@id`].format === 'uri') { return 'true'; } else { return 'false'; @@ -128,7 +129,7 @@ function formatmeta(schema) { type: gettype(schema), abstract: isabstract(schema), extensible: isextensible(schema), - status: schema['meta:status'] || undefined, + status: schema[keyword`meta:status`] || undefined, identifiable: isidentifiable(schema), custom: iscustom(schema), additional: schema.additionalProperties !== false, diff --git a/lib/markdownBuilder.js b/lib/markdownBuilder.js index 0c06bfca..25a9db26 100644 --- a/lib/markdownBuilder.js +++ b/lib/markdownBuilder.js @@ -20,6 +20,7 @@ const i18n = require('es2015-i18n-tag').default; const ghslugger = require('github-slugger'); const s = require('./symbols'); const { gentitle } = require('./formattingTools'); +const { keyword } = require('./keywords'); function build({ header, links = {}, includeproperties = [] } = {}) { const formats = { @@ -253,7 +254,7 @@ function build({ header, links = {}, includeproperties = [] } = {}) { function nullable(property) { const types = Array.isArray(property.type) ? property.type : [property.type]; - const nulltypes = flist(filter(types, mytype => mytype === 'null')); + const nulltypes = flist(filter(types, mytype => mytype === keyword`null`)); if (size(nulltypes)) { return text(i18n`can be null`); } @@ -299,16 +300,16 @@ function build({ header, links = {}, includeproperties = [] } = {}) { function maketypefact(definition, isarray = '') { const alltypes = Array.isArray(definition.type) ? definition.type : [definition.type]; // filter out types that are null - const realtypes = alltypes.filter(mytype => mytype !== 'null'); + const realtypes = alltypes.filter(mytype => mytype !== keyword`null`); // can the type be `null` - const isnullable = alltypes.filter(mytype => mytype === 'null').length > 0; + const isnullable = alltypes.filter(mytype => mytype === keyword`null`).length > 0; // is there only a single type or can there be multiple types const singletype = realtypes.length <= 1; const [firsttype] = realtypes; // is `null` the only allowed value const nulltype = isnullable && realtypes.length === 0; - const array = firsttype === 'array'; + const array = firsttype === keyword`array`; const merged = !!(definition.allOf || definition.anyOf || definition.oneOf || definition.not); if (array && definition.items) { @@ -333,7 +334,7 @@ function build({ header, links = {}, includeproperties = [] } = {}) { if (definition.title) { // if the type has a title, always create a link to the schema return [text(' ('), link(`${definition[s.slug]}.md`, '', text(definition.title)), text(')')]; - } else if (!singletype || firsttype === 'object' || merged) { + } else if (!singletype || firsttype === keyword`object` || merged) { return [text(' ('), link(`${definition[s.slug]}.md`, '', text(i18n`Details`)), text(')')]; } return []; @@ -345,7 +346,7 @@ function build({ header, links = {}, includeproperties = [] } = {}) { function makenullablefact(definition) { const alltypes = Array.isArray(definition.type) ? definition.type : [definition.type]; // can the type be `null` - const isnullable = alltypes.filter(mytype => mytype === 'null').length > 0; + const isnullable = alltypes.filter(mytype => mytype === keyword`null`).length > 0; if (isnullable) { return listItem(paragraph(text(i18n`can be null`))); @@ -452,7 +453,7 @@ function build({ header, links = {}, includeproperties = [] } = {}) { if (schema.enum) { console.log('enum!', schema[s.filename], schema[s.pointer]); - const metas = schema['meta:enum'] || {}; + const metas = schema[keyword`meta:enum`] || {}; constraints.push(paragraph([strong(text(i18n`constant`)), text(': '), text(i18n`the value of this property must be equal to one of the following values:`)])); constraints.push(table('left', [ tableRow([