LoginSignup
1
1

More than 5 years have passed since last update.

IPythonとbravadoでOpenAPI (Swagger) をテストする

Last updated at Posted at 2019-02-28

Swagger UI でぽちぽちやるタスクを IPython と bravado で行うととても便利。

補完を効かせる

__getattr__ で作られる属性の補完のために __dir__ が用意されているけど、2段階目の時点ではさらに __dir__ でたどってくれるわけではないので、 client を作成した直後に実体化しておくと良い。

for tag in dir(client): 
    setattr(client, tag, getattr(client, tag))

これで operationId まで補完されるようになる。

Base URL を変える

プログラム上で変えたい時は swagger_spec でアクセスする。

client.swagger_spec.api_url = "http://..."

後から API Token を設定する

client.swagger_spec.http_client に設定する。

client.swagger_spec.http_client.set_api_key(
    'api.yourhost.com', 'token',
    param_name='api_key', param_in='header'
)

Jupyter notebook

編集して一気に再実行できたりできる。Markdown を含めてテストケースを共有できたりもする。

autoreload と一緒に使う

よく使う共通の流れをファイルにして保存しておく。

1
1
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
1
1