Skip to content

Commit 5f91c84

Browse files
committed
fixed page breaks and extra spaces between various status-codes with missing body
1 parent cdbfa81 commit 5f91c84

File tree

4 files changed

+57
-75
lines changed

4 files changed

+57
-75
lines changed

index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
https://assets.zuora.com/zuora-documentation/swagger.yaml <<< Large spec with lot of markdown
1818
-->
1919

20-
21-
<rapi-pdf id='rapipdf' spec-url="./examples/specs/test.json" include-info="false" include-security="false" include-toc="false"> </rapi-pdf>
2220
<!--
23-
<rapi-pdf id='rapipdf' spec-url="https://api.apis.guru/v2/specs/bitbucket.org/2.0/swagger.json" include-info="false" include-security="false" include-toc="false"> </rapi-pdf>
21+
<rapi-pdf id='rapipdf' spec-url="./examples/specs/test.json" include-info="false" include-security="false" include-toc="false"> </rapi-pdf>
2422
-->
23+
<rapi-pdf id='rapipdf' spec-url="https://petstore.swagger.io/v2/swagger.json"> </rapi-pdf>
24+
2525

2626
<button onclick="changeSpec()">Change Spec</button>
2727
<script type="text/javascript">

src/utils/common-utils.js

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,7 @@ export function schemaToPdf (schema, obj=[], name, level=0) {
194194
{
195195
colSpan: 3,
196196
stack:[
197-
(name ? {
198-
text:[
199-
{text:name, style:['small', 'mono', 'blue']},
200-
{text:` {`, style:['small', 'mono', 'blue']},
201-
],
202-
}
203-
:{text:`root { `, style:['small', 'mono', 'blue']}),
197+
{text:`${name?name:'object'} { `, style:['small', 'mono', 'blue']},
204198
{text:(schema.description ? schema.description : ''), style:['sub', 'blue'],margin:[0,2,0,0]},
205199
{
206200
margin: [10, 0, 0, 0],
@@ -257,13 +251,7 @@ export function schemaToPdf (schema, obj=[], name, level=0) {
257251
{
258252
colSpan: 3,
259253
stack:[
260-
{
261-
text:[
262-
{text:name, style:['small', 'mono', 'blue']},
263-
{text:`${typeOfArr==='object'?'[{':'['}`, style:['small', 'mono', (typeOfArr === 'object'?'blue':'lightGray') ]},
264-
],
265-
margin:0
266-
},
254+
{text:`${name?name:'array '} ${typeOfArr==='object'?'[{':'['}` , style:['small', 'mono', (typeOfArr === 'object'?'blue':'lightGray')], margin:0},
267255
{text:(schema.description ? schema.description : ''), style:['small','lightGray'],margin:[0,2,0,0]},
268256
{
269257
margin: [10, 0, 0, 0],
@@ -281,7 +269,7 @@ export function schemaToPdf (schema, obj=[], name, level=0) {
281269
}
282270
else{
283271
obj = [
284-
{text:name, style:['small', 'mono', 'blue'],margin:0},
272+
{text:name, style:['small', 'mono'],margin:0},
285273
{text:`[${typeOfArr}]`, style:['small','mono', 'lightGray'], margin:0},
286274
{text:(schema.description?schema.description:''), style:['small', 'lightGray'],margin:[0,2,0,0]}
287275
];
@@ -303,37 +291,24 @@ export function schemaToPdf (schema, obj=[], name, level=0) {
303291
}
304292
});
305293

306-
// This is problematic
307-
if (allOfRows.length >= 1){
308-
obj = [{
309-
colSpan: 3,
310-
stack:[
311-
{text:`${name?name:'root'} {`, style:['small', 'mono', 'blue']},
312-
{text:(schema.description ? schema.description : ''), style:['sub', 'blue'],margin:[0,2,0,0]},
313-
{
314-
margin: [10, 0, 0, 0],
315-
widths: [ 'auto', 'auto', '*' ],
316-
layout: rowLinesOnlyTableLayout,
317-
table: {
318-
dontBreakRows: true,
319-
body: allOfRows
320-
}
321-
},
322-
{text:`}`, style:['small', 'mono', 'blue']}
323-
]
324-
}]
325-
}
326-
327-
/*
328-
obj = [
329-
{text:name,style:['small', 'mono'],margin:0},
330-
{text:(schema.type ? schema.type:''), style:['small', 'mono', 'lightGray'],margin:0},
331-
{text:(schema.description?schema.description:''), style:['small', 'lightGray'], margin:[0,2,0,0]}
332-
];
333-
*/
334-
294+
obj = [{
295+
colSpan: 3,
296+
stack:[
297+
{text:`${name?name:'object'} {`, style:['small', 'mono', 'blue']},
298+
{text:(schema.description ? schema.description : ''), style:['sub', 'blue'],margin:[0,2,0,0]},
299+
{
300+
margin: [10, 0, 0, 0],
301+
widths: [ 'auto', 'auto', '*' ],
302+
layout: rowLinesOnlyTableLayout,
303+
table: {
304+
dontBreakRows: true,
305+
body: allOfRows
306+
}
307+
},
308+
{text:`}`, style:['small', 'mono', 'blue']}
309+
]
310+
}]
335311

336-
337312
}
338313

339314
// Primitive Type (String, Integer, Boolean etc)

src/utils/pdf-gen-utils.js

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function getInfoDef(spec, bookTitle, localize){
2626
contactEmail,
2727
contactUrl,
2828
termsOfService
29-
]}
29+
]},
3030
]
3131
}
3232

@@ -47,13 +47,14 @@ export function getInfoDef(spec, bookTitle, localize){
4747
(spec.info.title ? {text:spec.info.title, style:['title', 'right']} : ''),
4848
(spec.info.version ? {text:`${localize.apiVersion}: ${spec.info.version}`, style:['p','b', 'right', 'alternate']} : ''),
4949
specInfDescrMarkDef,
50-
...contactDef
50+
...contactDef,
51+
{text:'', pageBreak:'after'},
5152
];
52-
5353
}
5454
else{
5555
content = [
56-
{text:bookTitle?bookTitle:apiVersion.apiReference, style:['h1', 'bold', 'primary','right', 'topMargin1']}
56+
{text:bookTitle?bookTitle:apiVersion.apiReference, style:['h1', 'bold', 'primary','right', 'topMargin1']},
57+
{text:'', pageBreak:'after'},
5758
];
5859
}
5960
return content;
@@ -63,7 +64,7 @@ export function getInfoDef(spec, bookTitle, localize){
6364
export function getSecurityDef(spec, tableLayout, localize){
6465
let content =[];
6566
if (spec.securitySchemes){
66-
content.push( {text:localize.securityAndAuthentication, style:['h3', 'b', 'primary','right', 'topMargin3'], pageBreak:'before'} );
67+
content.push( {text:localize.securityAndAuthentication, style:['h3', 'b', 'primary','right', 'topMargin3']} );
6768
content.push({text:localize.securitySchemes, style:['b','tableMargin']});
6869
let tableContent = [
6970
[ {text: localize.type, style: ['small','b']}, {text: localize.description, style: ['small','b']} ]
@@ -81,15 +82,17 @@ export function getSecurityDef(spec, tableLayout, localize){
8182
body: tableContent,
8283
},
8384
layout: tableLayout,
84-
style: 'tableMargin'
85+
style: 'tableMargin',
86+
pageBreak:'after'
8587
});
88+
8689
}
8790
return content;
8891
}
8992

