How to import API response schemas into testing env for validation (avoiding having to duplicate parts of schema)

Hi Postman community!

I have recently started using postman for our API documentation + testing and am learning about the various functionality it offers… something I’d love to do but can’t seem to figure out whether it’s possible, is to extract part of the API schema into a variable in a pre-request script. The reason I’d like to do this is that for testing generally I want to test that the response matches a schema, but I don’t want to have to duplicate parts of the API schema in the different tests across collections. To have 2 sets of response schemas defined for each endpoint (one in the API schema, another in each test area) feels icky, would like to keep redundancy to a minimum. One thing I’ve noticed is that the responses are validated against the API schema already, which is kind of what I’m looking to do, but there’s no way of turning this validation into a test that I can run?

Any advice on how I can meet my testing reqs one way or another would be highly appreciated.

Many thanks!


I’d recommend taking a look at the Postman contract test generator I made below. It sounds like it might do everything you’re trying to do already.

P.S. I’m giving talk at the Galaxy Conference on this next week, 2/4 if you’re interested. It saves an incredible amount of time and provides coverage impossible to achieve manually.

1 Like