fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at feat/skip-token 255 lines 5.3 kB view raw
1import { Logger } from '@hey-api/codegen-core'; 2 3import type { AnyConfig } from '../../config/shared'; 4import { Context } from '../../ir/context'; 5import { parseOpenApiSpec } from '..'; 6import { type OpenApiV3_0_X, parseV3_0_X } from '../3.0.x'; 7import { type OpenApiV3_1_X, parseV3_1_X } from '../3.1.x'; 8 9vi.mock('../3.0.x', () => ({ 10 parseV3_0_X: vi.fn(), 11})); 12vi.mock('../3.1.x', () => ({ 13 parseV3_1_X: vi.fn(), 14})); 15vi.mock('../../utils/config', () => { 16 const config: Partial<AnyConfig> = { 17 logs: { 18 file: false, 19 level: 'silent', 20 path: '', 21 }, 22 pluginOrder: [], 23 }; 24 return { 25 getConfig: () => config, 26 }; 27}); 28 29describe('OpenAPI parser', () => { 30 afterEach(() => { 31 vi.restoreAllMocks(); 32 }); 33 34 it('handles OpenAPI 3.0.0', () => { 35 const spec: OpenApiV3_0_X = { 36 info: { 37 title: '', 38 version: '1', 39 }, 40 openapi: '3.0.0', 41 paths: {}, 42 }; 43 const context = new Context({ 44 config: { 45 input: [], 46 logs: {}, 47 // @ts-expect-error 48 output: { 49 case: undefined, 50 entryFile: false, 51 path: '', 52 }, 53 // @ts-expect-error 54 parser: {}, 55 pluginOrder: [], 56 plugins: {}, 57 }, 58 dependencies: {}, 59 logger: new Logger(), 60 spec, 61 }); 62 parseOpenApiSpec(context); 63 expect(parseV3_0_X).toHaveBeenCalled(); 64 }); 65 66 it('handles OpenAPI 3.0.1', () => { 67 const spec: OpenApiV3_0_X = { 68 info: { 69 title: '', 70 version: '1', 71 }, 72 openapi: '3.0.1', 73 paths: {}, 74 }; 75 const context = new Context({ 76 config: { 77 input: [], 78 logs: {}, 79 // @ts-expect-error 80 output: { 81 case: undefined, 82 entryFile: false, 83 path: '', 84 }, 85 // @ts-expect-error 86 parser: {}, 87 pluginOrder: [], 88 plugins: {}, 89 }, 90 dependencies: {}, 91 logger: new Logger(), 92 spec, 93 }); 94 parseOpenApiSpec(context); 95 expect(parseV3_0_X).toHaveBeenCalled(); 96 }); 97 98 it('handles OpenAPI 3.0.2', () => { 99 const spec: OpenApiV3_0_X = { 100 info: { 101 title: '', 102 version: '1', 103 }, 104 openapi: '3.0.2', 105 paths: {}, 106 }; 107 const context = new Context({ 108 config: { 109 input: [], 110 logs: {}, 111 // @ts-expect-error 112 output: { 113 case: undefined, 114 entryFile: false, 115 path: '', 116 }, 117 // @ts-expect-error 118 parser: {}, 119 pluginOrder: [], 120 plugins: {}, 121 }, 122 dependencies: {}, 123 logger: new Logger(), 124 spec, 125 }); 126 parseOpenApiSpec(context); 127 expect(parseV3_0_X).toHaveBeenCalled(); 128 }); 129 130 it('handles OpenAPI 3.0.3', () => { 131 const spec: OpenApiV3_0_X = { 132 info: { 133 title: '', 134 version: '1', 135 }, 136 openapi: '3.0.3', 137 paths: {}, 138 }; 139 const context = new Context({ 140 config: { 141 input: [], 142 logs: {}, 143 // @ts-expect-error 144 output: { 145 case: undefined, 146 entryFile: false, 147 path: '', 148 }, 149 // @ts-expect-error 150 parser: {}, 151 pluginOrder: [], 152 plugins: {}, 153 }, 154 dependencies: {}, 155 logger: new Logger(), 156 spec, 157 }); 158 parseOpenApiSpec(context); 159 expect(parseV3_0_X).toHaveBeenCalled(); 160 }); 161 162 it('handles OpenAPI 3.0.4', () => { 163 const spec: OpenApiV3_0_X = { 164 info: { 165 title: '', 166 version: '1', 167 }, 168 openapi: '3.0.4', 169 paths: {}, 170 }; 171 const context = new Context({ 172 config: { 173 input: [], 174 logs: {}, 175 // @ts-expect-error 176 output: { 177 case: undefined, 178 entryFile: false, 179 path: '', 180 }, 181 // @ts-expect-error 182 parser: {}, 183 pluginOrder: [], 184 plugins: {}, 185 }, 186 dependencies: {}, 187 logger: new Logger(), 188 spec, 189 }); 190 parseOpenApiSpec(context); 191 expect(parseV3_0_X).toHaveBeenCalled(); 192 }); 193 194 it('handles OpenAPI 3.1.0', () => { 195 const spec: OpenApiV3_1_X = { 196 info: { 197 title: '', 198 version: '1', 199 }, 200 openapi: '3.1.0', 201 }; 202 const context = new Context({ 203 config: { 204 input: [], 205 logs: {}, 206 // @ts-expect-error 207 output: { 208 case: undefined, 209 entryFile: false, 210 path: '', 211 }, 212 // @ts-expect-error 213 parser: {}, 214 pluginOrder: [], 215 plugins: {}, 216 }, 217 dependencies: {}, 218 logger: new Logger(), 219 spec, 220 }); 221 parseOpenApiSpec(context); 222 expect(parseV3_1_X).toHaveBeenCalled(); 223 }); 224 225 it('handles OpenAPI 3.1.1', () => { 226 const spec: OpenApiV3_1_X = { 227 info: { 228 title: '', 229 version: '1', 230 }, 231 openapi: '3.1.1', 232 }; 233 const context = new Context({ 234 config: { 235 input: [], 236 logs: {}, 237 // @ts-expect-error 238 output: { 239 case: undefined, 240 entryFile: false, 241 path: '', 242 }, 243 // @ts-expect-error 244 parser: {}, 245 pluginOrder: [], 246 plugins: {}, 247 }, 248 dependencies: {}, 249 logger: new Logger(), 250 spec, 251 }); 252 parseOpenApiSpec(context); 253 expect(parseV3_1_X).toHaveBeenCalled(); 254 }); 255});