# Is it possible to have a shared Ajv schema?

**URL:** <https://community.postman.com/t/is-it-possible-to-have-a-shared-ajv-schema/7275>\
**Category:** Help Hub\
**Tags:** tests, ajv, shared-code\
**Created:** [August 20, 2019, 9:58pm UTC](https://community.postman.com/t/is-it-possible-to-have-a-shared-ajv-schema/7275 "2019-08-20T21:58:25Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![jshea](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jshea](https://community.postman.com/u/jshea)\
**Post date:** [August 29, 2019, 6:27pm UTC](https://community.postman.com/t/is-it-possible-to-have-a-shared-ajv-schema/7275/5 "2019-08-29T18:27:26Z")

</div>

That did it! I had a brain cramp on needing to parse the string back into an object.

For others that may read this Topic (ajv info in the documentation is lacking!):  
This was an invaluable resource for learning JSON Schema [https://json-schema.org/understanding-json-schema/](https://json-schema.org/understanding-json-schema/)  
You can run/test ajv and your schema at the command line with ajv-cli [https://www.npmjs.com/package/ajv-cli](https://www.npmjs.com/package/ajv-cli)  
I saved my schema to a file and a sample data file as well. This let me debug the schema much faster than in Postman  
I saved the schema as a collection variable and used this incantation in the Postman test

```
// Get the JSON schema from the collection variables
var Ajv = require('ajv'),
  ajv = new Ajv({allErrors: true, verbose: true}),
  schema = JSON.parse(pm.variables.get("ttSchema"));

// Test the payload against the JSON Schema
pm.test('Schema is valid', function() {
  let validationResult = ajv.validate(schema, pm.response.json());

  if (!validationResult) {
    console.log('ajv.errors');
    console.log(ajv.errors);
  }

  pm.expect(validationResult).to.be.true;
});

```

I used console.log() to see the errors. This isn’t an optimal way to get the errors. Better would be to get them to display in the Response/Test Results but I haven’t figured out how to do so.

---

_[View the full topic](https://community.postman.com/t/is-it-possible-to-have-a-shared-ajv-schema/7275)._