9093
// API details def
9194
export function getApiDef(spec, filterPath, sectionHeading, tableLayout, localize){
92-
let content =[{text: sectionHeading, style:['h2','b'],pageBreak:'before'}];
95+
let content =[{text: sectionHeading, style:['h2','b']}];
9396
let tagSeq=0;
9497

9598
// Sort by Tag name (allready sorted)
@@ -212,14 +215,14 @@ export function getApiDef(spec, filterPath, sectionHeading, tableLayout, localiz
212215
tocMargin: [0, 10, 0, 0],
213216
},
214217
tagDescrMarkDef,
215-
operationContent
218+
operationContent,
219+
{text:'', pageBreak:'after'}
216220
);
217221
}
218222

219223
});
220-
224+
//content.push({text:'', pageBreak:'after'});
221225
return content;
222-
223226
}
224227

225228

@@ -276,9 +279,9 @@ function getParameterTableDef(parameters, paramType, tableLayout, localize){
276279
}
277280
let tableContent = [
278281
[
279-
{text: localize.name, style: ['sub','b','alternate']},
280-
{text: localize.type, style: ['sub','b','alternate']},
281-
{text: localize.description, style: ['sub','b','alternate']}
282+
{text: localize.name, style: ['sub', 'b', 'alternate']},
283+
{text: localize.type, style: ['sub', 'b', 'alternate']},
284+
{text: localize.description, style: ['sub', 'b', 'alternate']}
282285
]
283286
];
284287

