@camunda8/docusaurus-plugin-openapi-docs 4.5.1

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 (170) hide show
  1. package/README.md +386 -0
  2. package/lib/index.d.ts +9 -0
  3. package/lib/index.js +714 -0
  4. package/lib/markdown/createArrayBracket.d.ts +2 -0
  5. package/lib/markdown/createArrayBracket.js +36 -0
  6. package/lib/markdown/createAuthentication.d.ts +2 -0
  7. package/lib/markdown/createAuthentication.js +173 -0
  8. package/lib/markdown/createAuthorization.d.ts +1 -0
  9. package/lib/markdown/createAuthorization.js +15 -0
  10. package/lib/markdown/createCallbackMethodEndpoint.d.ts +1 -0
  11. package/lib/markdown/createCallbackMethodEndpoint.js +20 -0
  12. package/lib/markdown/createCallbacks.d.ts +6 -0
  13. package/lib/markdown/createCallbacks.js +77 -0
  14. package/lib/markdown/createContactInfo.d.ts +2 -0
  15. package/lib/markdown/createContactInfo.js +39 -0
  16. package/lib/markdown/createDeprecationNotice.d.ts +6 -0
  17. package/lib/markdown/createDeprecationNotice.js +20 -0
  18. package/lib/markdown/createDescription.d.ts +1 -0
  19. package/lib/markdown/createDescription.js +13 -0
  20. package/lib/markdown/createDetails.d.ts +2 -0
  21. package/lib/markdown/createDetails.js +17 -0
  22. package/lib/markdown/createDetailsSummary.d.ts +2 -0
  23. package/lib/markdown/createDetailsSummary.js +17 -0
  24. package/lib/markdown/createDownload.d.ts +1 -0
  25. package/lib/markdown/createDownload.js +16 -0
  26. package/lib/markdown/createHeading.d.ts +1 -0
  27. package/lib/markdown/createHeading.js +20 -0
  28. package/lib/markdown/createLicense.d.ts +2 -0
  29. package/lib/markdown/createLicense.js +32 -0
  30. package/lib/markdown/createLogo.d.ts +2 -0
  31. package/lib/markdown/createLogo.js +18 -0
  32. package/lib/markdown/createMethodEndpoint.d.ts +1 -0
  33. package/lib/markdown/createMethodEndpoint.js +20 -0
  34. package/lib/markdown/createParamsDetails.d.ts +6 -0
  35. package/lib/markdown/createParamsDetails.js +18 -0
  36. package/lib/markdown/createRequestBodyDetails.d.ts +13 -0
  37. package/lib/markdown/createRequestBodyDetails.js +13 -0
  38. package/lib/markdown/createRequestHeader.d.ts +1 -0
  39. package/lib/markdown/createRequestHeader.js +23 -0
  40. package/lib/markdown/createRequestSchema.d.ts +14 -0
  41. package/lib/markdown/createRequestSchema.js +20 -0
  42. package/lib/markdown/createResponseSchema.d.ts +14 -0
  43. package/lib/markdown/createResponseSchema.js +20 -0
  44. package/lib/markdown/createSchema.d.ts +9 -0
  45. package/lib/markdown/createSchema.js +668 -0
  46. package/lib/markdown/createSchema.test.d.ts +1 -0
  47. package/lib/markdown/createSchema.test.js +913 -0
  48. package/lib/markdown/createStatusCodes.d.ts +9 -0
  49. package/lib/markdown/createStatusCodes.js +63 -0
  50. package/lib/markdown/createTermsOfService.d.ts +1 -0
  51. package/lib/markdown/createTermsOfService.js +31 -0
  52. package/lib/markdown/createVendorExtensions.d.ts +1 -0
  53. package/lib/markdown/createVendorExtensions.js +24 -0
  54. package/lib/markdown/createVersionBadge.d.ts +1 -0
  55. package/lib/markdown/createVersionBadge.js +19 -0
  56. package/lib/markdown/index.d.ts +5 -0
  57. package/lib/markdown/index.js +93 -0
  58. package/lib/markdown/schema.d.ts +3 -0
  59. package/lib/markdown/schema.js +157 -0
  60. package/lib/markdown/schema.test.d.ts +1 -0
  61. package/lib/markdown/schema.test.js +181 -0
  62. package/lib/markdown/utils.d.ts +20 -0
  63. package/lib/markdown/utils.js +68 -0
  64. package/lib/openapi/createRequestExample.d.ts +2 -0
  65. package/lib/openapi/createRequestExample.js +14 -0
  66. package/lib/openapi/createResponseExample.d.ts +2 -0
  67. package/lib/openapi/createResponseExample.js +14 -0
  68. package/lib/openapi/createSchemaExample.d.ts +7 -0
  69. package/lib/openapi/createSchemaExample.js +231 -0
  70. package/lib/openapi/index.d.ts +1 -0
  71. package/lib/openapi/index.js +12 -0
  72. package/lib/openapi/openapi.d.ts +12 -0
  73. package/lib/openapi/openapi.js +634 -0
  74. package/lib/openapi/openapi.test.d.ts +1 -0
  75. package/lib/openapi/openapi.test.js +33 -0
  76. package/lib/openapi/sdkExamples.d.ts +39 -0
  77. package/lib/openapi/sdkExamples.js +141 -0
  78. package/lib/openapi/types.d.ts +352 -0
  79. package/lib/openapi/types.js +8 -0
  80. package/lib/openapi/utils/loadAndResolveSpec.d.ts +2 -0
  81. package/lib/openapi/utils/loadAndResolveSpec.js +153 -0
  82. package/lib/openapi/utils/services/OpenAPIParser.d.ts +52 -0
  83. package/lib/openapi/utils/services/OpenAPIParser.js +343 -0
  84. package/lib/openapi/utils/services/RedocNormalizedOptions.d.ts +100 -0
  85. package/lib/openapi/utils/services/RedocNormalizedOptions.js +170 -0
  86. package/lib/openapi/utils/types/index.d.ts +2 -0
  87. package/lib/openapi/utils/types/index.js +23 -0
  88. package/lib/openapi/utils/types/open-api.d.ts +305 -0
  89. package/lib/openapi/utils/types/open-api.js +8 -0
  90. package/lib/openapi/utils/types.d.ts +307 -0
  91. package/lib/openapi/utils/types.js +8 -0
  92. package/lib/openapi/utils/utils/JsonPointer.d.ts +51 -0
  93. package/lib/openapi/utils/utils/JsonPointer.js +95 -0
  94. package/lib/openapi/utils/utils/helpers.d.ts +43 -0
  95. package/lib/openapi/utils/utils/helpers.js +230 -0
  96. package/lib/openapi/utils/utils/index.d.ts +3 -0
  97. package/lib/openapi/utils/utils/index.js +25 -0
  98. package/lib/openapi/utils/utils/openapi.d.ts +40 -0
  99. package/lib/openapi/utils/utils/openapi.js +605 -0
  100. package/lib/openapi/webhooks.test.d.ts +1 -0
  101. package/lib/openapi/webhooks.test.js +23 -0
  102. package/lib/options.d.ts +2 -0
  103. package/lib/options.js +70 -0
  104. package/lib/sidebars/index.d.ts +4 -0
  105. package/lib/sidebars/index.js +226 -0
  106. package/lib/sidebars/utils.d.ts +2 -0
  107. package/lib/sidebars/utils.js +30 -0
  108. package/lib/types.d.ts +138 -0
  109. package/lib/types.js +8 -0
  110. package/package.json +68 -0
  111. package/src/index.ts +955 -0
  112. package/src/markdown/__snapshots__/createSchema.test.ts.snap +1605 -0
  113. package/src/markdown/createArrayBracket.ts +35 -0
  114. package/src/markdown/createAuthentication.ts +209 -0
  115. package/src/markdown/createAuthorization.ts +13 -0
  116. package/src/markdown/createCallbackMethodEndpoint.ts +19 -0
  117. package/src/markdown/createCallbacks.ts +101 -0
  118. package/src/markdown/createContactInfo.ts +41 -0
  119. package/src/markdown/createDeprecationNotice.ts +31 -0
  120. package/src/markdown/createDescription.ts +12 -0
  121. package/src/markdown/createDetails.ts +16 -0
  122. package/src/markdown/createDetailsSummary.ts +16 -0
  123. package/src/markdown/createDownload.ts +15 -0
  124. package/src/markdown/createHeading.ts +23 -0
  125. package/src/markdown/createLicense.ts +34 -0
  126. package/src/markdown/createLogo.ts +21 -0
  127. package/src/markdown/createMethodEndpoint.ts +19 -0
  128. package/src/markdown/createParamsDetails.ts +22 -0
  129. package/src/markdown/createRequestBodyDetails.ts +24 -0
  130. package/src/markdown/createRequestHeader.ts +22 -0
  131. package/src/markdown/createRequestSchema.ts +32 -0
  132. package/src/markdown/createResponseSchema.ts +32 -0
  133. package/src/markdown/createSchema.test.ts +1075 -0
  134. package/src/markdown/createSchema.ts +864 -0
  135. package/src/markdown/createStatusCodes.ts +63 -0
  136. package/src/markdown/createTermsOfService.ts +30 -0
  137. package/src/markdown/createVendorExtensions.ts +22 -0
  138. package/src/markdown/createVersionBadge.ts +22 -0
  139. package/src/markdown/index.ts +145 -0
  140. package/src/markdown/schema.test.ts +208 -0
  141. package/src/markdown/schema.ts +188 -0
  142. package/src/markdown/utils.ts +89 -0
  143. package/src/openapi/__fixtures__/examples/openapi.yaml +49 -0
  144. package/src/openapi/__fixtures__/webhook/openapi.yaml +17 -0
  145. package/src/openapi/createRequestExample.ts +13 -0
  146. package/src/openapi/createResponseExample.ts +13 -0
  147. package/src/openapi/createSchemaExample.ts +292 -0
  148. package/src/openapi/index.ts +8 -0
  149. package/src/openapi/openapi.test.ts +40 -0
  150. package/src/openapi/openapi.ts +772 -0
  151. package/src/openapi/sdkExamples.ts +195 -0
  152. package/src/openapi/types.ts +458 -0
  153. package/src/openapi/utils/loadAndResolveSpec.ts +171 -0
  154. package/src/openapi/utils/services/OpenAPIParser.ts +434 -0
  155. package/src/openapi/utils/services/RedocNormalizedOptions.ts +330 -0
  156. package/src/openapi/utils/types/index.ts +10 -0
  157. package/src/openapi/utils/types/open-api.ts +303 -0
  158. package/src/openapi/utils/types.ts +304 -0
  159. package/src/openapi/utils/utils/JsonPointer.ts +99 -0
  160. package/src/openapi/utils/utils/helpers.ts +239 -0
  161. package/src/openapi/utils/utils/index.ts +11 -0
  162. package/src/openapi/utils/utils/openapi.ts +771 -0
  163. package/src/openapi/webhooks.test.ts +30 -0
  164. package/src/openapi-to-postmanv2.d.ts +10 -0
  165. package/src/options.ts +78 -0
  166. package/src/plugin-openapi.d.ts +88 -0
  167. package/src/sidebars/index.ts +322 -0
  168. package/src/sidebars/utils.ts +29 -0
  169. package/src/types.ts +180 -0
  170. package/tsconfig.json +7 -0
