Skip to content

Commit 956ffe1

Browse files
authored
Merge pull request #2667 from hey-api/fix/openapi-3-1-2
fix(parser): bump support for openapi 3.1.2
2 parents 1512832 + 3511fb8 commit 956ffe1

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
fix(parser): bump support for OpenAPI 3.1.2

packages/openapi-ts-tests/main/test/openapi-ts.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ export default defineConfig(() => {
3434
// },
3535
path: path.resolve(
3636
getSpecsPath(),
37-
'3.0.x',
38-
'circular.yaml',
37+
'3.1.x',
38+
// 'circular.yaml',
3939
// 'invalid',
4040
// 'openai.yaml',
41-
// 'full.yaml',
41+
'full.yaml',
4242
// 'opencode.yaml',
4343
// 'sdk-instance.yaml',
4444
// 'string-with-format.yaml',

packages/openapi-ts/src/config/utils/package.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export type Package = {
2727
) => boolean;
2828
};
2929

30+
export const satisfies: typeof semver.satisfies = (...args) =>
31+
semver.satisfies(...args);
32+
3033
export const packageFactory = (
3134
dependencies: Record<string, string>,
3235
): Package => ({
@@ -47,6 +50,6 @@ export const packageFactory = (
4750
typeof nameOrVersion === 'string'
4851
? dependencies[nameOrVersion]
4952
: nameOrVersion;
50-
return version ? semver.satisfies(version, range, optionsOrLoose) : false;
53+
return version ? satisfies(version, range, optionsOrLoose) : false;
5154
},
5255
});

packages/openapi-ts/src/openApi/3.1.x/types/spec.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface OpenApiV3_1_X {
2525
/**
2626
* **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.
2727
*/
28-
openapi: '3.1.0' | '3.1.1';
28+
openapi: '3.1.0' | '3.1.1' | '3.1.2';
2929
/**
3030
* The available paths and operations for the API.
3131
*/

packages/openapi-ts/src/openApi/index.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { satisfies } from '../config/utils/package';
12
import { IRContext } from '../ir/context';
23
import type { IR } from '../ir/types';
34
import type { Config } from '../types/config';
@@ -85,20 +86,14 @@ export const parseOpenApiSpec = ({
8586
return context;
8687
}
8788

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;
10297
}
10398

10499
throw new Error('Unsupported OpenAPI specification');

packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { satisfies } from '../../../config/utils/package';
12
import type { IR } from '../../../ir/types';
23
import type { OpenApiV2_0_XTypes } from '../../../openApi/2.0.x';
34
import type { OpenApiV3_0_XTypes } from '../../../openApi/3.0.x';
@@ -461,25 +462,21 @@ export const handler: HeyApiSchemasPlugin['Handler'] = ({ plugin }) => {
461462
return;
462463
}
463464

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;
484471
}
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');
485482
};

0 commit comments

Comments
 (0)