rapipdf 2.2.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 (175) 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 -7
  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 -53
  21. package/docs/api.html +0 -285
  22. package/docs/examples/example1.html +0 -68
  23. package/docs/examples/list.html +0 -27
  24. package/docs/examples/rapidoc-regular.woff2 +0 -0
  25. package/docs/examples/rapidoc-semi-bold.woff2 +0 -0
  26. package/docs/examples/roboto-mono-bold.woff2 +0 -0
  27. package/docs/examples/roboto-mono-regular.woff2 +0 -0
  28. package/docs/highlight/CHANGES.md +0 -1803
  29. package/docs/highlight/LICENSE +0 -24
  30. package/docs/highlight/README.md +0 -188
  31. package/docs/highlight/README.ru.md +0 -142
  32. package/docs/highlight/highlight.pack.js +0 -2
  33. package/docs/highlight/styles/a11y-dark.css +0 -99
  34. package/docs/highlight/styles/a11y-light.css +0 -99
  35. package/docs/highlight/styles/agate.css +0 -108
  36. package/docs/highlight/styles/an-old-hope.css +0 -89
  37. package/docs/highlight/styles/androidstudio.css +0 -66
  38. package/docs/highlight/styles/arduino-light.css +0 -88
  39. package/docs/highlight/styles/arta.css +0 -73
  40. package/docs/highlight/styles/ascetic.css +0 -45
  41. package/docs/highlight/styles/atelier-cave-dark.css +0 -83
  42. package/docs/highlight/styles/atelier-cave-light.css +0 -85
  43. package/docs/highlight/styles/atelier-dune-dark.css +0 -69
  44. package/docs/highlight/styles/atelier-dune-light.css +0 -69
  45. package/docs/highlight/styles/atelier-estuary-dark.css +0 -84
  46. package/docs/highlight/styles/atelier-estuary-light.css +0 -84
  47. package/docs/highlight/styles/atelier-forest-dark.css +0 -69
  48. package/docs/highlight/styles/atelier-forest-light.css +0 -69
  49. package/docs/highlight/styles/atelier-heath-dark.css +0 -69
  50. package/docs/highlight/styles/atelier-heath-light.css +0 -69
  51. package/docs/highlight/styles/atelier-lakeside-dark.css +0 -69
  52. package/docs/highlight/styles/atelier-lakeside-light.css +0 -69
  53. package/docs/highlight/styles/atelier-plateau-dark.css +0 -84
  54. package/docs/highlight/styles/atelier-plateau-light.css +0 -84
  55. package/docs/highlight/styles/atelier-savanna-dark.css +0 -84
  56. package/docs/highlight/styles/atelier-savanna-light.css +0 -84
  57. package/docs/highlight/styles/atelier-seaside-dark.css +0 -69
  58. package/docs/highlight/styles/atelier-seaside-light.css +0 -69
  59. package/docs/highlight/styles/atelier-sulphurpool-dark.css +0 -69
  60. package/docs/highlight/styles/atelier-sulphurpool-light.css +0 -69
  61. package/docs/highlight/styles/atom-one-dark-reasonable.css +0 -77
  62. package/docs/highlight/styles/atom-one-dark.css +0 -96
  63. package/docs/highlight/styles/atom-one-light.css +0 -96
  64. package/docs/highlight/styles/brown-paper.css +0 -64
  65. package/docs/highlight/styles/brown-papersq.png +0 -0
  66. package/docs/highlight/styles/codepen-embed.css +0 -60
  67. package/docs/highlight/styles/color-brewer.css +0 -71
  68. package/docs/highlight/styles/darcula.css +0 -77
  69. package/docs/highlight/styles/dark.css +0 -63
  70. package/docs/highlight/styles/darkula.css +0 -6
  71. package/docs/highlight/styles/default.css +0 -99
  72. package/docs/highlight/styles/docco.css +0 -97
  73. package/docs/highlight/styles/dracula.css +0 -76
  74. package/docs/highlight/styles/far.css +0 -71
  75. package/docs/highlight/styles/foundation.css +0 -88
  76. package/docs/highlight/styles/github-gist.css +0 -71
  77. package/docs/highlight/styles/github.css +0 -99
  78. package/docs/highlight/styles/gml.css +0 -78
  79. package/docs/highlight/styles/googlecode.css +0 -89
  80. package/docs/highlight/styles/grayscale.css +0 -101
  81. package/docs/highlight/styles/gruvbox-dark.css +0 -108
  82. package/docs/highlight/styles/gruvbox-light.css +0 -108
  83. package/docs/highlight/styles/hopscotch.css +0 -83
  84. package/docs/highlight/styles/hybrid.css +0 -102
  85. package/docs/highlight/styles/idea.css +0 -97
  86. package/docs/highlight/styles/ir-black.css +0 -73
  87. package/docs/highlight/styles/isbl-editor-dark.css +0 -112
  88. package/docs/highlight/styles/isbl-editor-light.css +0 -112
  89. package/docs/highlight/styles/kimbie.dark.css +0 -74
  90. package/docs/highlight/styles/kimbie.light.css +0 -74
  91. package/docs/highlight/styles/lightfair.css +0 -87
  92. package/docs/highlight/styles/magula.css +0 -70
  93. package/docs/highlight/styles/mono-blue.css +0 -59
  94. package/docs/highlight/styles/monokai-sublime.css +0 -83
  95. package/docs/highlight/styles/monokai.css +0 -70
  96. package/docs/highlight/styles/nord.css +0 -309
  97. package/docs/highlight/styles/obsidian.css +0 -88
  98. package/docs/highlight/styles/ocean.css +0 -74
  99. package/docs/highlight/styles/paraiso-dark.css +0 -72
  100. package/docs/highlight/styles/paraiso-light.css +0 -72
  101. package/docs/highlight/styles/pojoaque.css +0 -83
  102. package/docs/highlight/styles/pojoaque.jpg +0 -0
  103. package/docs/highlight/styles/purebasic.css +0 -96
  104. package/docs/highlight/styles/qtcreator_dark.css +0 -83
  105. package/docs/highlight/styles/qtcreator_light.css +0 -83
  106. package/docs/highlight/styles/railscasts.css +0 -106
  107. package/docs/highlight/styles/rainbow.css +0 -85
  108. package/docs/highlight/styles/routeros.css +0 -108
  109. package/docs/highlight/styles/school-book.css +0 -72
  110. package/docs/highlight/styles/school-book.png +0 -0
  111. package/docs/highlight/styles/shades-of-purple.css +0 -97
  112. package/docs/highlight/styles/solarized-dark.css +0 -84
  113. package/docs/highlight/styles/solarized-light.css +0 -84
  114. package/docs/highlight/styles/sunburst.css +0 -102
  115. package/docs/highlight/styles/tomorrow-night-blue.css +0 -75
  116. package/docs/highlight/styles/tomorrow-night-bright.css +0 -74
  117. package/docs/highlight/styles/tomorrow-night-eighties.css +0 -74
  118. package/docs/highlight/styles/tomorrow-night.css +0 -75
  119. package/docs/highlight/styles/tomorrow.css +0 -72
  120. package/docs/highlight/styles/vs.css +0 -68
  121. package/docs/highlight/styles/vs2015.css +0 -115
  122. package/docs/highlight/styles/xcode.css +0 -104
  123. package/docs/highlight/styles/xt256.css +0 -92
  124. package/docs/highlight/styles/zenburn.css +0 -80
  125. package/docs/images/console.svg +0 -12
  126. package/docs/images/dark_ss.png +0 -0
  127. package/docs/images/easy.svg +0 -14
  128. package/docs/images/fast.svg +0 -8
  129. package/docs/images/gears.svg +0 -11
  130. package/docs/images/light_ss.png +0 -0
  131. package/docs/images/logo-outline.png +0 -0
  132. package/docs/images/logo.png +0 -0
  133. package/docs/images/love.svg +0 -8
  134. package/docs/images/mask.svg +0 -16
  135. package/docs/images/mouse.svg +0 -7
  136. package/docs/images/pdf_sample1.png +0 -0
  137. package/docs/images/pdf_sample2.png +0 -0
  138. package/docs/images/webcomponent.svg +0 -13
  139. package/docs/index.css +0 -257
  140. package/docs/index.html +0 -186
  141. package/docs/rapipdf-min.js +0 -95
  142. package/docs/specs/allof-primitives.json +0 -80
  143. package/docs/specs/allof.json +0 -73
  144. package/docs/specs/anyof.json +0 -84
  145. package/docs/specs/basic.json +0 -75
  146. package/docs/specs/bitbucket.json +0 -12916
  147. package/docs/specs/data-types.yaml +0 -168
  148. package/docs/specs/gcloud.json +0 -1347
  149. package/docs/specs/no-server.json +0 -1
  150. package/docs/specs/oneof.json +0 -64
  151. package/docs/specs/petstore.json +0 -1042
  152. package/docs/specs/petstore_extended.yaml +0 -889
  153. package/docs/specs/temp.json +0 -53
  154. package/docs/specs/test-specs/large-models.json +0 -5998
  155. package/docs/specs/test-specs/long-descriptions.json +0 -5443
  156. package/docs/specs/test-specs/long-paths.json +0 -9562
  157. package/docs/specs/test-specs/oneof-allof-nested.yaml +0 -105
  158. package/docs/specs/test-specs/partial-spec-main.json +0 -29
  159. package/docs/specs/test-specs/partial.json +0 -17
  160. package/docs/specs/test-specs/petstore_complex_request.yaml +0 -335
  161. package/docs/specs/test-specs/petstore_experimental.yaml +0 -167
  162. package/docs/specs/test-specs/xxx-of-with-primitives-and-recursive-model.yaml +0 -952
  163. package/docs/welcome.html +0 -186
  164. package/index.html +0 -48
  165. package/logo.png +0 -0
  166. package/src/index.js +0 -3
  167. package/src/markdown.js +0 -120
  168. package/src/object-tree-gen.js +0 -370
  169. package/src/pdf-gen.js +0 -113
  170. package/src/pdf-parts-gen.js +0 -488
  171. package/src/rapipdf.js +0 -246
  172. package/src/spec-parser.js +0 -178
  173. package/src/table-layouts.js +0 -35
  174. package/src/vfs_fonts.js +0 -7
  175. package/webpack.config.js +0 -118
