Test run schema validation from API

Hello,

I have created a test collection from an API specification that got created through a swagger import. Now when I perform one of those calls, postman clearly states issues if the request or response does not adhere to the API specification (json bodies).
However is there a way to have the tests on this call fail depending on this API validation? I know there is a manual way to add a test through pm.response.to.have.jsonSchema by specifying a schema myself, but that seems rather tedious and error-prone to keep that up to date with the API spec and seems like double work since postman already performs the validation. Or does this ‘to.have.jsonSchema’ support a way to link to the relevant json object in my API specification directly?

Cheers.

1 Like

Allan Helton wrote something to generate tests bases on a Postman collection.,

It scans the collections in the Postman online workspace. If the collection is not there, it will not work.
Not sure if that is what you are looking for.

While that does look like an interesting project, it does not seem the ideal solution for the use case to for example combine the api validation with other tests in the postman collection.
Ideally, I could write the following test:
pm.test(“Validate schema”, () => {
pm.response.to.have.jsonSchema(schema);
});
Where ‘schema’ is referencing an openapi spec object instead of me having to define/copy the spec into a postman variable. Furthermore, a similar test could occur for the request body of the test.

1 Like

thanks for the awesome information.

I have the exact same requirement

1 Like

Hi @arne.vandeginste and @tom-redfern-swift, did you manage to find a solution for this? It would definitely spare me a lot of coding.
Thanks in advance!