Validate the response schema against openapi spec schema

Is there a way to validate the response schema against openapi spec schema?

Using Ajv, we can validate the response against schema like this.

var Ajv = require('ajv'),
    ajv = new Ajv({logger: console}),
    schema = {
        "properties": {
            "errors": {
                "type": "string"
            }
        }
    };

pm.test('Schema is valid', function() {
    var error = pm.response.json()['errors'];
    pm.expect(ajv.validate(schema, {errors: error})).to.be.true;
});

But instead of manually defining the schema as shown in above example, can we somehow get it from openapi spec.

Hi @spaceflight-admini11. Welcome to the Postman Community :postman:.

Currently, this is not possible in Postman. I will recommend that you make a feature request here.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.