@@ -1,488 +0,0 @@
1
- import marked from 'marked';
2
- import { rowLinesTableLayout } from '@/table-layouts';
3
- import { getMarkDownDef } from '@/markdown';
4
- import {
5
- getTypeInfo,
6
- schemaInObjectNotation,
7
- objectToTree,
8
- objectToTableTree,
9
- } from '@/object-tree-gen';
10
-
11
- // Info Def
12
- export function getInfoDef(spec, bookTitle, localize) {
13
- let content;
14
- if (spec.info) {
15
- let contactDef = [];
16
- let contactName;
17
- let contactEmail;
18
- let contactUrl;
19
- let termsOfService;
20
-
21
- if (spec.info.contact) {
22
- if (spec.info.contact.name) {
23
- contactName = { text: [{ text: `\n${localize.name}: `, style: ['b', 'small'] }, { text: spec.info.contact.name, style: ['small'] }] };
24
- }
25
- if (spec.info.contact.email) {
26
- contactEmail = { text: [{ text: `\n${localize.email}: `, style: ['b', 'small'] }, { text: spec.info.contact.email, style: ['small'] }] };
27
- }
28
- if (spec.info.contact.url) {
29
- contactUrl = { text: [{ text: `\n${localize.url}: `, style: ['b', 'small'] }, { text: spec.info.contact.url, style: ['small', 'blue'], link: spec.info.contact.url }] };
30
- }
31
- if (spec.info.termsOfService) {
32
- termsOfService = { text: [{ text: `\n${localize.termsOfService}: `, style: ['b', 'small'] }, { text: spec.info.termsOfService, style: ['small', 'blue'], link: spec.info.termsOfService }] };
33
- }
34
- contactDef = [
35
- { text: localize.contact, style: ['p', 'b', 'topMargin3'] },
36
- {
37
- text: [
38
- contactName,
39
- contactEmail,
40
- contactUrl,
41
- termsOfService,
42
- ],
43
- },
44
- ];
45
- }
46
-
47
- let specInfDescrMarkDef;
48
- if (spec.info.description) {
49
- const tokens = marked.lexer(spec.info.description);
50
- specInfDescrMarkDef = {
51
- stack: getMarkDownDef(tokens),
52
- style: ['topMargin3'],
53
- };
54
- } else {
55
- specInfDescrMarkDef = '';
56
- }
57
-
58
- content = [
59
- { text: bookTitle || localize.apiReference, style: ['h2', 'primary', 'right', 'b', 'topMargin1'] },
60
- (spec.info.title ? { text: spec.info.title, style: ['title', 'right'] } : ''),
61
- (spec.info.version ? { text: `${localize.apiVersion}: ${spec.info.version}`, style: ['p', 'b', 'right', 'alternate'] } : ''),
62
- specInfDescrMarkDef,
63
- ...contactDef,
64
- { text: '', pageBreak: 'after' },
65
- ];
66
- } else {
67
- content = [
68
- { text: bookTitle || localize.apiReference, style: ['h1', 'bold', 'primary', 'right', 'topMargin1'] },
69
- { text: '', pageBreak: 'after' },
70
- ];
71
- }
72
- return content;
73
- }
74
-
75
- // Security Def
76
- export function getSecurityDef(spec, localize) {
77
- const content = [];
78
- if (spec.securitySchemes) {
79
- content.push({ text: localize.securityAndAuthentication, style: ['h3', 'b', 'primary', 'right', 'topMargin3'] });
80
- content.push({ text: localize.securitySchemes, style: ['b', 'tableMargin'] });
81
- const tableContent = [
82
- [{ text: localize.key, style: ['small', 'b'] }, { text: localize.type, style: ['small', 'b'] }, { text: localize.description, style: ['small', 'b'] }],
83
- ];
84
- for (const key in spec.securitySchemes) {
85
- tableContent.push([
86
- key,
87
- spec.securitySchemes[key].type + (spec.securitySchemes[key].scheme ? (`, ${spec.securitySchemes[key].scheme}`) : '') + (spec.securitySchemes[key].bearerFormat ? (`, ${spec.securitySchemes[key].bearerFormat}`) : ''),
88
- spec.securitySchemes[key].description ? spec.securitySchemes[key].description : '',
89
- ]);
90
- }
91
-
92
- content.push({
93
- table: {
94
- headerRows: 1,
95
- body: tableContent,
96
- },
97
- layout: rowLinesTableLayout,
98
- style: 'tableMargin',
99
- pageBreak: 'after',
100
- });
101
- }
102
- return content;
103
- }
104
-
105
- // Parameter Table
106
- function getParameterTableDef(parameters, paramType, localize, includeExample = false) {
107
- // let filteredParams= parameters ? parameters.filter(param => param.in === paramType):[];
108
- if (parameters === undefined || parameters.length === 0) {
109
- return;
110
- }
111
- const tableContent = [
112
- [
113
- { text: localize.name, style: ['sub', 'b', 'alternate'] },
114
- { text: localize.type, style: ['sub', 'b', 'alternate'] },
115
- { text: includeExample ? localize.example : '', style: ['sub', 'b', 'alternate'] },
116
- { text: localize.description, style: ['sub', 'b', 'alternate'] },
117
- ],
118
- ];
119
- if (paramType === 'FORM DATA') {
120
- for (const paramName in parameters) {
121
- const param = parameters[paramName];
122
- let { type } = param;
123
- const format = param.format === 'binary' ? '(binary)' : '';
124
- if (type === 'array') {
125
- type = `array of ${param.items.type}`;
126
- }
127
- tableContent.push([
128
- { text: paramName, style: ['small', 'mono'] },
129
- { text: type + format, style: ['small', 'mono'] },
130
- { text: includeExample ? (param.example ? param.example : (param.examples && param.examples[0] ? param.examples[0] : '')) : '', style: ['small'], margin: [0, 2, 0, 0] },
131
- { text: param.description, style: ['small'], margin: [0, 2, 0, 0] },
132
- ]);
133
- }
134
- } else {
135
- parameters.map((param) => {
136
- const paramSchema = getTypeInfo(param.schema);
137
- tableContent.push([
138
- {
139
- text: [
140
- { text: param.required ? '*' : '', style: ['small', 'b', 'red', 'mono'] },
141
- { text: param.name, style: ['small', 'mono'] },
142
- (paramSchema.deprecated ? { text: `\n${localize.deprecated}`, style: ['small', 'red', 'b'] } : ''),
143
- ],
144
- },
145
- {
146
- stack: [
147
- { text: `${paramSchema.type === 'array' ? paramSchema.arrayType : (paramSchema.format ? paramSchema.format : paramSchema.type)}`, style: ['small', 'mono'] },
148
- (paramSchema.constrain ? { text: paramSchema.constrain, style: ['small', 'gray'] } : ''),
149
- (paramSchema.allowedValues ? {
150
- text: [
151
- { text: `${localize.allowed}: `, style: ['b', 'sub'] },
152
- { text: paramSchema.allowedValues, style: ['small', 'lightGray'] },
153
- ],
154
- } : ''
155
- ),
156
- (paramSchema.pattern ? { text: `${localize.pattern}: ${paramSchema.pattern}`, style: ['small', 'gray'] } : ''),
157
- ],
158
- },
159
- { text: includeExample ? (param.example ? param.example : (param.examples && param.examples[0] ? param.examples[0] : '')) : '', style: ['small'], margin: [0, 2, 0, 0] },
160
- { text: param.description, style: ['small'], margin: [0, 2, 0, 0] },
161
- ]);
162
- });
163
- }
164
-
165
- return [
166
- { text: `${paramType} ${localize.parameters}`.toUpperCase(), style: ['small', 'b'], margin: [0, 10, 0, 0] },
167
- {
168
- table: {
169
- headerRows: 1,
170
- dontBreakRows: true,
171
- widths: ['auto', 'auto', includeExample ? 'auto' : 0, '*'],
172
- body: tableContent,
173
- },
174
- layout: rowLinesTableLayout,
175
- style: 'tableMargin',
176
- },
177
- ];
178
- }
179
-
180
- // Request Body Def
181
- function getRequestBodyDef(requestBody, schemaStyle, localize) {
182
- if (!requestBody) {
183
- return;
184
- }
185
- const content = [];
186
- let formParamDef;
187
- for (const contentType in requestBody.content) {
188
- const contentTypeObj = requestBody.content[contentType];
189
- const requestBodyDef = [
190
- { text: `${localize.requestBody} - ${contentType}`, margin: [0, 10, 0, 0], style: ['small', 'b'] },
191
- ];
192
-
193
- if ((contentType.includes('form') || contentType.includes('multipart-form')) && contentTypeObj.schema) {
194
- formParamDef = getParameterTableDef(contentTypeObj.schema.properties, 'FORM DATA', localize);
195
- content.push(formParamDef);
196
- } else if (contentType.includes('json') || contentType.includes('xml')) {
197
- let origSchema = requestBody.content[contentType].schema;
198
- if (origSchema) {
199
- origSchema = JSON.parse(JSON.stringify(origSchema));
200
- const schemaInObjectNotaion = schemaInObjectNotation(origSchema);
201
-
202
- if (schemaStyle === 'object') {
203
- let treeDef;
204
- if (schemaInObjectNotaion['::type'] && schemaInObjectNotaion['::type'] === 'array') {
205
- treeDef = objectToTree(schemaInObjectNotaion['::props'], localize, 'array');
206
- } else {
207
- treeDef = objectToTree(schemaInObjectNotaion, localize);
208
- }
209
- requestBodyDef.push(treeDef);
210
- } else {
211
- // if Schema Style is Tree
212
- let schemaTableTreeDef;
213
- if (schemaInObjectNotaion['::type'] && schemaInObjectNotaion['::type'] === 'array') {
214
- schemaTableTreeDef = objectToTableTree(schemaInObjectNotaion['::prop'], localize, 'array');
215
- } else {
216
- schemaTableTreeDef = objectToTableTree(schemaInObjectNotaion, localize);
217
- }
218
- if (schemaTableTreeDef && schemaTableTreeDef.length > 0 && Array.isArray(schemaTableTreeDef[0]) && schemaTableTreeDef[0].length > 0) {
219
- schemaTableTreeDef.unshift([
220
- { text: localize.name, style: ['sub', 'b', 'alternate'] },
221
- { text: localize.type, style: ['sub', 'b', 'alternate'] },
222
- { text: localize.description, style: ['sub', 'b', 'alternate'] },
223
- ]);
224
-
225
- requestBodyDef.push({
226
- table: {
227
- headerRows: 1,
228
- body: schemaTableTreeDef,
229
- },
230
- layout: rowLinesTableLayout,
231
- margin: [0, 3, 0, 0],
232
- });
233
- }
234
- }
235
- }
236
- content.push(requestBodyDef);
237
- }
238
- }
239
- return content;
240
- }
241
-
242
- // Response Def
243
- function getResponseDef(responses, schemaStyle, localize) {
244
- const respDef = [];
245
- for (const statusCode in responses) {
246
- const allResponseDefs = [];
247
- for (const contentType in responses[statusCode].content) {
248
- const responseDef = [
249
- { text: `${localize.responseModel} - ${contentType}`, margin: [10, 10, 0, 0], style: ['small', 'b'] },
250
- ];
251
-
252
- let origSchema = responses[statusCode].content[contentType].schema;
253
- if (origSchema) {
254
- origSchema = JSON.parse(JSON.stringify(origSchema));
255
- const schemaInObjectNotaion = schemaInObjectNotation(origSchema);
256
- if (schemaStyle === 'object') {
257
- let schemaTreeDef;
258
- if (schemaInObjectNotaion['::type'] && schemaInObjectNotaion['::type'] === 'array') {
259
- schemaTreeDef = objectToTree(schemaInObjectNotaion['::props'], localize, 'array');
260
- } else {
261
- schemaTreeDef = objectToTree(schemaInObjectNotaion, localize);
262
- }
263
- if (Array.isArray(schemaTreeDef) && schemaTreeDef.length > 0) {
264
- schemaTreeDef[0].margin = [10, 5, 0, 0];
265
- responseDef.push(schemaTreeDef);
266
- }
267
- } else {
268
- // If Schema style is Table-Tree
269
- let schemaTableTreeDef;
270
- let rootObjectType;
271
- if (schemaInObjectNotaion['::type'] && schemaInObjectNotaion['::type'] === 'array') {
272
- schemaTableTreeDef = objectToTableTree(schemaInObjectNotaion['::props'], localize);
273
- rootObjectType = [{ text: 'ARRAY OF OBJECT WITH BELOW STRUCTURE', style: ['sub', 'b', 'alternate'], colSpan: 3 }];
274
- } else {
275
- schemaTableTreeDef = objectToTableTree(schemaInObjectNotaion, localize);
276
- rootObjectType = [{ text: 'OBJECT WITH BELOW STRUCTURE', style: ['sub', 'b', 'alternate'], colSpan: 3 }];
277
- }
278
- if (schemaTableTreeDef && schemaTableTreeDef.length > 0 && Array.isArray(schemaTableTreeDef[0]) && schemaTableTreeDef[0].length > 0) {
279
- schemaTableTreeDef.unshift(rootObjectType);
280
- schemaTableTreeDef.unshift([
281
- { text: localize.name, style: ['sub', 'b', 'alternate'] },
282
- { text: localize.type, style: ['sub', 'b', 'alternate'] },
283
- { text: localize.description, style: ['sub', 'b', 'alternate'] },
284
- ]);
285
-
286
- responseDef.push({
287
- table: {
288
- headerRows: 1,
289
- body: schemaTableTreeDef,
290
- dontBreakRows: true,
291
- },
292
- layout: rowLinesTableLayout,
293
- margin: [10, 3, 0, 0],
294
- });
295
- }
296
- }
297
- }
298
- allResponseDefs.push(responseDef);
299
- }
300
- respDef.push({
301
- text: [
302
- { text: `${localize.statusCode} - ${statusCode}: `, style: ['small', 'b'] },
303
- { text: responses[statusCode].description, style: ['small'] },
304
- ],
305
- margin: [0, 10, 0, 0],
306
- });
307
- if (allResponseDefs.length > 0) {
308
- respDef.push(allResponseDefs);
309
- }
310
- }
311
- return respDef;
312
- }
313
-
314
- // API details def
315
- export function getApiDef(spec, filterPath, schemaStyle, localize, includeExample) {
316
- const content = [{ text: localize.api, style: ['h2', 'b'] }];
317
- let tagSeq = 0;
318
-
319
- spec.tags.map((tag) => {
320
- const operationContent = [];
321
- let pathSeq = 0;
322
-
323
- for (let j = 0; j < tag.paths.length; j++) {
324
- const path = tag.paths[j];
325
- if (filterPath.trim() !== '') {
326
- if (path.path.includes(filterPath) === false) {
327
- continue;
328
- }
329
- }
330
- pathSeq += 1;
331
- operationContent.push({
332
- text: `${tagSeq + 1}.${pathSeq} ${path.method.toUpperCase()} ${path.path}`,
333
- style: ['topMargin3', 'mono', 'p', 'primary', 'b'],
334
- tocItem: true,
335
- tocStyle: ['small', 'blue', 'mono'],
336
- tocNumberStyle: ['small', 'blue', 'mono'],
337
- });
338
- operationContent.push({ text: '', style: ['topMarginRegular'] });
339
-
340
- let pathSummaryMarkDef; let pathDescrMarkDef; let
341
- tokens;
342
- if (path.summary) {
343
- tokens = marked.lexer(path.summary);
344
- pathSummaryMarkDef = {
345
- stack: getMarkDownDef(tokens),
346
- style: ['primary', 'b'],
347
- };
348
- operationContent.push(pathSummaryMarkDef);
349
- }
350
- if (path.description && path.description.trim() !== path.summary.trim()) {
351
- tokens = marked.lexer(path.description);
352
- pathDescrMarkDef = {
353
- stack: getMarkDownDef(tokens),
354
- };
355
- operationContent.push(pathDescrMarkDef);
356
- }
357
-
358
- // Generate Request Defs
359
- const requestSetDef = [];
360
- const pathParams = path.parameters ? path.parameters.filter((param) => param.in === 'path') : null;
361
- const queryParams = path.parameters ? path.parameters.filter((param) => param.in === 'query') : null;
362
- const headerParams = path.parameters ? path.parameters.filter((param) => param.in === 'header') : null;
363
- const cookieParams = path.parameters ? path.parameters.filter((param) => param.in === 'cookie') : null;
364
-
365
- const pathParamTableDef = getParameterTableDef(pathParams, 'path', localize, includeExample);
366
- const queryParamTableDef = getParameterTableDef(queryParams, 'query', localize, includeExample);
367
- const requestBodyTableDefs = getRequestBodyDef(path.requestBody, schemaStyle, localize, includeExample);
368
- const headerParamTableDef = getParameterTableDef(headerParams, 'header', localize, includeExample);
369
- const cookieParamTableDef = getParameterTableDef(cookieParams, 'cookie', localize, includeExample);
370
- operationContent.push({ text: localize.request, style: ['p', 'b', 'alternate'], margin: [0, 10, 0, 0] });
371
- if (pathParamTableDef || queryParamTableDef || headerParamTableDef || cookieParamTableDef || requestBodyTableDefs) {
372
- if (pathParamTableDef) {
373
- requestSetDef.push(pathParamTableDef);
374
- }
375
- if (queryParamTableDef) {
376
- requestSetDef.push(queryParamTableDef);
377
- }
378
- if (requestBodyTableDefs) {
379
- requestBodyTableDefs.map((v) => {
380
- requestSetDef.push(v);
381
- });
382
- }
383
- if (headerParamTableDef) {
384
- requestSetDef.push(headerParamTableDef);
385
- }
386
- if (cookieParamTableDef) {
387
- requestSetDef.push(cookieParamTableDef);
388
- }
389
- } else {
390
- requestSetDef.push({ text: localize.noRequestParameters, style: ['small', 'gray'], margin: [0, 5, 0, 0] });
391
- }
392
- if (requestSetDef && requestSetDef.length > 0) {
393
- operationContent.push({
394
- stack: requestSetDef,
395
- margin: [10, 0, 0, 0],
396
- });
397
- }
398
-
399
- // Generate Response Defs
400
- operationContent.push({ text: localize.response, style: ['p', 'b', 'alternate'], margin: [0, 10, 0, 0] });
401
- const respDef = getResponseDef(path.responses, schemaStyle, localize);
402
- if (respDef && respDef.length > 0) {
403
- operationContent.push({
404
- stack: respDef,
405
- margin: [10, 5, 0, 5],
406
- });
407
- }
408
-
409
- // End of Operation - Line
410
- operationContent.push({
411
- canvas: [{
412
- type: 'line', x1: 0, y1: 5, x2: 595 - 2 * 35, y2: 5, lineWidth: 0.5, lineColor: '#cccccc',
413
- }],
414
- });
415
- }
416
-
417
- if (pathSeq > 0) {
418
- tagSeq += 1;
419
- let tagDescrMarkDef; let
420
- tokens;
421
- if (tag.description) {
422
- tokens = marked.lexer(tag.description);
423
- tagDescrMarkDef = {
424
- stack: getMarkDownDef(tokens),
425
- style: ['topMarginRegular'],
426
- };
427
- } else {
428
- tagDescrMarkDef = { text: '' };
429
- }
430
-
431
- content.push(
432
- {
433
- text: `${tagSeq}. ${tag.name.toUpperCase()}`,
434
- style: ['h2', 'b', 'primary', 'tableMargin'],
435
- tocItem: true,
436
- tocStyle: ['small', 'b'],
437
- tocMargin: [0, 10, 0, 0],
438
- },
439
- tagDescrMarkDef,
440
- operationContent,
441
- { text: '', pageBreak: 'after' },
442
- );
443
- }
444
- });
445
- return content;
446
- }
447
-
448
-
449
- // API List Def
450
- export function getApiListDef(spec, sectionHeading, localize) {
451
- const content = [{ text: sectionHeading, style: ['h3', 'b'], pageBreak: 'none' }];
452
- spec.tags.map((tag, i) => {
453
- const tableContent = [
454
- [{ text: localize.method, style: ['small', 'b'] }, { text: localize.api, style: ['small', 'b'] }],
455
- ];
456
-
457
- tag.paths.map((path) => {
458
- tableContent.push([
459
- { text: path.method, style: ['small', 'mono', 'right'] },
460
- {
461
- margin: [0, 0, 0, 2],
462
- stack: [
463
- { text: path.path, style: ['small', 'mono'] },
464
- { text: path.summary, style: ['small', 'gray'] },
465
- ],
466
-
467
- },
468
- ]);
469
- });
470
-
471
- content.push(
472
- { text: tag.name, style: ['h6', 'b', 'primary', 'tableMargin'], pageBreak: i === 0 ? 'none' : 'after' },
473
- { text: tag.description, style: ['p'] },
474
- {
475
- table: {
476
- headerRows: 1,
477
- dontBreakRows: true,
478
- widths: ['auto', '*'],
479
- body: tableContent,
480
- },
481
- layout: rowLinesTableLayout,
482
- style: 'tableMargin',
483
- },
484
- );
485
- });
486
-
487
- return content;
488
- }