# Test run schema validation from API

**URL:** <https://community.postman.com/t/test-run-schema-validation-from-api/20977>\
**Category:** Help Hub\
**Tags:** tests, api\
**Created:** [March 3, 2021, 5:03pm UTC](https://community.postman.com/t/test-run-schema-validation-from-api/20977 "2021-03-03T17:03:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![arne.vandeginste](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@arne.vandeginste](https://community.postman.com/u/arne.vandeginste)\
**Post date:** [March 3, 2021, 5:03pm UTC](https://community.postman.com/t/test-run-schema-validation-from-api/20977/1 "2021-03-03T17:03:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![networkinss](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/networkinss/32/6587_2.png) [@networkinss](https://community.postman.com/u/networkinss)\
**Post date:** [March 4, 2021, 9:48pm UTC](https://community.postman.com/t/test-run-schema-validation-from-api/20977/2 "2021-03-04T21:48:20Z")

</div>

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

> **[allenheltondev/postman-contract-test-generator](https://github.com/allenheltondev/postman-contract-test-generator)**
>
> Postman collection and environment that will take an Open API Spec, validate component adherence, generate contract tests, and execute them.

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.

---

<div class="post-metadata">

**Author:** ![arne.vandeginste](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@arne.vandeginste](https://community.postman.com/u/arne.vandeginste)\
**Post date:** [March 4, 2021, 11:23pm UTC](https://community.postman.com/t/test-run-schema-validation-from-api/20977/3 "2021-03-04T23:23:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jackyjoy123](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jackyjoy123](https://community.postman.com/u/jackyjoy123)\
**Post date:** [October 9, 2021, 11:45am UTC](https://community.postman.com/t/test-run-schema-validation-from-api/20977/4 "2021-10-09T11:45:25Z")

</div>

thanks for the awesome information.

---

<div class="post-metadata">

**Author:** ![tom-redfern-swift](https://avatars.discourse-cdn.com/v4/letter/t/85e7bf/32.png) [@tom-redfern-swift](https://community.postman.com/u/tom-redfern-swift)\
**Post date:** [February 3, 2023, 3:01pm UTC](https://community.postman.com/t/test-run-schema-validation-from-api/20977/5 "2023-02-03T15:01:28Z")

</div>

I have the exact same requirement

---

<div class="post-metadata">

**Author:** ![lucapittino](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@lucapittino](https://community.postman.com/u/lucapittino)\
**Post date:** [April 9, 2024, 3:01pm UTC](https://community.postman.com/t/test-run-schema-validation-from-api/20977/6 "2024-04-09T15:01:29Z")

</div>

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!
