Skip to content

Commit bcfd827

Browse files
committed
fixed extra spacing between status-codes, array type representation in object tree
1 parent 59ae5f6 commit bcfd827

14 files changed

+215
-38
lines changed

dist/index.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
6+
<title>RapiPdf</title>
7+
</head>
8+
9+
<body>
10+
<!--
11+
Some sample spec to try
12+
http://10.21.83.83:8080/api/swagger.json
13+
https://api.apis.guru/v2/specs/stripe.com/2019-08-14/swagger.json
14+
https://api.apis.guru/v2/specs/github.com/v3/swagger.json
15+
https://api.apis.guru/v2/specs/bitbucket.org/2.0/swagger.json
16+
https://petstore.swagger.io/v2/swagger.json
17+
https://assets.zuora.com/zuora-documentation/swagger.yaml <<< Large spec with lot of markdown
18+
-->
19+
20+
<!--
21+
<rapi-pdf id='rapipdf' spec-url="./examples/specs/test.json" include-info="false" include-security="false" include-toc="false"> </rapi-pdf>
22+
-->
23+
<rapi-pdf id='rapipdf' spec-url="./examples/specs/petstore.json"> </rapi-pdf>
24+
25+
26+
<button onclick="changeSpec()">Change Spec</button>
27+
<script type="text/javascript">
28+
function changeSpec(){
29+
let el = document.getElementById("rapipdf");
30+
el.setAttribute('spec-url', 'set new attrib');
31+
}
32+
</script>
33+
34+
35+
<script type="text/javascript" src="rapipdf-min.js"></script></body>
36+
37+
</html>

dist/index.html.gz

585 Bytes
Binary file not shown.

dist/rapipdf-min.js

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rapipdf-min.js.gz

1.04 MB
Binary file not shown.

dist/rapipdf-min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rapipdf-min.js.map.gz

150 Bytes
Binary file not shown.

dist/report.html

Lines changed: 67 additions & 0 deletions
Large diffs are not rendered by default.

docs/rapipdf-min.js

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/specs/basic.json

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,31 @@
4545
"type": "object",
4646
"additionalProperties": false,
4747
"properties": {
48-
"empId" : { "type": "string", "description": "Employee ID"},
49-
"firstName" : { "type": "string", "description": "First name" },
50-
"lastName" : { "type": "string", "description": "Last Name" },
51-
"jobTitle" : { "type": "string", "description": "Job title" },
52-
"department": { "type": "string", "description": "Department name"},
53-
"salary" : { "type": "number", "description": "Salary per annum"}
48+
"name": { "type": "string"},
49+
"age": { "type": "integer"},
50+
"departments" : {
51+
"type": "array",
52+
"items": {
53+
"type": "string"
54+
}
55+
},
56+
"tags" : {
57+
"type": "array",
58+
"items": {
59+
"$ref": "#/definitions/department"
60+
}
61+
}
62+
}
63+
},
64+
"department": {
65+
"description": "Employee Details",
66+
"type": "object",
67+
"additionalProperties": false,
68+
"properties": {
69+
"deptId": { "type": "integer"},
70+
"name": { "type": "string"}
5471
}
5572
}
73+
5674
}
5775
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rapipdf",
3-
"version": "1.2.0",
3+
"version": "2.0.0",
44
"description": "RapiPdf - Generate PDF from Open API spec",
55
"author": "Mrinmoy Majumdar <mrin9@yahoo.com>",
66
"repository": {
@@ -21,7 +21,9 @@
2121
"rapipdf",
2222
"swagger",
2323
"swagger ui",
24-
"pdf"
24+
"pdf",
25+
"swagger pdf",
26+
"openapi pdf"
2527
],
2628
"main": "rapipdf.js",
2729
"module": "rapipdf.js",

src/utils/common-utils.js renamed to src/utils/object-tree-gen.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export function objectToTree(obj, keyDataType = 'object', keyName = 'object', ke
202202
if (typeof obj !== 'object') {
203203
const typeAndDescr = obj.split('~|~');
204204
return [
205-
{ text: `${keyName}`, style: ['small', 'mono'], margin: 0 },
205+
{ text: keyName, style: ['small', 'mono'], margin: 0 },
206206
{ text: (typeAndDescr[0] ? typeAndDescr[0] : ''), style: ['small', 'mono', 'lightGray'], margin: 0 },
207207
{ text: (typeAndDescr[1] ? typeAndDescr[1] : ''), style: ['small', 'lightGray'], margin: [0, 2, 0, 0] },
208208
];
@@ -236,17 +236,16 @@ export function objectToTree(obj, keyDataType = 'object', keyName = 'object', ke
236236
},
237237
];
238238
}
239-
240239
if (typeof obj[key] === 'object') {
241240
if (Array.isArray(obj[key])) {
242-
const arrayDef = objectToTree(obj[key][0], 'array', key);
241+
const arrayDef = objectToTree(obj[key], 'array', (key === '0' ? '' : key));
243242
rows.push(arrayDef);
244243
} else {
245-
const objectDef = objectToTree(obj[key], 'object', key);
244+
const objectDef = objectToTree(obj[key], 'object', (key === '0' ? '' : key));
246245
rows.push(objectDef);
247246
}
248247
} else {
249-
const primitiveDef = objectToTree(obj[key], 'primitive', key);
248+
const primitiveDef = objectToTree(obj[key], 'primitive', (key === '0' ? '' : key));
250249
rows.push(primitiveDef);
251250
}
252251
}
@@ -256,11 +255,11 @@ export function objectToTree(obj, keyDataType = 'object', keyName = 'object', ke
256255
keyDef = {
257256
text: [
258257
{ text: `${keyName.replace(':', ' ')}`, style: ['sub', 'b', 'blue'] },
259-
{ text: `${keyDataType === 'array' ? '[{' : '{'}`, style: ['small', 'mono'] },
258+
{ text: `${keyDataType === 'array' ? '[' : '{'}`, style: ['small', 'mono'] },
260259
],
261260
};
262261
} else {
263-
keyDef = { text: `${keyName} ${keyDataType === 'array' ? '[{' : '{'}`, style: ['small', 'mono'] };
262+
keyDef = { text: `${keyName} ${keyDataType === 'array' ? '[' : '{'}`, style: ['small', 'mono'] };
264263
}
265264

