Nango automatically validates your integration inputs and outputs. It also offers ways to further customize data validation in code. The guide will walk you through each approach.

Automatic validation

The validation is available during development and production and does not require any configuration from you:
  • CLI: Dry Run validation errors are logged and will halt execution when using --validation command option
  • Production: Validation errors are logged but do not halt execution

Available schema files

When you use Nango CLI, it automatically generates two schema files in the .nango folder:
  • schema.ts a TypeScript file that contains all your models
  • schema.json a JSON Schema file that is used for automatic data validation
These files can be versioned and integrated into your own codebase, ensuring consistency and reliability across different environments.

Validating integration outputs in your app

Using zod

You can use zod to validate the data you receive and send to integrations.
import * as z from 'zod';

const dataFromAPI = z.object({  
  ticketId: z.string(),
});

export default createSync({
  exec: async (nango) => {
    const response = await nango.get({ endpoint: '/tickets' });
    const isValid = dataFromAPI.parse(response.json);
    if (isValid) {
      [...]
    }
  },
});

Using schema.json in your codebase

JSON Schema is supported in most of the main software languages. Here is a non-exhaustive list of how you can directly use this file to validate the records you receive from Nango.
import { Ajv } from 'ajv';
import addFormats from 'ajv-formats';
import jsonSchema from '.nango/schema.json';

// Initiate AJV
const ajv = new Ajv({ allErrors: true, discriminator: true });
addFormats(ajv);

const modelToValidate = 'MyModelName';
const myData = {"id": "hello-word"};

// Compile the JSON schema
const validate = ajv.compile({
  ...jsonSchema,
  ...jsonSchema['definitions'][modelToValidate]
});

// Validate your data
validate(myData);

Custom validation

For more advanced use cases, you can generate your own validation schemas using the available files with the tool of your choice.
You can use the go-jsonschema golang package. This tool converts JSON Schema definitions into Golang structs. Note that some syntax is not supported by this package.
go-jsonschema -p main .nango/schema.json > test.go