Skip to main content

Function: addSchemaToEvent()

addSchemaToEvent(directory): (id, schema, version?) => Promise<void>

Defined in: events.ts:290

Add a schema to an event by it's id.

Optionally specify a version to add a schema to a specific version of the event.

Parameters

ParameterType
directorystring

Returns

Function

Parameters

ParameterType
idstring
schema{ fileName: string; schema: string; }
schema.fileNamestring
schema.schema?string
version?string

Returns

Promise<void>

Example

import utils from '@eventcatalog/utils';

const { addFileToEvent } = utils('/path/to/eventcatalog');

// JSON schema example
const schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "number"
}
},
"required": ["name", "age"]
};

// adds a file to the latest InventoryAdjusted event
await addFileToEvent('InventoryAdjusted', { schema, fileName: 'schema.json' });

// adds a file to a specific version of the InventoryAdjusted event
await addFileToEvent('InventoryAdjusted', { schema, fileName: 'schema.json' }, '0.0.1');