Skip to content

Commit 8761a8f

Browse files
committed
Replace js-yaml with yaml
Switch YAML parsing from `js-yaml` to `yaml`. Update the resolver to use `YAML.parse` when `JSON.parse` fails. Remove `js-yaml` and its types, add `yaml` as a runtime dependency. No public API changes. Signed-off-by: Sora Morimoto <sora@morimoto.io>
1 parent 6b93844 commit 8761a8f

File tree

4 files changed

+25
-36
lines changed

4 files changed

+25
-36
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"swagger-typescript-api": patch
3+
---
4+
5+
Replace `js-yaml` with `yaml`
6+
7+
Switch YAML parsing from `js-yaml` to `yaml`. Update the resolver to
8+
use `YAML.parse` when `JSON.parse` fails. Remove `js-yaml` and its types,
9+
add `yaml` as a runtime dependency. No public API changes.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,20 @@
5555
"citty": "^0.1.6",
5656
"consola": "^3.4.2",
5757
"eta": "^4.0.1",
58-
"js-yaml": "^4.1.0",
5958
"lodash": "^4.17.21",
6059
"nanoid": "^5.1.5",
6160
"openapi-types": "^12.1.3",
6261
"swagger-schema-official": "2.0.0-bab6bed",
6362
"swagger2openapi": "^7.0.8",
64-
"typescript": "~5.9.2"
63+
"typescript": "~5.9.2",
64+
"yaml": "^2.8.1"
6565
},
6666
"devDependencies": {
6767
"@biomejs/biome": "2.2.4",
6868
"@changesets/changelog-github": "0.5.1",
6969
"@changesets/cli": "2.29.7",
7070
"@tsconfig/node20": "20.1.6",
7171
"@tsconfig/strictest": "2.0.5",
72-
"@types/js-yaml": "4.0.9",
7372
"@types/node": "24.5.2",
7473
"@types/swagger2openapi": "7.0.4",
7574
"axios": "1.12.2",

src/swagger-schema-resolver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { consola } from "consola";
2-
import * as yaml from "js-yaml";
32
import lodash from "lodash";
43
import type { OpenAPI, OpenAPIV2 } from "openapi-types";
54
import * as swagger2openapi from "swagger2openapi";
5+
import * as YAML from "yaml";
66
import type { CodeGenConfig } from "./configuration.js";
77
import type { FileSystem } from "./util/file-system.js";
88
import { Request } from "./util/request.js";
@@ -114,8 +114,8 @@ export class SwaggerSchemaResolver {
114114

115115
try {
116116
return JSON.parse(file);
117-
} catch (e) {
118-
return yaml.load(file);
117+
} catch {
118+
return YAML.parse(file);
119119
}
120120
}
121121

yarn.lock

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,13 +1196,6 @@ __metadata:
11961196
languageName: node
11971197
linkType: hard
11981198

1199-
"@types/js-yaml@npm:4.0.9":
1200-
version: 4.0.9
1201-
resolution: "@types/js-yaml@npm:4.0.9"
1202-
checksum: 10c0/24de857aa8d61526bbfbbaa383aa538283ad17363fcd5bb5148e2c7f604547db36646440e739d78241ed008702a8920665d1add5618687b6743858fae00da211
1203-
languageName: node
1204-
linkType: hard
1205-
12061199
"@types/lodash@npm:^4.17.20":
12071200
version: 4.17.20
12081201
resolution: "@types/lodash@npm:4.17.20"
@@ -2531,17 +2524,6 @@ __metadata:
25312524
languageName: node
25322525
linkType: hard
25332526

2534-
"js-yaml@npm:^4.1.0":
2535-
version: 4.1.0
2536-
resolution: "js-yaml@npm:4.1.0"
2537-
dependencies:
2538-
argparse: "npm:^2.0.1"
2539-
bin:
2540-
js-yaml: bin/js-yaml.js
2541-
checksum: 10c0/184a24b4eaacfce40ad9074c64fd42ac83cf74d8c8cd137718d456ced75051229e5061b8633c3366b8aada17945a7a356b337828c19da92b51ae62126575018f
2542-
languageName: node
2543-
linkType: hard
2544-
25452527
"jsesc@npm:^3.0.2":
25462528
version: 3.1.0
25472529
resolution: "jsesc@npm:3.1.0"
@@ -3296,15 +3278,15 @@ __metadata:
32963278
linkType: hard
32973279

32983280
"rolldown-plugin-dts@npm:^0.16.5":
3299-
version: 0.16.5
3300-
resolution: "rolldown-plugin-dts@npm:0.16.5"
3281+
version: 0.16.6
3282+
resolution: "rolldown-plugin-dts@npm:0.16.6"
33013283
dependencies:
33023284
"@babel/generator": "npm:^7.28.3"
33033285
"@babel/parser": "npm:^7.28.4"
33043286
"@babel/types": "npm:^7.28.4"
33053287
ast-kit: "npm:^2.1.2"
33063288
birpc: "npm:^2.5.0"
3307-
debug: "npm:^4.4.1"
3289+
debug: "npm:^4.4.3"
33083290
dts-resolver: "npm:^2.1.2"
33093291
get-tsconfig: "npm:^4.10.1"
33103292
magic-string: "npm:^0.30.19"
@@ -3323,7 +3305,7 @@ __metadata:
33233305
optional: true
33243306
vue-tsc:
33253307
optional: true
3326-
checksum: 10c0/f15ba5ef752cb56db9289d71d62f371a06a04159d266efd7d19f7ff4a961730f4a2367f4f80d59322fbf6d2f3d5c7b36a2f3412c36e2cc49101976f5720939c8
3308+
checksum: 10c0/e13005cc3e70f99755ec176ceed5657b20fa8872e66943a9d7284a371d7536adff9513192273910e95ca149bcc6921987e01f0970f85b848b5eb48f29e0c0965
33273309
languageName: node
33283310
linkType: hard
33293311

@@ -3728,7 +3710,6 @@ __metadata:
37283710
"@changesets/cli": "npm:2.29.7"
37293711
"@tsconfig/node20": "npm:20.1.6"
37303712
"@tsconfig/strictest": "npm:2.0.5"
3731-
"@types/js-yaml": "npm:4.0.9"
37323713
"@types/lodash": "npm:^4.17.20"
37333714
"@types/node": "npm:24.5.2"
37343715
"@types/swagger-schema-official": "npm:^2.0.25"
@@ -3738,7 +3719,6 @@ __metadata:
37383719
citty: "npm:^0.1.6"
37393720
consola: "npm:^3.4.2"
37403721
eta: "npm:^4.0.1"
3741-
js-yaml: "npm:^4.1.0"
37423722
lodash: "npm:^4.17.21"
37433723
nanoid: "npm:^5.1.5"
37443724
openapi-types: "npm:^12.1.3"
@@ -3748,6 +3728,7 @@ __metadata:
37483728
typedoc: "npm:0.28.13"
37493729
typescript: "npm:~5.9.2"
37503730
vitest: "npm:3.2.4"
3731+
yaml: "npm:^2.8.1"
37513732
bin:
37523733
sta: ./dist/cli.js
37533734
swagger-typescript-api: ./dist/cli.js
@@ -3844,9 +3825,9 @@ __metadata:
38443825
linkType: hard
38453826

38463827
"tinyspy@npm:^4.0.3":
3847-
version: 4.0.3
3848-
resolution: "tinyspy@npm:4.0.3"
3849-
checksum: 10c0/0a92a18b5350945cc8a1da3a22c9ad9f4e2945df80aaa0c43e1b3a3cfb64d8501e607ebf0305e048e3c3d3e0e7f8eb10cea27dc17c21effb73e66c4a3be36373
3828+
version: 4.0.4
3829+
resolution: "tinyspy@npm:4.0.4"
3830+
checksum: 10c0/a8020fc17799251e06a8398dcc352601d2770aa91c556b9531ecd7a12581161fd1c14e81cbdaff0c1306c93bfdde8ff6d1c1a3f9bbe6d91604f0fd4e01e2f1eb
38503831
languageName: node
38513832
linkType: hard
38523833

@@ -4027,8 +4008,8 @@ __metadata:
40274008
linkType: hard
40284009

40294010
"vite@npm:^5.0.0 || ^6.0.0 || ^7.0.0-0":
4030-
version: 7.1.5
4031-
resolution: "vite@npm:7.1.5"
4011+
version: 7.1.6
4012+
resolution: "vite@npm:7.1.6"
40324013
dependencies:
40334014
esbuild: "npm:^0.25.0"
40344015
fdir: "npm:^6.5.0"
@@ -4077,7 +4058,7 @@ __metadata:
40774058
optional: true
40784059
bin:
40794060
vite: bin/vite.js
4080-
checksum: 10c0/782d2f20c25541b26d1fb39bef5f194149caff39dc25b7836e25f049ca919f2e2ce186bddb21f3f20f6195354b3579ec637a8ca08d65b117f8b6f81e3e730a9c
4061+
checksum: 10c0/2cd8baec0054956dae61289dd1497109c762cfc27ec6f6b88f39a15d5ddc7e0cc4559b72fbdd701b296c739d2f734d051c28e365539462fb92f83b5e7908f9de
40814062
languageName: node
40824063
linkType: hard
40834064

0 commit comments

Comments
 (0)