prismのモックサーバはexamples定義からレスポンスを返してくれる

公開日時

prismを使うとOpenAPI仕様書を元にしたモックサーバを起動できる。

yarn add -D @stoplight/prism-cli

dオプションをつけると仕様書の型定義を元に動的にレスポンスを組み立ててくれるが、返却される内容がランダムなものになってしまうため使い所が限られる。

yarn run prism mock -d openapi.v1.yaml

Remember: you can combine code, example and dynamic parameters. By default, when the code parameter is not given, Prism will always try to fetch an example using the exampleKey from the 200 HTTP responses only. You'll need to use the code parameter alongside the example one for any specific example using a different HTTP status code than 200.

prism-cliのドキュメントに上記が書かれており、API仕様書のレスポンスにexamplesを定義しておくと、prism側で該当サンプルを返してくれる。

yarn run prism mock openapi.v1.yaml

ということでOpenAPIで仕様書を作る際はexamplesも定義するようにしておきたい。


Related #js