You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When loading expectations from OpenAPI spec, for every operation mockserver only creates 1 expectation, even if there are different responses/code configured
#1806
Open
kapoorrohit opened this issue
Oct 14, 2023
· 3 comments
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
How you are running MockServer (i.e maven plugin, docker, etc) -> Java Client
Code you used to create expectations -> Expectation[] test = mockServer.upsert(
openAPIExpectation(
"file:/Users/..../openapi.yaml"
)
);
What error you saw -> Only first response returned for each operation
Expected behaviour
All responses to be returned
The text was updated successfully, but these errors were encountered:
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.
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
openAPIExpectation(
"file:/Users/..../openapi.yaml"
)
);
Expected behaviour
All responses to be returned
The text was updated successfully, but these errors were encountered: