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 5 years have passed since last update.

API Gateway でエクスポートした Swagger の json を差分比較しようとしたら、なぜかパラメーター順序が違うので比較しにくい

Posted at

標題の通りなのだが、例えば API Gateway で本番環境へ設定をデプロイする際、万全を期すため現行の本番ステージと開発ステージでどこが異なるかを事前に確認したい場合には、各ステージの API 設定を Swagger ファイル(json)にエクスポートして差分を見ることで詳細に知ることができる。

だが、json 書き出しライブラリが原因か分からないが、全然関係ない箇所でパラメーターの順序が異なることがたまにあり、単純な差分比較ができない状況になることがある。

そこで jq コマンド を使って、以下のように正規化することで比較しやすくなる。リリース直前に何度か同じ状況に陥り、その度にあわてるので、自分用メモとしてここに残して置く。

jq --sort-keys . swagger_dev.json > swagger_dev_normalized.json
jq --sort-keys . swagger_prod.json > swagger_prod_normalized.json

vimdiff swagger_{dev,prod}_normalized.json

そんなに使用頻度が高いわけではないが alias normalize_json='jq --sort-keys .' としておけば、もう少しあわてないですむかもしれない。

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?