@@ -292,9 +295,9 @@ function getParameterTableDef(parameters, paramType, tableLayout, localize){
292295
type = "array of " + param.items.type;
293296
}
294297
tableContent.push([
295-
{ text:paramName, style:['small','mono'] },
296-
{ text:type + format, style:['small','mono'] },
297-
{ text:param.description, style:['small'],margin:[0,2,0,0]},
298+
{ text:paramName, style:['small', 'mono'] },
299+
{ text:type + format, style:['small', 'mono' ] },
300+
{ text:param.description, style:['small'], margin:[0,2,0,0]},
298301
]);
299302
}
300303

@@ -312,11 +315,11 @@ function getParameterTableDef(parameters, paramType, tableLayout, localize){
312315
},
313316
{
314317
stack:[
315-
{ text: `${paramSchema.type==='array' ? paramSchema.arrayType:paramSchema.type}${paramSchema.format ? `(${paramSchema.format})`:'' }`, style:['small','mono']},
318+
{ text: `${paramSchema.type==='array' ? paramSchema.arrayType:paramSchema.type}${paramSchema.format ? `(${paramSchema.format})`:'' }`, style:['small','mono', 'gray']},
316319
( paramSchema.constrain ? { text: paramSchema.constrain, style:['small', 'gray']}:''),
317320
( paramSchema.allowedValues ? { text:[
318321
{text: localize.allowed+': ', style:['b','small']},
319-
{text: paramSchema.allowedValues, style:['small', 'gray']}
322+
{text: paramSchema.allowedValues, style:['small']}
320323
]} : ''
321324
),
322325
( paramSchema.pattern ? { text: `${localize.pattern}: ${paramSchema.pattern}`, style:['small','gray']}:''),
@@ -355,7 +358,7 @@ function getResponseDef(responses, tableLayout, localize){
355358
origSchema = JSON.parse(JSON.stringify(origSchema, removeCircularReferences()));
356359
reponseModelTableDef = schemaToPdf(origSchema);
357360
if (reponseModelTableDef && reponseModelTableDef[0] && reponseModelTableDef[0].stack){
358-
reponseModelTableDef[0].colSpan=undefined;
361+
reponseModelTableDef[0].colSpan = undefined;
359362
reponseModelTableDef = {
360363
margin:[0,5,0,0],
361364
//layout:tableLayout,
@@ -381,16 +384,19 @@ function getResponseDef(responses, tableLayout, localize){
381384
margin:[0,10,0,0]
382385
});
383386

384-
allResponseModelTabelDefs.map(function(respModelTableDef){
385-
respDef.push(respModelTableDef);
386-
})
387+
if (responses[statusCode].content){
388+
allResponseModelTabelDefs.map(function(respModelTableDef){
389+
respDef.push(respModelTableDef);
390+
})
391+
}
387392
}
393+
388394
return respDef;
389395
}
390396

391397
//API List Def
392398
export function getApiListDef(spec, sectionHeading, tableLayout, localize) {
393-
let content =[{text: sectionHeading, style:['h3','b'],pageBreak:'before'}];
399+
let content =[{text: sectionHeading, style:['h3','b'],pageBreak:'none'}];
394400
spec.tags.map(function(tag, i){
395401
let tableContent = [
396402
[ {text: localize.method, style: ['small','b']}, {text: localize.api, style: ['small','b']}]
@@ -411,7 +417,7 @@ export function getApiListDef(spec, sectionHeading, tableLayout, localize) {
411417
});
412418

413419
content.push(
414-
{text: tag.name, style:['h6','b','primary','tableMargin'], pageBreak: i === 0 ? 'none' : 'before'},
420+
{text: tag.name, style:['h6','b','primary','tableMargin'], pageBreak: i === 0 ? 'none' : 'after'},
415421
{text: tag.description, style:['p']},
416422
{
417423
table: {

src/utils/pdf-gen.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ export default async function createPdf(specUrl, options){
7373
toc: {
7474
title: {text: options.localize.index, style:['b', 'h2']},
7575
numberStyle: {bold: true},
76-
style:['small'],
77-
}
76+
style:['small']
77+
},
78+
pageBreak:'after'
7879
};
79-
allContent.push({text:'', pageBreak:'after'});
80+
// allContent.push({text:'', pageBreak:'after'});
8081
allContent.push(tocDef);
8182
}
8283
if (options.includeSecurity){

0 commit comments

Comments
 (0)