266265
return [{
@@ -277,7 +276,7 @@ export function objectToTree(obj, keyDataType = 'object', keyName = 'object', ke
277276
body: rows,
278277
},
279278
},
280-
{ text: `${keyDataType === 'array' ? '}]' : '}'}`, style: ['small', 'mono'] },
279+
{ text: `${keyDataType === 'array' ? ']' : '}'}`, style: ['small', 'mono'] },
281280
],
282281
}];
283282
}

src/utils/pdf-gen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import pdfMake from 'pdfmake/build/pdfmake.min';
22
import pdfFonts from '@/utils/vfs_fonts';
33
// import pdfFonts from "pdfmake/build/vfs_fonts";
44

5-
import ProcessSpec from '@/utils/parse-utils';
5+
import ProcessSpec from '@/utils/spec-parser';
66
import {
77
getInfoDef, getSecurityDef, getApiDef, getApiListDef,
8-
} from '@/utils/pdf-gen-utils';
8+
} from '@/utils/pdf-parts-gen';
99

1010
export default async function createPdf(specUrl, options) {
1111
const parsedSpec = await ProcessSpec(specUrl, options.pdfSortTags);

src/utils/pdf-gen-utils.js renamed to src/utils/pdf-parts-gen.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import marked from 'marked';
22
import {
33
getTypeInfo, schemaToObject, objectToTree,
4-
} from '@/utils/common-utils';
4+
} from '@/utils/object-tree-gen';
55

66
// Inline Markdown
77
export function getInlineMarkDownDef(txt) {
@@ -256,7 +256,7 @@ function getParameterTableDef(parameters, paramType, tableLayout, localize) {
256256
},
257257
{
258258
stack: [
259-
{ text: `${paramSchema.type === 'array' ? paramSchema.arrayType : paramSchema.type}${paramSchema.format ? `(${paramSchema.format})` : ''}`, style: ['small', 'mono'] },
259+
{ text: `${paramSchema.type === 'array' ? paramSchema.arrayType : (paramSchema.format ? paramSchema.format : paramSchema.type)}`, style: ['small', 'mono'] },
260260
(paramSchema.constrain ? { text: paramSchema.constrain, style: ['small', 'gray'] } : ''),
261261
(paramSchema.allowedValues ? {
262262
text: [
@@ -295,7 +295,6 @@ function getRequestBodyDef(requestBody, tableLayout, localize) {
295295
}
296296
const content = [];
297297
let formParamTableDef;
298-
299298
for (const contentType in requestBody.content) {
300299
const contentTypeObj = requestBody.content[contentType];
301300
let requestBodyTableDef;
@@ -304,7 +303,7 @@ function getRequestBodyDef(requestBody, tableLayout, localize) {
304303
content.push(formParamTableDef);
305304
} else if (contentType.includes('json') || contentType.includes('xml')) {
306305
let origSchema = requestBody.content[contentType].schema;
307-
if (origSchema && (origSchema.properties || origSchema.items)) {
306+
if (origSchema) {
308307
origSchema = JSON.parse(JSON.stringify(origSchema));
309308
const schemaInObjectNotaion = schemaToObject(origSchema);
310309
requestBodyTableDef = [
@@ -323,27 +322,26 @@ function getRequestBodyDef(requestBody, tableLayout, localize) {
323322
// Response Def
324323
function getResponseDef(responses, tableLayout, localize) {
325324
const respDef = [];
326-
const allResponseModelTabelDefs = [];
327325
for (const statusCode in responses) {
326+
const allResponseModelTabelDefs = [];
328327
for (const contentType in responses[statusCode].content) {
329328
let responseBodyTableDef;
330329
let origSchema = responses[statusCode].content[contentType].schema;
331-
if (origSchema && (origSchema.properties || origSchema.items)) {
330+
if (origSchema) {
332331
origSchema = JSON.parse(JSON.stringify(origSchema));
333332
const schemaInObjectNotaion = schemaToObject(origSchema);
334333
const respBody = objectToTree(schemaInObjectNotaion);
335334
responseBodyTableDef = [
336-
{ text: `${localize.responseModel} - ${contentType}`, margin: [0, 10, 0, 0], style: ['small', 'b'] },
337-
respBody,
335+
{ text: `${localize.responseModel} - ${contentType}`, margin: [10, 10, 0, 0], style: ['small', 'b'] },
336+
{ stack: respBody, margin: [10, 0, 0, 0] },
338337
];
339338
} else {
340339
responseBodyTableDef = [
341-
{ text: `${localize.responseModel} - ${contentType}`, margin: [0, 5, 0, 0], style: ['small', 'b'] },
340+
{ text: `${localize.responseModel} - ${contentType}`, margin: [10, 5, 0, 0], style: ['small', 'b'] },
342341
];
343342
}
344343
allResponseModelTabelDefs.push(responseBodyTableDef);
345344
}
346-
347345
respDef.push({
348346
text: [
349347
{ text: `${localize.statusCode} - ${statusCode}: `, style: ['small', 'b'] },
File renamed without changes.

0 commit comments

Comments
 (0)