Skip to content

Commit

Permalink
styling for tree-table added
Browse files Browse the repository at this point in the history
  • Loading branch information
mrin9 committed Oct 5, 2019
1 parent 037901a commit c70b9e5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/object-tree-gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export function schemaInObjectNotation(schema, obj = {}, level = 0) {
* @param {string} prevKeyDataType - data-type of previous key, it is either 'primitive', 'object' or 'array', based on this appropriate braces are used
* @param {string} prevKey - name of the key from previous recursive call stack
*/
export function objectToTree(obj, localize, prevKeyDataType = 'object', prevKey = 'object') {
export function objectToTree(obj, localize, prevKeyDataType = 'object', prevKey = '') {
if (typeof obj !== 'object') {
const propDescrArray = obj.split('~|~');
if (prevKeyDataType === 'array') {
Expand Down Expand Up @@ -262,7 +262,7 @@ export function objectToTree(obj, localize, prevKeyDataType = 'object', prevKey
if (typeof obj[key] === 'object' && obj[key]['::type']) {
let objectDef;
if (obj[key]['::type'] === 'array') {
objectDef = objectToTree(obj[key]['::props'], localize, obj[key]['::type'], key);
objectDef = objectToTree(obj[key]['::props'], localize, obj[key]['::type'], key, 'array');
} else {
objectDef = objectToTree(obj[key], localize, obj[key]['::type'], key);
}
Expand Down Expand Up @@ -315,7 +315,7 @@ export function objectToTree(obj, localize, prevKeyDataType = 'object', prevKey
table: {
headerRows: 0,
widths: ['auto', 'auto', '*'],
dontBreakRows: true,
dontBreakRows: false,
body: rows,
},
},
Expand Down
30 changes: 25 additions & 5 deletions src/pdf-parts-gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function getRequestBodyDef(requestBody, schemaStyle, localize) {
for (const contentType in requestBody.content) {
const contentTypeObj = requestBody.content[contentType];
const requestBodyDef = [
{ text: `${localize.requestBody} - ${contentType}`, margin: [0, 10, 0, 10], style: ['small', 'b'] },
{ text: `${localize.requestBody} - ${contentType}`, margin: [0, 10, 0, 0], style: ['small', 'b'] },
];

if ((contentType.includes('form') || contentType.includes('multipart-form')) && contentTypeObj.schema) {
Expand All @@ -202,18 +202,27 @@ function getRequestBodyDef(requestBody, schemaStyle, localize) {
}
requestBodyDef.push(treeDef);
} else {
// if Schema Style is Tree
let schemaTableTreeDef;
if (schemaInObjectNotaion['::type'] && schemaInObjectNotaion['::type'] === 'array') {
schemaTableTreeDef = objectToTableTree(schemaInObjectNotaion['::prop'], localize, 'array');
} else {
schemaTableTreeDef = objectToTableTree(schemaInObjectNotaion, localize);
}
if (schemaTableTreeDef && schemaTableTreeDef.length > 0) {
if (schemaTableTreeDef && schemaTableTreeDef.length > 0 && Array.isArray(schemaTableTreeDef[0]) && schemaTableTreeDef[0].length > 0) {
schemaTableTreeDef.unshift([
{ text: localize.name, style: ['sub', 'b', 'alternate'] },
{ text: localize.type, style: ['sub', 'b', 'alternate'] },
{ text: localize.description, style: ['sub', 'b', 'alternate'] },
]);

requestBodyDef.push({
table: {
headerRows: 1,
body: schemaTableTreeDef,
},
margin: [10, 10, 0, 0],
layout: rowLinesTableLayout,
margin: [0, 3, 0, 0],
});
}
}
Expand Down Expand Up @@ -245,19 +254,30 @@ function getResponseDef(responses, schemaStyle, localize) {
} else {
schemaTreeDef = objectToTree(schemaInObjectNotaion, localize);
}
responseDef.push(schemaTreeDef);
if (Array.isArray(schemaTreeDef) && schemaTreeDef.length > 0) {
schemaTreeDef[0].margin = [10, 5, 0, 0];
responseDef.push(schemaTreeDef);
}
} else {
// If Schema style is Tree
let schemaTableTreeDef;
if (schemaInObjectNotaion['::type'] && schemaInObjectNotaion['::type'] === 'array') {
schemaTableTreeDef = objectToTableTree(schemaInObjectNotaion['::prop'], localize, 'array');
} else {
schemaTableTreeDef = objectToTableTree(schemaInObjectNotaion, localize);
}
if (schemaTableTreeDef && schemaTableTreeDef.length > 0) {
if (schemaTableTreeDef && schemaTableTreeDef.length > 0 && Array.isArray(schemaTableTreeDef[0]) && schemaTableTreeDef[0].length > 0) {
schemaTableTreeDef.unshift([
{ text: localize.name, style: ['sub', 'b', 'alternate'] },
{ text: localize.type, style: ['sub', 'b', 'alternate'] },
{ text: localize.description, style: ['sub', 'b', 'alternate'] },
]);
responseDef.push({
table: {
headerRows: 1,
body: schemaTableTreeDef,
},
layout: rowLinesTableLayout,
margin: [10, 3, 0, 0],
});
}
Expand Down

0 comments on commit c70b9e5

Please sign in to comment.