How to route to a response example in spec #111
Prism says it can "Act as a mock server, routing incoming requests to example responses, ...".
I'm unable to get this functionality from using the petstore spec (locally):
@morgs32 can you paste the command that you are using here? Also, run 'prism version' and let me know what the output is.
Also, example isn't a valid key in the swagger specs, but examples is valid. You should change your examples too something like this:
The way you have your examples defined the response body that is mocked back by prism will be:
I assume you want to mock back just:
What version of prism are you using? If you are using 0.6.x then you can't control which example get's mocked back.
If you are using 2.0.0-beta.7, then you will need to create a prism instance, easiest way to do that is use our new stoplight platform. Here is an example of a prism instance that we set up, it is mocking back a todo api, and you can control the examples by adding a query string parameter __example=idofexample.
You can download prism 2.0.0-beta.7 here: https://github.com/stoplightio/prism/tree/2.x
And you can run a prism instance from the command line by using this command:
prism serve exportURLForInstance
For the Todo Instance above it would be:
This starts a server on localhost:4010, you can change the port prism starts on with: -p 4011.
You can copy the prism instance json to a project in stoplight, and replace the spec that is being mocked back by changing the spec in the prism instance config. Just update the API that prism is pointing to.
I am currently traveling for the holidays, and about to board my flight. I will set up an example on how to do that in the prism project above. But if you are feeling brave, you need to add a after rule for validation to your prism instance configuration.
Here is a scenario that does validation
I just added validation to the todos prism instance, Prism will add a header Sl-Valid to the response. If validation passes it will equal to true, otherwise it will be the errors from validation.
@kliyes Added some new abilities to the mock server, you can read about them here: