Skip to content

Commit

Permalink
fixes #732 - support multiple data types with object and array
Browse files Browse the repository at this point in the history
  • Loading branch information
mrin9 committed Jul 4, 2022
1 parent af4f651 commit aab6df7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/components/schema-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ export default class SchemaTable extends LitElement {
if (dataType === 'array') {
detailObjType = 'array of object'; // Array of Object
} else {
detailObjType = 'object';
detailObjType = data['::dataTypeLabel'] || data['::type'];
}
} else if (data['::type'] === 'array') {
if (dataType === 'array') {
// detailObjType = 'array of array'; // Array of array
detailObjType = `array of array ${arrayType !== 'object' ? `of ${arrayType}` : ''}`; // Array of array
} else {
detailObjType = 'array';
detailObjType = data['::dataTypeLabel'] || data['::type'];
}
}

Expand Down Expand Up @@ -244,7 +244,7 @@ export default class SchemaTable extends LitElement {
? html`${this.generateTree(data[0], 'xxx-of-option', '', '::ARRAY~OF', '', newSchemaLevel, newIndentLevel, '')}`
: html`
${Object.keys(data).map((dataKey) => html`
${['::title', '::description', '::type', '::props', '::deprecated', '::array-type', '::readwrite'].includes(dataKey)
${['::title', '::description', '::type', '::props', '::deprecated', '::array-type', '::readwrite', '::dataTypeLabel'].includes(dataKey)
? data[dataKey]['::type'] === 'array' || data[dataKey]['::type'] === 'object'
? html`${this.generateTree(
data[dataKey]['::type'] === 'array' ? data[dataKey]['::props'] : data[dataKey],
Expand Down
2 changes: 1 addition & 1 deletion src/components/schema-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export default class SchemaTree extends LitElement {
? html`${this.generateTree(data[0], 'xxx-of-option', '', '::ARRAY~OF', '', newSchemaLevel, newIndentLevel, data[0]['::readwrite'])}`
: html`
${Object.keys(data).map((dataKey) => html`
${['::title', '::description', '::type', '::props', '::deprecated', '::array-type', '::readwrite'].includes(dataKey)
${['::title', '::description', '::type', '::props', '::deprecated', '::array-type', '::readwrite', '::dataTypeLabel'].includes(dataKey)
? data[dataKey]['::type'] === 'array' || data[dataKey]['::type'] === 'object'
? html`${this.generateTree(
data[dataKey]['::type'] === 'array' ? data[dataKey]['::props'] : data[dataKey],
Expand Down
6 changes: 6 additions & 0 deletions src/utils/schema-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,9 @@ export function schemaInObjectNotation(schema, obj, level = 0, suffix = '') {
obj['::title'] = schema.title || '';
obj['::description'] = generateMarkdownForArrayAndObjectDescription(schema, level);
obj['::type'] = 'object';
if ((Array.isArray(schema.type) && schema.type.includes('null')) || schema.nullable) {
obj['::dataTypeLabel'] = 'object or null';
}
obj['::deprecated'] = schema.deprecated || false;
obj['::readwrite'] = schema.readOnly ? 'readonly' : schema.writeOnly ? 'writeonly' : '';
for (const key in schema.properties) {
Expand All @@ -701,6 +704,9 @@ export function schemaInObjectNotation(schema, obj, level = 0, suffix = '') {
obj['::title'] = schema.title || '';
obj['::description'] = generateMarkdownForArrayAndObjectDescription(schema, level);
obj['::type'] = 'array';
if ((Array.isArray(schema.type) && schema.type.includes('null')) || schema.nullable) {
obj['::dataTypeLabel'] = 'array or null';
}
obj['::deprecated'] = schema.deprecated || false;
obj['::readwrite'] = schema.readOnly ? 'readonly' : schema.writeOnly ? 'writeonly' : '';
if (schema.items?.items) {
Expand Down

0 comments on commit aab6df7

Please sign in to comment.