@kubb/ast 5.0.0-alpha.48 → 5.0.0-alpha.49
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.
- package/README.md +24 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +23 -23
- package/src/factory.ts +22 -4
- package/src/index.ts +1 -8
- package/src/mocks.ts +84 -15
- package/src/nodes/function.ts +5 -1
- package/src/printer.ts +11 -2
- package/src/transformers.ts +4 -1
- package/src/utils.ts +114 -17
- package/src/visitor.ts +55 -16
package/src/visitor.ts
CHANGED
|
@@ -337,7 +337,11 @@ async function _walk(node: Node, visitor: AsyncVisitor, recurse: boolean, limit:
|
|
|
337
337
|
await limit(() => visitor.output?.(node, { parent: parent as ParentOf<OutputNode> }))
|
|
338
338
|
break
|
|
339
339
|
case 'Operation':
|
|
340
|
-
await limit(() =>
|
|
340
|
+
await limit(() =>
|
|
341
|
+
visitor.operation?.(node, {
|
|
342
|
+
parent: parent as ParentOf<OperationNode>,
|
|
343
|
+
}),
|
|
344
|
+
)
|
|
341
345
|
break
|
|
342
346
|
case 'Schema':
|
|
343
347
|
await limit(() => visitor.schema?.(node, { parent: parent as ParentOf<SchemaNode> }))
|
|
@@ -346,7 +350,11 @@ async function _walk(node: Node, visitor: AsyncVisitor, recurse: boolean, limit:
|
|
|
346
350
|
await limit(() => visitor.property?.(node, { parent: parent as ParentOf<PropertyNode> }))
|
|
347
351
|
break
|
|
348
352
|
case 'Parameter':
|
|
349
|
-
await limit(() =>
|
|
353
|
+
await limit(() =>
|
|
354
|
+
visitor.parameter?.(node, {
|
|
355
|
+
parent: parent as ParentOf<ParameterNode>,
|
|
356
|
+
}),
|
|
357
|
+
)
|
|
350
358
|
break
|
|
351
359
|
case 'Response':
|
|
352
360
|
await limit(() => visitor.response?.(node, { parent: parent as ParentOf<ResponseNode> }))
|
|
@@ -399,7 +407,9 @@ export function transform(node: Node, options: TransformOptions): Node {
|
|
|
399
407
|
switch (node.kind) {
|
|
400
408
|
case 'Input': {
|
|
401
409
|
let input = node
|
|
402
|
-
const replaced = visitor.input?.(input, {
|
|
410
|
+
const replaced = visitor.input?.(input, {
|
|
411
|
+
parent: parent as ParentOf<InputNode>,
|
|
412
|
+
})
|
|
403
413
|
if (replaced) input = replaced
|
|
404
414
|
|
|
405
415
|
return {
|
|
@@ -410,45 +420,62 @@ export function transform(node: Node, options: TransformOptions): Node {
|
|
|
410
420
|
}
|
|
411
421
|
case 'Output': {
|
|
412
422
|
let output = node
|
|
413
|
-
const replaced = visitor.output?.(output, {
|
|
423
|
+
const replaced = visitor.output?.(output, {
|
|
424
|
+
parent: parent as ParentOf<OutputNode>,
|
|
425
|
+
})
|
|
414
426
|
if (replaced) output = replaced
|
|
415
427
|
|
|
416
428
|
return output
|
|
417
429
|
}
|
|
418
430
|
case 'Operation': {
|
|
419
431
|
let op = node
|
|
420
|
-
const replaced = visitor.operation?.(op, {
|
|
432
|
+
const replaced = visitor.operation?.(op, {
|
|
433
|
+
parent: parent as ParentOf<OperationNode>,
|
|
434
|
+
})
|
|
421
435
|
if (replaced) op = replaced
|
|
422
436
|
|
|
423
437
|
return {
|
|
424
438
|
...op,
|
|
425
439
|
parameters: op.parameters.map((p) => transform(p, { ...options, parent: op })),
|
|
426
440
|
requestBody: op.requestBody
|
|
427
|
-
? {
|
|
441
|
+
? {
|
|
442
|
+
...op.requestBody,
|
|
443
|
+
schema: op.requestBody.schema ? transform(op.requestBody.schema, { ...options, parent: op }) : undefined,
|
|
444
|
+
}
|
|
428
445
|
: undefined,
|
|
429
446
|
responses: op.responses.map((r) => transform(r, { ...options, parent: op })),
|
|
430
447
|
}
|
|
431
448
|
}
|
|
432
449
|
case 'Schema': {
|
|
433
450
|
let schema = node
|
|
434
|
-
const replaced = visitor.schema?.(schema, {
|
|
451
|
+
const replaced = visitor.schema?.(schema, {
|
|
452
|
+
parent: parent as ParentOf<SchemaNode>,
|
|
453
|
+
})
|
|
435
454
|
if (replaced) schema = replaced
|
|
436
455
|
|
|
437
456
|
const childOptions = { ...options, parent: schema }
|
|
438
457
|
|
|
439
458
|
return {
|
|
440
459
|
...schema,
|
|
441
|
-
...('properties' in schema && recurse
|
|
460
|
+
...('properties' in schema && recurse
|
|
461
|
+
? {
|
|
462
|
+
properties: schema.properties.map((p) => transform(p, childOptions)),
|
|
463
|
+
}
|
|
464
|
+
: {}),
|
|
442
465
|
...('items' in schema && recurse ? { items: schema.items?.map((i) => transform(i, childOptions)) } : {}),
|
|
443
466
|
...('members' in schema && recurse ? { members: schema.members?.map((m) => transform(m, childOptions)) } : {}),
|
|
444
467
|
...('additionalProperties' in schema && recurse && schema.additionalProperties && schema.additionalProperties !== true
|
|
445
|
-
? {
|
|
468
|
+
? {
|
|
469
|
+
additionalProperties: transform(schema.additionalProperties, childOptions),
|
|
470
|
+
}
|
|
446
471
|
: {}),
|
|
447
472
|
} as SchemaNode
|
|
448
473
|
}
|
|
449
474
|
case 'Property': {
|
|
450
475
|
let prop = node
|
|
451
|
-
const replaced = visitor.property?.(prop, {
|
|
476
|
+
const replaced = visitor.property?.(prop, {
|
|
477
|
+
parent: parent as ParentOf<PropertyNode>,
|
|
478
|
+
})
|
|
452
479
|
if (replaced) prop = replaced
|
|
453
480
|
|
|
454
481
|
return createProperty({
|
|
@@ -458,7 +485,9 @@ export function transform(node: Node, options: TransformOptions): Node {
|
|
|
458
485
|
}
|
|
459
486
|
case 'Parameter': {
|
|
460
487
|
let param = node
|
|
461
|
-
const replaced = visitor.parameter?.(param, {
|
|
488
|
+
const replaced = visitor.parameter?.(param, {
|
|
489
|
+
parent: parent as ParentOf<ParameterNode>,
|
|
490
|
+
})
|
|
462
491
|
if (replaced) param = replaced
|
|
463
492
|
|
|
464
493
|
return createParameter({
|
|
@@ -468,7 +497,9 @@ export function transform(node: Node, options: TransformOptions): Node {
|
|
|
468
497
|
}
|
|
469
498
|
case 'Response': {
|
|
470
499
|
let response = node
|
|
471
|
-
const replaced = visitor.response?.(response, {
|
|
500
|
+
const replaced = visitor.response?.(response, {
|
|
501
|
+
parent: parent as ParentOf<ResponseNode>,
|
|
502
|
+
})
|
|
472
503
|
if (replaced) response = replaced
|
|
473
504
|
|
|
474
505
|
return {
|
|
@@ -519,19 +550,27 @@ export function collect<T>(node: Node, options: CollectOptions<T>): Array<T> {
|
|
|
519
550
|
v = visitor.output?.(node, { parent: parent as ParentOf<OutputNode> })
|
|
520
551
|
break
|
|
521
552
|
case 'Operation':
|
|
522
|
-
v = visitor.operation?.(node, {
|
|
553
|
+
v = visitor.operation?.(node, {
|
|
554
|
+
parent: parent as ParentOf<OperationNode>,
|
|
555
|
+
})
|
|
523
556
|
break
|
|
524
557
|
case 'Schema':
|
|
525
558
|
v = visitor.schema?.(node, { parent: parent as ParentOf<SchemaNode> })
|
|
526
559
|
break
|
|
527
560
|
case 'Property':
|
|
528
|
-
v = visitor.property?.(node, {
|
|
561
|
+
v = visitor.property?.(node, {
|
|
562
|
+
parent: parent as ParentOf<PropertyNode>,
|
|
563
|
+
})
|
|
529
564
|
break
|
|
530
565
|
case 'Parameter':
|
|
531
|
-
v = visitor.parameter?.(node, {
|
|
566
|
+
v = visitor.parameter?.(node, {
|
|
567
|
+
parent: parent as ParentOf<ParameterNode>,
|
|
568
|
+
})
|
|
532
569
|
break
|
|
533
570
|
case 'Response':
|
|
534
|
-
v = visitor.response?.(node, {
|
|
571
|
+
v = visitor.response?.(node, {
|
|
572
|
+
parent: parent as ParentOf<ResponseNode>,
|
|
573
|
+
})
|
|
535
574
|
break
|
|
536
575
|
case 'FunctionParameter':
|
|
537
576
|
case 'ParameterGroup':
|