|
| 1 | +// https://github.com/swagger-api/swagger-js/issues/1116 |
| 2 | +import { buildRequest } from '../../../src/execute'; |
| 3 | + |
| 4 | +describe('buildRequest - OAS 3.0.x', () => { |
| 5 | + describe('test accept header', () => { |
| 6 | + const spec = { |
| 7 | + openapi: '3.0.0', |
| 8 | + servers: [ |
| 9 | + { |
| 10 | + url: 'https://test.com/v1', |
| 11 | + }, |
| 12 | + ], |
| 13 | + paths: { |
| 14 | + '/getMultiple': { |
| 15 | + get: { |
| 16 | + operationId: 'getMultiple', |
| 17 | + responses: { |
| 18 | + 200: { |
| 19 | + content: { |
| 20 | + 'application/xml': { |
| 21 | + schema: { |
| 22 | + type: 'array', |
| 23 | + items: 'string', |
| 24 | + }, |
| 25 | + }, |
| 26 | + 'application/json': { |
| 27 | + schema: { |
| 28 | + type: 'array', |
| 29 | + items: 'string', |
| 30 | + }, |
| 31 | + }, |
| 32 | + }, |
| 33 | + }, |
| 34 | + default: { |
| 35 | + description: 'Unexpected error', |
| 36 | + content: { |
| 37 | + 'application/json': { |
| 38 | + schema: { |
| 39 | + type: 'array', |
| 40 | + items: 'string', |
| 41 | + }, |
| 42 | + }, |
| 43 | + }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + }, |
| 49 | + }; |
| 50 | + |
| 51 | + test('should generate accept header according to defined responses', () => { |
| 52 | + const req = buildRequest({ |
| 53 | + spec, |
| 54 | + operationId: 'getMultiple', |
| 55 | + }); |
| 56 | + |
| 57 | + expect(req).toEqual({ |
| 58 | + url: 'https://test.com/v1/getMultiple', |
| 59 | + method: 'GET', |
| 60 | + credentials: 'same-origin', |
| 61 | + headers: { |
| 62 | + accept: 'application/xml, application/json', |
| 63 | + }, |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + test('should allow to override accept header according to defined responses', () => { |
| 68 | + const req = buildRequest({ |
| 69 | + spec, |
| 70 | + operationId: 'getMultiple', |
| 71 | + responseContentType: 'application/xml', |
| 72 | + }); |
| 73 | + |
| 74 | + expect(req).toEqual({ |
| 75 | + url: 'https://test.com/v1/getMultiple', |
| 76 | + method: 'GET', |
| 77 | + credentials: 'same-origin', |
| 78 | + headers: { |
| 79 | + accept: 'application/xml', |
| 80 | + }, |
| 81 | + }); |
| 82 | + }); |
| 83 | + }); |
| 84 | +}); |
0 commit comments