fork of hey-api/openapi-ts because I need some additional things
at feat/skip-token 43 lines 1.3 kB view raw
1import path from 'node:path'; 2 3import { getResolvedInput } from '../index'; 4 5describe('getResolvedInput', () => { 6 it('handles url', async () => { 7 const pathOrUrlOrSchema = 'https://foo.com'; 8 const resolvedInput = await getResolvedInput({ pathOrUrlOrSchema }); 9 expect(resolvedInput.type).toBe('url'); 10 expect(resolvedInput.schema).toBeUndefined(); 11 expect(resolvedInput.path).toBe('https://foo.com/'); 12 }); 13 14 it('handles file', async () => { 15 const pathOrUrlOrSchema = './path/to/openapi.json'; 16 const resolvedInput = await getResolvedInput({ pathOrUrlOrSchema }); 17 expect(resolvedInput.type).toBe('file'); 18 expect(resolvedInput.schema).toBeUndefined(); 19 expect(path.normalize(resolvedInput.path).toLowerCase()).toBe( 20 path.normalize(path.resolve('./path/to/openapi.json')).toLowerCase(), 21 ); 22 }); 23 24 it('handles raw spec', async () => { 25 const pathOrUrlOrSchema = { 26 info: { 27 version: '1.0.0', 28 }, 29 openapi: '3.1.0', 30 paths: {}, 31 }; 32 const resolvedInput = await getResolvedInput({ pathOrUrlOrSchema }); 33 expect(resolvedInput.type).toBe('json'); 34 expect(resolvedInput.schema).toEqual({ 35 info: { 36 version: '1.0.0', 37 }, 38 openapi: '3.1.0', 39 paths: {}, 40 }); 41 expect(resolvedInput.path).toBe(''); 42 }); 43});