# Invalid response schema validation - missing details

**URL:** <https://community.postman.com/t/invalid-response-schema-validation-missing-details/62029>\
**Category:** Help Hub\
**Tags:** schemavalidation\
**Created:** [June 10, 2024, 12:07pm UTC](https://community.postman.com/t/invalid-response-schema-validation-missing-details/62029 "2024-06-10T12:07:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tantchen81](https://avatars.discourse-cdn.com/v4/letter/t/e8c25b/32.png) [@tantchen81](https://community.postman.com/u/tantchen81)\
**Post date:** [June 10, 2024, 12:07pm UTC](https://community.postman.com/t/invalid-response-schema-validation-missing-details/62029/1 "2024-06-10T12:07:50Z")

</div>

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?

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

or

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

pm.test("Is valid JSON:API", function () {
    pm.expect(
        ajv.validate(collectionPageSchema, body),
        ajv.errorsText(ajv.errors)
    ).to.be.true;
});

```

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [June 10, 2024, 1:36pm UTC](https://community.postman.com/t/invalid-response-schema-validation-missing-details/62029/2 "2024-06-10T13:36:44Z")

</div>

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](https://learning.postman.com/docs/designing-and-developing-your-api/developing-an-api/validating-elements-against-schema/#enabling-request-validation) compares your response against the schema and gives you appropriate warnings on what may be wrong.

---

<div class="post-metadata">

**Author:** ![tantchen81](https://avatars.discourse-cdn.com/v4/letter/t/e8c25b/32.png) [@tantchen81](https://community.postman.com/u/tantchen81)\
**Post date:** [June 10, 2024, 2:09pm UTC](https://community.postman.com/t/invalid-response-schema-validation-missing-details/62029/3 "2024-06-10T14:09:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [June 10, 2024, 2:26pm UTC](https://community.postman.com/t/invalid-response-schema-validation-missing-details/62029/4 "2024-06-10T14:26:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tantchen81](https://avatars.discourse-cdn.com/v4/letter/t/e8c25b/32.png) [@tantchen81](https://community.postman.com/u/tantchen81)\
**Post date:** [June 10, 2024, 2:44pm UTC](https://community.postman.com/t/invalid-response-schema-validation-missing-details/62029/5 "2024-06-10T14:44:55Z")

</div>

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 😉

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [June 16, 2024, 3:59pm UTC](https://community.postman.com/t/invalid-response-schema-validation-missing-details/62029/6 "2024-06-16T15:59:44Z")

</div>

Hi @tantchen81. I totally understand this.

Would you mind raising this as a feature request [here](https://github.com/postmanlabs/postman-app-support/issues/new/choose) so we can look into some possibilities? I’d really appreciate you doing that.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [July 16, 2024, 3:59pm UTC](https://community.postman.com/t/invalid-response-schema-validation-missing-details/62029/7 "2024-07-16T15:59:47Z")

</div>

Closed on July 16, 2024, 3:59pm UTC

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