Invalid response schema validation - missing details

I have imported a swagger schema with which I want to validate my requests. Everything works very well. However, I am missing detailed information when the validation fails with The response body didn’t match the specified schema, which is not very helpful.

My idea was to perform an AJV validation in the post-response to get detailed errors. Is there a way to access the imported schema in this context? Or do I only have the option to redefine the schema at this point?

const body = pm.response.json();
const collectionPageSchema = pm.getCurrentResponseSchemaOrSomething(); ????


const collectionPageSchema = pm.api.definition.paths[...] ???

pm.test("Is valid JSON:API", function () {
        ajv.validate(collectionPageSchema, body),

Hi @tantchen81. Welcome to the Postman Community!

The schema defined within the API builder is not programmatically available in Postman scripts. You’ll have to store that schema as a variable or in the package library and validate it using Ajv. Additionally, turning on request validation compares your response against the schema and gives you appropriate warnings on what may be wrong.

Tanks for reply @gbadebo-bello,

ok this was my fear. Of course the request validation is already on but not very helpful to debug the body schema.

Ah, I see. You’d have to store the schema separately to use it for a custom validation in your test scripts.

No, my hope was to get the schema programmatically from the already imported API builder an make a custom validation in a test-script. But it seems the solution is to repeat the schema in the test-script again.

This is no approach for me. Never repeat yourself in coding :wink:

Hi @tantchen81. I totally understand this.

Would you mind raising this as a feature request here so we can look into some possibilities? I’d really appreciate you doing that.