rapipdf 2.1.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +66 -14
  2. package/dist/chunks/generate-BQLGaRvK.js +386 -0
  3. package/dist/chunks/generate-BQLGaRvK.js.LICENSE.txt +224 -0
  4. package/dist/chunks/localize-CRvDVkIz.js +8 -0
  5. package/dist/node.js +13096 -0
  6. package/dist/node.js.LICENSE.txt +195 -0
  7. package/dist/rapipdf-min.js +352 -90
  8. package/dist/rapipdf-min.js.LICENSE.txt +224 -0
  9. package/dist/rapipdf.js +69 -0
  10. package/package.json +58 -52
  11. package/src/node.d.ts +82 -0
  12. package/src/rapipdf.d.ts +50 -0
  13. package/.babelrc +0 -11
  14. package/.eslintrc +0 -28
  15. package/dist/index.html +0 -48
  16. package/dist/index.html.gz +0 -0
  17. package/dist/rapipdf-min.js.gz +0 -0
  18. package/dist/rapipdf-min.js.map +0 -1
  19. package/dist/rapipdf-min.js.map.gz +0 -0
  20. package/dist/report.html +0 -67
  21. package/docs/examples/example1.html +0 -68
  22. package/docs/examples/list.html +0 -27
  23. package/docs/examples/rapidoc-regular.woff2 +0 -0
  24. package/docs/examples/rapidoc-semi-bold.woff2 +0 -0
  25. package/docs/examples/roboto-mono-bold.woff2 +0 -0
  26. package/docs/examples/roboto-mono-regular.woff2 +0 -0
  27. package/docs/highlight/CHANGES.md +0 -1803
  28. package/docs/highlight/LICENSE +0 -24
  29. package/docs/highlight/README.md +0 -188
  30. package/docs/highlight/README.ru.md +0 -142
  31. package/docs/highlight/highlight.pack.js +0 -2
  32. package/docs/highlight/styles/a11y-dark.css +0 -99
  33. package/docs/highlight/styles/a11y-light.css +0 -99
  34. package/docs/highlight/styles/agate.css +0 -108
  35. package/docs/highlight/styles/an-old-hope.css +0 -89
  36. package/docs/highlight/styles/androidstudio.css +0 -66
  37. package/docs/highlight/styles/arduino-light.css +0 -88
  38. package/docs/highlight/styles/arta.css +0 -73
  39. package/docs/highlight/styles/ascetic.css +0 -45
  40. package/docs/highlight/styles/atelier-cave-dark.css +0 -83
  41. package/docs/highlight/styles/atelier-cave-light.css +0 -85
  42. package/docs/highlight/styles/atelier-dune-dark.css +0 -69
  43. package/docs/highlight/styles/atelier-dune-light.css +0 -69
  44. package/docs/highlight/styles/atelier-estuary-dark.css +0 -84
  45. package/docs/highlight/styles/atelier-estuary-light.css +0 -84
  46. package/docs/highlight/styles/atelier-forest-dark.css +0 -69
  47. package/docs/highlight/styles/atelier-forest-light.css +0 -69
  48. package/docs/highlight/styles/atelier-heath-dark.css +0 -69
  49. package/docs/highlight/styles/atelier-heath-light.css +0 -69
  50. package/docs/highlight/styles/atelier-lakeside-dark.css +0 -69
  51. package/docs/highlight/styles/atelier-lakeside-light.css +0 -69
  52. package/docs/highlight/styles/atelier-plateau-dark.css +0 -84
  53. package/docs/highlight/styles/atelier-plateau-light.css +0 -84
  54. package/docs/highlight/styles/atelier-savanna-dark.css +0 -84
  55. package/docs/highlight/styles/atelier-savanna-light.css +0 -84
  56. package/docs/highlight/styles/atelier-seaside-dark.css +0 -69
  57. package/docs/highlight/styles/atelier-seaside-light.css +0 -69
  58. package/docs/highlight/styles/atelier-sulphurpool-dark.css +0 -69
  59. package/docs/highlight/styles/atelier-sulphurpool-light.css +0 -69
  60. package/docs/highlight/styles/atom-one-dark-reasonable.css +0 -77
  61. package/docs/highlight/styles/atom-one-dark.css +0 -96
  62. package/docs/highlight/styles/atom-one-light.css +0 -96
  63. package/docs/highlight/styles/brown-paper.css +0 -64
  64. package/docs/highlight/styles/brown-papersq.png +0 -0
  65. package/docs/highlight/styles/codepen-embed.css +0 -60
  66. package/docs/highlight/styles/color-brewer.css +0 -71
  67. package/docs/highlight/styles/darcula.css +0 -77
  68. package/docs/highlight/styles/dark.css +0 -63
  69. package/docs/highlight/styles/darkula.css +0 -6
  70. package/docs/highlight/styles/default.css +0 -99
  71. package/docs/highlight/styles/docco.css +0 -97
  72. package/docs/highlight/styles/dracula.css +0 -76
  73. package/docs/highlight/styles/far.css +0 -71
  74. package/docs/highlight/styles/foundation.css +0 -88
  75. package/docs/highlight/styles/github-gist.css +0 -71
  76. package/docs/highlight/styles/github.css +0 -99
  77. package/docs/highlight/styles/gml.css +0 -78
  78. package/docs/highlight/styles/googlecode.css +0 -89
  79. package/docs/highlight/styles/grayscale.css +0 -101
  80. package/docs/highlight/styles/gruvbox-dark.css +0 -108
  81. package/docs/highlight/styles/gruvbox-light.css +0 -108
  82. package/docs/highlight/styles/hopscotch.css +0 -83
  83. package/docs/highlight/styles/hybrid.css +0 -102
  84. package/docs/highlight/styles/idea.css +0 -97
  85. package/docs/highlight/styles/ir-black.css +0 -73
  86. package/docs/highlight/styles/isbl-editor-dark.css +0 -112
  87. package/docs/highlight/styles/isbl-editor-light.css +0 -112
  88. package/docs/highlight/styles/kimbie.dark.css +0 -74
  89. package/docs/highlight/styles/kimbie.light.css +0 -74
  90. package/docs/highlight/styles/lightfair.css +0 -87
  91. package/docs/highlight/styles/magula.css +0 -70
  92. package/docs/highlight/styles/mono-blue.css +0 -59
  93. package/docs/highlight/styles/monokai-sublime.css +0 -83
  94. package/docs/highlight/styles/monokai.css +0 -70
  95. package/docs/highlight/styles/nord.css +0 -309
  96. package/docs/highlight/styles/obsidian.css +0 -88
  97. package/docs/highlight/styles/ocean.css +0 -74
  98. package/docs/highlight/styles/paraiso-dark.css +0 -72
  99. package/docs/highlight/styles/paraiso-light.css +0 -72
  100. package/docs/highlight/styles/pojoaque.css +0 -83
  101. package/docs/highlight/styles/pojoaque.jpg +0 -0
  102. package/docs/highlight/styles/purebasic.css +0 -96
  103. package/docs/highlight/styles/qtcreator_dark.css +0 -83
  104. package/docs/highlight/styles/qtcreator_light.css +0 -83
  105. package/docs/highlight/styles/railscasts.css +0 -106
  106. package/docs/highlight/styles/rainbow.css +0 -85
  107. package/docs/highlight/styles/routeros.css +0 -108
  108. package/docs/highlight/styles/school-book.css +0 -72
  109. package/docs/highlight/styles/school-book.png +0 -0
  110. package/docs/highlight/styles/shades-of-purple.css +0 -97
  111. package/docs/highlight/styles/solarized-dark.css +0 -84
  112. package/docs/highlight/styles/solarized-light.css +0 -84
  113. package/docs/highlight/styles/sunburst.css +0 -102
  114. package/docs/highlight/styles/tomorrow-night-blue.css +0 -75
  115. package/docs/highlight/styles/tomorrow-night-bright.css +0 -74
  116. package/docs/highlight/styles/tomorrow-night-eighties.css +0 -74
  117. package/docs/highlight/styles/tomorrow-night.css +0 -75
  118. package/docs/highlight/styles/tomorrow.css +0 -72
  119. package/docs/highlight/styles/vs.css +0 -68
  120. package/docs/highlight/styles/vs2015.css +0 -115
  121. package/docs/highlight/styles/xcode.css +0 -104
  122. package/docs/highlight/styles/xt256.css +0 -92
  123. package/docs/highlight/styles/zenburn.css +0 -80
  124. package/docs/images/console.svg +0 -12
  125. package/docs/images/dark_ss.png +0 -0
  126. package/docs/images/easy.svg +0 -14
  127. package/docs/images/fast.svg +0 -8
  128. package/docs/images/gears.svg +0 -11
  129. package/docs/images/light_ss.png +0 -0
  130. package/docs/images/logo.png +0 -0
  131. package/docs/images/love.svg +0 -8
  132. package/docs/images/mask.svg +0 -16
  133. package/docs/images/mouse.svg +0 -7
  134. package/docs/images/pdf_sample1.png +0 -0
  135. package/docs/images/pdf_sample2.png +0 -0
  136. package/docs/images/webcomponent.svg +0 -13
  137. package/docs/index.css +0 -254
  138. package/docs/index.html +0 -376
  139. package/docs/rapipdf-min.js +0 -95
  140. package/docs/specs/allof-primitives.json +0 -80
  141. package/docs/specs/allof.json +0 -73
  142. package/docs/specs/anyof.json +0 -84
  143. package/docs/specs/basic.json +0 -75
  144. package/docs/specs/bitbucket.json +0 -12916
  145. package/docs/specs/data-types.yaml +0 -168
  146. package/docs/specs/gcloud.json +0 -1347
  147. package/docs/specs/no-server.json +0 -1
  148. package/docs/specs/oneof.json +0 -64
  149. package/docs/specs/petstore.json +0 -1042
  150. package/docs/specs/petstore_extended.yaml +0 -889
  151. package/docs/specs/temp.json +0 -53
  152. package/docs/specs/test-specs/large-models.json +0 -5998
  153. package/docs/specs/test-specs/long-descriptions.json +0 -5443
  154. package/docs/specs/test-specs/long-paths.json +0 -9562
  155. package/docs/specs/test-specs/oneof-allof-nested.yaml +0 -105
  156. package/docs/specs/test-specs/partial-spec-main.json +0 -29
  157. package/docs/specs/test-specs/partial.json +0 -17
  158. package/docs/specs/test-specs/petstore_complex_request.yaml +0 -335
  159. package/docs/specs/test-specs/petstore_experimental.yaml +0 -167
  160. package/docs/specs/test-specs/xxx-of-with-primitives-and-recursive-model.yaml +0 -952
  161. package/docs/welcome.html +0 -369
  162. package/index.html +0 -48
  163. package/logo.png +0 -0
  164. package/src/index.js +0 -3
  165. package/src/markdown.js +0 -120
  166. package/src/object-tree-gen.js +0 -370
  167. package/src/pdf-gen.js +0 -113
  168. package/src/pdf-parts-gen.js +0 -488
  169. package/src/rapipdf.js +0 -246
  170. package/src/spec-parser.js +0 -162
  171. package/src/table-layouts.js +0 -35
  172. package/src/vfs_fonts.js +0 -7
  173. package/webpack.config.js +0 -118
