|
1 | 1 | import xmock from 'xmock'; |
| 2 | +import cloneDeep from 'lodash/cloneDeep'; |
2 | 3 |
|
3 | 4 | import Swagger from '../src/index'; |
4 | 5 |
|
@@ -710,4 +711,107 @@ describe('constructor', () => { |
710 | 711 | .catch(cb); |
711 | 712 | }); |
712 | 713 | }); |
| 714 | + |
| 715 | + describe('skipNormalization', () => { |
| 716 | + const spec = { |
| 717 | + openapi: '3.0.0', |
| 718 | + info: { |
| 719 | + title: 'Cloudpotato - Medwork', |
| 720 | + description: 'The Cloudpotato API', |
| 721 | + version: '1.0.3', |
| 722 | + contact: {}, |
| 723 | + }, |
| 724 | + tags: [], |
| 725 | + servers: [], |
| 726 | + paths: { |
| 727 | + '/v1/clients/{id}/groups': { |
| 728 | + get: { |
| 729 | + operationId: 'getGroups', |
| 730 | + summary: '', |
| 731 | + parameters: [ |
| 732 | + { |
| 733 | + name: 'options', |
| 734 | + required: false, |
| 735 | + in: 'query', |
| 736 | + schema: { |
| 737 | + type: 'string', |
| 738 | + }, |
| 739 | + }, |
| 740 | + { |
| 741 | + name: 'id', |
| 742 | + required: true, |
| 743 | + in: 'path', |
| 744 | + schema: { |
| 745 | + type: 'number', |
| 746 | + }, |
| 747 | + }, |
| 748 | + ], |
| 749 | + responses: { |
| 750 | + 200: { |
| 751 | + description: '', |
| 752 | + }, |
| 753 | + }, |
| 754 | + tags: ['clients'], |
| 755 | + security: [ |
| 756 | + { |
| 757 | + bearer: [], |
| 758 | + }, |
| 759 | + ], |
| 760 | + }, |
| 761 | + }, |
| 762 | + '/v1/groups': { |
| 763 | + get: { |
| 764 | + operationId: 'getGroups', |
| 765 | + summary: '', |
| 766 | + parameters: [], |
| 767 | + responses: { |
| 768 | + 200: { |
| 769 | + description: '', |
| 770 | + }, |
| 771 | + }, |
| 772 | + tags: ['groups'], |
| 773 | + security: [ |
| 774 | + { |
| 775 | + bearer: [], |
| 776 | + }, |
| 777 | + ], |
| 778 | + }, |
| 779 | + }, |
| 780 | + }, |
| 781 | + }; |
| 782 | + |
| 783 | + /** |
| 784 | + * We're deep-cloning the spec before using it as resolution mutates |
| 785 | + * the original object. |
| 786 | + */ |
| 787 | + |
| 788 | + describe('skipNormalization', () => { |
| 789 | + describe('given skipNormalization option not provided', () => { |
| 790 | + test('should resolve with normalized interfaces', async () => { |
| 791 | + const client = await new Swagger({ spec: cloneDeep(spec) }); |
| 792 | + |
| 793 | + expect(client.apis.clients.getGroups1).toBeInstanceOf(Function); |
| 794 | + expect(client.apis.groups.getGroups2).toBeInstanceOf(Function); |
| 795 | + }); |
| 796 | + }); |
| 797 | + |
| 798 | + describe('given skipNormalization option provided as `false`', () => { |
| 799 | + test('should resolve with normalized interfaces', async () => { |
| 800 | + const client = await new Swagger({ spec: cloneDeep(spec), skipNormalization: false }); |
| 801 | + |
| 802 | + expect(client.apis.clients.getGroups1).toBeInstanceOf(Function); |
| 803 | + expect(client.apis.groups.getGroups2).toBeInstanceOf(Function); |
| 804 | + }); |
| 805 | + }); |
| 806 | + |
| 807 | + describe('given skipNormalization option provided as `true`', () => { |
| 808 | + test('should resolve with normalized interfaces', async () => { |
| 809 | + const client = await new Swagger({ spec: cloneDeep(spec), skipNormalization: true }); |
| 810 | + |
| 811 | + expect(client.apis.clients.getGroups).toBeInstanceOf(Function); |
| 812 | + expect(client.apis.groups.getGroups).toBeInstanceOf(Function); |
| 813 | + }); |
| 814 | + }); |
| 815 | + }); |
| 816 | + }); |
713 | 817 | }); |
0 commit comments