|
1 | 1 | import path from 'node:path'; |
| 2 | +import { expect } from 'vitest'; |
| 3 | +import { OpenAPIVersion } from '../../src'; |
2 | 4 | import { Reader } from '../../src/generator/Reader'; |
3 | 5 |
|
4 | 6 | it('read local', async () => { |
5 | 7 | const reader = new Reader(); |
6 | 8 | reader.cwd = path.resolve(__dirname, '../example-json/3.0'); |
7 | | - const document = await reader.read('pet-store.json'); |
8 | | - expect(document.openapi).toBeTypeOf('string'); |
| 9 | + const migrated = await reader.read('pet-store.json'); |
| 10 | + |
| 11 | + expect(migrated).toHaveLength(2); |
| 12 | + expect(migrated[0].version).toEqual(OpenAPIVersion.V3_0); |
| 13 | + expect(migrated[1].version).toEqual(OpenAPIVersion.V3_1); |
9 | 14 | }); |
10 | 15 |
|
11 | 16 | it('read remote', async () => { |
12 | 17 | const reader = new Reader(); |
13 | | - const document = await reader.read('https://gw.alipayobjects.com/os/antfincdn/LyDMjDyIhK/1611471979478-opa.json'); |
14 | | - expect(document.openapi).toEqual('3.1.0'); |
| 18 | + const migrated = await reader.read('https://petstore31.swagger.io/api/v31/openapi.json'); |
| 19 | + |
| 20 | + expect(migrated).toHaveLength(1); |
| 21 | + expect(migrated[0].version).toEqual(OpenAPIVersion.V3_1); |
15 | 22 | }); |
16 | 23 |
|
17 | 24 | it('read object', async () => { |
18 | 25 | const reader = new Reader(); |
19 | | - const document = await reader.read({ |
| 26 | + const migrated = await reader.read({ |
20 | 27 | info: { |
21 | 28 | title: 'test', |
22 | 29 | version: '1', |
23 | 30 | }, |
24 | 31 | openapi: '3.0.0', |
25 | 32 | paths: {}, |
26 | 33 | }); |
27 | | - expect(document.openapi).toEqual('3.1.0'); |
| 34 | + |
| 35 | + expect(migrated).toHaveLength(2); |
| 36 | + expect(migrated[0].version).toEqual(OpenAPIVersion.V3_0); |
| 37 | + expect(migrated[1].version).toEqual(OpenAPIVersion.V3_1); |
28 | 38 | }); |
0 commit comments