0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

swaggerをjsonで書いて、ついでに分割して管理する

Last updated at Posted at 2021-01-09

概要

タイトルの通り。
コードが肥大するので分割して管理する。
jsonでやってますが、スクリプトの拡張子変更すればyamlでもいけるはず。

完成物

アーキテクチャ

ディレクトリ構造

root
├── docs
│   ├── paths      // 監視対象ディレクトリ
│   ├── info
│   ├── _index.json  // rootファイル
│   └── swagger.json // bundleされたファイル
└── package.json

手順

1. packageなどをインストール

$ npm i -D swagger swagger-cli chokidar chokidar-cli

2. npmスクリプト編集

"scripts": {
  "build:swagger": "swagger-cli bundle ./docs/_index.json > ./docs/swagger.json",
  "watch:swagger": "chokidar './docs/paths' -c 'npm run build:swagger'"
}

3. スクリプトを実行してファイルを監視

$ npm run watch:swagger

4. VSCで swagger.jsonSwagger Viewer で開く

swagger.json を開いて(activeにして)から、 Command + Shift + p を押下し、
OpenAPI: show preview using~ を選択する。
previewが展開されればOK。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?