|
513 | 513 | end
|
514 | 514 | end
|
515 | 515 | end
|
| 516 | + |
| 517 | + describe 'recursive_call' do |
| 518 | + before :each do |
| 519 | + subject.send(:recursive_call, properties, 'test', nested_params) |
| 520 | + end |
| 521 | + |
| 522 | + let(:properties) { {} } |
| 523 | + |
| 524 | + context 'when nested params is an array' do |
| 525 | + let(:nested_params) do |
| 526 | + [ |
| 527 | + { |
| 528 | + in: 'body', |
| 529 | + name: 'aliases', |
| 530 | + description: 'The aliases of test.', |
| 531 | + type: 'array', |
| 532 | + items: { type: 'string' }, |
| 533 | + required: true |
| 534 | + } |
| 535 | + ] |
| 536 | + end |
| 537 | + |
| 538 | + let(:expected_properties) do |
| 539 | + { |
| 540 | + type: 'array', |
| 541 | + items: { |
| 542 | + type: 'object', |
| 543 | + properties: { |
| 544 | + aliases: { |
| 545 | + type: 'string', |
| 546 | + description: 'The aliases of test.' |
| 547 | + } |
| 548 | + }, |
| 549 | + required: [:aliases] |
| 550 | + } |
| 551 | + } |
| 552 | + end |
| 553 | + |
| 554 | + it 'adds property as symbol with array type and items' do |
| 555 | + expect(properties[:test]).to eq expected_properties |
| 556 | + end |
| 557 | + end |
| 558 | + |
| 559 | + context 'when nested params is not an array' do |
| 560 | + let(:nested_params) do |
| 561 | + [ |
| 562 | + { |
| 563 | + in: 'body', |
| 564 | + name: 'id', |
| 565 | + description: 'The unique ID of test.', |
| 566 | + type: 'string', |
| 567 | + required: true |
| 568 | + } |
| 569 | + ] |
| 570 | + end |
| 571 | + |
| 572 | + let(:expected_properties) do |
| 573 | + { |
| 574 | + type: 'object', |
| 575 | + required: [:id], |
| 576 | + properties: { |
| 577 | + id: { |
| 578 | + type: 'string', |
| 579 | + description: 'The unique ID of test.' |
| 580 | + } |
| 581 | + } |
| 582 | + } |
| 583 | + end |
| 584 | + |
| 585 | + it 'adds property as symbol with object type' do |
| 586 | + expect(properties[:test]).to eq expected_properties |
| 587 | + end |
| 588 | + end |
| 589 | + end |
| 590 | + |
| 591 | + describe 'add_properties_to_definition' do |
| 592 | + before :each do |
| 593 | + subject.send(:add_properties_to_definition, definition, properties, []) |
| 594 | + end |
| 595 | + |
| 596 | + context 'when definition has items key' do |
| 597 | + let(:definition) do |
| 598 | + { |
| 599 | + type: 'array', |
| 600 | + items: { |
| 601 | + type: 'object', |
| 602 | + properties: { |
| 603 | + description: 'Test description' |
| 604 | + } |
| 605 | + } |
| 606 | + } |
| 607 | + end |
| 608 | + |
| 609 | + let(:properties) do |
| 610 | + { |
| 611 | + strings: { |
| 612 | + type: 'string', |
| 613 | + description: 'string elements' |
| 614 | + } |
| 615 | + } |
| 616 | + end |
| 617 | + |
| 618 | + let(:expected_definition) do |
| 619 | + { |
| 620 | + type: 'array', |
| 621 | + items: { |
| 622 | + type: 'object', |
| 623 | + properties: { |
| 624 | + description: 'Test description', |
| 625 | + strings: { |
| 626 | + type: 'string', |
| 627 | + description: 'string elements' |
| 628 | + } |
| 629 | + } |
| 630 | + } |
| 631 | + } |
| 632 | + end |
| 633 | + |
| 634 | + it 'deep merges properties into definition item properties' do |
| 635 | + expect(definition).to eq expected_definition |
| 636 | + end |
| 637 | + end |
| 638 | + |
| 639 | + context 'when definition does not have items key' do |
| 640 | + let(:definition) do |
| 641 | + { |
| 642 | + type: 'object', |
| 643 | + properties: { |
| 644 | + parent: { |
| 645 | + type: 'object', |
| 646 | + description: 'Parent to child' |
| 647 | + } |
| 648 | + } |
| 649 | + } |
| 650 | + end |
| 651 | + |
| 652 | + let(:properties) do |
| 653 | + { |
| 654 | + parent: { |
| 655 | + type: 'object', |
| 656 | + properties: { |
| 657 | + id: { |
| 658 | + type: 'string', |
| 659 | + description: 'Parent ID' |
| 660 | + } |
| 661 | + }, |
| 662 | + required: [:id] |
| 663 | + } |
| 664 | + } |
| 665 | + end |
| 666 | + |
| 667 | + let(:expected_definition) do |
| 668 | + { |
| 669 | + type: 'object', |
| 670 | + properties: { |
| 671 | + parent: { |
| 672 | + type: 'object', |
| 673 | + description: 'Parent to child', |
| 674 | + properties: { |
| 675 | + id: { |
| 676 | + type: 'string', |
| 677 | + description: 'Parent ID' |
| 678 | + } |
| 679 | + }, |
| 680 | + required: [:id] |
| 681 | + } |
| 682 | + } |
| 683 | + } |
| 684 | + end |
| 685 | + |
| 686 | + it 'deep merges properties into definition properties' do |
| 687 | + expect(definition).to eq expected_definition |
| 688 | + end |
| 689 | + end |
| 690 | + end |
516 | 691 | end
|
517 | 692 | end
|
0 commit comments