Composability

With Rivet composability, you are able to reuse fundamental pieces of your contracts, such as data types, to make them much more maintainable. We do this by leveraging CommonJS modules and compiling your contracts to JSON.

Composing with shared types

JSON Schema has a limited number of data types that it supports. For example, string, number, boolean. However, you can build custom data type validation using the pattern key in JSON schema.

Custom Data Types

You can create custom data types to share between your contracts. If you need them on multiple applications, consider using an npm module.

Custom animal data type:

// types/animal.js
module.exports = {
  id: 'types.animal',
  type: 'string',
  pattern: 'cat|dog'
};

Usage:

// example.contract.js
const animal = require('./types/animal');

module.exports = {
  title: 'Example',
  type: 'object',
  properties: {
    pet: animal,
  },
  required: ['pet']
};

Rivet default types

Rivet ships with a few pre-defined data types.

Default Types

Below are the pre-defined types and their definitions.

email

Example Matches:

phone

Example Matches:

jwt

Example Matches:

uri

Example Matches:

uuid

Example Matches:

Last updated

Was this helpful?