Open kapoorrohit opened 1 year ago
Any update on this ?
A single request can return only one response. So All response to be returned
is not applicable.
The mock server documentation states:
if multiple response bodies are specified for an operation (i.e. different status codes) the first response body is used by default, however this can be controlled by using operationsAndResponses
- link
Using operationsAndResponses you can create an expectation to return a specific response. This way you could create multiple expectations each with a different response. However each request will still get only one response, so you still have to figure out what you want to achieve.
I have a similar scenario where I use the OpenAPI Specification to create mocks. https://www.mock-server.com/mock_server/using_openapi.html. Using the operationsAndResponses argument I am creating two mocks for the same operation ID but for different status codes for example operation-id is getPetByID and the status code is 200 & 400. But when I hit the endpoint to get the response from Mockserver for the 200 status code it returns a response either from 400 or 200 which is matched first. My question is how should I create mock data for these two status codes for a single operation ID so that Mockserver can return response 200 when the request is valid and 400 when the request is invalid.
var mockServerClient = require('mockserver-client').mockServerClient; mockServerClient("localhost", 1080).openAPIExpectation({ "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json", "operationsAndResponses": { "showPetById": "200" } }).then( function () { console.log("expectation created"); }, function (error) { console.log(error); } );
mockServerClient("localhost", 1080).openAPIExpectation({ "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json", "operationsAndResponses": { "showPetById": "400" } }).then( function () { console.log("expectation created"); }, function (error) { console.log(error); } );
Describe the issue Open API spec has responses like 200, 401, 500. But when I create expectations from this Open API, it only returns first response for every operation.
MockServer version 5.15.0
Expected behaviour All responses to be returned