Skip to content

Commit 3ecb620

Browse files
authored
fix: remove type assertion, use type guard (#534)
1 parent eb6a668 commit 3ecb620

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/utils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,17 @@ export function nodeType(obj: any): SchemaObjectType | undefined {
6767
/** Return OpenAPI version from definition */
6868
export function swaggerVersion(definition: OpenAPI2 | OpenAPI3): 2 | 3 {
6969
// OpenAPI 3
70-
const { openapi } = definition as OpenAPI3;
71-
if (openapi && parseInt(openapi, 10) === 3) {
72-
return 3;
70+
if ("openapi" in definition) {
71+
if (parseInt(definition.openapi, 10) === 3) {
72+
return 3;
73+
}
7374
}
7475

7576
// OpenAPI 2
76-
const { swagger } = definition as OpenAPI2;
77-
if (swagger && parseInt(swagger, 10) === 2) {
78-
return 2;
77+
if ("swagger" in definition) {
78+
if (parseInt(definition.swagger, 10) === 2) {
79+
return 2;
80+
}
7981
}
8082

8183
throw new Error(

0 commit comments

Comments
 (0)