swagger.json のルーティングをCLIで確認する

goaを使ってAPIのデザインをしているときに、ルーティングの確認がしたくなる。

ikawahaさんの、goa tips : swagger-ui を使って手っ取り早く API を試す - 押してダメならふて寝しろ にあるように、swagger-ui用のルーティングを使うことで確認ができるのだが、正直もんにょりする。

という話を会社で話していたところ、後輩がCLIのツールを作ってくれた。

GitHub - decafe09/swrt

swagger.json をパースして、ルーティングを表示してくれる。

$ curl -s http://petstore.swagger.io/v2/swagger.json > swagger.json
$ swrt
http://petstore.swagger.io/v2
   PUT  /pet
  POST  /pet
   GET  /pet/findByStatus
   GET  /pet/findByTags
   GET  /pet/{petId}
  POST  /pet/{petId}
DELETE  /pet/{petId}
  POST  /pet/{petId}/uploadImage
   GET  /store/inventory
  POST  /store/order
   GET  /store/order/{orderId}
DELETE  /store/order/{orderId}
  POST  /user
  POST  /user/createWithArray
  POST  /user/createWithList
   GET  /user/login
   GET  /user/logout
   GET  /user/{username}
   PUT  /user/{username}
DELETE  /user/{username}

さっと確認したいときはこれで十分。便利。

jsonをPIPEで受け取れた方が楽かなぁと思ったので、そのうちプルリクしよう。