Mock server validation

Hi there, is it possible to create validations in requestBody so that 200 response is not always a response.

I have created a schema, collection and now a mock server, i get a 200 response, but the issue is that I have made certain requestBody fields as required fields in my schema, but when I send a request without these fields I still get a 200 response, when i want a 400, is there a way to create this kind of validation?

I thought if i have required: true in the requestBode then it would follow suite in the mock server.

Hi @decentration

Could you check the below video and see if it helps a bit further?

More details in this article here.

Hi @decentration,

Welcome to the community! :clap:

Thats a great question. Since these are mocked responses, they are static in nature, meaning when you send a request to that endpoint, you’re going to get a static response, regardless of the request.

Mock server implementations are mostly used to get started with developing out an API in your web server, something a developer can use to know how to respond to requests.

What you’d want to do, is create a separate request, with an insufficient request body, that does not follow your schema, that will respond with a 400. Meaning, you create a new malformed request, or add an example to an existing request, that responds with a 400, given different request criteria.

Then, when you match against that request criteria, a 400 should return, and you can perform any validation there via your test script, saying you expect a 400 status code.

In general though, you since these are mocked requests, you arent going to get any dynamic validation on the mock server end, because its meant to be static. So thats why you must make a static “bad request”, so that a developer knows how a “bad request” should look like, and its associated response.

You can watch a video that I made that should help explain this, although more so with a 200 response.

Let me know if this helps!