Skip to main content
New project sponsor 🪝Hookdeck: Serverless infrastructure for event-driven architecture. Learn more.

addSchemaToEvent

Callable

  • addSchemaToEvent(directory: string): (id: string, schema: { fileName: string; schema: string }, version?: string) => Promise<void>

  • 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.

    @example
    import utils from '@eventcatalog/utils';

    const { addSchemaToEvent } = 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 schema to the latest InventoryAdjusted event
    await addSchemaToEvent('InventoryAdjusted', { schema, fileName: 'schema.json' });

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