@@ -1,370 +0,0 @@
1
- /* Generates an object containing type and constraint info */
2
- export function getTypeInfo(schema) {
3
- if (!schema) {
4
- return;
5
- }
6
- const info = {
7
- type: schema.$ref
8
- ? '{recursive}'
9
- : schema.enum
10
- ? 'enum'
11
- : schema.format
12
- ? schema.format
13
- : schema.type,
14
- format: schema.format ? schema.format : '',
15
- pattern: (schema.pattern && !schema.enum) ? schema.pattern : '',
16
- readOrWriteOnly: schema.readOnly
17
- ? 'READ-ONLY'
18
- : schema.writeOnly
19
- ? 'WRITE-ONLY'
20
- : '',
21
- deprecated: schema.deprecated ? 'DEPRECATED' : '',
22
- default: schema.default === 0 ? '0' : (schema.default ? schema.default : ''),
23
- description: schema.description ? schema.description : '',
24
- allowedValues: '',
25
- constrain: '',
26
- arrayType: '',
27
- typeInfoText: '',
28
- };
29
- if (info.type === '{recursive}') {
30
- info.description = schema.$ref.substring(schema.$ref.lastIndexOf('/') + 1);
31
- }
32
-
33
- // Set the Type
34
- if (schema.enum) {
35
- let opt = '';
36
- schema.enum.map((v) => {
37
- opt += `${v}, `;
38
- });
39
- info.type = 'enum';
40
- info.allowedValues = opt.slice(0, -2);
41
- } else if (schema.type) {
42
- info.type = schema.type;
43
- }
44
-
45
- if (schema.type === 'array' || schema.items) {
46
- const arraySchema = schema.items;
47
- info.arrayType = `${schema.type} of ${arraySchema.type}`;
48
- info.default = arraySchema.default === 0 ? '0 ' : (arraySchema.default ? arraySchema.default : '');
49
- if (arraySchema.enum) {
50
- let opt = '';
51
- arraySchema.enum.map((v) => {
52
- opt += `${v}, `;
53
- });
54
- info.allowedValues = opt.slice(0, -2);
55
- }
56
- } else if (schema.type === 'integer' || schema.type === 'number') {
57
- if (schema.minimum !== undefined && schema.maximum !== undefined) {
58
- info.constrain = `${schema.exclusiveMinimum ? '>' : 'between '}${schema.minimum} and ${schema.exclusiveMaximum ? '<' : ''} ${schema.maximum}`;
59
- } else if (schema.minimum !== undefined && schema.maximum === undefined) {
60
- info.constrain = `${schema.exclusiveMinimum ? '>' : '>='}${schema.minimum}`;
61
- } else if (schema.minimum === undefined && schema.maximum !== undefined) {
62
- info.constrain = `${schema.exclusiveMaximum ? '<' : '<='}${schema.maximum}`;
63
- }
64
- if (schema.multipleOf !== undefined) {
65
- info.constrain = `multiple of ${schema.multipleOf}`;
66
- }
67
- } else if (schema.type === 'string') {
68
- if (schema.minLength !== undefined && schema.maxLength !== undefined) {
69
- info.constrain = `${schema.minLength} to ${schema.maxLength} chars`;
70
- } else if (schema.minLength !== undefined && schema.maxLength === undefined) {
71
- info.constrain = `min:${schema.minLength} chars`;
72
- } else if (schema.minLength === undefined && schema.maxLength !== undefined) {
73
- info.constrain = `max:${schema.maxLength} chars`;
74
- }
75
- }
76
- info.typeInfoText = `${info.type}~|~${info.readOrWriteOnly} ${info.deprecated}~|~${info.constrain}~|~${info.default}~|~${info.allowedValues}~|~${info.pattern}~|~${info.description}`;
77
- return info;
78
- }
79
-
80
- function generatePropDescription(propDescrArray, localize) {
81
- const descrStack = [];
82
- // Set Read or Write only
83
- if (propDescrArray[1].trim()) {
84
- descrStack.push({
85
- text: `${propDescrArray[1]}`, style: ['sub', 'b', 'darkGray'], margin: [0, 3, 0, 0],
86
- });
87
- }
88
-
89
- // Set Constraints
90
- if (propDescrArray[2]) {
91
- descrStack.push({
92
- text: `${propDescrArray[2]}`, style: ['small', 'mono', 'darkGray'],
93
- });
94
- }
95
-
96
- // Set Default
97
- if (propDescrArray[3]) {
98
- descrStack.push({
99
- text: [
100
- { text: `${localize.default}:`, style: ['sub', 'b', 'darkGray'] },
101
- { text: propDescrArray[3], style: ['small', 'darkGray', 'mono'] },
102
- ],
103
- });
104
- }
105
-
106
- // Set Allowed
107
- if (propDescrArray[4]) {
108
- descrStack.push({
109
- text: [
110
- { text: `${localize.allowed}:`, style: ['sub', 'b', 'darkGray'] },
111
- { text: propDescrArray[4], style: ['small', 'lightGray', 'mono'] },
112
- ],
113
- });
114
- }
115
-
116
- // Set Pattern
117
- if (propDescrArray[5]) {
118
- descrStack.push({
119
- text: [
120
- { text: `${localize.pattern}:`, style: ['sub', 'b', 'darkGray'] },
121
- { text: propDescrArray[5], style: ['small', 'lightGray', 'mono'] },
122
- ],
123
- });
124
- }
125
- if (propDescrArray[6]) {
126
- descrStack.push({
127
- text: `${propDescrArray[6]}`,
128
- style: ['sub', 'lightGray'],
129
- margin: [0, 3, 0, 0],
130
- });
131
- }
132
- return descrStack;
133
- }
134
-
135
- /**
136
- * For changing OpenAPI-Schema to an Object Notation,
137
- * This Object would further be an input to `objectToTree()` to generate a pdfDefs representing an Object-Tree
138
- * @param {object} schema - Schema object from OpenAPI spec
139
- * @param {object} obj - recursivly pass this object to generate object notation
140
- * @param {number} level - contains the recursion depth
141
- */
142
- export function schemaInObjectNotation(schema, obj = {}, level = 0) {
143
- if (!schema) {
144
- return;
145
- }
146
- if (schema.type === 'object' || schema.properties) { // If Object
147
- obj['::description'] = schema.description ? schema.description : '';
148
- obj['::type'] = 'object';
149
- for (const key in schema.properties) {
150
- if (schema.required && schema.required.includes(key)) {
151
- obj[`${key}*`] = schemaInObjectNotation(schema.properties[key], {}, (level + 1));
152
- } else {
153
- obj[key] = schemaInObjectNotation(schema.properties[key], {}, (level + 1));
154
- }
155
- }
156
- } else if (schema.items) { // If Array
157
- obj['::description'] = schema.description ? schema.description : '';
158
- obj['::type'] = 'array';
159
- obj['::props'] = schemaInObjectNotation(schema.items, {}, (level + 1));
160
- } else if (schema.allOf) {
161
- const objWithAllProps = {};
162
- if (schema.allOf.length === 1 && !schema.allOf[0].properties && !schema.allOf[0].items) {
163
- // If allOf has single item and the type is not an object or array, then its a primitive
164
- const tempSchema = schema.allOf[0];
165
- return `${getTypeInfo(tempSchema).typeInfoText}`;
166
- }
167
- // If allOf is an array of multiple elements, then all the keys makes a single object
168
- schema.allOf.map((v) => {
169
- if (v.type === 'object' || v.properties || v.allOf || v.anyOf || v.oneOf) {
170
- const partialObj = schemaInObjectNotation(v, {}, (level + 1));
171
- Object.assign(objWithAllProps, partialObj);
172
- } else if (v.type === 'array' || v.items) {
173
- const partialObj = [schemaInObjectNotation(v, {}, (level + 1))];
174
- Object.assign(objWithAllProps, partialObj);
175
- } else if (v.type) {
176
- const prop = `prop${Object.keys(objWithAllProps).length}`;
177
- const typeObj = getTypeInfo(v);
178
- objWithAllProps[prop] = `${typeObj.typeInfoText}`;
179
- } else {
180
- return '';
181
- }
182
- });
183
-
184
- obj = objWithAllProps;
185
- } else if (schema.anyOf || schema.oneOf) {
186
- let i = 1;
187
- const objWithAnyOfProps = {};
188
- const xxxOf = schema.anyOf ? 'anyOf' : 'oneOf';
189
- schema[xxxOf].map((v) => {
190
- if (v.type === 'object' || v.properties || v.allOf || v.anyOf || v.oneOf) {
191
- const partialObj = schemaInObjectNotation(v, {}, (level + 1));
192
- objWithAnyOfProps[`OPTION:${i}`] = partialObj;
193
- i++;
194
- } else if (v.type === 'array' || v.items) {
195
- const partialObj = [schemaInObjectNotation(v, {}, (level + 1))];
196
- Object.assign(objWithAnyOfProps, partialObj);
197
- } else {
198
- const prop = `prop${Object.keys(objWithAnyOfProps).length}`;
199
- objWithAnyOfProps[prop] = `${getTypeInfo(v).typeInfoText}`;
200
- }
201
- });
202
- obj[(schema.anyOf ? 'ANY:OF' : 'ONE:OF')] = objWithAnyOfProps;
203
- } else {
204
- const typeObj = getTypeInfo(schema);
205
- if (typeObj.typeInfoText) {
206
- return `${typeObj.typeInfoText}`;
207
- }
208
- return '';
209
- }
210
- return obj;
211
- }
212
-
213
- /**
214
- * For changing an object to Tree (array of pdfDefs, which when feeded to pdfMake would produce a indented object tree)
215
- * @param {object} obj - keys to iterate
216
- * @param {string} prevKeyDataType - data-type of previous key, it is either 'primitive', 'object' or 'array', based on this appropriate braces are used
217
- * @param {string} prevKey - name of the key from previous recursive call stack
218
- */
219
- export function objectToTree(obj, localize, prevKeyDataType = 'object', prevKey = '') {
220
- if (typeof obj !== 'object') {
221
- const propDescrArray = obj.split('~|~');
222
- if (prevKeyDataType === 'array') {
223
- propDescrArray[0] = `[${propDescrArray[0]}]`;
224
- }
225
- const descrStack = generatePropDescription(propDescrArray, localize);
226
-
227
- return [
228
- { text: prevKey, style: ['small', 'mono'], margin: 0 },
229
- { text: (propDescrArray[0] ? propDescrArray[0] : ''), style: ['small', 'mono', 'lightGray'], margin: 0 },
230
- { stack: descrStack, margin: 0 },
231
- ];
232
- }
233
-
234
- // Important - pdfMake needs one row with all the cells for colSpan to work properly
235
- const rows = [
236
- [{ text: '', margin: 0 }, { text: '', margin: 0 }, { text: '', margin: 0 }],
237
- ];
238
-
239
- for (const key in obj) {
240
- // If ANY_OF or ONE_OF
241
- if (key === 'ANY:OF' || key === 'ONE:OF') {
242
- const allOptions = [];
243
- for (const k in obj[key]) {
244
- allOptions.push(objectToTree(obj[key][k], localize, 'object', k));
245
- }
246
- return [
247
- {
248
- colSpan: 3,
249
- stack: [
250
- { text: `${prevKey}`, style: ['small', 'mono'] },
251
- {
252
- margin: [10, 0, 0, 0],
253
- stack: [
254
- { text: `${key.replace(':', ' ')}`, style: ['sub', 'blue', 'b'], margin: [0, 5, 0, 0] },
255
- ...allOptions,
256
- ],
257
- },
258
- ],
259
- },
260
- ];
261
- }
262
- if (typeof obj[key] === 'object' && obj[key]['::type']) {
263
- let objectDef;
264
- if (obj[key]['::type'] === 'array') {
265
- objectDef = objectToTree(obj[key]['::props'], localize, obj[key]['::type'], key, 'array');
266
- } else {
267
- objectDef = objectToTree(obj[key], localize, obj[key]['::type'], key);
268
- }
269
- rows.push(objectDef);
270
- } else if (key.startsWith('::') === false) {
271
- const primitiveDef = objectToTree(obj[key], localize, 'primitive', key);
272
- rows.push(primitiveDef);
273
- }
274
- }
275
-
276
- let keyDef;
277
- if (prevKey.startsWith('OPTION:')) {
278
- keyDef = {
279
- text: [
280
- { text: `${prevKey.replace(':', ' ')}`, style: ['sub', 'b', 'blue'] },
281
- { text: `${prevKeyDataType === 'array' ? '[{' : '{'}`, style: ['small', 'mono'] },
282
- ],
283
- };
284
- } else {
285
- keyDef = {
286
- stack: [
287
- { text: `${prevKey} ${prevKeyDataType === 'array' ? '[{' : '{'}`, style: ['small', 'mono'] },
288
- ],
289
- };
290
-
291
- if (obj['::description'] || prevKeyDataType === 'array') {
292
- keyDef.stack.push(
293
- {
294
- text: `${prevKeyDataType === 'array' ? 'Array of object: ' : ''} ${obj['::description'] ? obj['::description'] : ''}`,
295
- style: ['sub', 'gray'],
296
- margin: [0, 0, 0, 4],
297
- },
298
- );
299
- }
300
- }
301
-
302
- return [{
303
- colSpan: 3,
304
- stack: [
305
- keyDef,
306
- {
307
- margin: [10, 0, 0, 0],
308
- layout: {
309
- defaultBorder: false,
310
- hLineWidth() { return 0; },
311
- vLineWidth() { return 0; },
312
- paddingTop() { return 0; },
313
- paddingBottom() { return 0; },
314
- },
315
- table: {
316
- headerRows: 0,
317
- widths: ['auto', 'auto', '*'],
318
- dontBreakRows: false,
319
- body: rows,
320
- },
321
- },
322
- { text: `${prevKeyDataType === 'array' ? '}]' : '}'}`, style: ['small', 'mono'] },
323
- ],
324
- }];
325
- }
326
-
327
- /**
328
- * For changing an object to Table-Tree (array of pdfDefs, which when feeded to pdfMake would produce a indented table tree)
329
- * @param {object} obj - keys to iterate
330
- * @param {string} keyDataType - is 'primitive', 'object' or 'array', based on this appropriate braces are used
331
- * @param {string} keyName - name of the key from previous recursive call stack
332
- * @param {string} keyDescr - description of the key
333
- */
334
- export function objectToTableTree(obj, localize, allRows = [], level = 0) {
335
- const leftMargin = level * 10;
336
- if (!obj || typeof obj === 'string') {
337
- return [{ text: '' }];
338
- }
339
- for (const key in obj) {
340
- if (typeof obj[key] === 'object') {
341
- let objType;
342
- if (obj[key]['::type'] === 'array') {
343
- objType = 'array';
344
- } else {
345
- objType = 'object';
346
- }
347
- const objRow = [
348
- { text: key, style: ['small', 'b'], margin: [leftMargin, 0, 0, 0] },
349
- { text: objType, style: ['small', 'mono', 'lightGray'], margin: 0 },
350
- { text: '', margin: 0 },
351
- ];
352
- allRows.push(objRow);
353
- if (obj[key]['::type'] === 'array') {
354
- objectToTableTree(obj[key]['::props'], localize, allRows, (level + 1));
355
- } else {
356
- objectToTableTree(obj[key], localize, allRows, (level + 1));
357
- }
358
- } else if (typeof obj[key] === 'string' && (key.startsWith('::') === false)) {
359
- const typeAndDescr = obj[key].split('~|~');
360
- const descrStack = generatePropDescription(typeAndDescr, localize);
361
-
362
- allRows.push([
363
- { text: key, style: ['small'], margin: [leftMargin, 0, 0, 0] },
364
- { text: (typeAndDescr[0] ? typeAndDescr[0] : ''), style: ['small', 'mono', 'lightGray'], margin: 0 },
365
- { stack: ((descrStack && descrStack.length) > 0 ? descrStack : [{ text: '' }]), margin: 0 },
366
- ]);
367
- }
368
- }
369
- return allRows;
370
- }
package/src/pdf-gen.js DELETED
@@ -1,113 +0,0 @@
1
- import pdfMake from 'pdfmake/build/pdfmake.min';
2
- import pdfFonts from '@/vfs_fonts';
3
- // import pdfFonts from "pdfmake/build/vfs_fonts";
4
-
5
- import ProcessSpec from '@/spec-parser';
6
- import {
7
- getInfoDef, getSecurityDef, getApiDef, getApiListDef,
8
- } from '@/pdf-parts-gen';
9
-
10
- export default async function createPdf(specUrl, options) {
11
- const parsedSpec = await ProcessSpec(specUrl, options.pdfSortTags);
12
-
13
- const pdfStyles = {
14
- title: { fontSize: 32 },
15
- h1: { fontSize: 22 },
16
- h2: { fontSize: 20 },
17
- h3: { fontSize: 18 },
18
- h4: { fontSize: 16 },
19
- h5: { fontSize: 14 },
20
- h6: { fontSize: 12, bold: true },
21
- p: { fontSize: 12 },
22
- small: { fontSize: 10 },
23
- sub: { fontSize: 8 },
24
- right: { alignment: 'right' },
25
- left: { alignment: 'left' },
26
- topMargin1: { margin: [0, 180, 0, 10] },
27
- topMargin2: { margin: [0, 60, 0, 5] },
28
- topMargin3: { margin: [0, 20, 0, 3] },
29
- topMargin4: { margin: [0, 15, 0, 3] },
30
- topMarginRegular: { margin: [0, 3, 0, 0] },
31
- tableMargin: { margin: [0, 5, 0, 15] },
32
- b: { bold: true },
33
- i: { italics: true },
34
- primary: { color: (options.pdfPrimaryColor ? options.pdfPrimaryColor : '#b44646') },
35
- alternate: { color: (options.pdfAlternateColor ? options.pdfAlternateColor : '#005b96') },
36
- gray: { color: 'gray' },
37
- lightGray: { color: '#aaaaaa' },
38
- darkGray: { color: '#666666' },
39
- red: { color: 'orangered' },
40
- blue: { color: '#005b96' },
41
- mono: { font: 'RobotoMono', fontSize: 10 },
42
- };
43
-
44
- const allContent = [];
45
- let infoDef = {};
46
- let tocDef = {};
47
- let securityDef = {};
48
- let apiListDef = {};
49
- let apiDef = {};
50
-
51
- if (options.includeInfo) {
52
- infoDef = getInfoDef(parsedSpec, options.pdfTitle, options.localize);
53
- allContent.push(infoDef);
54
- }
55
- if (options.includeToc) {
56
- tocDef = {
57
- toc: {
58
- title: { text: options.localize.index, style: ['b', 'h2'] },
59
- numberStyle: { bold: true },
60
- style: ['small'],
61
- },
62
- pageBreak: 'after',
63
- };
64
- // allContent.push({text:'', pageBreak:'after'});
65
- allContent.push(tocDef);
66
- }
67
- if (options.includeSecurity) {
68
- securityDef = getSecurityDef(parsedSpec, options.localize);
69
- allContent.push(securityDef);
70
- }
71
- if (options.includeApiDetails) {
72
- apiDef = getApiDef(parsedSpec, '', options.pdfSchemaStyle, options.localize, options.includeExample);
73
- allContent.push(apiDef);
74
- }
75
- if (options.includeApiList) {
76
- apiListDef = getApiListDef(parsedSpec, options.localize.apiList, options.localize);
77
- allContent.push(apiListDef);
78
- }
79
-
80
- const finalDocDef = {
81
- footer(currentPage, pageCount) {
82
- return {
83
- margin: 10,
84
- columns: [
85
- { text: options.pdfFooterText, style: ['sub', 'gray', 'left'] },
86
- { text: `${currentPage} of ${pageCount}`, style: ['sub', 'gray', 'right'] },
87
- ],
88
- };
89
- },
90
- content: allContent,
91
- styles: pdfStyles,
92
- };
93
-
94
-
95
- pdfMake.fonts = {
96
- Roboto: {
97
- normal: 'Roboto-Regular.ttf',
98
- bold: 'Roboto-Medium.ttf',
99
- italics: 'Roboto-Italic.ttf',
100
- bolditalics: 'Roboto-Medium.ttf',
101
- },
102
- RobotoMono: {
103
- normal: 'RobotoMono-Regular.ttf',
104
- bold: 'RobotoMono-Regular.ttf',
105
- italics: 'RobotoMono-Regular.ttf',
106
- bolditalics: 'RobotoMono-Regular.ttf',
107
- },
108
-
109
- };
110
- // pdfMake.vfs = pdfFonts.pdfMake.vfs;
111
- pdfMake.vfs = pdfFonts;
112
- pdfMake.createPdf(finalDocDef).open();
113
- }