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.

Merge pull request #2667 from hey-api/fix/openapi-3-1-2

fix(parser): bump support for openapi 3.1.2

authored by

Lubos and committed by
GitHub
956ffe1b 1512832e

+39 -39
+5
.changeset/gorgeous-spiders-build.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix(parser): bump support for OpenAPI 3.1.2
+3 -3
packages/openapi-ts-tests/main/test/openapi-ts.config.ts
··· 34 34 // }, 35 35 path: path.resolve( 36 36 getSpecsPath(), 37 - '3.0.x', 38 - 'circular.yaml', 37 + '3.1.x', 38 + // 'circular.yaml', 39 39 // 'invalid', 40 40 // 'openai.yaml', 41 - // 'full.yaml', 41 + 'full.yaml', 42 42 // 'opencode.yaml', 43 43 // 'sdk-instance.yaml', 44 44 // 'string-with-format.yaml',
+4 -1
packages/openapi-ts/src/config/utils/package.ts
··· 27 27 ) => boolean; 28 28 }; 29 29 30 + export const satisfies: typeof semver.satisfies = (...args) => 31 + semver.satisfies(...args); 32 + 30 33 export const packageFactory = ( 31 34 dependencies: Record<string, string>, 32 35 ): Package => ({ ··· 47 50 typeof nameOrVersion === 'string' 48 51 ? dependencies[nameOrVersion] 49 52 : nameOrVersion; 50 - return version ? semver.satisfies(version, range, optionsOrLoose) : false; 53 + return version ? satisfies(version, range, optionsOrLoose) : false; 51 54 }, 52 55 });
+1 -1
packages/openapi-ts/src/openApi/3.1.x/types/spec.d.ts
··· 25 25 /** 26 26 * **REQUIRED**. This string MUST be the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#versions version number} of the OpenAPI Specification that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling to interpret the OpenAPI document. This is _not_ related to the API {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoVersion `info.version`} string. 27 27 */ 28 - openapi: '3.1.0' | '3.1.1'; 28 + openapi: '3.1.0' | '3.1.1' | '3.1.2'; 29 29 /** 30 30 * The available paths and operations for the API. 31 31 */
+9 -14
packages/openapi-ts/src/openApi/index.ts
··· 1 + import { satisfies } from '../config/utils/package'; 1 2 import { IRContext } from '../ir/context'; 2 3 import type { IR } from '../ir/types'; 3 4 import type { Config } from '../types/config'; ··· 85 86 return context; 86 87 } 87 88 88 - switch (context.spec.openapi) { 89 - case '3.0.0': 90 - case '3.0.1': 91 - case '3.0.2': 92 - case '3.0.3': 93 - case '3.0.4': 94 - parseV3_0_X(context as IR.Context<OpenApi.V3_0_X>); 95 - return context; 96 - case '3.1.0': 97 - case '3.1.1': 98 - parseV3_1_X(context as IR.Context<OpenApi.V3_1_X>); 99 - return context; 100 - default: 101 - break; 89 + if (satisfies(context.spec.openapi, '>=3.0.0 <3.1.0')) { 90 + parseV3_0_X(context as IR.Context<OpenApi.V3_0_X>); 91 + return context; 92 + } 93 + 94 + if (satisfies(context.spec.openapi, '>=3.1.0')) { 95 + parseV3_1_X(context as IR.Context<OpenApi.V3_1_X>); 96 + return context; 102 97 } 103 98 104 99 throw new Error('Unsupported OpenAPI specification');
+17 -20
packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts
··· 1 + import { satisfies } from '../../../config/utils/package'; 1 2 import type { IR } from '../../../ir/types'; 2 3 import type { OpenApiV2_0_XTypes } from '../../../openApi/2.0.x'; 3 4 import type { OpenApiV3_0_XTypes } from '../../../openApi/3.0.x'; ··· 461 462 return; 462 463 } 463 464 464 - switch (plugin.context.spec.openapi) { 465 - case '3.0.0': 466 - case '3.0.1': 467 - case '3.0.2': 468 - case '3.0.3': 469 - case '3.0.4': 470 - schemasV3_0_X({ 471 - context: plugin.context as IR.Context<OpenApi.V3_0_X>, 472 - plugin, 473 - }); 474 - break; 475 - case '3.1.0': 476 - case '3.1.1': 477 - schemasV3_1_X({ 478 - context: plugin.context as IR.Context<OpenApi.V3_1_X>, 479 - plugin, 480 - }); 481 - break; 482 - default: 483 - throw new Error('Unsupported OpenAPI specification'); 465 + if (satisfies(plugin.context.spec.openapi, '>=3.0.0 <3.1.0')) { 466 + schemasV3_0_X({ 467 + context: plugin.context as IR.Context<OpenApi.V3_0_X>, 468 + plugin, 469 + }); 470 + return; 484 471 } 472 + 473 + if (satisfies(plugin.context.spec.openapi, '>=3.1.0')) { 474 + schemasV3_1_X({ 475 + context: plugin.context as IR.Context<OpenApi.V3_1_X>, 476 + plugin, 477 + }); 478 + return; 479 + } 480 + 481 + throw new Error('Unsupported OpenAPI specification'); 485 482 };