@@ -0,0 +1,1075 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ import * as prettier from "prettier";
9
+
10
+ import { createNodes } from "./createSchema";
11
+ import { SchemaObject } from "../openapi/types";
12
+
13
+ describe("createNodes", () => {
14
+ describe("oneOf", () => {
15
+ it("should create readable MODs for oneOf primitive properties", async () => {
16
+ const schema: SchemaObject = {
17
+ "x-tags": ["clown"],
18
+ type: "object",
19
+ properties: {
20
+ oneOfProperty: {
21
+ oneOf: [
22
+ {
23
+ type: "object",
24
+ properties: {
25
+ noseLength: {
26
+ type: "number",
27
+ },
28
+ },
29
+ required: ["noseLength"],
30
+ description: "Clown's nose length",
31
+ },
32
+ {
33
+ type: "array",
34
+ items: {
35
+ type: "string",
36
+ },
37
+ description: "Array of strings",
38
+ },
39
+ {
40
+ type: "boolean",
41
+ },
42
+ {
43
+ type: "number",
44
+ },
45
+ {
46
+ type: "string",
47
+ },
48
+ ],
49
+ },
50
+ },
51
+ };
52
+ expect(
53
+ await Promise.all(
54
+ createNodes(schema, "request").map(
55
+ async (md: any) => await prettier.format(md, { parser: "babel" })
56
+ )
57
+ )
58
+ ).toMatchSnapshot();
59
+ });
60
+
61
+ it("should handle oneOf with different primitive types", async () => {
62
+ const schema: SchemaObject = {
63
+ type: "object",
64
+ properties: {
65
+ oneOfProperty: {
66
+ oneOf: [
67
+ { type: "string" },
68
+ { type: "number" },
69
+ { type: "boolean" },
70
+ ],
71
+ },
72
+ },
73
+ };
74
+
75
+ expect(
76
+ await Promise.all(
77
+ createNodes(schema, "response").map(
78
+ async (md: any) => await prettier.format(md, { parser: "babel" })
79
+ )
80
+ )
81
+ ).toMatchSnapshot();
82
+ });
83
+
84
+ it("should handle oneOf with complex types", async () => {
85
+ const schema: SchemaObject = {
86
+ type: "object",
87
+ properties: {
88
+ oneOfProperty: {
89
+ oneOf: [
90
+ {
91
+ type: "object",
92
+ properties: {
93
+ objectProp: { type: "string" },
94
+ },
95
+ },
96
+ {
97
+ type: "array",
98
+ items: { type: "number" },
99
+ },
100
+ ],
101
+ },
102
+ },
103
+ };
104
+
105
+ expect(
106
+ await Promise.all(
107
+ createNodes(schema, "response").map(
108
+ async (md: any) => await prettier.format(md, { parser: "babel" })
109
+ )
110
+ )
111
+ ).toMatchSnapshot();
112
+ });
113
+
114
+ it("should handle nested oneOf clauses", async () => {
115
+ const schema: SchemaObject = {
116
+ type: "object",
117
+ properties: {
118
+ oneOfProperty: {
119
+ oneOf: [
120
+ {
121
+ type: "object",
122
+ properties: {
123
+ nestedOneOfProp: {
124
+ oneOf: [{ type: "string" }, { type: "number" }],
125
+ },
126
+ },
127
+ },
128
+ { type: "boolean" },
129
+ ],
130
+ },
131
+ },
132
+ };
133
+
134
+ expect(
135
+ await Promise.all(
136
+ createNodes(schema, "response").map(
137
+ async (md: any) => await prettier.format(md, { parser: "babel" })
138
+ )
139
+ )
140
+ ).toMatchSnapshot();
141
+ });
142
+
143
+ // TypeError: Cannot read properties of undefined (reading 'length')
144
+ // eslint-disable-next-line jest/no-commented-out-tests
145
+ // it("should handle oneOf with discriminator", async () => {
146
+ // const schema: SchemaObject = {
147
+ // type: "object",
148
+ // discriminator: { propertyName: "type" },
149
+ // properties: {
150
+ // type: { type: "string" },
151
+ // },
152
+ // oneOf: [
153
+ // {
154
+ // type: "object",
155
+ // properties: {
156
+ // type: { type: "string", enum: ["typeA"] },
157
+ // propA: { type: "string" },
158
+ // },
159
+ // required: ["type"],
160
+ // },
161
+ // {
162
+ // type: "object",
163
+ // properties: {
164
+ // type: { type: "string", enum: ["typeB"] },
165
+ // propB: { type: "number" },
166
+ // },
167
+ // required: ["type"],
168
+ // },
169
+ // ],
170
+ // };
171
+
172
+ // expect(
173
+ // await Promise.all(
174
+ // createNodes(schema, "response").map(
175
+ // async (md: any) => await prettier.format(md, { parser: "babel" })
176
+ // )
177
+ // )
178
+ // ).toMatchSnapshot();
179
+ // });
180
+
181
+ it("should handle oneOf with shared properties", async () => {
182
+ const schema: SchemaObject = {
183
+ type: "object",
184
+ properties: {
185
+ sharedProp: { type: "string" },
186
+ oneOfProperty: {
187
+ oneOf: [
188
+ {
189
+ type: "object",
190
+ properties: {
191
+ specificPropA: { type: "string" },
192
+ },
193
+ },
194
+ {
195
+ type: "object",
196
+ properties: {
197
+ specificPropB: { type: "number" },
198
+ },
199
+ },
200
+ ],
201
+ },
202
+ },
203
+ };
204
+
205
+ expect(
206
+ await Promise.all(
207
+ createNodes(schema, "response").map(
208
+ async (md: any) => await prettier.format(md, { parser: "babel" })
209
+ )
210
+ )
211
+ ).toMatchSnapshot();
212
+ });
213
+
214
+ it("should handle oneOf with required properties", async () => {
215
+ const schema: SchemaObject = {
216
+ type: "object",
217
+ properties: {
218
+ oneOfProperty: {
219
+ oneOf: [
220
+ {
221
+ type: "object",
222
+ properties: {
223
+ requiredPropA: { type: "string" },
224
+ },
225
+ required: ["requiredPropA"],
226
+ },
227
+ {
228
+ type: "object",
229
+ properties: {
230
+ requiredPropB: { type: "number" },
231
+ },
232
+ required: ["requiredPropB"],
233
+ },
234
+ ],
235
+ },
236
+ },
237
+ };
238
+
239
+ expect(
240
+ await Promise.all(
241
+ createNodes(schema, "response").map(
242
+ async (md: any) => await prettier.format(md, { parser: "babel" })
243
+ )
244
+ )
245
+ ).toMatchSnapshot();
246
+ });
247
+ });
248
+
249
+ describe("anyOf", () => {
250
+ it("should render primitives within anyOf", async () => {
251
+ const schema: SchemaObject = {
252
+ type: "object",
253
+ properties: {
254
+ oneOfProperty: {
255
+ anyOf: [
256
+ {
257
+ type: "integer",
258
+ },
259
+ {
260
+ type: "boolean",
261
+ },
262
+ ],
263
+ title: "One of int or bool",
264
+ },
265
+ },
266
+ };
267
+
268
+ expect(
269
+ await Promise.all(
270
+ createNodes(schema, "response").map(
271
+ async (md: any) => await prettier.format(md, { parser: "babel" })
272
+ )
273
+ )
274
+ ).toMatchSnapshot();
275
+ });
276
+
277
+ it("should render oneOf within anyOf", async () => {
278
+ const schema: SchemaObject = {
279
+ type: "object",
280
+ properties: {
281
+ oneOfProperty: {
282
+ anyOf: [
283
+ {
284
+ oneOf: [
285
+ {
286
+ type: "integer",
287
+ },
288
+ {
289
+ type: "boolean",
290
+ },
291
+ ],
292
+ title: "An int or a bool",
293
+ },
294
+ {
295
+ type: "string",
296
+ },
297
+ ],
298
+ title: "One of int or bool, or a string",
299
+ },
300
+ },
301
+ };
302
+
303
+ expect(
304
+ await Promise.all(
305
+ createNodes(schema, "response").map(
306
+ async (md: any) => await prettier.format(md, { parser: "babel" })
307
+ )
308
+ )
309
+ ).toMatchSnapshot();
310
+ });
311
+ });
312
+
313
+ describe("allOf", () => {
314
+ it("should render same-level properties with allOf", async () => {
315
+ const schema: SchemaObject = {
316
+ allOf: [
317
+ {
318
+ type: "object",
319
+ properties: {
320
+ allOfProp1: {
321
+ type: "string",
322
+ },
323
+ allOfProp2: {
324
+ type: "string",
325
+ },
326
+ },
327
+ },
328
+ ],
329
+ properties: {
330
+ parentProp1: {
331
+ type: "string",
332
+ },
333
+ parentProp2: {
334
+ type: "string",
335
+ },
336
+ },
337
+ };
338
+
339
+ expect(
340
+ await Promise.all(
341
+ createNodes(schema, "response").map(
342
+ async (md: any) => await prettier.format(md, { parser: "babel" })
343
+ )
344
+ )
345
+ ).toMatchSnapshot();
346
+ });
347
+
348
+ it("should correctly merge nested properties from multiple allOf schemas", async () => {
349
+ const schema: SchemaObject = {
350
+ allOf: [
351
+ {
352
+ type: "object",
353
+ properties: {
354
+ outerProp1: {
355
+ type: "object",
356
+ properties: {
357
+ innerProp1: {
358
+ type: "string",
359
+ },
360
+ },
361
+ },
362
+ },
363
+ },
364
+ {
365
+ type: "object",
366
+ properties: {
367
+ outerProp2: {
368
+ type: "object",
369
+ properties: {
370
+ innerProp2: {
371
+ type: "number",
372
+ },
373
+ },
374
+ },
375
+ },
376
+ },
377
+ ],
378
+ };
379
+
380
+ expect(
381
+ await Promise.all(
382
+ createNodes(schema, "response").map(
383
+ async (md: any) => await prettier.format(md, { parser: "babel" })
384
+ )
385
+ )
386
+ ).toMatchSnapshot();
387
+ });
388
+
389
+ it("should correctly handle shared required properties across allOf schemas", async () => {
390
+ const schema: SchemaObject = {
391
+ allOf: [
392
+ {
393
+ type: "object",
394
+ properties: {
395
+ sharedProp: {
396
+ type: "string",
397
+ },
398
+ },
399
+ required: ["sharedProp"],
400
+ },
401
+ {
402
+ type: "object",
403
+ properties: {
404
+ anotherProp: {
405
+ type: "number",
406
+ },
407
+ },
408
+ required: ["anotherProp"],
409
+ },
410
+ ],
411
+ };
412
+
413
+ expect(
414
+ await Promise.all(
415
+ createNodes(schema, "response").map(
416
+ async (md: any) => await prettier.format(md, { parser: "babel" })
417
+ )
418
+ )
419
+ ).toMatchSnapshot();
420
+ });
421
+
422
+ // Could not resolve values for path:"properties.conflictingProp.type". They are probably incompatible. Values:
423
+ // "string"
424
+ // "number"
425
+ // eslint-disable-next-line jest/no-commented-out-tests
426
+ // it("should handle conflicting properties in allOf schemas", async () => {
427
+ // const schema: SchemaObject = {
428
+ // allOf: [
429
+ // {
430
+ // type: "object",
431
+ // properties: {
432
+ // conflictingProp: {
433
+ // type: "string",
434
+ // },
435
+ // },
436
+ // },
437
+ // {
438
+ // type: "object",
439
+ // properties: {
440
+ // conflictingProp: {
441
+ // type: "number",
442
+ // },
443
+ // },
444
+ // },
445
+ // ],
446
+ // };
447
+
448
+ // expect(
449
+ // await Promise.all(
450
+ // createNodes(schema, "response").map(
451
+ // async (md: any) => await prettier.format(md, { parser: "babel" })
452
+ // )
453
+ // )
454
+ // ).toMatchSnapshot();
455
+ // });
456
+
457
+ // Could not resolve values for path:"type". They are probably incompatible. Values:
458
+ // "object"
459
+ // "array"
460
+ // eslint-disable-next-line jest/no-commented-out-tests
461
+ // it("should handle mixed data types in allOf schemas", async () => {
462
+ // const schema: SchemaObject = {
463
+ // allOf: [
464
+ // {
465
+ // type: "object",
466
+ // properties: {
467
+ // mixedTypeProp1: {
468
+ // type: "string",
469
+ // },
470
+ // },
471
+ // },
472
+ // {
473
+ // type: "array",
474
+ // items: {
475
+ // type: "number",
476
+ // },
477
+ // },
478
+ // ],
479
+ // };
480
+
481
+ // expect(
482
+ // await Promise.all(
483
+ // createNodes(schema, "response").map(
484
+ // async (md: any) => await prettier.format(md, { parser: "babel" })
485
+ // )
486
+ // )
487
+ // ).toMatchSnapshot();
488
+ // });
489
+
490
+ it("should correctly deep merge properties in allOf schemas", async () => {
491
+ const schema: SchemaObject = {
492
+ allOf: [
493
+ {
494
+ type: "object",
495
+ properties: {
496
+ deepProp: {
497
+ type: "object",
498
+ properties: {
499
+ innerProp1: {
500
+ type: "string",
501
+ },
502
+ },
503
+ },
504
+ },
505
+ },
506
+ {
507
+ type: "object",
508
+ properties: {
509
+ deepProp: {
510
+ type: "object",
511
+ properties: {
512
+ innerProp2: {
513
+ type: "number",
514
+ },
515
+ },
516
+ },
517
+ },
518
+ },
519
+ ],
520
+ };
521
+
522
+ expect(
523
+ await Promise.all(
524
+ createNodes(schema, "response").map(
525
+ async (md: any) => await prettier.format(md, { parser: "babel" })
526
+ )
527
+ )
528
+ ).toMatchSnapshot();
529
+ });
530
+
531
+ // eslint-disable-next-line jest/no-commented-out-tests
532
+ // it("should handle discriminator with allOf schemas", async () => {
533
+ // const schema: SchemaObject = {
534
+ // allOf: [
535
+ // {
536
+ // type: "object",
537
+ // discriminator: {
538
+ // propertyName: "type",
539
+ // },
540
+ // properties: {
541
+ // type: {
542
+ // type: "string",
543
+ // },
544
+ // },
545
+ // },
546
+ // {
547
+ // type: "object",
548
+ // properties: {
549
+ // specificProp: {
550
+ // type: "string",
551
+ // },
552
+ // },
553
+ // },
554
+ // ],
555
+ // };
556
+
557
+ // expect(
558
+ // await Promise.all(
559
+ // createNodes(schema, "response").map(
560
+ // async (md: any) => await prettier.format(md, { parser: "babel" })
561
+ // )
562
+ // )
563
+ // ).toMatchSnapshot();
564
+ // });
565
+ });
566
+
567
+ describe("discriminator", () => {
568
+ it("should handle basic discriminator with oneOf", async () => {
569
+ const schema: SchemaObject = {
570
+ type: "object",
571
+ discriminator: { propertyName: "type" },
572
+ properties: {
573
+ type: { type: "string" },
574
+ },
575
+ oneOf: [
576
+ {
577
+ type: "object",
578
+ properties: {
579
+ type: { type: "string", enum: ["typeA"] },
580
+ propA: { type: "string" },
581
+ },
582
+ required: ["type"],
583
+ },
584
+ {
585
+ type: "object",
586
+ properties: {
587
+ type: { type: "string", enum: ["typeB"] },
588
+ propB: { type: "number" },
589
+ },
590
+ required: ["type"],
591
+ },
592
+ ],
593
+ };
594
+
595
+ expect(
596
+ await Promise.all(
597
+ createNodes(schema, "response").map(
598
+ async (md: any) => await prettier.format(md, { parser: "babel" })
599
+ )
600
+ )
601
+ ).toMatchSnapshot();
602
+ });
603
+
604
+ it("should handle discriminator with shared properties", async () => {
605
+ const schema: SchemaObject = {
606
+ type: "object",
607
+ discriminator: { propertyName: "type" },
608
+ properties: {
609
+ type: { type: "string" },
610
+ sharedProp: { type: "string" },
611
+ },
612
+ oneOf: [
613
+ {
614
+ type: "object",
615
+ properties: {
616
+ type: { type: "string", enum: ["typeA"] },
617
+ propA: { type: "string" },
618
+ },
619
+ required: ["type"],
620
+ },
621
+ {
622
+ type: "object",
623
+ properties: {
624
+ type: { type: "string", enum: ["typeB"] },
625
+ propB: { type: "number" },
626
+ },
627
+ required: ["type"],
628
+ },
629
+ ],
630
+ };
631
+
632
+ expect(
633
+ await Promise.all(
634
+ createNodes(schema, "response").map(
635
+ async (md: any) => await prettier.format(md, { parser: "babel" })
636
+ )
637
+ )
638
+ ).toMatchSnapshot();
639
+ });
640
+
641
+ it("should handle discriminator with nested schemas", async () => {
642
+ const schema: SchemaObject = {
643
+ type: "object",
644
+ discriminator: { propertyName: "type" },
645
+ properties: {
646
+ type: { type: "string" },
647
+ },
648
+ oneOf: [
649
+ {
650
+ type: "object",
651
+ properties: {
652
+ type: { type: "string", enum: ["typeA"] },
653
+ nestedA: {
654
+ type: "object",
655
+ properties: {
656
+ propA1: { type: "string" },
657
+ propA2: { type: "number" },
658
+ },
659
+ },
660
+ },
661
+ required: ["type"],
662
+ },
663
+ {
664
+ type: "object",
665
+ properties: {
666
+ type: { type: "string", enum: ["typeB"] },
667
+ nestedB: {
668
+ type: "object",
669
+ properties: {
670
+ propB1: { type: "string" },
671
+ propB2: { type: "boolean" },
672
+ },
673
+ },
674
+ },
675
+ required: ["type"],
676
+ },
677
+ ],
678
+ };
679
+
680
+ expect(
681
+ await Promise.all(
682
+ createNodes(schema, "response").map(
683
+ async (md: any) => await prettier.format(md, { parser: "babel" })
684
+ )
685
+ )
686
+ ).toMatchSnapshot();
687
+ });
688
+
689
+ it("should handle discriminator with additional properties", async () => {
690
+ const schema: SchemaObject = {
691
+ type: "object",
692
+ discriminator: { propertyName: "type" },
693
+ properties: {
694
+ type: { type: "string" },
695
+ },
696
+ oneOf: [
697
+ {
698
+ type: "object",
699
+ properties: {
700
+ type: { type: "string", enum: ["typeA"] },
701
+ propA: { type: "string" },
702
+ },
703
+ additionalProperties: false,
704
+ required: ["type"],
705
+ },
706
+ {
707
+ type: "object",
708
+ properties: {
709
+ type: { type: "string", enum: ["typeB"] },
710
+ propB: { type: "number" },
711
+ },
712
+ additionalProperties: true,
713
+ required: ["type"],
714
+ },
715
+ ],
716
+ };
717
+
718
+ expect(
719
+ await Promise.all(
720
+ createNodes(schema, "response").map(
721
+ async (md: any) => await prettier.format(md, { parser: "babel" })
722
+ )
723
+ )
724
+ ).toMatchSnapshot();
725
+ });
726
+
727
+ it("should handle discriminator with allOf", async () => {
728
+ const schema: SchemaObject = {
729
+ type: "object",
730
+ discriminator: { propertyName: "type" },
731
+ properties: {
732
+ type: { type: "string" },
733
+ },
734
+ allOf: [
735
+ {
736
+ oneOf: [
737
+ {
738
+ type: "object",
739
+ properties: {
740
+ type: { type: "string", enum: ["typeA"] },
741
+ propA: { type: "string" },
742
+ },
743
+ required: ["type"],
744
+ },
745
+ {
746
+ type: "object",
747
+ properties: {
748
+ type: { type: "string", enum: ["typeB"] },
749
+ propB: { type: "number" },
750
+ },
751
+ required: ["type"],
752
+ },
753
+ ],
754
+ },
755
+ {
756
+ type: "object",
757
+ properties: {
758
+ sharedProp: { type: "string" },
759
+ },
760
+ },
761
+ ],
762
+ };
763
+
764
+ expect(
765
+ await Promise.all(
766
+ createNodes(schema, "response").map(
767
+ async (md: any) => await prettier.format(md, { parser: "babel" })
768
+ )
769
+ )
770
+ ).toMatchSnapshot();
771
+ });
772
+
773
+ it("should handle discriminator with required properties", async () => {
774
+ const schema: SchemaObject = {
775
+ type: "object",
776
+ discriminator: { propertyName: "type" },
777
+ properties: {
778
+ type: { type: "string" },
779
+ },
780
+ oneOf: [
781
+ {
782
+ type: "object",
783
+ properties: {
784
+ type: { type: "string", enum: ["typeA"] },
785
+ propA: { type: "string" },
786
+ },
787
+ required: ["type", "propA"],
788
+ },
789
+ {
790
+ type: "object",
791
+ properties: {
792
+ type: { type: "string", enum: ["typeB"] },
793
+ propB: { type: "number" },
794
+ },
795
+ required: ["type", "propB"],
796
+ },
797
+ ],
798
+ };
799
+
800
+ expect(
801
+ await Promise.all(
802
+ createNodes(schema, "response").map(
803
+ async (md: any) => await prettier.format(md, { parser: "babel" })
804
+ )
805
+ )
806
+ ).toMatchSnapshot();
807
+ });
808
+
809
+ it("should handle basic discriminator with mapping", async () => {
810
+ const schema: SchemaObject = {
811
+ type: "object",
812
+ discriminator: {
813
+ propertyName: "type",
814
+ mapping: {
815
+ typeA: "#/definitions/TypeA",
816
+ typeB: "#/definitions/TypeB",
817
+ },
818
+ },
819
+ properties: {
820
+ type: { type: "string" },
821
+ },
822
+ oneOf: [
823
+ {
824
+ type: "object",
825
+ properties: {
826
+ type: { type: "string", enum: ["typeA"] },
827
+ propA: { type: "string" },
828
+ },
829
+ required: ["type"],
830
+ },
831
+ {
832
+ type: "object",
833
+ properties: {
834
+ type: { type: "string", enum: ["typeB"] },
835
+ propB: { type: "number" },
836
+ },
837
+ required: ["type"],
838
+ },
839
+ ],
840
+ };
841
+
842
+ expect(
843
+ await Promise.all(
844
+ createNodes(schema, "response").map(
845
+ async (md: any) => await prettier.format(md, { parser: "babel" })
846
+ )
847
+ )
848
+ ).toMatchSnapshot();
849
+ });
850
+
851
+ it("should handle discriminator with shared properties and mapping", async () => {
852
+ const schema: SchemaObject = {
853
+ type: "object",
854
+ discriminator: {
855
+ propertyName: "type",
856
+ mapping: {
857
+ typeA: "#/definitions/TypeA",
858
+ typeB: "#/definitions/TypeB",
859
+ },
860
+ },
861
+ properties: {
862
+ type: { type: "string" },
863
+ sharedProp: { type: "string" },
864
+ },
865
+ oneOf: [
866
+ {
867
+ type: "object",
868
+ properties: {
869
+ type: { type: "string", enum: ["typeA"] },
870
+ propA: { type: "string" },
871
+ },
872
+ required: ["type"],
873
+ },
874
+ {
875
+ type: "object",
876
+ properties: {
877
+ type: { type: "string", enum: ["typeB"] },
878
+ propB: { type: "number" },
879
+ },
880
+ required: ["type"],
881
+ },
882
+ ],
883
+ };
884
+
885
+ expect(
886
+ await Promise.all(
887
+ createNodes(schema, "response").map(
888
+ async (md: any) => await prettier.format(md, { parser: "babel" })
889
+ )
890
+ )
891
+ ).toMatchSnapshot();
892
+ });
893
+
894
+ it("should handle discriminator with allOf and mapping", async () => {
895
+ const schema: SchemaObject = {
896
+ type: "object",
897
+ discriminator: {
898
+ propertyName: "type",
899
+ mapping: {
900
+ typeA: "#/definitions/TypeA",
901
+ typeB: "#/definitions/TypeB",
902
+ },
903
+ },
904
+ properties: {
905
+ type: { type: "string" },
906
+ },
907
+ allOf: [
908
+ {
909
+ oneOf: [
910
+ {
911
+ type: "object",
912
+ properties: {
913
+ type: { type: "string", enum: ["typeA"] },
914
+ propA: { type: "string" },
915
+ },
916
+ required: ["type"],
917
+ },
918
+ {
919
+ type: "object",
920
+ properties: {
921
+ type: { type: "string", enum: ["typeB"] },
922
+ propB: { type: "number" },
923
+ },
924
+ required: ["type"],
925
+ },
926
+ ],
927
+ },
928
+ {
929
+ type: "object",
930
+ properties: {
931
+ sharedProp: { type: "string" },
932
+ },
933
+ },
934
+ ],
935
+ };
936
+
937
+ expect(
938
+ await Promise.all(
939
+ createNodes(schema, "response").map(
940
+ async (md: any) => await prettier.format(md, { parser: "babel" })
941
+ )
942
+ )
943
+ ).toMatchSnapshot();
944
+ });
945
+
946
+ it("should handle discriminator with required properties and mapping", async () => {
947
+ const schema: SchemaObject = {
948
+ type: "object",
949
+ discriminator: {
950
+ propertyName: "type",
951
+ mapping: {
952
+ typeA: "#/definitions/TypeA",
953
+ typeB: "#/definitions/TypeB",
954
+ },
955
+ },
956
+ properties: {
957
+ type: { type: "string" },
958
+ },
959
+ oneOf: [
960
+ {
961
+ type: "object",
962
+ properties: {
963
+ type: { type: "string", enum: ["typeA"] },
964
+ propA: { type: "string" },
965
+ },
966
+ required: ["type", "propA"],
967
+ },
968
+ {
969
+ type: "object",
970
+ properties: {
971
+ type: { type: "string", enum: ["typeB"] },
972
+ propB: { type: "number" },
973
+ },
974
+ required: ["type", "propB"],
975
+ },
976
+ ],
977
+ };
978
+
979
+ expect(
980
+ await Promise.all(
981
+ createNodes(schema, "response").map(
982
+ async (md: any) => await prettier.format(md, { parser: "babel" })
983
+ )
984
+ )
985
+ ).toMatchSnapshot();
986
+ });
987
+ });
988
+
989
+ describe("additionalProperties", () => {
990
+ it.each([
991
+ [
992
+ {
993
+ allOf: [
994
+ {
995
+ oneOf: [
996
+ {
997
+ type: "object",
998
+ properties: {
999
+ type: {
1000
+ type: "string",
1001
+ enum: ["nose"],
1002
+ },
1003
+ },
1004
+ required: ["type"],
1005
+ },
1006
+ {
1007
+ type: "object",
1008
+ properties: {
1009
+ type: {
1010
+ type: "string",
1011
+ enum: ["mouth"],
1012
+ },
1013
+ },
1014
+ required: ["type"],
1015
+ },
1016
+ {
1017
+ type: "object",
1018
+ properties: {
1019
+ type: {
1020
+ type: "string",
1021
+ enum: ["eyes"],
1022
+ },
1023
+ default: {
1024
+ type: "string",
1025
+ },
1026
+ },
1027
+ required: ["type"],
1028
+ },
1029
+ ],
1030
+ },
1031
+ {
1032
+ type: "object",
1033
+ properties: {
1034
+ description: {
1035
+ type: "string",
1036
+ description: "Description of the body part.",
1037
+ },
1038
+ },
1039
+ required: ["description"],
1040
+ },
1041
+ ],
1042
+ },
1043
+ ],
1044
+ [
1045
+ {
1046
+ type: "array",
1047
+ items: { type: "object", properties: { a: "string", b: "number" } },
1048
+ },
1049
+ ],
1050
+ [{ type: "string" }],
1051
+ [{ type: "number" }],
1052
+ [{ type: "integer" }],
1053
+ [{ type: "boolean" }],
1054
+ [false],
1055
+ [true],
1056
+ [{}],
1057
+ ] as [SchemaObject["additionalProperties"]][])(
1058
+ "should handle additionalProperties: %p",
1059
+ async (additionalProperties) => {
1060
+ const schema: SchemaObject = {
1061
+ type: "object",
1062
+ additionalProperties,
1063
+ };
1064
+
1065
+ expect(
1066
+ await Promise.all(
1067
+ createNodes(schema, "request").map(
1068
+ async (md: any) => await prettier.format(md, { parser: "babel" })
1069
+ )
1070
+ )
1071
+ ).toMatchSnapshot();
1072
+ }
1073
+ );
1074
+ });
1075
+ });